scripts / upgrade /
1d0fb93 8 years ago
1 contributor
43 lines | 0.777kb
#!/bin/bash

set -e

test -n "$1"

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

conf=$HOME/.config/upgrade_hosts.conf

test -r $conf

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