117 lines
3.0 KiB
Plaintext
117 lines
3.0 KiB
Plaintext
|
#!/bin/bash
|
||
|
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||
|
source /etc/ulibauto || exit 1
|
||
|
|
||
|
function display_help() {
|
||
|
uecho "$scriptname: import/exporter une docker-machine
|
||
|
|
||
|
USAGE
|
||
|
$scriptname -d NAME
|
||
|
$scriptname -l ARCHIVE
|
||
|
|
||
|
OPTIONS
|
||
|
-d, --dump
|
||
|
Exporter la machine
|
||
|
-l, --load
|
||
|
Import la machine"
|
||
|
}
|
||
|
|
||
|
action=
|
||
|
args=(
|
||
|
--help '$exit_with display_help'
|
||
|
-d,--dump,-x,--export,-s,--save action=dump
|
||
|
-l,--load,-i,--import action=load
|
||
|
)
|
||
|
parse_args "$@"; set -- "${args[@]}"
|
||
|
|
||
|
if [ -z "$action" ]; then
|
||
|
case "$1" in
|
||
|
d|dump|x|export|s|save) action=dump; shift;;
|
||
|
l|load|i|import) action=load; shift;;
|
||
|
*) die "Vous devez spécifier l'action à effectuer";;
|
||
|
esac
|
||
|
fi
|
||
|
|
||
|
case "$action" in
|
||
|
dump)
|
||
|
############################################################################
|
||
|
name="$1"
|
||
|
[ -n "$name" ] || die "Vous devez spécifier le nom de la machine"
|
||
|
|
||
|
srcdir="$HOME/.docker/machine/machines/$name"
|
||
|
[ -d "$srcdir" ] || die "$name: nom de machine incorrect"
|
||
|
|
||
|
ac_set_tmpdir workdir
|
||
|
destdir="$workdir/$name"
|
||
|
|
||
|
archive="${name}-machine.tar.gz"
|
||
|
|
||
|
estep "Copie des fichiers"
|
||
|
cp -r "$srcdir" "$workdir" || die
|
||
|
for i in ca-key.pem ca.pem key.pem cert.pem; do
|
||
|
[ -f "$destdir/$i" ] || {
|
||
|
cp "$HOME/.docker/machine/certs/$i" "$destdir" || die
|
||
|
}
|
||
|
done
|
||
|
|
||
|
estep "Correction des chemins"
|
||
|
sed -i "\
|
||
|
s|$HOME/.docker/machine|DOCKER_MACHINE_HOME|g
|
||
|
s|DOCKER_MACHINE_HOME/certs/|DOCKER_MACHINE_HOME/machines/$name/|g
|
||
|
" "$destdir/config.json" || die
|
||
|
|
||
|
estep "Génération de $archive"
|
||
|
tar czf "$archive" -C "$workdir" "$name" || die
|
||
|
|
||
|
ac_clean "$workdir"
|
||
|
;;
|
||
|
|
||
|
load)
|
||
|
############################################################################
|
||
|
archive="$1"
|
||
|
[ -n "$archive" ] || die "Vous devez spécifier l'archive à importer"
|
||
|
|
||
|
setx archivename=basename -- "$archive"
|
||
|
if [[ "$archivename" == *-machine.tar.gz ]]; then
|
||
|
name="${archivename%-machine.tar.gz}"
|
||
|
else
|
||
|
die "$archive: n'est pas une archive docker-machine"
|
||
|
fi
|
||
|
|
||
|
destdir="$HOME/.docker/machine/machines"
|
||
|
machinedir="$destdir/$name"
|
||
|
origdir="$HOME/${name}-machine.orig"
|
||
|
if [ -d "$machinedir" ]; then
|
||
|
ewarn "$name: une machine du même nom existe déjà"
|
||
|
ask_yesno "Voulez-vous l'écraser?" N || die
|
||
|
|
||
|
[ -d "$origdir" ] && rm -rf "$origdir"
|
||
|
mv "$machinedir" "$origdir"
|
||
|
fi
|
||
|
|
||
|
ac_set_tmpdir workdir
|
||
|
srcdir="$workdir/$name"
|
||
|
|
||
|
estep "Extraction de l'archive"
|
||
|
tar xzf "$archive" -C "$workdir"
|
||
|
|
||
|
[ -d "$srcdir" ] || die "L'archive n'est pas pour la machine $name"
|
||
|
|
||
|
estep "Corriger les chemins"
|
||
|
sed -i "\
|
||
|
s|DOCKER_MACHINE_HOME|$HOME/.docker/machine|g
|
||
|
" "$srcdir/config.json" || die
|
||
|
|
||
|
estep "Installation de la machine"
|
||
|
mkdir -p "$destdir"
|
||
|
mv "$srcdir" "$destdir"
|
||
|
|
||
|
if [ -d "$origdir" ]; then
|
||
|
enote "Une fois que la machine aura été testée, vous pouvez supprimer ce répertoire:
|
||
|
$origdir"
|
||
|
fi
|
||
|
|
||
|
ac_clean "$workdir"
|
||
|
;;
|
||
|
esac
|