-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.sh
64 lines (52 loc) · 1.36 KB
/
runner.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh
port=22
target=$1; shift
master_key=$(cat ~/.ssh/id_rsa.pub)
SSH_OPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ConnectTimeout=5"
while getopts ":p:" opt; do
case $opt in
p)
port=$OPTARG
;;
\?)
echo "invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
shift $((OPTIND -1))
check_error () {
if [ $1 -gt 0 ]; then
echo "exit code: $1"
exit $1
fi
}
execute () {
while [ 1 ]; do
ssh $SSH_OPTS -n -t -t $target -p $port $1
exitCode=$?
if [ $exitCode -gt 0 ]; then
if [ $exitCode -eq 255 ]; then
echo "exit code: $exitCode"
sleep 3
else
echo "exit code: $exitCode"
exit $exitCode
fi
else
break
fi
done
}
scp $SSH_OPTS -P $port init.sh $target:/root/init.sh || check_error $?
execute "/bin/sh /root/init.sh"
execute "reboot"
scp $SSH_OPTS -P $port install.sh $target:/root/install.sh || check_error $?
execute "/bin/sh /root/install.sh"
execute "reboot"
execute "uname -a; zpool status"
/usr/bin/expect -c 'expect "\n" { eval spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no usr@$myhost.example.com; interact }'