scripts / upgrade /
e773abc 7 years ago
1 contributor
46 lines | 0.937kb
#!/bin/bash

set -e

# le seul paramètre accepté est le nom de la cible 
# tel que défini dans le fichier de configuration
test -n "$1"

nc=/bin/nc
wakeonlan=/usr/bin/wakeonlan
ssh=/usr/bin/ssh

conf=$HOME/.config/upgrade_hosts.conf

test -r $conf

# pour récupérer les information concernant la cible
eval $(/usr/local/bin/readconf --conf=$conf --array=user --array=identity -s $1)

test -n "$ip"
test -n "$port"
test -n "${identity[1]}"

if test -n "$lock"; then
    test -f $lock && exit
fi

alive=0

if $nc -zw2 $ip $port; then alive=1; fi

if ! $alive; then
    $wakeonlan -i $ip $mac
    sleep 10
    $nc -zw2 $ip $port
fi

# la clé publique ${identity[1]} doit contenir la commande d'upgrade
$ssh -i ${identity[1]} ${user[1]:-root}@$ip

sleep 60

# la clé publique ${identity[2]} doit contenir la commande de remise en veille
if ! $alive && test -n "${identity[2]}"; then
    $ssh -i ${identity[2]} ${user[2]:-root}@$ip
fi