Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 10, 2020. It is now read-only.

Commit e3e2f10

Browse files
committed
Merge branch 'add_scripts'
2 parents aacd7e1 + c46c159 commit e3e2f10

File tree

2 files changed

+368
-0
lines changed

2 files changed

+368
-0
lines changed

β€Žscripts/eev4β€Ž

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
#!/usr/bin/env bash
2+
3+
PROJECT_NAME="eev4"
4+
EE_INSTALL_DIR="/opt/$PROJECT_NAME"
5+
ETC_HOSTS=/etc/hosts
6+
LOCALHOST_IP="127.0.0.1"
7+
WEBROOT="/var/www"
8+
9+
# runs the given command as root (detects if we are root already)
10+
runAsRoot() {
11+
local CMD="$*"
12+
13+
if [ $EUID -ne 0 ]; then
14+
CMD="sudo $CMD"
15+
fi
16+
17+
$CMD
18+
}
19+
20+
# help provides possible cli arguments
21+
help () {
22+
echo -e "\nUsage: eev4 [Global Options]"
23+
echo -e "\nGlobal Options:"
24+
echo -e "\t[--help|-h ]\t\tprints this help"
25+
26+
echo -e "\nCommands: "
27+
echo -e "\tcreate\t\t\tCreate new site"
28+
echo -e "\tdelete\t\t\tDelete existing site"
29+
echo -e "\twp\t\t\tUse wp-cli with a site"
30+
31+
echo -e "\nUsage: eev4 create SITE [Options]"
32+
echo -e "\nOptions:"
33+
echo -e "\t[--wp ]\t\t\tWordPress Site"
34+
echo -e "\t[--wpsubdir ]\t\tWordPress Multisite with Subdirectory"
35+
echo -e "\t[--wpsubdomain ]\tWordPress Multisite with Subdomains"
36+
37+
echo -e "\nUsage: eev4 delete SITE"
38+
39+
echo -e "\nUsage: eev4 wp SITE [ARG...]"
40+
echo -e "\te.g. eev4 wp example.com theme list"
41+
}
42+
43+
singleWordPress() {
44+
echo "Installing WordPress site $SITE_NAME"
45+
mkdir -p "$WEBROOT" > /dev/null 2>&1
46+
47+
###
48+
# Setup site configuration
49+
###
50+
echo "Configuring project..." && sleep 1
51+
mkdir -p "$WEBROOT/$SITE_NAME" > /dev/null 2>&1
52+
cp "$EE_INSTALL_DIR/docker-compose.yml" "$WEBROOT/$SITE_NAME"
53+
cp -r "$EE_INSTALL_DIR/config" "$WEBROOT/$SITE_NAME"
54+
mv "$WEBROOT/$SITE_NAME/config/.env.example" "$WEBROOT/$SITE_NAME/.env"
55+
sed -i.bak "s/\(VIRTUAL_HOST=\)\(site1.test\)/1円$SITE_NAME/" "$WEBROOT/$SITE_NAME/.env"
56+
57+
###
58+
# Setup site networking
59+
###
60+
echo "Configuring network..." && sleep 1
61+
runNginxProxy
62+
docker network create $SITE_NAME
63+
docker network connect $SITE_NAME nginx-proxy
64+
65+
###
66+
# Start the containers
67+
###
68+
pushd "$WEBROOT/$SITE_NAME" > /dev/null 2>&1
69+
docker-compose up -d
70+
popd > /dev/null 2>&1
71+
72+
echo "$SITE_NAME created."
73+
read -p "Would you like to add domain to /etc/host?(y/N) " -n 1 -r
74+
if [[ $REPLY =~ ^[Yy]$ ]]; then
75+
addHost "$SITE_NAME"
76+
fi
77+
}
78+
79+
multisiteSubdirectory() {
80+
echo "Installing WordPress Multisite with Subdirectory"
81+
}
82+
83+
multisiteSubdomain() {
84+
echo "Installing WordPress Multisite with Subdomain"
85+
}
86+
87+
deleteSingleWordPress() {
88+
read -p "Are you sure you want to delete the site?(y/N) " -n 1 -r
89+
if [[ $REPLY =~ ^[Yy]$ ]]; then
90+
pushd "$WEBROOT/$SITE_NAME" > /dev/null 2>&1
91+
docker-compose down -v
92+
popd > /dev/null 2>&1
93+
94+
sudo rm -rf "$WEBROOT/$SITE_NAME"
95+
docker network disconnect "$SITE_NAME" nginx-proxy
96+
docker network rm "$SITE_NAME"
97+
fi
98+
}
99+
100+
runWpCliCommand() {
101+
pushd "$WEBROOT/$SITE_NAME" > /dev/null 2>&1
102+
docker-compose exec --user=www-data php wp "${@}"
103+
popd > /dev/null 2>&1
104+
}
105+
106+
removeHost() {
107+
HOSTNAME=1ドル
108+
if [ -n "$(grep $HOSTNAME /etc/hosts)" ]
109+
then
110+
echo "$HOSTNAME Found in your $ETC_HOSTS, Removing now...";
111+
sudo sed -i".bak" "/$HOSTNAME/d" $ETC_HOSTS
112+
else
113+
echo "$HOSTNAME was not found in your $ETC_HOSTS";
114+
fi
115+
}
116+
117+
addHost() {
118+
HOSTNAME=1ドル
119+
HOSTS_LINE="$LOCALHOST_IP\t$HOSTNAME"
120+
echo
121+
if [ -n "$(grep $HOSTNAME /etc/hosts)" ]; then
122+
echo "$HOSTNAME already exists : $(grep $HOSTNAME $ETC_HOSTS)"
123+
else
124+
echo "Adding $HOSTNAME to your $ETC_HOSTS";
125+
sudo -- sh -c -e "echo '$HOSTS_LINE' >> /etc/hosts";
126+
127+
if [ -n "$(grep $HOSTNAME /etc/hosts)" ]; then
128+
echo -e "$HOSTNAME was added succesfully \n $(grep $HOSTNAME /etc/hosts)";
129+
else
130+
echo "Failed to add $HOSTNAME, Try again!";
131+
fi
132+
fi
133+
}
134+
135+
# check if ports 80 and 443 are free.
136+
portsFree() {
137+
ports=( 80 443 )
138+
free=0
139+
for port in "${ports[@]}" ; do
140+
# count the number of occurrences of $port in output: 1 = in use; 0 = not in use
141+
result=$(ss -ln src :$port | grep -Ec -e "\<$port\>")
142+
if [ "$result" -eq 1 ]; then
143+
free=1
144+
fi
145+
done
146+
return $free
147+
}
148+
149+
# check if nginx-proxy container is running
150+
isNginxProxyRunning() {
151+
docker inspect -f '{{.State.Running}}' nginx-proxy > /dev/null 2>&1
152+
if [[ $? == 0 ]]; then
153+
return 0
154+
else
155+
# For any exit code other than 0, return 1.
156+
return 1
157+
fi
158+
}
159+
160+
# run jwilder/nginx-proxy container
161+
runNginxProxy() {
162+
if ! isNginxProxyRunning; then
163+
if ! portsFree; then
164+
echo "Please make sure ports 80 and 443 are free."
165+
else
166+
docker run --name nginx-proxy --restart always -d -p 80:80 -p 443:443 \
167+
-v /etc/nginx/htpasswd:/etc/nginx/htpasswd \
168+
-v /etc/nginx/certs:/etc/nginx/certs \
169+
-v /etc/nginx/conf.d:/etc/nginx/conf.d \
170+
-v /var/run/docker.sock:/tmp/docker.sock:ro \
171+
jwilder/nginx-proxy
172+
fi
173+
fi
174+
}
175+
176+
# fail_trap is executed if an error occurs.
177+
fail_trap() {
178+
result=$?
179+
if [ "$result" != "0" ]; then
180+
if [[ -n "$INPUT_ARGUMENTS" ]]; then
181+
echo "Failed to run with the arguments provided: $INPUT_ARGUMENTS"
182+
help
183+
else
184+
help
185+
fi
186+
echo -e "\tFor support, go to https://github.com/EasyEngine/docker-compose-wordpress."
187+
fi
188+
exit $result
189+
}
190+
191+
192+
# Execution
193+
194+
#Stop execution on any error
195+
trap "fail_trap" EXIT
196+
set -e
197+
198+
# Parsing input arguments (if any)
199+
export INPUT_ARGUMENTS="${@}"
200+
set -u
201+
if [[ $# -eq 0 ]]; then
202+
help
203+
fi
204+
while [[ $# -gt 0 ]]; do
205+
case 1ドル in
206+
'--help'|-h)
207+
help
208+
exit 0
209+
;;
210+
'create')
211+
shift
212+
if [[ $# -ne 0 ]]; then
213+
export SITE_NAME="${1}"
214+
shift
215+
if [[ $# -ne 0 ]]; then
216+
case 1ドル in
217+
'--wp')
218+
singleWordPress
219+
exit 0
220+
;;
221+
'--wpsubdir')
222+
singleWordPress
223+
exit 0
224+
;;
225+
'--wpsubdomain')
226+
singleWordPress
227+
exit 0
228+
;;
229+
esac
230+
shift
231+
else
232+
echo -e "Please provide type of site you want to create."
233+
exit 0
234+
fi
235+
else
236+
echo -e "Please provide name of site."
237+
exit 0
238+
fi
239+
;;
240+
'delete')
241+
shift
242+
if [[ $# -ne 0 ]]; then
243+
export SITE_NAME="${1}"
244+
deleteSingleWordPress
245+
else
246+
echo -e "Please provide name of site."
247+
exit 0
248+
fi
249+
;;
250+
'wp')
251+
shift
252+
if [[ $# -ne 0 ]]; then
253+
export SITE_NAME="${1}"
254+
shift
255+
runWpCliCommand "${@}"
256+
exit 0
257+
else
258+
echo -e "Please provide name of site."
259+
exit 0
260+
fi
261+
;;
262+
*) exit 1
263+
;;
264+
esac
265+
shift
266+
done
267+
set +u

β€Žscripts/setupβ€Ž

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env bash
2+
3+
PROJECT_NAME="eev4"
4+
REPO_URL="https://github.com/EasyEngine/docker-compose-wordpress"
5+
VERSION="master"
6+
7+
# runs the given command as root (detects if we are root already)
8+
runAsRoot() {
9+
local CMD="$*"
10+
11+
if [ $EUID -ne 0 ]; then
12+
CMD="sudo $CMD"
13+
fi
14+
15+
$CMD
16+
}
17+
18+
# fail_trap is executed if an error occurs.
19+
fail_trap() {
20+
result=$?
21+
if [ "$result" != "0" ]; then
22+
echo -e "\n\nFailed to install $PROJECT_NAME"
23+
echo "For support, go to https://github.com/EasyEngine/docker-compose-wordpress."
24+
fi
25+
cleanup
26+
exit $result
27+
}
28+
29+
# cleanup temporary files
30+
cleanup() {
31+
rm -rf "$EE_TMP_ROOT"
32+
}
33+
34+
# checks dependencies requried to run this setup
35+
checkDependencies() {
36+
dependencies=(
37+
"git^git - https://git-scm.com/downloads"
38+
"docker^docker - https://docs.docker.com/engine/installation"
39+
"docker-compose^docker-compose - https://docs.docker.com/compose/install" )
40+
41+
pass=0
42+
43+
for dependency in "${dependencies[@]}" ; do
44+
dep="${dependency%%^*}"
45+
msg="${dependency##*^}"
46+
if ! type "$dep" > /dev/null 2>&1; then
47+
echo "Please install $msg"
48+
pass=1
49+
fi
50+
done
51+
52+
return $pass
53+
}
54+
55+
# cloneRepo clones the repository to a temporary location
56+
cloneRepo() {
57+
EE_TMP_ROOT="$(mktemp -dt ee-installer-XXXXXX)"
58+
EE_TMP_REPO="$EE_TMP_ROOT/docker-compose-wordpress"
59+
echo "Clone repo $REPO_URL"
60+
git clone -b "$VERSION" "$REPO_URL" "$EE_TMP_REPO"
61+
}
62+
63+
# installScript installs the main script.
64+
installScript() {
65+
EE_INSTALL_DIR="/opt/$PROJECT_NAME"
66+
EE_SCRIPT="scripts/eev4"
67+
EE_SCRIPT_INSTALL_PATH="/usr/local/bin/eev4"
68+
69+
rm -rf "$EE_INSTALL_DIR"
70+
echo "Preparing to install into $EE_INSTALL_DIR"
71+
runAsRoot cp -r "$EE_TMP_REPO" "$EE_INSTALL_DIR"
72+
runAsRoot ln -s "$EE_INSTALL_DIR/$EE_SCRIPT" "$EE_SCRIPT_INSTALL_PATH"
73+
echo -e "\nInstall complete!"
74+
echo "Run '$PROJECT_NAME' to get started."
75+
}
76+
77+
# testVersion tests the installed script to make sure it is working.
78+
testInstalled() {
79+
EE_INSTALLED="$(which $PROJECT_NAME)"
80+
if [ "$?" = "1" ]; then
81+
return 1
82+
else
83+
echo "$PROJECT_NAME already installed into $EE_INSTALLED"
84+
return 0
85+
fi
86+
}
87+
88+
# Execution
89+
90+
#Stop execution on any error
91+
trap "fail_trap" EXIT
92+
set -e
93+
94+
if ! testInstalled; then
95+
if ! checkDependencies; then
96+
exit 1;
97+
fi
98+
cloneRepo
99+
installScript
100+
fi
101+
cleanup

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /