scripts / upgrade /
Newer Older
43 lines | 0.774kb
ajout script d'upgrade
Sébastien MARQUE authored on 2016-11-04
1
#!/bin/bash
2

            
3
set -e
4

            
5
test -n "$1"
6

            
7
nc=/bin/nc
8
wakeonlan=/usr/bin/wakeonlan
9
ssh=/usr/bin/ssh
10

            
11
conf=$HOME/.config/upgrade_hosts.conf
12

            
13
test -r $conf
14

            
15
eval $(/usr/local/bin/readconf --conf=$conf --array=user --array=identity $1)
16

            
17
test -n "$ip"
18
test -n "$port"
19
test -n "${identity[1]}"
20

            
21
if test -n "$lock"; then
22
    test -f $lock && exit
23
fi
24

            
25
alive=0
26

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

            
29
if ! $alive; then
30
    $wakeonlan -i $ip $mac
31
    sleep 10
32
    $nc -zw2 $ip $port
33
fi
34

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

            
38
sleep 60
39

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