Skip to content
This repository was archived by the owner on Aug 10, 2020. It is now read-only.

Commit 8b84788

Browse files
authoredFeb 2, 2018
Merge pull request #29 from EasyEngine/add_osx_support
Add macOS support
2 parents c1923e3 + df36abc commit 8b84788

File tree

2 files changed

+96
-46
lines changed

2 files changed

+96
-46
lines changed
 

‎scripts/ee4

+77-45
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#!/usr/bin/env bash
22

33
PROJECT_NAME="ee4"
4-
EE_INSTALL_DIR="/opt/$PROJECT_NAME"
54
ETC_HOSTS=/etc/hosts
65
LOCALHOST_IP="127.0.0.1"
76

7+
# initOS discovers the operating system for this system.
8+
initOS() {
9+
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
10+
}
11+
812
# runs the given command as root (detects if we are root already)
913
runAsRoot() {
1014
local CMD="$*"
@@ -18,15 +22,17 @@ runAsRoot() {
1822

1923
# help provides possible cli arguments
2024
help () {
21-
echo -e "\nUsage: ee4 [Global Options]"
25+
echo -e "\nUsage: ee4 [Global Options|Commands]"
2226
echo -e "\nGlobal Options:"
2327
echo -e "\t[--help|-h ]\t\tprints this help"
2428

2529
echo -e "\nCommands: "
2630
echo -e "\tcreate\t\t\tCreate new site"
31+
echo -e "\tdb\t\t\tEnter mysql shell"
2732
echo -e "\tdelete\t\t\tDelete existing site"
2833
echo -e "\trestart\t\t\tReload configuration for existing site"
2934
echo -e "\twp\t\t\tUse wp-cli with a site"
35+
echo -e "\tupdate\t\t\tUpdate ee4"
3036

3137
echo -e "\nUsage: ee4 create SITE [Options] [Suboptions]"
3238
echo -e "\nOptions:"
@@ -42,12 +48,21 @@ help () {
4248
echo -e "\te.g. ee4 wp example.com theme list"
4349
}
4450

45-
singleWordPress() {
46-
echo "Installing WordPress site $SITE_NAME"
51+
createWebroot()
52+
{
4753
if ! [[ -d "$WEBROOT" ]]; then
48-
runAsRoot mkdir -p "$WEBROOT" > /dev/null 2>&1
54+
mkdir -p "$WEBROOT" > /dev/null 2>&1
55+
if [ "$?" -eq 1 ]; then
56+
runAsRoot mkdir -p "$WEBROOT" > /dev/null 2>&1
57+
runAsRoot chown -R "$USER": "$WEBROOT"
58+
fi
4959
fi
60+
}
61+
62+
singleWordPress() {
63+
createWebroot
5064

65+
echo "Installing WordPress site $SITE_NAME"
5166
###
5267
# Setup site configuration
5368
###
@@ -57,13 +72,15 @@ singleWordPress() {
5772
cp -r "$EE_INSTALL_DIR/config" "$WEBROOT/$SITE_NAME"
5873
mv "$WEBROOT/$SITE_NAME/config/.env.example" "$WEBROOT/$SITE_NAME/.env"
5974
sed -i.bak "s/\(VIRTUAL_HOST=\)\(site1.test\)/\1$SITE_NAME/" "$WEBROOT/$SITE_NAME/.env"
75+
sed -i.bak "/^.*LETSENCRYPT.*/d" "$WEBROOT/$SITE_NAME/docker-compose.yml"
76+
find "$WEBROOT/$SITE_NAME" -mindepth 1 -maxdepth 3 -name '*.bak' -exec rm {} \;
6077

6178
###
6279
# Setup site networking
6380
###
6481
echo "Configuring network..." && sleep 1
6582
runNginxProxyAndLetsEncrypt
66-
docker network create $SITE_NAME
83+
docker network create $SITE_NAME > /dev/null 2>&1
6784
docker network connect $SITE_NAME nginx-proxy
6885

6986
###
@@ -77,12 +94,13 @@ singleWordPress() {
7794
read -p "Would you like to add domain to /etc/host?(y/N) " -n 1 -r
7895
if [[ $REPLY =~ ^[Yy]$ ]]; then
7996
addHost "$SITE_NAME"
97+
addHost "mail.$SITE_NAME"
8098
fi
8199
}
82100

83101
singleWordPressLetsEncrypt() {
102+
createWebroot
84103
echo "Installing WordPress site $SITE_NAME"
85-
mkdir -p "$WEBROOT" > /dev/null 2>&1
86104

87105
###
88106
# Setup site configuration
@@ -93,13 +111,14 @@ singleWordPressLetsEncrypt() {
93111
cp -r "$EE_INSTALL_DIR/config" "$WEBROOT/$SITE_NAME"
94112
mv "$WEBROOT/$SITE_NAME/config/.env.example" "$WEBROOT/$SITE_NAME/.env"
95113
sed -i.bak "s/\(VIRTUAL_HOST=\)\(site1.test\)/\1$SITE_NAME/" "$WEBROOT/$SITE_NAME/.env"
114+
find "$WEBROOT/$SITE_NAME" -mindepth 1 -maxdepth 3 -name '*.bak' -exec rm {} \;
96115

97116
###
98117
# Setup site networking
99118
###
100119
echo "Configuring network..." && sleep 1
101120
runNginxProxyAndLetsEncrypt
102-
docker network create $SITE_NAME
121+
docker network create $SITE_NAME > /dev/null 2>&1
103122
docker network connect $SITE_NAME nginx-proxy
104123
docker network connect $SITE_NAME letsencrypt
105124

@@ -114,6 +133,7 @@ singleWordPressLetsEncrypt() {
114133
read -p "Would you like to add domain to /etc/host?(y/N) " -n 1 -r
115134
if [[ $REPLY =~ ^[Yy]$ ]]; then
116135
addHost "$SITE_NAME"
136+
addHost "mail.$SITE_NAME"
117137
fi
118138
}
119139

@@ -139,6 +159,7 @@ deleteSingleWordPress() {
139159
fi
140160
docker network rm "$SITE_NAME"
141161
fi
162+
removeHost "$SITE_NAME"
142163
}
143164

144165
restartSingleWordPress() {
@@ -153,10 +174,15 @@ runWpCliCommand() {
153174
popd > /dev/null 2>&1
154175
}
155176

177+
useDbShell() {
178+
pushd "$WEBROOT/$SITE_NAME" > /dev/null 2>&1
179+
docker-compose exec db sh -c 'mysql -p$MYSQL_ROOT_PASSWORD'
180+
popd > /dev/null 2>&1
181+
}
182+
156183
removeHost() {
157184
HOSTNAME=$1
158-
if [ -n "$(grep $HOSTNAME /etc/hosts)" ]
159-
then
185+
if [ -n "$(grep $HOSTNAME /etc/hosts)" ]; then
160186
echo "$HOSTNAME Found in your $ETC_HOSTS, Removing now...";
161187
sudo sed -i".bak" "/$HOSTNAME/d" $ETC_HOSTS
162188
else
@@ -188,8 +214,13 @@ portsFree() {
188214
free=0
189215
for port in "${ports[@]}" ; do
190216
# count the number of occurrences of $port in output: 1 = in use; 0 = not in use
191-
result=$(ss -ln src :$port | grep -Ec -e "\<$port\>")
192-
if [ "$result" -eq 1 ]; then
217+
if [[ "$OS" == 'linux' ]]; then
218+
checkPortCMD="netstat -lnp tcp | grep "
219+
elif [[ "$OS" == 'darwin' ]]; then
220+
checkPortCMD="netstat -anp tcp | grep LISTEN | grep "
221+
fi
222+
runAsRoot $checkPortCMD $port > /dev/null 2>&1
223+
if [ "$?" -eq 1 ]; then
193224
free=1
194225
fi
195226
done
@@ -229,11 +260,11 @@ runNginxProxyAndLetsEncrypt() {
229260
echo "Please make sure ports 80 and 443 are free."
230261
else
231262
docker run --name nginx-proxy --restart always -d -p 80:80 -p 443:443 \
232-
-v /etc/nginx/htpasswd:/etc/nginx/htpasswd \
233-
-v /etc/nginx/certs:/etc/nginx/certs \
234-
-v /etc/nginx/vhost.d \
235-
-v /usr/share/nginx/html \
236-
-v /etc/nginx/conf.d:/etc/nginx/conf.d \
263+
-v ~/.ee4/etc/nginx/certs:/etc/nginx/certs \
264+
-v ~/.ee4/etc/nginx/conf.d:/etc/nginx/conf.d \
265+
-v ~/.ee4/etc/nginx/htpasswd:/etc/nginx/htpasswd \
266+
-v ~/.ee4/etc/nginx/vhost.d:/etc/nginx/vhost.d \
267+
-v ~/.ee4/usr/share/nginx/html:/usr/share/nginx/html \
237268
-v /var/run/docker.sock:/tmp/docker.sock:ro \
238269
jwilder/nginx-proxy
239270

@@ -245,55 +276,45 @@ runNginxProxyAndLetsEncrypt() {
245276
fi
246277
}
247278

248-
# fail_trap is executed if an error occurs.
249-
fail_trap() {
250-
result=$?
251-
if [ "$result" != "0" ]; then
252-
if [[ -n "$INPUT_ARGUMENTS" ]]; then
253-
echo "Failed to run with the arguments provided: $INPUT_ARGUMENTS"
254-
help
255-
else
256-
help
257-
fi
258-
echo -e "\tFor support, go to https://github.com/EasyEngine/docker-compose-wordpress."
259-
fi
260-
exit $result
261-
}
262-
263279
initEE4() {
264280
if ! [[ -d ~/.ee4 ]]; then
265281
mkdir ~/.ee4
266282
fi
267283

268284
if [[ $# -eq 0 ]]; then
269-
read -p "Where would you like to create your sites(default: ~/Documents/Sites): "
270-
WEBROOT="${REPLY:-~/Documents/Sites}"
285+
read -p "Where would you like to create your sites(default: ~/Sites): "
286+
WEBROOT="${REPLY:-~/Sites}"
271287
elif [[ $# -eq 1 ]]; then
272288
WEBROOT="$1"
273289
fi
274290

275-
echo "WEBROOT=$WEBROOT" > ~/.ee4/config
291+
echo "WEBROOT=$WEBROOT" >> ~/.ee4/config
276292
}
277293

278294
updateEE4() {
279295
REPO_URL="${1:-https://github.com/EasyEngine/docker-compose-wordpress}"
280296
VERSION="${2:-master}"
297+
EE_TMP_ROOT="$(mktemp -dt ee-installer-XXXXXX)"
298+
EE_TMP_REPO="$EE_TMP_ROOT/docker-compose-wordpress"
281299

282-
echo "git pull -b "$VERSION" "$REPO_URL""
283-
284-
pushd "$EE_INSTALL_DIR" > /dev/null 2>&1
285-
git pull "$REPO_URL" "$VERSION"
286-
popd > /dev/null 2>&1
300+
echo "Updating ee4"
301+
git clone -b "$VERSION" "$REPO_URL" "$EE_TMP_REPO"
302+
runAsRoot cp -r "$EE_TMP_REPO/*" "$EE_INSTALL_DIR"
303+
rm -rf "$EE_TMP_ROOT"
287304
}
288305

289306
# Execution
290307

291-
#Stop execution on any error
292-
trap "fail_trap" EXIT
293-
set -e
294-
295-
[[ -f ~/.ee4/config ]] && source ~/.ee4/config || initEE4
308+
if [[ -f ~/.ee4/config ]]; then
309+
grep 'WEBROOT' ~/.ee4/config > /dev/null 2>&1
310+
if [[ $? -eq 0 ]]; then
311+
source ~/.ee4/config
312+
else
313+
initEE4
314+
fi
315+
fi
296316

317+
initOS
297318
# Parsing input arguments (if any)
298319
export INPUT_ARGUMENTS="${@}"
299320
set -u
@@ -355,6 +376,17 @@ while [[ $# -gt 0 ]]; do
355376
exit 0
356377
fi
357378
;;
379+
'db')
380+
shift
381+
if [[ $# -ne 0 ]]; then
382+
export SITE_NAME="${1}"
383+
useDbShell
384+
else
385+
echo -e "Please provide name of site."
386+
exit 0
387+
fi
388+
;;
389+
358390
'init')
359391
shift
360392
if [[ $# -ne 0 ]]; then

‎scripts/setup

+19-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ PROJECT_NAME="ee4"
44
REPO_URL="${REPO_URL:-https://github.com/EasyEngine/docker-compose-wordpress}"
55
VERSION="${VERSION:-master}"
66

7+
# initOS discovers the operating system for this system.
8+
initOS() {
9+
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
10+
}
711

812
# runs the given command as root (detects if we are root already)
913
runAsRoot() {
@@ -53,6 +57,14 @@ checkDependencies() {
5357
return $pass
5458
}
5559

60+
initEE4() {
61+
if ! [[ -d ~/.ee4 ]]; then
62+
mkdir ~/.ee4
63+
fi
64+
65+
echo "EE_INSTALL_DIR=$EE_INSTALL_DIR" >> ~/.ee4/config
66+
}
67+
5668
# cloneRepo clones the repository to a temporary location
5769
cloneRepo() {
5870
EE_TMP_ROOT="$(mktemp -dt ee-installer-XXXXXX)"
@@ -63,7 +75,11 @@ cloneRepo() {
6375

6476
# installScript installs the main script.
6577
installScript() {
66-
EE_INSTALL_DIR="${EE_INSTALL_DIR:-/opt/$PROJECT_NAME}"
78+
if [[ "$OS" == 'linux' ]]; then
79+
EE_INSTALL_DIR="${EE_INSTALL_DIR:-/opt/$PROJECT_NAME}"
80+
elif [[ "$OS" == 'darwin' ]]; then
81+
EE_INSTALL_DIR="${EE_INSTALL_DIR:-/Applications/$PROJECT_NAME}"
82+
fi
6783
EE_SCRIPT="scripts/ee4"
6884
EE_SCRIPT_INSTALL_PATH="${EE_SCRIPT_INSTALL_PATH:-/usr/local/bin/ee4}"
6985

@@ -72,6 +88,7 @@ installScript() {
7288
runAsRoot cp -r "$EE_TMP_REPO" "$EE_INSTALL_DIR"
7389
runAsRoot ln -s "$EE_INSTALL_DIR/$EE_SCRIPT" "$EE_SCRIPT_INSTALL_PATH"
7490
echo -e "\nInstall complete!"
91+
initEE4
7592
echo "Run '$PROJECT_NAME' to get started."
7693
}
7794

@@ -92,6 +109,7 @@ testInstalled() {
92109
trap "fail_trap" EXIT
93110
set -e
94111

112+
initOS
95113
if ! testInstalled; then
96114
if ! checkDependencies; then
97115
exit 1;

0 commit comments

Comments
 (0)
This repository has been archived.