-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsetup.sh
More file actions
262 lines (248 loc) · 6.99 KB
/
setup.sh
File metadata and controls
262 lines (248 loc) · 6.99 KB
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/bin/sh
function validate_url(){
if [[ `curl --insecure -L --fail -I -s $1 2>&1 | grep 'HTTP/1.1 302 Found'` ]]; then
return 0
else
return 1
fi
}
# Read inut from cmd for control
while true; do
read -p " Please choose your container runtime:
Install balenaEngine(recommend): 1
Install Docker: 2
Cancel installation: [C]ancel
" RUNTIME
case $RUNTIME in
[1] ) break;;
[2] ) break;;
[Cc]* ) exit;;
* ) echo "Please choose a valid value (1 or 2) or cancel the installation.";;
esac
done
# Read inut from cmd for control
while true; do
read -p " Do you wish to install docker-compose?
" COMPOSE
case $COMPOSE in
[Yy]* ) COMPOSE=yes; break;;
[Nn]* ) COMPOSE=no; break;;
[Cc]* ) exit;;
* ) echo "Please answer yes/no or [c]ancel the installation.";;
esac
done
### Version selection removed due to incompatiblity of new versions (systemd is required)
#while read -p "Version xx.xx.xx (let empty for default balenaEngine 18.9.7, Docker 19.03.12): " VERSION; do
# if [ $VERSION ]; then
# break;
# elif [ -z $VERSION ]; then
if [ $RUNTIME = "1" ]; then
VERSION="18.9.7"
break;
else
VERSION="19.03.8"
break;
fi
# fi
# done
# VERSION=$(echo "$VERSION" | sed 's|+|.|g')
machine=$(uname -m)
case "$machine" in
# "armv5"*)
# arch="armv5"
# ;;
# "armv6"*)
# arch="armv6"
# ;;
"armv7"*)
arch="armv7"
;;
# "armv8"*)
# arch="aarch64"
# ;;
# "aarch64"*)
# arch="aarch64"
# ;;
# "i386")
# arch="i386"
# ;;
# "i686")
# arch="i386"
# ;;
"x86_64")
arch="x86_64"
;;
*)
echo "Unknown machine type: $machine"
exit 1
esac
### Set user rights to archive
chown -R root:root ./archive
chmod -R 755 ./archive
case "$RUNTIME" in
### Install balenaEngine
1)
echo "Starting Balena installation..."
BALENA_URL="https://github.com/balena-os/balena-engine/releases/download/v${VERSION}/balena-engine-v${VERSION}-${arch}.tar.gz"
### Check for the available fitting architecture
case "$arch" in
"armv7")
if validate_url $BALENA_URL; then
# Go on when File exists!
break;
else
echo "Balena Version is not available for $arch!"
arch="armv7hf"
BALENA_URL="https://github.com/balena-os/balena-engine/releases/download/v${VERSION}/balena-engine-v${VERSION}-${arch}.tar.gz"
if validate_url $BALENA_URL; then
# Go on when File exists!
break;
else
echo "Balena Version is not available for $arch!"
arch="armhf"
BALENA_URL="https://github.com/balena-os/balena-engine/releases/download/v${VERSION}/balena-engine-v${VERSION}-${arch}.tar.gz"
if validate_url $BALENA_URL; then
# Go on when File exists!
break;
else
echo "Balena Version is not available for $arch!"
exit 1
fi
fi
fi
;;
"x86_64")
if validate_url $BALENA_URL; then
# Go on when File exists!
break;
else
echo "Balena Version is not available for $arch!"
exit 1
fi
;;
esac
### Download and unzip balenaEngine
curl --insecure -L --fail "$BALENA_URL" -o ./balena-engine-v${VERSION}-${arch}.tar.gz
tar xzv -C /usr/bin --strip-components=1 -f balena-engine-v${VERSION}-${arch}.tar.gz
rm balena-engine-v${VERSION}-${arch}.tar.gz
if [ -d /usr/bin/balena-engine ]; then
mv /usr/bin/balena-engine /usr/bin/tmp
mv /usr/bin/tmp/* /usr/bin/
rmdir /usr/bin/tmp
fi
#### Copy configs and add group
cp -a ./archive/balena/etc/. /etc/
cp -a ./archive/balena/usr/. /usr/
groupadd balena
usermod -a -G balena admin
usermod -a -G balena plcnext_firmware
### Add alias for balena-engine
echo "alias docker=\"/usr/bin/balena-engine\"" >> /opt/plcnext/.bashrc
echo "alias balena=\"/usr/bin/balena-engine\"" >> /opt/plcnext/.bashrc
update-rc.d -s balena defaults
## Install docker-compose
if [ $COMPOSE = "yes" ]; then
echo "Starting docker-compose installation for Balena..."
COMPOSE_URL="https://github.com/docker/compose/releases/download/1.29.2/run.sh"
mkdir /usr/bin
if validate_url $COMPOSE_URL; then
curl --insecure -L --fail $COMPOSE_URL -o /usr/bin/docker-compose
sed -i 's/docker.sock/balena-engine.sock/g' /usr/bin/docker-compose
sed -i 's/exec docker/exec balena-engine/g' /usr/bin/docker-compose
case "$arch" in
"armv7")
sed -i 's/docker\/compose/apptower\/docker-compose/g' /usr/bin/docker-compose
;;
"armhf")
sed -i 's/docker\/compose/apptower\/docker-compose/g' /usr/bin/docker-compose
;;
"armv7hf")
sed -i 's/docker\/compose/apptower\/docker-compose/g' /usr/bin/docker-compose
;;
esac
sed -i 's/$DOCKER_HOST:$DOCKER_HOST/$DOCKER_HOST:\/var\/run\/docker.sock/g' /usr/bin/docker-compose
chgrp balena /usr/bin/docker-compose
chmod g+x /usr/bin/docker-compose
break;
else
echo "Docker-Compose is not installed!"
fi
fi
cat <<EOF
Installation successful!
_ _
| |__ __ _| | ___ _ __ __ _
| '_ \\ / _\` | |/ _ \\ '_ \ / _\` |
| |_) | (_| | | __/ | | | (_| |
|_.__/ \__,_|_|\___|_| |_|\__,_|
the container engine for the IoT
EOF
;;
2)
echo "Starting Docker installation..."
### Download Docker
if [ $arch = "armv7" ]; then
arch="armhf"
fi
DOCKER_URL="https://download.docker.com/linux/static/stable/${arch}/docker-$VERSION.tgz"
### Check for the available fitting architecture
case "$arch" in
"armhf")
if validate_url $DOCKER_URL; then
# Go on when File exists!
break;
else
echo "Docker Version is not available for $arch!"
exit 1
fi
;;
"x86_64")
if validate_url $DOCKER_URL; then
# Go on when File exists!
break;
else
echo "Docker Version is not available for $arch!"
exit 1
fi
;;
esac
wget "$DOCKER_URL"
tar xzv -C /usr/bin --strip-components=1 -f docker-$VERSION.tgz
rm docker-$VERSION.tgz
## Copy configs and add group
cp -a ./archive/docker/etc/. /etc/
cp -a ./archive/docker/usr/. /usr/
groupadd docker
usermod -a -G docker admin
usermod -a -G docker plcnext_firmware
update-rc.d -s docker defaults
## Install docker-compose
if [ $COMPOSE = "yes" ]; then
echo "Starting docker-compose installation..."
COMPOSE_URL="https://github.com/docker/compose/releases/download/1.29.2/run.sh"
mkdir /usr/bin
if validate_url $COMPOSE_URL; then
curl --insecure -L --fail $COMPOSE_URL -o /usr/bin/docker-compose
case "$arch" in
"armv7")
sed -i 's/docker\/compose/apptower\/docker-compose/g' /usr/bin/docker-compose
;;
"armhf")
sed -i 's/docker\/compose/apptower\/docker-compose/g' /usr/bin/docker-compose
;;
"armv7hf")
sed -i 's/docker\/compose/apptower\/docker-compose/g' /usr/bin/docker-compose
;;
esac
chgrp docker /usr/bin/docker-compose
chmod g+x /usr/bin/docker-compose
break;
else
echo "Docker-Compose is not installed!"
fi
fi
cat <<EOF
Docker installation successful!
EOF
;;
esac