Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit 6f732ee

Browse files
authored
Merge pull request #20 from wplib/0.16.1
0.16.1
2 parents e5d55f7 + 50c5f94 commit 6f732ee

File tree

11 files changed

+214
-39
lines changed

11 files changed

+214
-39
lines changed

bin/composer

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ check_image()
2222

2323
SCRIPT="`basename $0`"
2424
REQVERS="`echo $SCRIPT | sed -r 's/composer-([0-9]*\.[0-9]*)/\1/'`"
25-
EXEC="/usr/local/bin/composer-$REQVERS"
25+
EXEC="/opt/box/bin/composer-$REQVERS"
2626

2727

2828
if [ -x "$EXEC" ]

bin/mysql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
check_image()
4+
{
5+
# VERSION="`docker container ls -af label=container.class="database" -f "status=running" --format='wplib/{{.Label "container.name"}}:{{.Label "container.version"}}' 2>/dev/null`"
6+
VERSION="`docker container ls -af label=container.class="database" -f "status=running" --format='{{.Label "container.version"}}' 2>/dev/null`"
7+
8+
if [ "$VERSION" == "" ]
9+
then
10+
echo "WPLib: No MySQL database running."
11+
return 1
12+
fi
13+
14+
MAJORVERSION="`docker container ls -af label=container.class="database" -f "status=running" --format='{{.Label "container.majorversion"}}' 2>/dev/null`"
15+
IP="`docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql-${VERSION}`"
16+
17+
return 0
18+
}
19+
20+
21+
if check_image
22+
then
23+
exec box container shell wplib/mysql:${MAJORVERSION} mysql -h ${IP} "$@"
24+
fi
25+

bin/php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ check_image()
2222

2323
SCRIPT="`basename $0`"
2424
REQVERS="`echo $SCRIPT | sed -r 's/php-([0-9]*\.[0-9]*)/\1/'`"
25-
EXEC="/usr/local/bin/php-$REQVERS"
25+
EXEC="/opt/box/bin/php-$REQVERS"
2626

2727

2828
if [ -x "$EXEC" ]

bin/wp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ check_image()
2222

2323
SCRIPT="`basename $0`"
2424
REQVERS="`echo $SCRIPT | sed -r 's/wp-([0-9]*\.[0-9]*)/\1/'`"
25-
EXEC="/usr/local/bin/wp-$REQVERS"
25+
EXEC="/opt/box/bin/wp-$REQVERS"
2626

2727

2828
if [ -x "$EXEC" ]

cli/commands/container

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,15 @@ d_shell()
312312
error_cni
313313
else
314314
# echo "$ECHO_PREFIX ${GREEN}Shell to container: ${CYAN}${IMAGE}${RESET}" 1>&2
315-
docker run --name ${CONTAINER_NAME}-shell --rm -i -t ${IMAGE_NETWORK} ${IMAGE_ARGS} ${IMAGE_VOLUMES} ${IMAGE} "$@"
315+
if [ -t 0 ]
316+
then
317+
# TTY allocated.
318+
docker run --name ${CONTAINER_NAME}-shell --rm -i -t ${IMAGE_NETWORK} ${IMAGE_ARGS} ${IMAGE_VOLUMES} ${IMAGE} "$@"
319+
else
320+
# TTY not allocated.
321+
docker run --name ${CONTAINER_NAME}-exec --rm -i ${IMAGE_NETWORK} ${IMAGE_ARGS} ${IMAGE_VOLUMES} ${IMAGE} "$@"
322+
fi
323+
316324
if [ "$?" == "1" ]
317325
then
318326
error_ccbi

cli/commands/database

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,24 +156,29 @@ function database_import() {
156156

157157
fi
158158

159+
if [ ! $(has_arg --no-backup) ]; then
159160
database_backup "${basefile}.bak"
160-
161161
if [ $? -ne 0 ]; then
162162
output "Error when backing up to ${basefile}.bak"
163163
return 4
164+
fi
164165
fi
165166

166-
output "Dropping any prior tables"
167+
if [ ! $(has_arg --no-droptables) ]; then
167168

168-
if [ ! $(has_arg --dryrun) ]; then
169-
box container exec ${database} mysql -h ${DB_HOST_IP} -u wordpress -pwordpress -Nse "show tables;" wordpress 2>&1 | grep -v "Warning:" > /tmp/mysql-table-list.txt
170-
cat /tmp/mysql-table-list.txt | while read table
171-
do
169+
output "Dropping any prior tables"
170+
171+
if [ ! $(has_arg --dryrun) ]; then
172+
box container exec ${database} mysql -h ${DB_HOST_IP} -u wordpress -pwordpress -Nse "show tables;" wordpress 2>&1 | grep -v "Warning:" > /tmp/mysql-table-list.txt
173+
cat /tmp/mysql-table-list.txt | while read table
174+
do
172175
box container exec ${database} mysql -h ${DB_HOST_IP} -u wordpress -pwordpress -e "drop table $table" wordpress 2>&1 | grep -v "Warning:"
173-
done
174-
rm /tmp/mysql-table-list.txt
176+
done
177+
rm /tmp/mysql-table-list.txt
178+
fi
179+
output "Tables dropped"
180+
175181
fi
176-
output "Tables dropped"
177182

178183
if [ "" != "$(cat "${importfilepath}" | grep "utf8mb4_unicode_520_ci")" ]; then
179184
#

cli/commands/help

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ${YELLOW}WPLib Box ${GREEN}CLI${RESET} usage:
77
box ${GREEN}database${RESET} [<args>] - Manage databases.
88
box ${GREEN}container${RESET} [<args>] - Manage Docker containers.
99
10-
box ${GREEN}start${RESET} - Start Docker containers found in project.json's services object.
10+
box ${GREEN}startup${RESET} - Start Docker containers found in project.json's services object.
1111
box ${GREEN}restart${RESET} - Restart Docker containers found in project.json's services object.
1212
box ${GREEN}shutdown${RESET} - Shutdown all Docker containers.
1313

cli/commands/self-update

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ EOF
5656

5757

5858
chmod a+x /tmp/self-update.$$
59-
exec bash /tmp/self-update.$$
59+
exec sudo /tmp/self-update.$$

cli/commands/shutdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
22

33
source "${WPLIB_BOX_INCLUDES_DIR}/read-json"
4-
box container stop $database $webserver $processvm $kvstore $cache $sqladmin $webadmin
5-
# box container shutdown
4+
# box container stop $database $webserver $processvm $kvstore $cache $sqladmin $webadmin
5+
box container shutdown

commands/help

Lines changed: 0 additions & 22 deletions
This file was deleted.

etc/box-completion.bash

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#/usr/bin/env bash
2+
3+
################################################################################
4+
# Command completion for 'box'
5+
_box()
6+
{
7+
local cur=${COMP_WORDS[COMP_CWORD]}
8+
local prev=${COMP_WORDS[COMP_CWORD-1]}
9+
10+
11+
case "${COMP_WORDS[1]}" in
12+
'container')
13+
# /opt/box/bin/box container help
14+
_box_container
15+
return 0
16+
;;
17+
18+
'database')
19+
COMPREPLY=($(compgen -W "backup import chunk unchunk credentials dbname username password" -- $cur))
20+
return 0
21+
;;
22+
23+
'startup')
24+
COMPREPLY=($(compgen -W "" -- $cur))
25+
return 0
26+
;;
27+
28+
'restart')
29+
COMPREPLY=($(compgen -W "" -- $cur))
30+
return 0
31+
;;
32+
33+
'shutdown')
34+
COMPREPLY=($(compgen -W "" -- $cur))
35+
return 0
36+
;;
37+
38+
'status')
39+
COMPREPLY=($(compgen -W "" -- $cur))
40+
return 0
41+
;;
42+
43+
'shell')
44+
COMPREPLY=($(compgen -W "" -- $cur))
45+
return 0
46+
;;
47+
48+
'version')
49+
COMPREPLY=($(compgen -W "" -- $cur))
50+
return 0
51+
;;
52+
53+
'self-update')
54+
COMPREPLY=($(compgen -W "$(git --git-dir=/opt/box/.git tag)" -- $cur))
55+
return 0
56+
;;
57+
58+
'test')
59+
COMPREPLY=($(compgen -W "$(find /opt/box/cli/tests -maxdepth 1 -type f -printf '%f\n')" -- $cur))
60+
return 0
61+
;;
62+
63+
'help')
64+
COMPREPLY=($(compgen -W "" -- $cur))
65+
return 0
66+
;;
67+
esac
68+
69+
COMPREPLY=($(compgen -W "database container startup restart shutdown status shell version self-update test help" -- $cur))
70+
}
71+
complete -F _box box
72+
73+
74+
75+
################################################################################
76+
# Command completion for 'box container'
77+
_box_container()
78+
{
79+
local cur=${COMP_WORDS[COMP_CWORD]}
80+
local prev=${COMP_WORDS[COMP_CWORD-1]}
81+
82+
case "$prev" in
83+
'stop'|'restart')
84+
_box_container_running
85+
return 0
86+
;;
87+
88+
'start'|'restart'|'rm'|'clean'|'refresh')
89+
_box_container_stopped
90+
return 0
91+
;;
92+
93+
'ls'|'inspect'|'log')
94+
_box_container_all
95+
return 0
96+
;;
97+
98+
'pull'|'install')
99+
_box_container_dockerhub
100+
return 0
101+
;;
102+
esac
103+
104+
COMPREPLY=($(compgen -W "install ls start stop rm clean refresh update show shutdown reallyclean inspect log pull" -- $cur))
105+
return 0
106+
}
107+
108+
_box_container_running()
109+
{
110+
local cur=${COMP_WORDS[COMP_CWORD]}
111+
112+
COMPREPLY=($(compgen -W "$(docker container ls -af label=container.project=wplib -f status=running --format='{{.Image}}')" -- $cur))
113+
return 0
114+
}
115+
116+
117+
_box_container_stopped()
118+
{
119+
local cur=${COMP_WORDS[COMP_CWORD]}
120+
121+
COMPREPLY=($(compgen -W "$(docker container ls -af label=container.project=wplib -f status=created -f status=exited --format='{{.Image}}')" -- $cur))
122+
return 0
123+
}
124+
125+
126+
_box_container_all()
127+
{
128+
local cur=${COMP_WORDS[COMP_CWORD]}
129+
130+
COMPREPLY=($(compgen -W "$(docker container ls -af label=container.project=wplib --format='{{.Image}}')" -- $cur))
131+
return 0
132+
}
133+
134+
135+
_box_container_dockerhub()
136+
{
137+
local IMAGES
138+
local IMAGE_NAME
139+
local VERSIONS
140+
local IMAGE_VERSION
141+
local REPLY
142+
local cur=${COMP_WORDS[COMP_CWORD]}
143+
144+
IMAGES="`jq -r '.results|.[]|.name' /opt/box/etc/respositories.json`"
145+
for IMAGE_NAME in $IMAGES
146+
do
147+
VERSIONS="`jq -r '.results|.[]|.name' /opt/box/etc/images/${IMAGE_NAME}.json`"
148+
for IMAGE_VERSION in $VERSIONS
149+
do
150+
REPLY="$REPLY wplib/${IMAGE_NAME}:$IMAGE_VERSION"
151+
done
152+
153+
done
154+
155+
COMPREPLY=($(compgen -W "$REPLY" -- $cur))
156+
return 0
157+
}
158+
159+

0 commit comments

Comments
 (0)