-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
49 lines (36 loc) · 1.4 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
#!/bin/bash
cat << EndOfMessage
_____ _ _ ____ ___ _ _ ____ ____ ___ ___
|_ _| | | | _ \|_ _| \ | |/ ___| | _ \|_ _| |_ \\
| | | | | | |_) || || \| | | _ | |_) || | ) |
| | | |_| | _ < | || |\ | |_| | | _ / | | / /
|_| \___/|_| \_|___|_| \_|\____| |_| |___| |___|
EndOfMessage
if [ $# -eq 0 ]
then
echo "Must have a valid ssh <target>."
echo "./deploy.sh <target>"
exit 1
fi
# Build application and create tar
echo "Building bundle..."
[ -f ".env" ] && mv .env .env-disabled
cp .env-production .env
[ ! -d "./node_modules" ] && npm install &> deploy.install.log
npm run build &> deploy.build.log
rm ./build/index.html
mv ./build/index.asp.html ./build/index.asp
echo
# Deploy and extract
echo "Upload bundle to $1"
# credit to @srcshelton in Turing Pi Discord, tar to remote folder instead of sending the bundle
tar -cf - ./build | ssh "$1" 'tar -xvf - -C /mnt/var' &> deploy.remote.log
echo
now=$(date +%s)
echo "Backing up service to '/mnt/sdcard/www-$now.tar' and deploying turing-pi-ui"
# credit to @srcshelton in Turing Pi Discord, backup existing www directory to the sdcard
# shellcheck disable=SC2029
ssh "$1" "[ -d /mnt/var/www ] && [ -d /mnt/sdcard ] && tar cf /mnt/sdcard/www-$now.tar -C /mnt/var/ www && rm -rf /mnt/var/www && mv /mnt/var/build /mnt/var/www" &>> deploy.remote.log
echo
echo "Cleaning up..."
[ -f ".env-disabled" ] && mv .env-disabled .env