Browse Source

import_from_archive

main
pvincent 2 weeks ago
parent
commit
772fec9e82
  1. 3
      .vscode/settings.json
  2. 13
      sympa/doc/migration.md
  3. 7
      sympa/miaou/miaou-migrate-sympa-from-container
  4. 6
      sympa/resources/tools/sympa_export.bash
  5. 52
      sympa/resources/tools/sympa_import.bash
  6. 18
      sympa/resources/tools/sympa_purge.bash

3
.vscode/settings.json

@ -17,7 +17,8 @@
"**/*.mdown", "**/*.mdown",
"**/*.md", "**/*.md",
"**/sympa/miaou/*", "**/sympa/miaou/*",
"**/*.sh"
"**/*.sh",
"**/*.bash"
], ],
"bashIde.shfmt.simplifyCode": true, "bashIde.shfmt.simplifyCode": true,
"bashIde.shfmt.spaceRedirects": true, "bashIde.shfmt.spaceRedirects": true,

13
sympa/doc/migration.md

@ -66,3 +66,16 @@ To: debian13, sympa 6.2.76
* CONTAINER=listes.artcode.re * CONTAINER=listes.artcode.re
* miaou/miaou-migrate-sympa-from-container $CONTAINER * miaou/miaou-migrate-sympa-from-container $CONTAINER
# aliases
append_or_replace: /etc/postfix/main.cf
```
myhostname = <SYMPA_DOMAIN>
alias_maps = hash:/etc/aliases, hash:/etc/mail/sympa/aliases
alias_database = hash:/etc/aliases, hash:/etc/mail/sympa/aliases
```
copy:
* /etc/mail/sympa/aliases{,.db}

7
sympa/miaou/miaou-migrate-sympa-from-container

@ -83,7 +83,10 @@ function create_new_container {
pct stop $vmid pct stop $vmid
/opt/miaou-bash/tools/append_or_replace "^net0.*$" "$SYMPA_NET0\n$net1" $vm_conf_file /opt/miaou-bash/tools/append_or_replace "^net0.*$" "$SYMPA_NET0\n$net1" $vm_conf_file
pct start $vmid pct start $vmid
}
function import_from_archive {
"$BASEDIR"/miaou-install-from-import-sympa $CONTAINER $SYMPA_ARCHIVE
} }
# MAIN # MAIN
@ -96,10 +99,12 @@ export_sympa
get_container_net0 get_container_net0
stop_old_container stop_old_container
create_new_container create_new_container
import_from_archive
# 5. install sympa # 5. install sympa
# 6. import old data # 6. import old data
# 7. fix_dmarc_off + fix_dkim_global_on + fix external origin
# 7. fix_dmarc_off + fix_dkim_global_on
# 8. fix external origin
# allowed_external_origin * # allowed_external_origin *
# (https://gitlab.cemea.org/cemeaweb/khazad-dum/-/issues/110) # (https://gitlab.cemea.org/cemeaweb/khazad-dum/-/issues/110)

6
sympa/resources/tools/sympa_export.bash

@ -17,16 +17,20 @@ function export_database {
db_name=sympa db_name=sympa
db_user=sympa db_user=sympa
db_passwd=$(grep '^db_passwd' /etc/sympa/sympa/sympa.conf | cut -f2) db_passwd=$(grep '^db_passwd' /etc/sympa/sympa/sympa.conf | cut -f2)
PGPASSWORD=$db_passwd pg_dump -h localhost -U "$db_user" "$db_name" | gzip >"$temp_dir/database.psql.gz"
PGPASSWORD=$db_passwd pg_dump -h localhost -U "$db_user" "$db_name" | gzip > "$temp_dir/database.psql.gz"
} }
function export_files { function export_files {
tar -C / -cf "$temp_dir/files.tar" etc/sympa/sympa/sympa.conf tar -C / -cf "$temp_dir/files.tar" etc/sympa/sympa/sympa.conf
tar -C / -uf "$temp_dir/files.tar" etc/sympa/data_structure.version tar -C / -uf "$temp_dir/files.tar" etc/sympa/data_structure.version
tar -C / -uf "$temp_dir/files.tar" etc/sympa/auth.conf tar -C / -uf "$temp_dir/files.tar" etc/sympa/auth.conf
tar -C / -uf "$temp_dir/files.tar" etc/mail/sympa/aliases{,.db}
[[ -d /etc/dkimkeys ]] && tar -C / -uf "$temp_dir/files.tar" etc/dkimkeys/mail.{private,txt} [[ -d /etc/dkimkeys ]] && tar -C / -uf "$temp_dir/files.tar" etc/dkimkeys/mail.{private,txt}
tar -C / -uf "$temp_dir/files.tar" var/lib/sympa tar -C / -uf "$temp_dir/files.tar" var/lib/sympa
tar -C / -uf "$temp_dir/files.tar" var/spool/sympa tar -C / -uf "$temp_dir/files.tar" var/spool/sympa
gzip "$temp_dir/files.tar" gzip "$temp_dir/files.tar"
} }

52
sympa/resources/tools/sympa_import.bash

@ -8,6 +8,8 @@ DB_NAME=sympa
DB_USER="$DB_NAME" DB_USER="$DB_NAME"
DB_PASS="$DB_NAME" DB_PASS="$DB_NAME"
SYMPA_DOMAIN=''
## functions ## functions
function usage { function usage {
@ -37,8 +39,8 @@ function uncompress_export_file {
function import_database { function import_database {
echo -n "import database $DB_NAME..." echo -n "import database $DB_NAME..."
sudo -u postgres dropdb "$DB_NAME" 2>/dev/null
sudo -u postgres createdb -O "$DB_USER" "$DB_NAME" 2>/dev/null
sudo -u postgres dropdb "$DB_NAME" 2> /dev/null
sudo -u postgres createdb -O "$DB_USER" "$DB_NAME" 2> /dev/null
gunzip -c "$export_tmp"/database.psql.gz | PGPASSWORD="$DB_PASS" psql -h localhost -U "$DB_USER" "$DB_NAME" gunzip -c "$export_tmp"/database.psql.gz | PGPASSWORD="$DB_PASS" psql -h localhost -U "$DB_USER" "$DB_NAME"
echo OK echo OK
} }
@ -61,6 +63,13 @@ function import_files_etc_sympa {
replace_conf_entry_from_export wwsympa_url replace_conf_entry_from_export wwsympa_url
replace_conf_entry_from_export listmaster replace_conf_entry_from_export listmaster
replace_conf_entry_from_export lang replace_conf_entry_from_export lang
/opt/miaou-bash/tools/append_or_replace "^aliases_program.*$" "aliases_program postalias" /etc/sympa/sympa/sympa.conf
}
function import_files_etc_mail_sympa_aliases {
mv etc/mail/sympa/aliases{,.db} /etc/mail/sympa/
chown sympa:sympa /etc/mail/sympa/aliases{,.db}
} }
function import_files_etc_dkimkeys { function import_files_etc_dkimkeys {
@ -86,8 +95,11 @@ function import_files {
cd "$files_temp" cd "$files_temp"
tar -xf "$export_tmp/files.tar.gz" tar -xf "$export_tmp/files.tar.gz"
import_files_etc_sympa import_files_etc_sympa
import_files_etc_mail_sympa_aliases
[[ -d etc/dkimkeys ]] && import_files_etc_dkimkeys [[ -d etc/dkimkeys ]] && import_files_etc_dkimkeys
import_files_lib import_files_lib
import_files_spool import_files_spool
@ -96,7 +108,7 @@ function import_files {
function import_certbot { function import_certbot {
local sympa_domain=$(grep '^domain' /etc/sympa/sympa/sympa.conf | cut -f2)
SYMPA_DOMAIN=$(grep '^domain' /etc/sympa/sympa/sympa.conf | cut -f2)
if [[ -f "$export_tmp/certbot.tar" ]]; then if [[ -f "$export_tmp/certbot.tar" ]]; then
echo -n "import certbot..." echo -n "import certbot..."
@ -107,7 +119,7 @@ function import_certbot {
# add options-ssl-nginx.conf # add options-ssl-nginx.conf
if [[ ! -f /etc/letsencrypt/options-ssl-nginx.conf ]]; then if [[ ! -f /etc/letsencrypt/options-ssl-nginx.conf ]]; then
tee /etc/letsencrypt/options-ssl-nginx.conf <<EOF
tee /etc/letsencrypt/options-ssl-nginx.conf << EOF
# This file contains important security parameters. If you modify this file # This file contains important security parameters. If you modify this file
# manually, Certbot will be unable to automatically provide future security # manually, Certbot will be unable to automatically provide future security
# updates. Instead, Certbot will print and log an error message with a path to # updates. Instead, Certbot will print and log an error message with a path to
@ -130,7 +142,7 @@ EOF
# add ssl-dhparams.pem # add ssl-dhparams.pem
if [[ ! -f /etc/letsencrypt/ssl-dhparams.pem ]]; then if [[ ! -f /etc/letsencrypt/ssl-dhparams.pem ]]; then
tee /etc/letsencrypt/ssl-dhparams.pem <<EOF
tee /etc/letsencrypt/ssl-dhparams.pem << EOF
-----BEGIN DH PARAMETERS----- -----BEGIN DH PARAMETERS-----
MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz
+8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a +8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a
@ -147,7 +159,7 @@ EOF
# change nginx # change nginx
if ! grep -Pq '^\s+listen 443' /etc/nginx/sites-enabled/sympa.conf; then if ! grep -Pq '^\s+listen 443' /etc/nginx/sites-enabled/sympa.conf; then
tee /etc/nginx/sites-available/sympa.conf <<EOF
tee /etc/nginx/sites-available/sympa.conf << EOF
server { server {
listen 80; listen 80;
server_name _; server_name _;
@ -156,10 +168,10 @@ server {
server { server {
listen 443 ssl; listen 443 ssl;
server_name $sympa_domain;
server_name $SYMPA_DOMAIN;
ssl_certificate /etc/letsencrypt/live/$sympa_domain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$sympa_domain/privkey.pem;
ssl_certificate /etc/letsencrypt/live/$SYMPA_DOMAIN/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$SYMPA_DOMAIN/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf; include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
@ -200,15 +212,17 @@ function migrate_sympa {
function stop_services { function stop_services {
echo -n "stop services..." echo -n "stop services..."
sudo systemctl stop sympa.service
sudo systemctl stop wwsympa.socket
systemctl stop sympa.service
systemctl stop wwsympa.socket
systemctl stop postfix.service
echo OK echo OK
} }
function start_services { function start_services {
echo -n "start services..." echo -n "start services..."
sudo systemctl start sympa.service
sudo systemctl start wwsympa.socket
systemctl start sympa.service
systemctl start wwsympa.socket
systemctl start postfix.service
echo OK echo OK
} }
@ -218,6 +232,14 @@ function remove_temp {
echo OK echo OK
} }
function configure_postfix {
echo "$SYMPA_DOMAIN" > /etc/mailname
/opt/miaou-bash/tools/append_or_replace "^myhostname =.*$" "myhostname = $SYMPA_DOMAIN" /etc/postfix/main.cf
/opt/miaou-bash/tools/append_or_replace "^alias_maps =.*$" "alias_maps = hash:/etc/aliases, hash:/etc/mail/sympa/aliases" /etc/postfix/main.cf
/opt/miaou-bash/tools/append_or_replace "^alias_database =.*$" "alias_database = hash:/etc/aliases, hash:/etc/mail/sympa/aliases" /etc/postfix/main.cf
}
function import { function import {
create_temp create_temp
@ -225,7 +247,9 @@ function import {
stop_services stop_services
import_database import_database
import_files import_files
import_certbot
import_certbot # SYMPA_DOMAIN got populated!
configure_postfix
start_services start_services
migrate_sympa migrate_sympa

18
sympa/resources/tools/sympa_purge.bash

@ -55,6 +55,24 @@ function purge {
fi fi
done done
# MAIL/SYMPA/ALIASES
local escaped="${SYMPA_DOMAIN//./\\.}"
local regex="-e ^## -e ^#- -e $escaped"
local to_purge=$(grep -v ${regex@E} /etc/mail/sympa/aliases)
if [[ -n $to_purge ]]; then
echo "ALIASES: useless entries"
echo '------------------------'
echo "$to_purge"
echo '------------------------'
grep ${regex@E} /etc/mail/sympa/aliases > /etc/mail/sympa/aliases
newaliases # build the `.db` version
local number_to_purge=$(echo "$to_purge" | wc -l)
echo "$number_to_purge entries removed!"
fi
} }
### MAIN ### MAIN

Loading…
Cancel
Save