This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install
executable file
·352 lines (297 loc) · 9.76 KB
/
install
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/bin/bash
# Check if user is root
if [ $(id -u) -eq 0 ];then
ERR="\033[1;31m"
NORMAL="\033[0;39m"
INFO="\033[1;34m"
WARN="\033[1;33m"
OK="\033[1;32m"
pigetLogo(){
echo -ne $OK
cat<<EOF
██████╗ ██╗ ██████╗ ███████╗████████╗
██╔══██╗██║██╔════╝ ██╔════╝╚══██╔══╝
██████╔╝██║██║ ███╗█████╗ ██║
██╔═══╝ ██║██║ ██║██╔══╝ ██║
██║ ██║╚██████╔╝███████╗ ██║
╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═╝
EOF
}
updatePi(){
echo "Update Raspberry Pi" >> /tmp/pigetInstall.log
echo -ne "$INFO -----> Update Raspberry Pi $NORMAL"
# Update packages list
echo "apt-get update" >> /tmp/pigetInstall.log
debconf-apt-progress -- apt-get -q -y update
globalError=$?
if [[ $globalError -ne 0 ]];then
echo "ERROR: Update Raspberry Pi failed" >> /tmp/pigetInstall.log
tail /var/log/pat/term.log >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] I wasn't able to update packages $NORMAL"
exit 1
fi
# Upgrade packages
echo "apt-get upgrade" >> /tmp/pigetInstall.log
debconf-apt-progress -- apt-get -q -y upgrade
globalError=$?
if [[ $globalError -ne 0 ]];then
echo "ERROR: Upgrade Raspberry Pi failed" >> /tmp/pigetInstall.log
tail /var/log/pat/term.log >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] I wasn't able to upgrade packages $NORMAL"
exit 1
fi
# Install git
echo "apt-get install git" >> /tmp/pigetInstall.log
debconf-apt-progress -- apt-get install -q -y git
globalError=$?
if [[ $globalError -ne 0 ]];then
echo "ERROR: Can't get git" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] I wasn't able to download git $NORMAL"
tail /var/log/pat/term.log >> /tmp/pigetInstall.log
exit 1
fi
# Install pip
echo "apt-get install python-pip" >> /tmp/pigetInstall.log
debconf-apt-progress -- apt-get install -q -y python-pip
globalError=$?
if [[ $globalError -ne 0 ]];then
echo "ERROR: Can't get pip" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] I wasn't able to download pip $NORMAL"
tail /var/log/pat/term.log >> /tmp/pigetInstall.log
exit 1
fi
# Install tabulate (to make markdown table)
pip install --quiet tabulate
echo -e "$OK [OK] $NORMAL"
}
checkInternet(){
echo "Check internet" >> /tmp/pigetInstall.log
echo -ne "$INFO -----> Connect to github.com $NORMAL"
ping -c1 www.github.com > /dev/null 2>&1 && internet=1 || internet=0
if [[ $internet -eq 0 ]]
then
echo "Cannot connect to github.com" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : You are not connected to the internet $NORMAL"
exit 1
else
echo -e "$OK [OK] $NORMAL"
fi
}
generateDir(){
# Create piget directory
echo "Create folders" >> /tmp/pigetInstall.log
echo -ne "$INFO -----> Create folders $NORMAL"
if [ ! -d /opt/piget ];then
echo "/opt/piget" >> /tmp/pigetInstall.log
mkdir /opt/piget
if [ $? -ne 0 ] ;then
echo "ERROR : /opt/piget wasn't created" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : /opt/piget wasn't created $NORMAL"
exit 1
fi
fi
# Create user dirs
if [ ! -d /opt/user ];then
echo "/opt/user" >> /tmp/pigetInstall.log
mkdir /opt/user
if [ $? -ne 0 ] ;then
echo "ERROR : /opt/user wasn't created" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : /opt/user wasn't created $NORMAL"
exit 1
fi
fi
# Create user config
if [ ! -d /opt/user/settings ];then
echo "/opt/user/settings" >> /tmp/pigetInstall.log
mkdir /opt/user/settings
mkdir /opt/user/settings/pi
echo "pigetnet" > /opt/user/settings/pi/repo.txt
if [ $? -ne 0 ] ;then
echo "ERROR : /opt/user/settings wasn't created" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : /opt/user/settings wasn't created $NORMAL"
exit 1
fi
fi
echo -e "$OK [OK] $NORMAL"
}
generateCore(){
echo -ne "$INFO -----> Get core $NORMAL"
if [ -d /opt/piget/core ];then
#We remove core functions if previously installed
echo "Remove /opt/piget/core" >> /tmp/pigetInstall.log
rm -rf /opt/piget/core
if [ $? -ne 0 ];then
echo "ERROR: Cannot remove /opt/piget/core" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to clone pigetnet/core $NORMAL"
exit 1
fi
fi
#Cloning core scripts repository
echo "Clone pigetnet/core to /opt/piget/core" >> /tmp/pigetInstall.log
git clone https://github.com/pigetnet/core /opt/piget/core >> /tmp/pigetInstall.log 2>&1
if [ $? -ne 0 ];then
echo "ERROR: Cannot clone pigetnet/core" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to clone pigetnet/core $NORMAL"
exit 1
else
echo -e "$OK [OK] $NORMAL"
fi
}
# Create symbolic links
createSymLink(){
echo -ne "$INFO -----> Create links $NORMAL"
#Remove previously created links
if [ -L /net ];then
echo "remove /net link" >> /tmp/pigetInstall.log
rm /net
if [ $? -ne 0 ];then
echo "ERROR: Cannot remove /net link" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to remove /net $NORMAL"
exit 1
fi
fi
if [ -L /pi ];then
echo "remove /pi link" >> /tmp/pigetInstall.log
rm /pi
if [ $? -ne 0 ];then
echo "ERROR: Cannot remove /pi link" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to remove /pi $NORMAL"
exit 1
fi
fi
if [ -L /show ];then
echo "remove /show link" >> /tmp/pigetInstall.log
rm /show
if [ $? -ne 0 ];then
echo "ERROR: Cannot remove /show link" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to remove /show $NORMAL"
exit 1
fi
fi
if [ -L /string ];then
echo "remove /string link" >> /tmp/pigetInstall.log
rm /string
if [ $? -ne 0 ];then
echo "Cannot remove /string link" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to remove /string $NORMAL"
exit 1
fi
fi
if [ -L /system ];then
echo "remove /system link" >> /tmp/pigetInstall.log
rm /system
if [ $? -ne 0 ];then
echo "ERROR: Cannot remove /system link" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to remove /system $NORMAL"
exit 1
fi
fi
if [ -L /do ];then
echo "remove /do link" >> /tmp/pigetInstall.log
rm /do
if [ $? -ne 0 ];then
echo "ERROR: Cannot remove /do link" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to remove /do $NORMAL"
exit 1
fi
fi
if [ -L /user ];then
rm /user
if [ $? -ne 0 ];then
echo "ERROR: Cannot remove /user link" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to create /user $NORMAL"
exit 1
fi
fi
#Generate links
echo "create /net link" >> /tmp/pigetInstall.log
ln -s /opt/piget/core/net /net
if [ $? -ne 0 ];then
echo "ERROR: Cannot create /net link" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to create /net $NORMAL"
exit 1
fi
echo "create /pi link" >> /tmp/pigetInstall.log
ln -s /opt/piget/core/pi /pi
if [ $? -ne 0 ];then
echo "ERROR: Cannot create /pi link" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to create /pi $NORMAL"
exit 1
fi
echo "create /show link" >> /tmp/pigetInstall.log
ln -s /opt/piget/core/show /show
if [ $? -ne 0 ];then
echo "ERROR: Cannot create /show link" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to create /show $NORMAL"
exit 1
fi
echo "create /string link" >> /tmp/pigetInstall.log
ln -s /opt/piget/core/string /string
if [ $? -ne 0 ];then
echo "ERROR: Cannot create /string link" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to create /string $NORMAL"
exit 1
fi
echo "create /system link" >> /tmp/pigetInstall.log
ln -s /opt/piget/core/system /system
if [ $? -ne 0 ];then
echo "ERROR: Cannot create /system link" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to create /system $NORMAL"
exit 1
fi
echo "create /do link" >> /tmp/pigetInstall.log
ln -s /opt/piget/ /do
if [ $? -ne 0 ];then
echo "ERROR: Cannot create /do link" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to create /do $NORMAL"
exit 1
fi
echo "create /user link" >> /tmp/pigetInstall.log
ln -s /opt/user/ /user
if [ $? -ne 0 ];then
echo "ERROR: Cannot create /user link" >> /tmp/pigetInstall.log
echo -e "$ERR [ERR] : I wasn't able to create /user $NORMAL"
exit 1
fi
echo -e "$OK [OK] $NORMAL"
}
configureTimeZone(){
echo -ne "$INFO -----> Setup timezone : $NORMAL"
#Sielnt install for tzupdate
pip install --quiet tzupdate
#Check if tzupdate for installed
if [ -f /usr/local/bin/tzupdate ];then
tzupdate > /dev/null >> /tmp/pigetInstall.log 2>&1
#Get geographic region
currentTimeZone=$(tzupdate -p|awk '{print $4}')
echo -e "$WARN : $currentTimeZone $NORMAL"
else
echo -e "$WARN [WARN] I wasn't able to setup timezone $NORMAL"
fi
}
copy_bashrc(){
cp /do/core/conf/piget_bashrc_pi /home/pi/.bashrc
cp /do/core/conf/piget_bashrc_root /root/.bashrc
}
clear
pigetLogo
echo -e "$WARN Logs will be saved at /tmp/pigetInstall.log $NORMAL"
# Start log
echo "Piget Install Log" > /tmp/pigetInstall.log
echo "-----------------" >> /tmp/pigetInstall.log
cd /
checkInternet
updatePi
generateDir
generateCore
createSymLink
configureTimeZone
copy_bashrc
echo " "
echo -e "$INFO Installation finished ! $OK"
echo -e "--------------------------------------- $NORMAL"
echo -e "Type $OK /pi/start $NORMAL to start using piget"
else
echo "You must be root to install piget"
echo "Try: curl -L piget.madnerd.org|sudo bash"
fi