diff --git a/.vscode/settings.json b/.vscode/settings.json index 63d37e2..4fd166d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,7 +17,8 @@ "**/*.mdown", "**/*.md", "**/sympa/miaou/*", - "**/*.sh" + "**/*.sh", + "**/*.bash" ], "bashIde.shfmt.simplifyCode": true, "bashIde.shfmt.spaceRedirects": true, diff --git a/sympa/doc/migration.md b/sympa/doc/migration.md index 2158190..b75f2a1 100644 --- a/sympa/doc/migration.md +++ b/sympa/doc/migration.md @@ -66,3 +66,16 @@ To: debian13, sympa 6.2.76 * CONTAINER=listes.artcode.re * miaou/miaou-migrate-sympa-from-container $CONTAINER + +# aliases + +append_or_replace: /etc/postfix/main.cf + +``` +myhostname = +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} diff --git a/sympa/miaou/miaou-migrate-sympa-from-container b/sympa/miaou/miaou-migrate-sympa-from-container index 7499c9f..c5923e2 100755 --- a/sympa/miaou/miaou-migrate-sympa-from-container +++ b/sympa/miaou/miaou-migrate-sympa-from-container @@ -83,7 +83,10 @@ function create_new_container { pct stop $vmid /opt/miaou-bash/tools/append_or_replace "^net0.*$" "$SYMPA_NET0\n$net1" $vm_conf_file pct start $vmid +} +function import_from_archive { + "$BASEDIR"/miaou-install-from-import-sympa $CONTAINER $SYMPA_ARCHIVE } # MAIN @@ -96,10 +99,12 @@ export_sympa get_container_net0 stop_old_container create_new_container +import_from_archive # 5. install sympa # 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 * # (https://gitlab.cemea.org/cemeaweb/khazad-dum/-/issues/110) diff --git a/sympa/resources/tools/sympa_export.bash b/sympa/resources/tools/sympa_export.bash index 0a1d34d..6d57ffb 100755 --- a/sympa/resources/tools/sympa_export.bash +++ b/sympa/resources/tools/sympa_export.bash @@ -17,16 +17,20 @@ function export_database { db_name=sympa db_user=sympa 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 { 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/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} + tar -C / -uf "$temp_dir/files.tar" var/lib/sympa tar -C / -uf "$temp_dir/files.tar" var/spool/sympa + gzip "$temp_dir/files.tar" } diff --git a/sympa/resources/tools/sympa_import.bash b/sympa/resources/tools/sympa_import.bash index ecac63c..0b24af2 100755 --- a/sympa/resources/tools/sympa_import.bash +++ b/sympa/resources/tools/sympa_import.bash @@ -8,6 +8,8 @@ DB_NAME=sympa DB_USER="$DB_NAME" DB_PASS="$DB_NAME" +SYMPA_DOMAIN='' + ## functions function usage { @@ -37,8 +39,8 @@ function uncompress_export_file { function import_database { 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" echo OK } @@ -61,6 +63,13 @@ function import_files_etc_sympa { replace_conf_entry_from_export wwsympa_url replace_conf_entry_from_export listmaster 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 { @@ -86,8 +95,11 @@ function import_files { cd "$files_temp" tar -xf "$export_tmp/files.tar.gz" + import_files_etc_sympa + import_files_etc_mail_sympa_aliases [[ -d etc/dkimkeys ]] && import_files_etc_dkimkeys + import_files_lib import_files_spool @@ -96,7 +108,7 @@ function import_files { 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 echo -n "import certbot..." @@ -107,7 +119,7 @@ function import_certbot { # add options-ssl-nginx.conf if [[ ! -f /etc/letsencrypt/options-ssl-nginx.conf ]]; then - tee /etc/letsencrypt/options-ssl-nginx.conf < /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 { create_temp @@ -225,7 +247,9 @@ function import { stop_services import_database import_files - import_certbot + import_certbot # SYMPA_DOMAIN got populated! + configure_postfix + start_services migrate_sympa diff --git a/sympa/resources/tools/sympa_purge.bash b/sympa/resources/tools/sympa_purge.bash index 42b92a5..6374446 100755 --- a/sympa/resources/tools/sympa_purge.bash +++ b/sympa/resources/tools/sympa_purge.bash @@ -55,6 +55,24 @@ function purge { fi 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