-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
156 lines (145 loc) · 4.56 KB
/
run.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
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
#!/bin/bash
echo "***************************"
echo "* BEGIN DEPLOY SCRIPT *"
echo "***************************"
echo ""
# Determine the actual script location, resolving symlinks
SCRIPT_PATH=$(readlink -f "$0")
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
# Set SITEPATH based on the script's directory
SITEPATHAPP=$(echo "$SCRIPT_DIR" | awk -F'/' '{print $4}')
# Set the config file path
CONFIG_FILE=~/${SITEPATHAPP}/config.sh
# Source the config file if it exists
if [ -f "$CONFIG_FILE" ]; then
cat $CONFIG_FILE
source "$CONFIG_FILE"
else
# Prompt for configuration values if the file doesn't exist
read -p "Enter SITEPATH (doc root location within ~ like public_html or sub): " SITEPATH
read -p "Enter REPONAME (not including vendor name): " REPONAME
# Save the configuration
echo "SITEPATH=${SITEPATH}" > $CONFIG_FILE
echo "REPONAME=${REPONAME}" >> $CONFIG_FILE
fi
cd ~/${SITEPATH}_app/${REPONAME}
# Define the function to run the appropriate npm command
run_npm_script() {
local PACKAGE_JSON="package.json"
# Check if the package.json file exists
if [[ ! -f "$PACKAGE_JSON" ]]; then
return
fi
# Check for 'build'/'prod'/'production' script in package.json
if grep -q '"build":' "$PACKAGE_JSON"; then
npm run build
elif grep -q '"prod":' "$PACKAGE_JSON"; then
npm run prod
elif grep -q '"production":' "$PACKAGE_JSON"; then
npm run production
else
echo "No valid 'build' or 'prod' or 'production' script found in package.json."
fi
}
run_make_self_executable() {
chmod u+x vendor/brendanpetty/deployer/run.sh
}
options=("Exit" "FULL UPDATE" "Git Status" "Git Fetch" "Git Pull" "Git Diff" "Git Clean (force)" "Git Reset" "Composer Install" "NPM Install" "NPM Build" "Artisan Migrate" "Artisan Cache" "Artisan Seed")
while true
do
echo ""
echo ""
echo "Select an action (1-${#options[@]}): "
select opt in "${options[@]}"
do
case $opt in
"Exit")
echo "See ya!"
exit 0
;;
"FULL UPDATE")
echo "git pull"
git pull
echo "composer install --no-dev"
composer install --no-dev
echo "make self executable (after update)"
run_make_self_executable
if [[ -f "package.json" ]]; then
echo "npm install"
npm install
echo "run npm build"
run_npm_script
fi
if [[ -f "artisan" ]]; then
echo "artisan migrate --force"
php artisan migrate --force
echo "artisan config cache"
php artisan config:cache
echo "artisan route cache"
php artisan route:cache
echo "artisan view cache"
php artisan view:cache
fi
echo "finished"
break
;;
"Git Status")
git status
break
;;
"Git Fetch")
git fetch
break
;;
"Git Pull")
git pull
break
;;
"Git Clean (force)")
git clean -df
break
;;
"Git Reset")
git reset --hard
break
;;
"Git Diff")
git diff -R
git diff --cached --stat
git diff origin/main
break
;;
"Composer Install")
composer install --no-dev
echo "make self executable (after update)"
run_make_self_executable
break
;;
"NPM Install")
npm install
break
;;
"NPM Build")
run_npm_script
break
;;
"Artisan Migrate")
php artisan migrate
break
;;
"Artisan Cache")
php artisan config:cache
php artisan route:cache
php artisan view:cache
break
;;
"Artisan Seed")
php artisan db:seed
break
;;
*)
echo "Invalid option $opt. Please try again"
;;
esac
done
done