forked from 360disrupt/grassberry-high
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
92 lines (76 loc) · 1.92 KB
/
deploy.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
#!/bin/bash
RestartDaemon () {
echo "restarting pm2"
pm2 kill && pm2 start /home/pi/app/processes.json
}
Deploy () {
echo "stopping pm2"
pm2 stop all
#delete old version
if [ -d /home/pi/app/dist ]; then
mv /home/pi/app/dist /home/pi/app/dist.del
fi
if [ -d /home/pi/app/dist.new ]; then #from rsync
mv /home/pi/app/dist.new /home/pi/app/dist
else #err
echo "WARNING no deployment files"
exit 1
fi
}
UnzipVersion () {
path="$1"
if [[ "$path" == "" ]]; then
echo "No Unzip Path specified in script"
return 1
fi
#in case a failed installation exists
if [ -d /home/pi/app/dist.unzip/dist ]; then
rm -rf /home/pi/app/dist.unzip
fi
#create directory and unzip into
mkdir /home/pi/app/dist.unzip
tar -xzf "$path" -C /home/pi/app/dist.unzip
rm -rf "$path"
#move files from this directory into according folders
mv /home/pi/app/dist.unzip/dist /home/pi/app/dist.new
if [ -f /home/pi/app/dist.unzip/bower.json ]; then
mv /home/pi/app/dist.unzip/bower.json /home/pi/app/bower.json
fi
if [ -f /home/pi/app/dist.unzip/package.json ]; then
mv /home/pi/app/dist.unzip/package.json /home/pi/app/package.json
fi
rm -rf /home/pi/app/dist.unzip
}
InstallDependencies () {
cd /home/pi/app/ || exit 1
npm install --production --config.interactive=false
sudo -u pi bower install --config.interactive=false
}
Clean () {
#clean
rm -rf /home/pi/app/dist.del
echo "Cleaned App"
}
Main () {
echo whoami
noInstall=$1
#unzip if there is a zipped version (autodownloader)
if [ -f /home/pi/app/newVersion.tar.gz ]; then
UnzipVersion "/home/pi/app/newVersion.tar.gz"
fi
#dependencies
if [[ $noInstall != 'true' ]]; then
echo "installing dep"
InstallDependencies
fi
#deploy or restart
if [ -d /home/pi/app/dist.new ]; then
Deploy
RestartDaemon
Clean
else
echo "NOTHING to DEPLOY just restarting A"
RestartDaemon
fi
}
Main "$1"