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

Commit

Permalink
Merge pull request #20 from wplib/0.16.1
Browse files Browse the repository at this point in the history
0.16.1
  • Loading branch information
MickMake authored May 21, 2018
2 parents e5d55f7 + 50c5f94 commit 6f732ee
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 39 deletions.
2 changes: 1 addition & 1 deletion bin/composer
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ check_image()

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


if [ -x "$EXEC" ]
Expand Down
25 changes: 25 additions & 0 deletions bin/mysql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

check_image()
{
# VERSION="`docker container ls -af label=container.class="database" -f "status=running" --format='wplib/{{.Label "container.name"}}:{{.Label "container.version"}}' 2>/dev/null`"
VERSION="`docker container ls -af label=container.class="database" -f "status=running" --format='{{.Label "container.version"}}' 2>/dev/null`"

if [ "$VERSION" == "" ]
then
echo "WPLib: No MySQL database running."
return 1
fi

MAJORVERSION="`docker container ls -af label=container.class="database" -f "status=running" --format='{{.Label "container.majorversion"}}' 2>/dev/null`"
IP="`docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql-${VERSION}`"

return 0
}


if check_image
then
exec box container shell wplib/mysql:${MAJORVERSION} mysql -h ${IP} "$@"
fi

2 changes: 1 addition & 1 deletion bin/php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ check_image()

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


if [ -x "$EXEC" ]
Expand Down
2 changes: 1 addition & 1 deletion bin/wp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ check_image()

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


if [ -x "$EXEC" ]
Expand Down
10 changes: 9 additions & 1 deletion cli/commands/container
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,15 @@ d_shell()
error_cni
else
# echo "$ECHO_PREFIX ${GREEN}Shell to container: ${CYAN}${IMAGE}${RESET}" 1>&2
docker run --name ${CONTAINER_NAME}-shell --rm -i -t ${IMAGE_NETWORK} ${IMAGE_ARGS} ${IMAGE_VOLUMES} ${IMAGE} "$@"
if [ -t 0 ]
then
# TTY allocated.
docker run --name ${CONTAINER_NAME}-shell --rm -i -t ${IMAGE_NETWORK} ${IMAGE_ARGS} ${IMAGE_VOLUMES} ${IMAGE} "$@"
else
# TTY not allocated.
docker run --name ${CONTAINER_NAME}-exec --rm -i ${IMAGE_NETWORK} ${IMAGE_ARGS} ${IMAGE_VOLUMES} ${IMAGE} "$@"
fi

if [ "$?" == "1" ]
then
error_ccbi
Expand Down
23 changes: 14 additions & 9 deletions cli/commands/database
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,29 @@ function database_import() {

fi

if [ ! $(has_arg --no-backup) ]; then
database_backup "${basefile}.bak"

if [ $? -ne 0 ]; then
output "Error when backing up to ${basefile}.bak"
return 4
fi
fi

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

if [ ! $(has_arg --dryrun) ]; then
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
cat /tmp/mysql-table-list.txt | while read table
do
output "Dropping any prior tables"

if [ ! $(has_arg --dryrun) ]; then
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
cat /tmp/mysql-table-list.txt | while read table
do
box container exec ${database} mysql -h ${DB_HOST_IP} -u wordpress -pwordpress -e "drop table $table" wordpress 2>&1 | grep -v "Warning:"
done
rm /tmp/mysql-table-list.txt
done
rm /tmp/mysql-table-list.txt
fi
output "Tables dropped"

fi
output "Tables dropped"

if [ "" != "$(cat "${importfilepath}" | grep "utf8mb4_unicode_520_ci")" ]; then
#
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/help
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ${YELLOW}WPLib Box ${GREEN}CLI${RESET} usage:
box ${GREEN}database${RESET} [<args>] - Manage databases.
box ${GREEN}container${RESET} [<args>] - Manage Docker containers.
box ${GREEN}start${RESET} - Start Docker containers found in project.json's services object.
box ${GREEN}startup${RESET} - Start Docker containers found in project.json's services object.
box ${GREEN}restart${RESET} - Restart Docker containers found in project.json's services object.
box ${GREEN}shutdown${RESET} - Shutdown all Docker containers.
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/self-update
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ EOF


chmod a+x /tmp/self-update.$$
exec bash /tmp/self-update.$$
exec sudo /tmp/self-update.$$
4 changes: 2 additions & 2 deletions cli/commands/shutdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

source "${WPLIB_BOX_INCLUDES_DIR}/read-json"
box container stop $database $webserver $processvm $kvstore $cache $sqladmin $webadmin
# box container shutdown
# box container stop $database $webserver $processvm $kvstore $cache $sqladmin $webadmin
box container shutdown
22 changes: 0 additions & 22 deletions commands/help

This file was deleted.

159 changes: 159 additions & 0 deletions etc/box-completion.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#/usr/bin/env bash

################################################################################
# Command completion for 'box'
_box()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}


case "${COMP_WORDS[1]}" in
'container')
# /opt/box/bin/box container help
_box_container
return 0
;;

'database')
COMPREPLY=($(compgen -W "backup import chunk unchunk credentials dbname username password" -- $cur))
return 0
;;

'startup')
COMPREPLY=($(compgen -W "" -- $cur))
return 0
;;

'restart')
COMPREPLY=($(compgen -W "" -- $cur))
return 0
;;

'shutdown')
COMPREPLY=($(compgen -W "" -- $cur))
return 0
;;

'status')
COMPREPLY=($(compgen -W "" -- $cur))
return 0
;;

'shell')
COMPREPLY=($(compgen -W "" -- $cur))
return 0
;;

'version')
COMPREPLY=($(compgen -W "" -- $cur))
return 0
;;

'self-update')
COMPREPLY=($(compgen -W "$(git --git-dir=/opt/box/.git tag)" -- $cur))
return 0
;;

'test')
COMPREPLY=($(compgen -W "$(find /opt/box/cli/tests -maxdepth 1 -type f -printf '%f\n')" -- $cur))
return 0
;;

'help')
COMPREPLY=($(compgen -W "" -- $cur))
return 0
;;
esac

COMPREPLY=($(compgen -W "database container startup restart shutdown status shell version self-update test help" -- $cur))
}
complete -F _box box



################################################################################
# Command completion for 'box container'
_box_container()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}

case "$prev" in
'stop'|'restart')
_box_container_running
return 0
;;

'start'|'restart'|'rm'|'clean'|'refresh')
_box_container_stopped
return 0
;;

'ls'|'inspect'|'log')
_box_container_all
return 0
;;

'pull'|'install')
_box_container_dockerhub
return 0
;;
esac

COMPREPLY=($(compgen -W "install ls start stop rm clean refresh update show shutdown reallyclean inspect log pull" -- $cur))
return 0
}

_box_container_running()
{
local cur=${COMP_WORDS[COMP_CWORD]}

COMPREPLY=($(compgen -W "$(docker container ls -af label=container.project=wplib -f status=running --format='{{.Image}}')" -- $cur))
return 0
}


_box_container_stopped()
{
local cur=${COMP_WORDS[COMP_CWORD]}

COMPREPLY=($(compgen -W "$(docker container ls -af label=container.project=wplib -f status=created -f status=exited --format='{{.Image}}')" -- $cur))
return 0
}


_box_container_all()
{
local cur=${COMP_WORDS[COMP_CWORD]}

COMPREPLY=($(compgen -W "$(docker container ls -af label=container.project=wplib --format='{{.Image}}')" -- $cur))
return 0
}


_box_container_dockerhub()
{
local IMAGES
local IMAGE_NAME
local VERSIONS
local IMAGE_VERSION
local REPLY
local cur=${COMP_WORDS[COMP_CWORD]}

IMAGES="`jq -r '.results|.[]|.name' /opt/box/etc/respositories.json`"
for IMAGE_NAME in $IMAGES
do
VERSIONS="`jq -r '.results|.[]|.name' /opt/box/etc/images/${IMAGE_NAME}.json`"
for IMAGE_VERSION in $VERSIONS
do
REPLY="$REPLY wplib/${IMAGE_NAME}:$IMAGE_VERSION"
done

done

COMPREPLY=($(compgen -W "$REPLY" -- $cur))
return 0
}


0 comments on commit 6f732ee

Please sign in to comment.