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
2.2 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' ]] && [[ -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/
local sympa_domain=$(miaou-exec $CONTAINER -- grep ^domain /etc/sympa/sympa/sympa.conf | cut -f2)
echo sympa_domain=$sympa_domain
local sympa_authenticity_key_host=$(ssh-keygen -lF $sympa_domain | grep "^$sympa_domain ED25519" | head -1)
[[ -z $sympa_authenticity_key_host ]] &&
echo "fake additional has failed due to unknown machine: $sympa_domain. please connect once like: \`ssh $sympa_domain\` then retry" &&
exit 11
miaou-exec $CONTAINER -- bash <<EOF
ssh-keyscan -t ed25519 -H $sympa_domain >> /root/.ssh/known_hosts
EOF
local sympa_authenticity_key_container=$(miaou-exec $CONTAINER -- ssh-keygen -lF $sympa_domain | grep "^$sympa_domain ED25519" | head -1)
[[ "$sympa_authenticity_key_host" != "$sympa_authenticity_key_container" ]] &&
echo "authenticity key for machine: $sympa_domain mismatched!. please compare like: \`ssh-keygen -lF $sympa_domain\` both from host and container" &&
exit 12
miaou-recipe "$CONTAINER" "$BASEDIR"/../recipe/sympa_ldap_auth_remote.recipe
echo 'install fake additional...OK'
}
# MAIN
set -Eue
parse_options $*
"$BASEDIR"/miaou-install-sympa "$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"
install_fake_additional