X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=vm_remote;h=19ce8d4cb654f7de6d6d8ee9c94fa974dee6bda6;hb=fe76c838090f262ec477c6a73d1bf9d988033b56;hp=237f4210903af85f36d7eb847463935b31c3eacb;hpb=c6358beea0be57737b6a6980657b7b5744e51774;p=lhc%2Fateliers.git diff --git a/vm_remote b/vm_remote index 237f421..19ce8d4 100755 --- a/vm_remote +++ b/vm_remote @@ -4,62 +4,63 @@ tool=${0%/*} . "$tool"/lib/functions.sh . "$tool"/etc/vm.sh -rule_help () { +rule_help () { # SYNTAX: [--hidden] + local hidden; [ ${1:+set} ] || hidden=set cat >&2 <<-EOF - DESCRIPTION: ce script regroupe des fonctions utilitaires - pour gérer la VM _depuis_ une machine distante ; - il sert à la fois d'outil et de documentation. - Voir \`$tool/vm_host' pour les utilitaires côté machine hôte. - Voir \`$tool/vm_hosted' pour les utilitaires côté VM hébergée. + DESCRIPTION: + ce script regroupe des règles pour administrer la VM ($vm_fqdn) + _depuis_ une machine distante ; + il sert à la fois d'outil (aisément bidouillable) + et de documentation (préçise). + Voir \`$tool/vm_host' pour les règles côté machine hôte ($vm_host). + Voir \`$tool/vm_hosted' pour les règles côté VM hébergée ($vm_fqdn). SYNTAX: $0 \$RULE \${RULE}_SYNTAX RULES: - $(sed -ne 's/^rule_\([^_][^ ]*\) () {\( *#.*\|\)/\t\1\2/p' "$tool"/vm.sh "$0") + $(sed -ne "s/^rule_\(${hidden:+[^_]}[^ ]*\) () {\( *#.*\|\)/ \1\2/p" "$tool"/etc/vm.sh "$0") ENVIRONMENT: TRACE # affiche les commandes avant leur exécution - $(sed -ne 's/^readonly \([^ ][^ =]*\).*}\( *#.*\|\)$/\t$\1\2/p' "$tool"/vm.sh "$0") + $(sed -ne 's/^readonly \([^ ][^ =]*\).*}\( *#.*\|\)$/\t$\1\2/p' "$tool"/etc/vm.sh "$0") EOF } -rule_git_config () { +rule_git_config () { # DESCRIPTION: configure le .git local pour bien pousser ( cd "$tool" - git config remote.host.url >/dev/null || + git remote rm host || true git remote add host $vm_host:tool/vm - git config --replace remote.host HEAD:refs/heads/origin - git config remote.$vm.url >/dev/null || - git remote add vm root@$vm_fqdn:tool/vm - git config --replace remote.$vm HEAD:refs/heads/origin + git config --replace remote.host.push HEAD:refs/heads/origin + git remote rm hosted || true + git remote add hosted root@$vm_fqdn:tool/vm + git config --replace remote.hosted.push HEAD:refs/heads/origin ) } -rule_git_push () { # SYNTAX: {host|vm} $git_commit_options +rule_git_push () { # SYNTAX: {host|hosted} $git_push_options local remote=${1#remote=}; shift - git add . && - git commit -a -C HEAD "$@" && - GIT_SSH=./vm_ssh git push -v -f "$remote" + GIT_SSH=./vm_ssh git push -v "$remote" "$@" } rule_ssh () { "$tool"/vm_ssh $vm_fqdn "$@" } rule__ssh_known_hosts_update () { - "$tool"/vm_ssh $vm_fqdn "$@" \ + rule ssh \ -o StrictHostKeyChecking=no \ -o CheckHostIP=no \ -o HashKnownHosts=no \ whoami } -rule_disk_key_send () { +rule_key_disk_send () { gpg --decrypt var/lib/luks/$vm_fqdn.key.gpg | "$tool"/vm_ssh root@$vm_fqdn "$@" \ -o CheckHostIP=no \ -o HostKeyAlias=init.$vm_fqdn \ tee /lib/cryptsetup/passfifo \>/dev/null } -rule_disk_key_backup () { +rule_key_disk_backup () { for part in root var home do mkdir -p var/lib/luks - rule_ssh -l root ' \ + rule ssh -l root ' \ tmp=$(mktemp) cryptsetup luksHeaderBackup \ /dev/$vm_lvm_vg/${vm_lvm_lv}_${part} \ @@ -77,9 +78,8 @@ ${1+shift} case $rule in (help);; (*) - test ! "$(hostname --fqdn)" = "$vm_fqdn" - test ! "$(hostname --fqdn)" = "$vm_host" - set "${TRACE:+-x}" + assert 'test ! "$(hostname --fqdn)" = "$vm_fqdn"' vm_fqdn + assert 'test ! "$(hostname --fqdn)" = "$vm_host"' vm_host ;; esac -rule_$rule "$@" +rule $rule "$@"