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 #19 from wplib/0.16.0
Browse files Browse the repository at this point in the history
0.16.0
  • Loading branch information
MickMake authored May 3, 2018
2 parents 3e81702 + c70c92b commit 6437485
Show file tree
Hide file tree
Showing 91 changed files with 1,006 additions and 835 deletions.
1 change: 0 additions & 1 deletion bin/composer-1.4

This file was deleted.

1 change: 0 additions & 1 deletion bin/composer-1.5

This file was deleted.

1 change: 0 additions & 1 deletion bin/wp-1.0

This file was deleted.

1 change: 0 additions & 1 deletion bin/wp-1.1

This file was deleted.

1 change: 0 additions & 1 deletion bin/wp-1.2

This file was deleted.

1 change: 0 additions & 1 deletion bin/wp-1.3

This file was deleted.

1 change: 0 additions & 1 deletion bin/wp-1.4

This file was deleted.

3 changes: 2 additions & 1 deletion box
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

source /opt/box/includes/functions
source /opt/box/includes/constants
source "${WPLIB_BOX_COLORS_FILE}"

#
#
Expand All @@ -26,7 +27,7 @@ if [ "" == "${error}" ];then

if [ "${WPLIB_BOX_COMMAND}" == "help" ]; then
source "${command_file}"
check_updates_available "$*"
#check_updates_available "$*"
echo 1>&2
exit
fi
Expand Down
6 changes: 2 additions & 4 deletions commands/container
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

DEFAULT_PROJECT="wplib"

source "${WPLIB_BOX_COLORS_FILE}"

# Return codes from functions.
RETURN_OK="0"
RETURN_NO_IMAGE_NAME="1"
Expand Down Expand Up @@ -122,8 +120,8 @@ error_car()
error_cas()
{
RETURN="$?"
echo "$ECHO_PREFIX ${YELLOW}Warning ${CYAN}${IMAGE}${YELLOW} container already stopped.${RESET}"
echo "Look for possible fixes here: ${CYAN}http://wplib.github.io/wplib-box/errors/W018/${RESET}"
echo "$ECHO_PREFIX ${CYAN}${IMAGE}${GREEN} container already stopped.${RESET}"
# echo "Look for possible fixes here: ${CYAN}http://wplib.github.io/wplib-box/errors/W018/${RESET}"
return $RETURN
}

Expand Down
6 changes: 1 addition & 5 deletions commands/database
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
DEFAULT_PROJECT="wplib"

DB_HOST_IP="172.42.0.1"
source "${WPLIB_BOX_COLORS_FILE}"
source "${WPLIB_BOX_COMMANDS_DIR}/readJSON"
source "${WPLIB_BOX_INCLUDES_DIR}/read-json"

trap ctrl_c INT

Expand Down Expand Up @@ -167,9 +166,6 @@ function database_import() {
output "Dropping any prior tables"

if [ ! $(has_arg --dryrun) ]; then
#
# @TODO: Switch this to using Docker
#
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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 18 additions & 15 deletions commands/help
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#!/usr/bin/env bash

echo
echo WPLib Box CLI Usage:
echo
echo " - box <command>"
echo
echo WPLib Box CLI Commands:
echo
for file in $WPLIB_BOX_COMMANDS_DIR/*; do
if [ -f "${file}" ]; then
basename=$(basename "$file")
echo " - ${basename}"
fi
done
echo
echo IMPORTANT! These commands WILL BE CHANGING in a future release of WPLib Box. Be warned!
cat <<EOF
${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}restart${RESET} - Restart Docker containers found in project.json's services object.
box ${GREEN}shutdown${RESET} - Shutdown all Docker containers.
box ${GREEN}status${RESET} - Output status of WPLib Box's standard containers.
box ${GREEN}version${RESET} - Display the current version of this WPLib Box VM.
box ${GREEN}self-update${RESET} - Update this CLI tool to the latest version for this Box version.
box ${GREEN}test${RESET} - Update this CLI tool to the latest version for this Box version.
box [${GREEN}help${RESET}] - Display the above information.
EOF
20 changes: 0 additions & 20 deletions commands/package-delete

This file was deleted.

20 changes: 0 additions & 20 deletions commands/package-install

This file was deleted.

Empty file modified commands/restart
100644 → 100755
Empty file.
7 changes: 3 additions & 4 deletions commands/shutdown
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash

# source "${WPLIB_BOX_COMMANDS_DIR}/readJSON"
# box container stop $mail $proxy $database $webserver $processvm $kvstore $cache $sqladmin $webadmin
box container shutdown

source "${WPLIB_BOX_INCLUDES_DIR}/read-json"
box container stop $database $webserver $processvm $kvstore $cache $sqladmin $webadmin
box container shutdown
Empty file removed commands/site-list
Empty file.
13 changes: 12 additions & 1 deletion commands/startup
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
#!/usr/bin/env bash

source "${WPLIB_BOX_COMMANDS_DIR}/readJSON"
source "${WPLIB_BOX_INCLUDES_DIR}/read-json"
box container start $mail $proxy $database $webserver $processvm $kvstore $cache $sqladmin $webadmin

if [[ ! -e "${WPLIB_BOX_CLI_DIR}/PROVISION" && -e "${WPLIB_BOX_SQL_DIR}/provision.sql" ]] ; then

sudo bash -c "date +'%Y%m%d %H%M%S' > \"${WPLIB_BOX_CLI_DIR}/PROVISION\""
box database import provision.sql

#
# @todo check return value and if error delete ${WPLIB_BOX_CLI_DIR}/PROVISION
#

fi
2 changes: 1 addition & 1 deletion commands/status
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

source "${WPLIB_BOX_COMMANDS_DIR}/readJSON"
source "${WPLIB_BOX_INCLUDES_DIR}/read-json"
box container ls $database $webserver $processvm $kvstore $cache $sqladmin $webadmin
196 changes: 196 additions & 0 deletions commands/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
#!/bin/bash
#
# Master test script.
#


DEFAULT_PROJECT="wplib"

# Return codes from functions.
RETURN_OK="0"
RETURN_NOK="1"
RETURN_NOSCRIPT="2"
RETURN_NOEXEC="3"
VALID_RETURN=42


exec_cmd()
{
EXECTMPFILE="`mktemp /tmp/BoxTest.XXX`"

echo "$ECHO_PREFIX ${RESET} - EXEC: \"${CYAN}$@${RESET}\""
$@ >& $EXECTMPFILE
RETURN="$?"
if [ "$RETURN" == "$RETURN_OK" ]
then
echo "$ECHO_PREFIX ${RESET} - ${GREEN}EXEC: RETURN($RETURN)${RESET}"
cat $EXECTMPFILE | sed "s/^/$ECHO_PREFIX ${RESET} - ${GREEN}EXEC:${RESET} /"
else
echo "$ECHO_PREFIX ${RESET} - ${RED}EXEC: RETURN($RETURN)${RESET}"
cat $EXECTMPFILE | sed "s/^/$ECHO_PREFIX ${RESET} - ${RED}EXEC:${RESET} /"
fi

return $RETURN
}


echo_info()
{
echo "$ECHO_PREFIX ${RESET} - INFO: $@"

return 0
}


echo_warning()
{
echo "$ECHO_PREFIX ${RESET} - ${YELLOW}INFO: $@"

return 1
}


echo_error()
{
echo "$ECHO_PREFIX ${RESET} - ${RED}INFO: $@"

return 2
}


################################################################################
# OK. This is where things get funky, so I need to explain the flow
# 1. THIS script will call scripts within /opt/box/tests.
# 2. Each of those scripts will SOURCE THIS script to pick up some common functions.
#
# So place everything above here that should be included in called scripts.
# This means the following will avoid an endless loop.
if [ "$AVOID_LOOP" == "OK" ]
then
return
fi
AVOID_LOOP="OK"
export AVOID_LOOP


ctrl_c()
{
tput sgr0
echo ""
echo "$ECHO_PREFIX Aborting script."
exit
}

trap ctrl_c INT


error_nts()
{
RETURN="$?"
echo "$ECHO_PREFIX ${YELLOW}Unknown command.${RESET}"
return $RETURN
}


d_ls()
{
for SCRIPT in $ALLSCRIPTS
do
if [[ -x "/opt/box/tests/$SCRIPT" && -f "/opt/box/tests/$SCRIPT" ]]
then
STDOUT="`/opt/box/tests/$SCRIPT info`"
if [ "$?" == "$VALID_RETURN" ]
then
echo "$STDOUT"
fi
fi
done

return $RETURN_OK
}


d_exec()
{
SCRIPT="$1"
shift

if [ ! -r "/opt/box/tests/$SCRIPT" ]
then
echo "$ECHO_PREFIX ${YELLOW}NO SCRIPT - ${CYAN}${SCRIPT}${RESET}"
return $RETURN_NOSCRIPT
fi

if [ ! -x "/opt/box/tests/$SCRIPT" ]
then
echo "$ECHO_PREFIX ${YELLOW}NO EXEC - ${CYAN}${SCRIPT}${RESET}"
return $RETURN_NOEXEC
fi

echo "################################################################################"
echo "$ECHO_PREFIX ${YELLOW}Run${RESET} - ${CYAN}${SCRIPT}${RESET}"
/opt/box/tests/$SCRIPT "$@"
RETURN="$?"
if [ "$RETURN" == "$RETURN_OK" ]
then
echo "$ECHO_PREFIX ${GREEN}OK${RESET} - ${CYAN}${SCRIPT}${RESET}"
else
echo "$ECHO_PREFIX ${RED}FAILED($RETURN)${RESET} - ${CYAN}${SCRIPT}${RESET}"
fi
echo ""

return $RETURN_OK
}


d_help()
{
cat <<EOF
box test - Show this help.
box test ${GREEN}list${RESET} - List all scripts in /opt/box/tests.
box test ${GREEN}run${RESET} - Run all tests in /opt/box/tests.
box test ${GREEN}run [script]${RESET} - Run a specific test.
EOF
}


################################################################################
ALLSCRIPTS="`ls -1 /opt/box/tests`"

CMD="$1"
shift
SCRIPTS="$@"

case $CMD in
'list'|'ls')
d_ls
;;

''|'help')
d_help
;;

'run')
if [ "$1" == "" ]
then
SCRIPTS="$ALLSCRIPTS"
fi
;;

*)
error_nts
d_help
exit 1
;;
esac


for SCRIPT in $SCRIPTS
do
d_exec $SCRIPT
done

rm -f /tmp/BoxTest.*

exit 0

File renamed without changes.
Loading

0 comments on commit 6437485

Please sign in to comment.