forked from AlexanderSilvaB/Mari
-
Notifications
You must be signed in to change notification settings - Fork 2
/
sync
executable file
·148 lines (133 loc) · 3.59 KB
/
sync
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
if [ "$#" -lt 1 ]; then
echo "Invalid number of arguments"
echo "Usage: ./sync robot-hostname"
exit
fi
robot=$1
toolchain="rinobot-robot"
sudo=false
ssh=false
root=false
services=false
home=true
restart=false
build=false
configure=false
uninstall=false
clear=false
pwd="nao"
user="nao"
nextIsPwd=false
nextIsUser=false
ct=0
for i in "$@" ; do
if [ $nextIsPwd == true ] ; then
pwd=$i
nextIsPwd=false
elif [ $nextIsUser == true ] ; then
user=$i
nextIsUser=false
elif [[ $i == "--pwd" ]] ; then
nextIsPwd=true
elif [[ $i == "--user" ]] ; then
nextIsUser=true
elif [[ $i == "--sudo" ]] ; then
sudo=true
elif [[ $i == "--clear" ]] ; then
clear=true
elif [[ $i == "--ssh" ]] ; then
ssh=true
elif [[ $i == "--root" ]] ; then
root=true
elif [[ $i == "--services" ]] ; then
services=true
elif [[ $i == "--not-home" ]] ; then
home=false
elif [[ $i == "--restart" ]] ; then
restart=true
elif [[ $i == "--build" ]] ; then
build=true
elif [[ $i == "--uninstall" ]] ; then
uninstall=true
elif [[ $i == "--configure" ]] ; then
configure=true
elif [[ $i == "--initial" ]] ; then
configure=true
build=true
sudo=true
ssh=true
root=true
services=true
home=true
restart=true
elif [[ $i == "--all" ]] ; then
build=true
sudo=true
ssh=true
root=true
services=true
home=true
restart=true
elif [[ $ct -gt 0 ]]; then
toolchain=$i
fi
ct=$((ct+1))
done
echo "Syncing build $toolchain to $robot"
SSH_CMD="sshpass -p $pwd ssh -o StrictHostKeyChecking=no -o ControlMaster=auto -o ControlPath=/tmp/control_%l_%h_%p_%r"
if [ $clear == true ]; then
echo "Cleaning $toolchain"
rm -rf src/build-$toolchain
exit
fi
if [ $uninstall == true ]; then
echo "Uninstalling from $robot"
exit
fi
if [ $build == true ]; then
if [ $configure == true ]; then
./build $2 -configure
else
./build $2
fi
fi
if [ $ssh == true ]; then
echo "Sync keys"
rm ~/.ssh/known_hosts
if [ ! -f ~/.ssh/id_rsa ]; then
ssh-keygen -t rsa -f ~/.ssh/id_rsa -q -P ""
fi
ssh-keyscan $robot >> ~/.ssh/known_hosts
#ssh-copy-id $user@$robot
fi
if [ $sudo == true ]; then
echo "Disable sudo"
$SSH_CMD -t -l nao $robot "su -c 'tee /etc/sudoers <<< \"nao ALL=(ALL) NOPASSWD:ALL\" && chmod 0440 /etc/sudoers && chown root:root /etc/sudoers'"
fi
echo "Placing files"
cp src/build-$toolchain/sdk/bin/rinobot root/home/nao/
cp src/build-$toolchain/sdk/lib/libagent.so root/home/nao/naoqi/preferences/libagent.so
chmod +x root/home/nao/rinobot
if [ $root == true ]; then
echo "Sync root"
sshpass -p $pwd rsync -aburvP --rsync-path="sudo rsync" root/etc $user@$robot:/
fi
if [ $home == true ]; then
echo "Sync home"
sshpass -p $pwd rsync -aurvP root/home/nao/ $user@$robot:~/
fi
if [ $services == true ]; then
echo "Turning off services we do not use"
$SSH_CMD $user@$robot "sudo rc-update add connman boot"
$SSH_CMD $user@$robot "sudo rc-update del connman boot"
$SSH_CMD $user@$robot "sudo rc-update add qimessaging-json default"
$SSH_CMD $user@$robot "sudo rc-update del qimessaging-json default"
echo "Turning on services needed"
$SSH_CMD $user@$robot "sudo rc-update del ntp-client default"
$SSH_CMD $user@$robot "sudo rc-update add ntp-client default"
fi
if [ $restart == true ]; then
echo "Restart Naoqi"
$SSH_CMD $user@$robot "sudo /etc/init.d/naoqi restart"
fi