forked from back4app/parse-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-homolog.sh
executable file
·100 lines (85 loc) · 2.42 KB
/
deploy-homolog.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
93
94
95
96
97
98
99
100
#!/bin/bash
# Back4App variables
host=34.192.186.60
user=ubuntu
pem=AppContainers.pem
branch=$(git symbolic-ref --short HEAD)
git='~/bin/git-parse-dashboard'
# Check if ENV VAR is defined
if [[ ! $b4a_certs_path ]]; then
echo 'Set b4a_certs_path environment variable, please!' && exit
fi
# Define usage function
usage() {
echo
echo
echo "Usage: $0
[--type <parse-dashboard, parse-dashboard2>] (required)
Specifies the type of dashboard to deploy. Valid options are 'parse-dashboard' and 'parse-dashboard2'.
[--remote <branch>] (optional)
Specifies the Git 'remote' repository from which to deploy.
If not provided, the 'origin' remote will be used."
echo
echo
}
# Initialize custom variables
remote=""
type=""
commands=""
# Parse command-line options
ARGS=$(getopt -o r:t: --long remote:,type: -n "$0" -- "$@")
eval set -- "$ARGS"
while true; do
case "$1" in
-r | --remote)
remote="$2"
shift 2
;;
-t | --type)
if [[ -z "$2" ]]; then
echo "Error: Value for --type is empty."
usage
exit 1
fi
type="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Invalid option: $1"
usage
exit 1
;;
esac
done
# Check if origin or type are empty
if [[ -z "$remote" ]]; then
remote="origin"
elif [[ -z "$type" ]]; then
echo "--type must be provided."
usage
exit 1
fi
case "$type" in
"parse-dashboard")
folder="~/scm/parse-dashboard"
;;
"parse-dashboard2")
folder="~/scm/parse-dashboard2"
;;
*)
echo "Error: Invalid value for --type. Expected 'parse-dashboard' or 'parse-dashboard2'."
usage
exit 1
;;
esac
echo "Deploying origin: ${remote}"
commands+="sudo su back4app -c '. ~/.nvm/nvm.sh && nvm use 14 "
commands+="&& cd $folder && rm -rf node_modules && $git reset --hard "
commands+="&& $git remote update && $git remote update && $git checkout $branch && $git merge $remote/$branch "
commands+="&& npm install && sed -i \"s/http:\/\/localhost:4000\/parseapi/https:\/\/dashboard-homolog.back4app.com\/parseapi/\" node_modules/parse/lib/browser/settings.js "
commands+="&& npm run build-homolog'"
ssh -t -i $b4a_certs_path/$pem $user@$host $commands