-
Notifications
You must be signed in to change notification settings - Fork 3
/
update
executable file
·82 lines (69 loc) · 3.98 KB
/
update
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
#!/bin/bash
usage() {
echo -e 'USAGE:\n\t./update [OPTION]\n'
echo -e 'OPTIONS:\n'
echo -e '\t-p, --pull-and-run-prod'
}
pullAndRun() {
echo -e "\n$(tput setaf 2)################################################################
# #
# PULL & RUN PROJECT #
# #
################################################################$(tput sgr 0)\n\n"
echo -e "$(tput setaf 2)git add .$(tput sgr 0)"
git add .
echo -e "\n\n$(tput setaf 2)git commit -m \"commit from script\"$(tput sgr 0)"
git commit -m "commit from script"
echo -e "\n\n$(tput setaf 2)git pull$(tput sgr 0)"
git pull
echo -e "\n\n$(tput setaf 2)git push$(tput sgr 0)"
git push
echo -e "\n\n$(tput setaf 2)ssh -i hypertube.pem -t [email protected] git -C /var/www/hypertube/ pull$(tput sgr 0)"
ssh -i hypertube.pem -t [email protected] git -C /var/www/hypertube/ pull
echo -e "\n\n$(tput setaf 2)ssh -i hypertube.pem -t [email protected] npm run --prefix /var/www/hypertube/ build-prod$(tput sgr 0)"
ssh -i hypertube.pem -t [email protected] npm run --prefix /var/www/hypertube/ build-prod
ssh -i hypertube.pem -t [email protected] /var/www/hypertube/api/bin/console c:c
ssh -i hypertube.pem -t [email protected] /var/www/hypertube/api/bin/console c:c --env=PROD
ssh -i hypertube.pem -t [email protected] chown -R www-data: /var/www/
echo -e "\n\n$(tput setaf 2)################################################################
# #
# PROJECT PULLED & COMPILED #
# #
################################################################$(tput sgr 0)\n\n"
}
runProject() {
chmod 400 hypertube.pem
tar --exclude='./node_modules' --exclude='./api/vendor' --exclude='./api/var' -czvf output.tar.gz .
scp -i hypertube.pem ./output.tar.gz [email protected]:/opt/
ssh -i hypertube.pem -t [email protected] rm -rf /var/www/hypertube/*
ssh -i hypertube.pem -t [email protected] tar xvf /opt/output.tar.gz -C /var/www/hypertube/
ssh -i hypertube.pem -t [email protected] npm i --prefix /var/www/hypertube/
ssh -i hypertube.pem -t [email protected] composer install -d /var/www/hypertube/api/
ssh -i hypertube.pem -t [email protected] npm run --prefix /var/www/hypertube/ build-prod
ssh -i hypertube.pem -t [email protected] rm -rf /var/www/hypertube/api/config/jwt/
ssh -i hypertube.pem -t [email protected] mkdir /var/www/hypertube/api/config/jwt/
# Getting JWT_PASSPHRASE in order to create keys
JWT_PASSPHRASE="`ssh -o LogLevel=QUIET -i hypertube.pem -t [email protected] "grep JWT_PASSPHRASE /var/www/hypertube/api/.env | cut -f2 -d '='"`"
# Removing '\r' at the end of JWT_PASSPHRASE
JWT_PASSPHRASE="${JWT_PASSPHRASE/$'\r'/}"
ssh -i hypertube.pem -t [email protected] openssl genrsa -out /var/www/hypertube/api/config/jwt/private.pem -aes256 -passout pass:$JWT_PASSPHRASE 4096
ssh -i hypertube.pem -t [email protected] openssl rsa -pubout -in /var/www/hypertube/api/config/jwt/private.pem -passin pass:$JWT_PASSPHRASE -out /var/www/hypertube/api/config/jwt/public.pem
ssh -i hypertube.pem -t [email protected] chown -R www-data: /var/www/
ssh -i hypertube.pem -t [email protected] chown -R www-data: /var/www/
ssh -i hypertube.pem -t [email protected] rm -f /opt/output.tar.gz
rm -f output.tar.gz
}
if [ $# -eq 1 ]; then
case $1 in
-p | --pull-and-run)
pullAndRun
;;
*)
usage
exit 1
;;
esac
else
runProject
exit 0
fi