-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathros-mavros-installation.sh
228 lines (202 loc) · 7.82 KB
/
ros-mavros-installation.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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
if [ -d "/var" ];
then
echo "/var directory exist."
if [ -d "/var/zenadrone" ];
then
echo "---------------------- 1: zenadrone directory exist ----------------------"
if [ -d "/var/zenadrone/mavros" ];
then
echo "---------------------- 1: mavros directory exist ----------------------"
else
mkdir -p /var/zenadrone/mavros
if [ $? -eq 0 ];
then
echo "---------------------- 2: Successfully created 'mavros' directory ----------------------"
else
echo "---------------------- 2: mkdir mavros encountered an error ----------------------"
exit 1
fi
fi
else
mkdir /var/zenadrone
if [ $? -eq 0 ];
then
echo "---------------------- 1-2: Successfully created 'zenadrone' directory ----------------------"
if [ -d "/var/zenadrone/mavros" ];
then
echo "---------------------- 1-2: mavros directory exist ----------------------"
else
mkdir -p /var/zenadrone/mavros
if [ $? -eq 0 ];
then
echo "---------------------- 2-1: Successfully created 'mavros' directory ----------------------"
else
echo "---------------------- 2-2: mkdir mavros encountered an error ----------------------"
exit 1
fi
fi
else
echo "---------------------- 2-3: mkdir zenadrone encountered an error ----------------------"
exit 1
fi
fi
else
echo "---------------------- 1: var directory not exist ----------------------"
fi
if command -v jq &>/dev/null; then
echo "---------------------- 3: Found jq ----------------------"
else
apt install jq -y
if [ $? -eq 0 ]; then
echo "---------------------- 3: Installed "jq" successfully ----------------------"
else
echo "---------------------- 3: encountered an error ----------------------"
exit 1
fi
fi
if command -v git &>/dev/null; then
echo "---------------------- 4: Found git ----------------------"
else
apt install git -y
if [ $? -eq 0 ]; then
echo "---------------------- 4: ran successfully ----------------------"
else
echo "---------------------- 4: encountered an error ----------------------"
exit 1
fi
fi
ZDIQRepoURL="https://github.com/MuhammadBilal1/ZDIQCommands.git"
ZDIQTargetPath="/var/zenadrone/ZDIQCommands"
git clone "$ZDIQRepoURL" "$ZDIQTargetPath"
if [ $? -eq 0 ]; then
cd /var/zenadrone/ZDIQCommands
git config --global --add safe.directory /var/zenadrone/ZDIQCommands
echo "---------------------- 5: Repository Cloned successfully ----------------------"
else
echo "---------------------- 5: encountered an error ----------------------"
exit 1
fi
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
if [ $? -eq 0 ]; then
echo "---------------------- 6: ran successfully ----------------------"
else
echo "---------------------- 6: encountered an error ----------------------"
fi
sudo apt install curl -y
if [ $? -eq 0 ]; then
echo "---------------------- 7: found curl ----------------------"
else
echo "---------------------- 7: encountered an error ----------------------"
fi
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
if [ $? -eq 0 ]; then
echo "---------------------- 8: ran successfully ----------------------"
else
echo "---------------------- 8: encountered an error ----------------------"
fi
sudo apt update
if [ $? -eq 0 ]; then
echo "---------------------- 9: ran successfully ----------------------"
else
echo "---------------------- 9: encountered an error ----------------------"
fi
sudo apt install ros-noetic-desktop-full -y
if [ $? -eq 0 ]; then
echo "---------------------- 10: Successfully installed ros-noetic-desktop-full ----------------------"
else
echo "---------------------- 10: encountered an error ----------------------"
fi
sudo apt install python3-rosdep -y
if [ $? -eq 0 ]; then
echo "---------------------- 11: Successfully installed python3-rosdep ----------------------"
else
echo "---------------------- 11: encountered an error ----------------------"
fi
sudo rosdep init
if [ $? -eq 0 ]; then
echo "---------------------- 12: ran successfully ----------------------"
else
echo "---------------------- 12: encountered an error ----------------------"
fi
rosdep update
if [ $? -eq 0 ]; then
echo "---------------------- 13: Successfully ran rosdep update ----------------------"
else
echo "---------------------- 13: encountered an error----------------------"
fi
sudo apt install ros-noetic-mavros ros-noetic-mavros-extras -y
if [ $? -eq 0 ]; then
echo "---------------------- 14: Successfully installed ros-noetic-mavros ros-noetic-mavros-extras ----------------------"
else
echo "---------------------- 14: encountered an error ----------------------"
fi
cd /var/zenadrone/ZDIQCommands
chmod +x ros-mavros-installation.sh
if [ $? -eq 0 ]; then
echo "---------------------- 15: ran successfully ----------------------"
else
echo "---------------------- 15: encountered an error ----------------------"
fi
sudo ./ros-mavros-installation.sh
if [ $? -eq 0 ]; then
echo "---------------------- 16: ran successfully ----------------------"
else
echo "---------------------- 16: encountered an error ----------------------"
fi
sudo mv /var/zenadrone/ZDIQCommands/geographiclib_datasets/* /usr/share/GeographicLib/
if [ $? -eq 0 ]; then
echo "---------------------- 17: ran successfully ----------------------"
else
echo "---------------------- 17: encountered an error ----------------------"
fi
source /opt/ros/noetic/setup.bash
if [ $? -eq 0 ]; then
echo "---------------------- 18: ran successfully ----------------------"
else
echo "---------------------- 18: encountered an error ----------------------"
fi
if command -v python3-pip &>/dev/null; then
echo "---------------------- 19: Found python3-pip ----------------------"
else
apt install python3-pip -y
if [ $? -eq 0 ]; then
echo "---------------------- 19-1: ran successfully ----------------------"
else
echo "---------------------- 19-1: encountered an error ----------------------"
fi
fi
ServicesPath="/var/zenadrone/ZDIQCommands"
SystemPath="/etc/systemd/system"
sudo ln -s $ServicesPath/ros-mavros.service $SystemPath/ros-mavros.service
if [ $? -eq 0 ]; then
echo "---------------------- 20: Successfully created symlink for ros-mavros.service ----------------------"
else
echo "---------------------- 20: encountered an error ----------------------"
exit 1
fi
sudo chmod u+x $SystemPath/ros-mavros.service
if [ $? -eq 0 ]; then
echo "---------------------- 21: Successfully make services executables ----------------------"
else
echo "---------------------- 21: encountered an error ----------------------"
fi
sudo systemctl daemon-reload
if [ $? -eq 0 ]; then
echo "---------------------- 22: Successfully reloaded daemon ----------------------"
else
echo "---------------------- 22: encountered an error ----------------------"
fi
sudo systemctl enable ros-mavros.service
if [ $? -eq 0 ]; then
echo "---------------------- 23: Successfully enabled services to run on startup ----------------------"
else
echo "---------------------- 23: encountered an error ----------------------"
fi
sudo systemctl start ros-mavros.service
if [ $? -eq 0 ]; then
echo "---------------------- 24: Successfully started services ----------------------"
else
echo "---------------------- 24: encountered an error ----------------------"
fi
sudo systemctl status ros-mavros.service