-
Notifications
You must be signed in to change notification settings - Fork 5
/
n
executable file
·208 lines (198 loc) · 6.56 KB
/
n
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash
NABSPATH="$(dirname "${BASH_SOURCE[0]}")"
source "$(dirname "${BASH_SOURCE[0]}")/bin/repos.sh"
# Infer the current working project from the current folder;
projects=("${newspack_plugins[@]}" "newspack-theme") # create a new list with the appended value
target_folder=""
for plugin in "${projects[@]}"; do
if [[ "$PWD" == *"$plugin"* ]]; then
target_folder=$plugin
fi
done
path_param=""
current_site_path="/var/www/html"
current_site_relative_path="html"
# if current working folder is a folder inside the additional-sites folder, set the current_site to it
# if I am inside this folder several levels, return only the name of the first folder after additional-sites
if [[ "$PWD" == *"additional-sites-html"* ]]; then
current_site=$(echo $PWD | sed -e 's/.*additional-sites-html\///' | cut -d'/' -f1)
current_site_path="/var/www/additional-sites-html/$current_site"
current_site_relative_path="additional-sites-html/$current_site"
path_param="--path=$current_site_path"
fi
cd "$(dirname "$0")"
source .env
if [ $# -eq 0 ]; then
echo "No arguments provided"
exit 1
fi
if [ ! -z "$USE_CUSTOM_APACHE_USER" ]
then
USER_COMMAND="--user $USE_CUSTOM_APACHE_USER "
else
USER_COMMAND=""
fi
require_target_folder() {
if [[ -z "$target_folder" ]]; then
echo "Error: You must be inside one of the repos to run this command." >&2
exit 1
fi
}
start() {
file="docker-compose.yml"
if [ "$2" == "8.0" ]; then
file="docker-compose-80.yml"
fi
if [ "$2" == "7.4" ]; then
file="docker-compose-74.yml"
fi
docker-compose -f $file up -d
}
stop() {
docker-compose down
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
sh)
docker exec -it $USER_COMMAND newspack_dev /bin/bash
;;
rsh)
docker exec -it newspack_dev /bin/bash
;;
cd-install)
echo "This will install the ncd command in your system. Please inform the file you want to add this to (e.g. .bashrc)"
read -e -p "> $HOME/" file
target="$HOME/$file"
snippet="source $NABSPATH/bin/ncd.sh"
if grep -Fxq "$snippet" $target
then
echo "ncd is already installed on $target"
else
echo "NEWSPACK_DOCKER_ROOT=$NABSPATH" >> $target
echo $snippet >> $target
echo "ncd installed!"
echo
echo "Restart your terminal or run 'source $target' to start using it"
echo
echo "To use it, just type 'ncd <folder>'"
echo "It will look for matches on the repos folder, the additional-sites-html folder and the plugins folder of the main site"
fi
;;
install)
docker exec -it $USER_COMMAND newspack_dev sh -c "/var/scripts/install.sh $current_site_path"
;;
uninstall)
docker exec -it $USER_COMMAND newspack_dev sh -c "/var/scripts/uninstall.sh $current_site_path"
;;
reset-site)
docker exec -it $USER_COMMAND newspack_dev sh -c "/var/scripts/reset-site.sh $current_site_path"
;;
tail)
tail -f $current_site_relative_path/wp-content/debug.log
;;
wp)
cmd="wp --allow-root $path_param ${@:2}"
docker exec -it $USER_COMMAND newspack_dev $cmd
;;
db)
docker exec -it $USER_COMMAND newspack_dev sh -c "wp db cli --allow-root $path_param"
;;
shell)
docker exec -it $USER_COMMAND newspack_dev sh -c "wp shell --allow-root $path_param"
;;
install-manager)
docker exec -it $USER_COMMAND newspack_dev sh -c "/var/scripts/install-manager.sh"
;;
setup-manager)
docker exec -it $USER_COMMAND newspack_dev sh -c "/var/scripts/init-wp-manager.sh"
docker exec -it $USER_COMMAND newspack_dev sh -c "/var/scripts/setup-manager.sh"
;;
sites-add)
docker exec -it newspack_dev sh -c "/var/scripts/sites-add.sh $2"
read -p "Do you want to add this domain to your local hosts file? (Y/n): " choice
choice=${choice,,}
if [[ "$choice" != "n" ]]; then
echo "127.0.0.1 $2.local" | sudo tee -a /etc/hosts
fi
;;
sites-list)
docker exec -it newspack_dev sh -c "/var/scripts/sites-list.sh ${@:2}"
;;
sites-drop)
docker exec -it newspack_dev sh -c "/var/scripts/sites-drop.sh ${@:2}"
;;
build)
if [[ -n "$2" ]]; then
target_folder=$2
fi
docker exec -it $USER_COMMAND newspack_dev sh -c "/var/scripts/build-repos.sh $target_folder"
;;
watch)
require_target_folder
docker exec -it $USER_COMMAND newspack_dev sh -c "/var/scripts/watch-repo.sh $target_folder"
;;
test-php)
require_target_folder
command="/var/scripts/test-php.sh $target_folder ${@:2}"
docker exec -it $USER_COMMAND newspack_dev sh -c "$command"
;;
test-js)
require_target_folder
docker exec -it $USER_COMMAND newspack_dev sh -c "/var/scripts/test-js.sh $target_folder"
;;
composer)
require_target_folder
command="/var/scripts/composer.sh $target_folder ${@:2}"
docker exec -it $USER_COMMAND newspack_dev sh -c "$command"
;;
npm)
require_target_folder
command="/var/scripts/npm.sh $target_folder ${@:2}"
docker exec -it $USER_COMMAND newspack_dev sh -c "$command"
;;
secrets)
docker exec -it $USER_COMMAND newspack_dev sh -c "wp eval-file /var/scripts/generate-secrets.php --allow-root"
;;
secrets-import)
docker exec -it $USER_COMMAND newspack_dev sh -c "/var/scripts/import-secrets.sh"
;;
snapshot)
docker exec -it $USER_COMMAND newspack_dev sh -c "/var/scripts/snapshot-create.sh $2"
;;
snapshot-load)
docker exec -it $USER_COMMAND newspack_dev sh -c "/var/scripts/snapshot-load.sh $2"
;;
jncp)
cmd="/var/scripts/jn-cp.sh ${@:2}"
docker exec -it $USER_COMMAND newspack_dev $cmd
;;
jninit)
cmd="/var/scripts/jn-init.sh ${@:2}"
docker exec -it $USER_COMMAND newspack_dev $cmd
;;
pull)
for dir in repos/*/; do
cd "$dir"
if [ -d ".git" ]; then
echo "Updating repository: $dir"
git pull
fi
cd ..
done
;;
setup-newspack-network)
docker exec -it $USER_COMMAND newspack_dev sh -c "/var/scripts/setup-newspack-network.sh"
;;
*)
echo Unknown command
;;
esac