You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.8 KiB

#!/usr/bin/env bash
# CONSTANTS
BASEDIR=$(dirname "$0")
CONTAINER=''
IMPORT_FILE=''
# FUNCTIONS
function usage {
echo "$(basename "$0") <CONTAINER_NAME> <BACKUP_SYMPA_FILE>"
}
function parse_options {
while [[ $# -gt 0 ]]; do
case "$1" in
--help | -h)
usage && exit 0
;;
*)
if [[ -z $CONTAINER ]]; then
CONTAINER=$1
elif [[ -z $IMPORT_FILE ]]; then
IMPORT_FILE=$1
else
echo >&2 "Unknown option: $1" && usage && exit 2
fi
;;
esac
shift 1 # Move to the next argument
done
[[ -z $CONTAINER ]] && [[ ! -f $IMPORT_FILE ]] && (usage && exit 1) || true
}
function assert_fake_sympa {
[[ $(fqdn) =~ topcode|x270 ]] && [[ -d /opt/miaou-incus ]]
}
function install_fake_additional {
assert_fake_sympa || return
echo 'install fake additional...'
miaou-push $CONTAINER $HOME/.ssh/id_ed25519 /root/.ssh/
miaou-push $CONTAINER $HOME/.ssh/id_ed25519.pub /root/.ssh/
miaou-recipe "$CONTAINER" "$BASEDIR"/../recipe/sympa_ldap_auth_remote.recipe
}
function fix_configuration_entries {
echo 'fix configuration entries...'
miaou-recipe "$CONTAINER" "$BASEDIR"/../recipe/sympa_fix_dkim_dmarc.recipe
miaou-recipe "$CONTAINER" "$BASEDIR"/../recipe/sympa_fix_external_origin.recipe
miaou-recipe "$CONTAINER" "$BASEDIR"/../recipe/sympa_fix_personalization.recipe
}
function import {
echo "copy the backup to container..."
import_base=$(basename $IMPORT_FILE)
echo "copy import file: $import_base"
miaou-push $CONTAINER $IMPORT_FILE /root/
echo "launch the import process..."
miaou-exec $CONTAINER -- /opt/miaou-sympa/tools/sympa_import.bash "/root/$import_base"
}
function install {
echo "install SYMPA to CONTAINER=$CONTAINER"
"$BASEDIR"/miaou-install-sympa "$CONTAINER"
echo "install SYMPA ...success"
}
# MAIN
set -Eue
parse_options "$@"
install
import
fix_configuration_entries
install_fake_additional