Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial port of the existing bash library functions.

  • Loading branch information...
commit d26b493348cf6731536941242c39814abfcb0186 0 parents
@freeformsystems authored
7 .gitignore
@@ -0,0 +1,7 @@
+private
+.DS_Store
+target
+node_modules
+indexes
+*.log
+erl_crash.dump
47 LICENSE
@@ -0,0 +1,47 @@
+Copyright 2012 Freeform Systems and other contributors
+http://github.com/freeformsystems/xpm
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+NO WARRANTY OR LIABILITY
+
+YOU EXPRESSLY AGREE THAT DOWNLOADING THE SOFTWARE AND ANY USE OF THE
+SOFTWARE IS AT YOUR OWN RISK. NO WARRANTY, REPRESENTATION, CONDITION,
+UNDERTAKING OR TERM - EXPRESS OR IMPLIED, STATUTORY OR OTHERWISE -
+INCLUDING BUT NOT LIMITED TO THE CONDITION, QUALITY, DURABILITY,
+PERFORMANCE, ACCURACY, STABILITY, RELIABILITY, NON-INFRINGEMENT,
+MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE OR USE OF THE
+SOFTWARE IS GIVEN OR ASSUMED BY FREEFORM SYSTEMS LTD. ALL SUCH
+WARRANTIES, REPRESENTATIONS, CONDITIONS, UNDERTAKINGS AND TERMS ARE
+HEREBY EXCLUDED. FREEFORM SYSTEMS LTD MAKES NO WARRANTY THAT THE
+SOFTWARE WILL MEET YOUR REQUIREMENTS, OR THAT IT WILL BE UNINTERRUPTED,
+TIMELY, SECURE, OR ERROR FREE; IN NO EVENT SHALL FREEFORM SYSTEMS LTD
+BE LIABLE TO ANY PARTY FOR ANY DAMAGES INCLUDING WITHOUT LIMITATION,
+ANY DIRECT, INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, DAMAGES FOR LOSS OF BUSINESS
+PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR INFORMATION, LOSS
+OF PROFITS AND SAVINGS AND THE LIKE), OR ANY OTHER DAMAGES ARISING -
+IN ANY WAY, SHAPE OR FORM - OUT OF THE AVAILABILITY, USE, RELIANCE ON,
+INABILITY TO UTILIZE OR IMPROPER USE OF THE SOFTWARE EVEN IF FREEFORM
+SYSTEMS LTD SHALL HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES,
+AND REGARDLESS OF THE FORM OF ACTION, WHETHER IN CONTRACT, TORT, OR
+OTHERWISE. BECAUSE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR
+LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, THE ABOVE EXCLUSIONS
+OF INCIDENTAL AND CONSEQUENTIAL DAMAGES MAY NOT APPLY TO YOU.
39 README.md
@@ -0,0 +1,39 @@
+# Strike
+
+A suite of utility functions for *bash* programs.
+
+### lib
+
+The main library functions are located in the `lib` directory.
+
+### test
+
+Tests are located in the `test` directory, you can run all tests with:
+
+ ./bin/runner
+
+When writing tests for failure situations; those that expect a non-zero exit status to indicate that the test has passed must prefix the name of the test program with `fail`.
+
+## Conventions
+
+Functions in `bash` can only return integer values so the convention is to assign a function's return value to the `_result` global variable which can subsequently be accessed with `$_result`.
+
+## Dependencies
+
+In addtion to `bash` external program dependencies are listed here:
+
+* `basename`
+* `dirname`
+* `type`
+* `id`
+* `echo`
+* `find`
+* `tar`
+* `zip`
+* `du`
+* `ln`
+* `rm`
+* `cd`
+* `cp`
+* `mkdir`
+* `touch`
81 bin/runner
@@ -0,0 +1,81 @@
+#!/usr/bin/env bash
+
+#get absolute path to running script
+name=`basename $0`;
+abspath=$(cd ${BASH_SOURCE[0]%/*} && echo $PWD/${0##*/});
+exedir=`dirname "$abspath"`;
+libdir="$exedir/../lib";
+testdir="$exedir/../test";
+
+export PROGRAM_NAME="test-runner";
+
+#bring in the shared libraries
+source "$libdir/shared";
+
+source "$exedir/../test/lib/dir";
+
+#if [ -t 1 ]; then
+# echo "IS TERMINAL";
+#fi
+
+#bar="variable";
+#var="this is a messages with spaces and a $bar";
+#echo "$var";
+
+#usage "this is a %s message %s" "usage" "'for you'";
+#usage_description "this is a %s message %s" "description" "'for you'";
+#info "this is a %s message %s" "info" 'for you';
+#warn "this is a %s warning %s" "strong" "'for you'";
+#error "this is a %s error %s" "bad" "'for you'";
+#quit 1 "this is a %s error %s" "fatal" "'for you'";
+#success "this is a %s message %s" "success" "'for you'";
+#exit;
+
+#info "-h";
+#exit;
+
+test_runner_dir $testdir;
+
+#usage "this %s a %s" "is" "test";
+
+#get_git_commit_message;
+#echo "git message: $_result";
+
+#get_git_commit_message "initial commit";
+#echo "custom git message: $_result";
+
+#git_test_dir="/Users/cyberfunk/Desktop/git-test";
+#rmdir "$git_test_dir";
+#mkdirp "$git_test_dir";
+
+#git_repository "$git_test_dir";
+#git_init "$git_test_dir";
+#echo "$RANDOM" > "$git_test_dir/test-file";
+#git_status "$git_test_dir";
+#echo "git status after add is $?";
+#touch "$git_test_dir/log-file.log";
+#touch "$git_test_dir/pid-file.pid";
+#git_ignore "$git_test_dir" "*.log" "*.pid";
+#git_add "$git_test_dir";
+#git_commit "$git_test_dir" "initial commit";
+#echo "git status after commit is $?";
+#git_submodule_add "$git_test_dir" "$LIBRARY_REPO" "$LIBRARY_SUBMODULE_REPO_PATH";
+#git_add "$git_test_dir";
+#git_commit "$git_test_dir" "added library sub-module";
+
+#result=`git ls-remote --tags git@github.com:stax/server.git`;
+#echo "git remote tag list $result : $?";
+
+#result=`git ls-remote --tags git@github.com:stax/stack.git`;
+#echo "git remote tag list $result : $?";
+
+#git_ls_remote_tags "git@github.com:stax/server.git";
+#echo "got remote tags: $_result";
+#git_find_tag "dev-0.0.1" "$_result";
+
+#TODO: ensure this actually checks that all tests passed
+if [ $? -eq 0 ]; then
+ success "tests in %s passed" "$testdir";
+fi
+
+quit 1 "tests in %s failed" "$testdir";
40 lib/archive-util
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+
+######################################################################
+# archive-utils
+#
+# Utilties for working with the archives.
+######################################################################
+
+function extract_tar {
+ local archive="$1";
+ local target="$2";
+
+ #change into the target directory for extraction
+ if [ `pwd` != "$target" ]; then
+ cdir "$target" > /dev/null;
+ fi
+
+ info "$EXTRACTING" "`basename $archive`" "$target";
+
+ #extract the archive
+ tar xzf "$archive" --directory="$target";
+}
+
+function create_tar {
+ local archive="$1";
+ local target="$2";
+
+ local dir=`dirname "$target"`;
+ local name=`basename "$target"`;
+
+ #change into the target directory for extraction
+ if [ `pwd` != "$dir" ]; then
+ cdir "$dir" > /dev/null;
+ fi
+
+ info "$ARCHIVING" "$archive" "$target";
+
+ #create the archive
+ tar czf "$archive" "$name";
+}
22 lib/clean-util
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+######################################################################
+# clean-util
+#
+# Utilities for cleaning target directories.
+######################################################################
+
+function clean_target_directories {
+ local target_dir="$1";
+ expand_path "$target_dir";
+ target_dir="$_result";
+
+ info "$CLEANING" "$target_dir/target";
+
+ #find target build directories
+ local targets=`find $target_dir -name target -type d`;
+ for f in $targets
+ do
+ rmdir "$f";
+ done
+}
184 lib/constants
@@ -0,0 +1,184 @@
+#!/usr/bin/env bash
+
+######################################################################
+# common
+#
+# Common variables for all programs.
+######################################################################
+
+#keep track of the original working directory
+OWD=$PWD;
+
+#target shell that must be in use
+TSHELL="bash";
+
+DEFAULT_HOST="stax.net";
+DB_HOST="db.${DEFAULT_HOST}";
+DEFAULT_URL_SCHEME="https://";
+
+WWW_URL="${DEFAULT_URL_SCHEME}www.${DEFAULT_HOST}";
+DB_URL="${DEFAULT_URL_SCHEME}${DB_HOST}";
+
+DB_AUTH_USER="appserver";
+
+#the primary user name
+USER_NAME="stax";
+
+#the primary group name
+GROUP_NAME="stax";
+
+#full os specific type and host type
+OS_INSTALL="$OSTYPE-$HOSTTYPE";
+
+#darwin12-x86_64 == Mountain Lion (bash 3.2.48) ?
+#darwin10.0-x86_64 == Snow Leopard (10.6.8) (bash 3.2.48)
+#darwin10.8.0-i386 == Snow Leopard (10.6.8) (bash 4.2)
+
+if [ "$OS_INSTALL" == "darwin12-x86_64" ] || [ "$OS_INSTALL" == "darwin10.8.0-i386" ];
+ then OS_INSTALL="darwin10.0-x86_64";
+fi
+
+#darwin12-x86_64
+
+#common paths
+INSTALL_NAME="stax";
+
+#the default environment used when installing
+INSTALL_ENV="production";
+
+DEFAULT_INSTALL_PREFIX="/usr/local";
+DEFAULT_VAR_PREFIX="/usr/local/var";
+DEFAULT_SRC_PREFIX="/usr/local/src";
+
+#TODO: remove this duplication?
+INSTALL_PATH="$DEFAULT_INSTALL_PREFIX";
+
+BASE_PATH="$DEFAULT_INSTALL_PREFIX/$INSTALL_NAME";
+
+#the name of the folder used to store user home directories
+USERS_NAME="users";
+
+#the name of the file used for user-specific path configuration
+PATHS_CONF_NAME=".stax-paths.json";
+
+#
+USERS_HOME_PATH="$DEFAULT_VAR_PREFIX/$INSTALL_NAME/$USERS_NAME";
+
+#common names used
+BIN_NAME="bin";
+SBIN_NAME="sbin";
+VAR_NAME="var";
+RUN_NAME="run";
+LOG_NAME="log";
+TMP_NAME="tmp";
+LIB_NAME="lib";
+DB_NAME="db";
+CONF_NAME="conf";
+APP_NAME="app";
+PRIVATE_NAME="private";
+PUBLIC_NAME="public";
+KEYS_NAME="keys";
+REPOS_NAME="repos";
+STACK_NAME="stack";
+STATIC_NAME="static";
+SERVER_NAME="server";
+WEBAPP_NAME="webapp";
+DBTOOLS_NAME="dbtools";
+DATA_NAME="data";
+INSTALLERS_NAME="installers";
+PREREQUISITES_NAME="prerequisites";
+EXTRAS_NAME="extras";
+MODULES_NAME="modules";
+CERTS_NAME="certs";
+SOCK_NAME="sock";
+WWW_NAME="www";
+
+COUCHDB_NAME="couchdb";
+REDIS_NAME="redis";
+NGINX_NAME="nginx";
+NODE_NAME="node";
+
+#core paths for installation
+REPO_PATH="$BASE_PATH/$REPOS_NAME";
+STACK_PATH="$BASE_PATH/$STACK_NAME";
+
+#remote repositories
+LIBRARY_REPO="git@github.com:stax/library.git";
+STATIC_REPO="git@github.com:stax/static.git";
+SERVER_REPO="git@github.com:stax/server.git";
+
+#TODO: default tags to use for the various repositories
+#STACK_TAG="dev-0.0.1";
+#STATIC_TAG="dev-0.0.1";
+#SERVER_TAG="dev-0.0.1";
+
+LIBRARY_SUBMODULE_REPO_PATH="support/library";
+
+#the private repository should be local for the moment
+PRIVATE_REPO="$HOME/git/$INSTALL_NAME/$PRIVATE_NAME";
+
+#name of the rc file
+DROP_RC=".droprc";
+
+#TODO: ensure these paths are reconfigured after a prefix is set once a --prefix argument is integrated
+
+#preparation files
+INSTALL_PRIVATE_PATH="$BASE_PATH/$PRIVATE_NAME";
+INSTALL_BIN_PATH="$BASE_PATH/$BIN_NAME";
+INSTALL_TMP_PATH="$BASE_PATH/$TMP_NAME";
+INSTALL_DATA_PATH="$BASE_PATH/$DATA_NAME";
+INSTALL_SBIN_PATH="$BASE_PATH/$SBIN_NAME";
+INSTALL_VAR_PATH="$BASE_PATH/$VAR_NAME";
+INSTALL_LOG_PATH="$INSTALL_VAR_PATH/$LOG_NAME";
+INSTALL_DB_PATH="$DEFAULT_VAR_PREFIX/$DB_NAME";
+INSTALL_DB_REDIS_PATH="$INSTALL_DB_PATH/$REDIS_NAME";
+INSTALL_DB_COUCHDB_PATH="$INSTALL_DB_PATH/$COUCHDB_NAME";
+INSTALL_LOG_INSTALLERS_PATH="$INSTALL_LOG_PATH/$INSTALLERS_NAME";
+INSTALL_RUN_PATH="$INSTALL_VAR_PATH/$RUN_NAME";
+INSTALL_CONF_PATH="$INSTALL_VAR_PATH/$CONF_NAME";
+INSTALL_PUBLIC_PATH="$BASE_PATH/$PUBLIC_NAME";
+
+INSTALL_STATIC_PATH="$BASE_PATH/$STATIC_NAME";
+
+CONSOLE_PLIST="$INSTALL_DATA_PATH/plist/com.stax.console.plist";
+
+#web application modules
+INSTALL_SERVER_PATH="$BASE_PATH/$SERVER_NAME";
+INSTALL_WEBAPP_PATH="$INSTALL_SERVER_PATH/$WEBAPP_NAME";
+INSTALL_DBTOOLS_PATH="$INSTALL_SERVER_PATH/$DBTOOLS_NAME";
+
+#pid files for application servers
+INSTALL_APP_RUN_PATH="$INSTALL_RUN_PATH/$APP_NAME";
+INSTALL_APP_SOCK_PATH="$INSTALL_RUN_PATH/$SOCK_NAME";
+
+#symlink for the current configuration
+INSTALL_CONF_SYM_LINK="$BASE_PATH/$CONF_NAME";
+
+#root settings
+ROOT_USER="root";
+
+#node settings
+NODE_USER="stax-app";
+INSTALL_NODE_CONF_PATH="$INSTALL_PRIVATE_PATH/$APP_NAME/$CONF_NAME";
+
+#nginx settings
+NGINX_USER="stax-www";
+NGINX_PID_FILE="$INSTALL_RUN_PATH/${NGINX_NAME}.pid";
+NGINX_CERTS="$INSTALL_PRIVATE_PATH/$CERTS_NAME/$NGINX_NAME";
+
+#redis settings
+REDIS_USER="stax-db";
+REDIS_PID_FILE="$INSTALL_RUN_PATH/${REDIS_NAME}.pid";
+REDIS_LOG="$INSTALL_LOG_PATH/redis.log";
+REDIS_CONF="$INSTALL_CONF_SYM_LINK/redis.conf";
+
+#couchdb settings
+COUCHDB_USER="stax-db";
+COUCHDB_PID_FILE="$INSTALL_RUN_PATH/${COUCHDB_NAME}.pid";
+COUCHDB_STD_OUT_LOG="$INSTALL_LOG_PATH/${COUCHDB_NAME}.stdout.log";
+COUCHDB_STD_ERR_LOG="$INSTALL_LOG_PATH/${COUCHDB_NAME}.stderr.log";
+COUCHDB_DIR="$INSTALL_DB_PATH/couchdb";
+COUCHDB_LOG="$INSTALL_LOG_PATH/couch.log";
+#path to couchdb configuration files
+COUCHDB_CONFIG_PATH="$INSTALL_CONF_SYM_LINK/$COUCHDB_NAME";
+COUCHDB_CONFIG_ADMINS_PATH="$INSTALL_PRIVATE_PATH/$DB_NAME/$COUCHDB_NAME/admins.ini";
37 lib/exit-codes
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+
+######################################################################
+# exit-codes
+#
+# Variables containing program exit codes.
+######################################################################
+
+#success exit code
+SUCCESS=0;
+
+#error exit codes
+ERR_WRONG_SHELL=100;
+
+#missing a program dependency
+ERR_MISSING_PROGRAM=101;
+
+#error while extracting an archive
+ERR_ARCHIVE_EXTRACT_FAIL=102;
+
+#missing installation scripts for a platform - unsupported platform
+ERR_MISSING_PLATFORM_INSTALL=103;
+
+#missing source path arguments for an installation script
+ERR_MISSING_SOURCE_PATH=104;
+
+#an installation source path is not a valid directory that is both executable and writable
+ERR_INVALID_SOURCE_PATH=105;
+
+#missing the full name argument for an installation script
+ERR_MISSING_FULL_NAME=106;
+
+#missing the short name argument for an installation script
+ERR_MISSING_SHORT_NAME=107;
+
+#TODO
+ERR_MISSING_PROGRAM_LIST=200;
207 lib/fs
@@ -0,0 +1,207 @@
+#!/usr/bin/env bash
+
+######################################################################
+# fs
+#
+# Utilties for working with the filesystem.
+######################################################################
+
+######################################################################
+# Tests if a path exists and is a directory.
+#
+# $1 The path to the directory.
+######################################################################
+function directory {
+ info "$CHECK_DIRECTORY" "$1";
+ test -d "$1";
+ #if [ -d $1 ]; then
+ # return 0;
+ #fi
+ #return 1;
+}
+
+######################################################################
+# Copies a file or directory recursively forcing an overwrite.
+#
+# cp -rf
+#
+# $1 The source file or folder.
+# $2 The destination file or parent folder.
+######################################################################
+function copy {
+ local src="$1";
+ local dest="$2";
+ cp -rf "$src" "$dest" > /dev/null 2>&1;
+ if [ $? -eq 0 ]; then
+ info "$COPY_SUCCESS" "$src" "$dest";
+ return 0;
+ else
+ error "$COPY_ERROR" "$src" "$dest";
+ return 1;
+ fi
+}
+
+######################################################################
+# Moves a file or directory.
+#
+# mv
+#
+# $1 The source file or folder.
+# $2 The destination file or parent folder.
+######################################################################
+function move {
+ local src="$1";
+ local dest="$2";
+ mv "$src" "$dest" > /dev/null 2>&1;
+ if [ $? -eq 0 ]; then
+ info "$MOVE_SUCCESS" "$src" "$dest";
+ return 0;
+ else
+ error "$MOVE_ERROR" "$src" "$dest";
+ return 1;
+ fi
+}
+
+######################################################################
+# Creates a soft symbolic link.
+#
+# If a symbolic link already exists then it is removed prior to
+# creation of the new symbolic link.
+#
+# ln -s
+#
+# $1 The source for the symbolic link.
+# $2 The destination for the symbolic link.
+######################################################################
+function symlink {
+ local src="$1";
+ local dest="$2";
+ #symlink exists, attempt to remove it before creation
+ if [ -h "$dest" ]; then
+ rm "$dest";
+ fi
+ ln -s "$src" "$dest" > /dev/null 2>&1;
+ if [ $? -eq 0 ]; then
+ info "$SYM_LINK_SUCCESS" "$src" "$dest";
+ return 0;
+ else
+ error "$SYM_LINK_ERROR" "$src" "$dest";
+ return 1;
+ fi
+}
+
+######################################################################
+# Expands a path to an absolute representation of an existing
+# directory.
+#
+# $1 The path to the directory.
+######################################################################
+function expand_path {
+ local dir="$1";
+ if [ -d "$dir" ]; then
+ local owd=`pwd`;
+ cd "$dir" > /dev/null;
+ _result=`pwd`;
+ cd "$owd";
+ elif [ ! -d "$dir" ]; then
+ local nm=`basename $dir`
+ dir=`dirname $dir`;
+ expand_path "$dir";
+ _result="$_result/$nm";
+ fi
+
+ if [ ! -e "$dir" -o ! -e "$_result" ]; then
+ error "unable to expand path %s" "$1";
+ _result="$1";
+ fi
+}
+
+######################################################################
+# Creates a directory including any non-existing directories.
+#
+# $1 The path to the directory.
+######################################################################
+function mkdirp {
+ local dir="$1";
+ if [ ! -d "$dir" ]; then
+ mkdir -p "$dir";
+ fi
+ if [ $? -eq 0 ]; then
+ info "$CREATED_DIRECTORY" "$dir";
+ return 0;
+ else
+ error "$DIRECTORY_CREATE_FAIL" "$dir";
+ return 1;
+ fi
+}
+
+######################################################################
+# Attempts to change directory and print the new working directory.
+#
+# $1 The path to the directory.
+######################################################################
+function cdir {
+ local dir="$1";
+ cd "$dir";
+ if [ $? -eq 0 ]; then
+ info "$CHANGED_DIRECTORY" "$dir";
+ return 0;
+ else
+ error "$DIRECTORY_CHANGE_FAIL" "$dir";
+ return 1;
+ fi
+}
+
+######################################################################
+# Attempts to verify whether a directory is allowed for removal.
+#
+# $1 The path to the directory.
+######################################################################
+function validate_rmdir {
+ local dir="$1";
+ if [ -z "$dir" -o "$dir" == "/" -o "$dir" == "." -o "$dir" == ".." -o "$dir" == "./" ]; then
+ quit 1 "deletion of %s not allowed" "$dir";
+ fi
+}
+
+######################################################################
+# Attempts to remove a directory.
+#
+# $1 The path to the directory.
+######################################################################
+function rmdir {
+ local dir="$1";
+ validate_rmdir "$dir";
+ expand_path "$dir";
+ dir=$_result;
+ validate_rmdir "$dir";
+ rm -rf "$dir";
+ if [ $? -eq 0 ]; then
+ info "$REMOVED_DIRECTORY" "$dir";
+ return 0;
+ else
+ error "$DIRECTORY_REMOVE_FAIL" "$dir";
+ return 1;
+ fi
+}
+
+######################################################################
+# Attempts to remove a directory as the root user.
+#
+# $1 The path to the directory.
+######################################################################
+function sudo_rmdir {
+ local dir="$1";
+ validate_rmdir "$dir";
+ expand_path "$dir";
+ dir=$_result;
+ validate_rmdir "$dir";
+ sudo rm -rf "$dir";
+ if [ $? -eq 0 ]; then
+ info "$SUDO_REMOVED_DIRECTORY" "$dir";
+ return 0;
+ else
+ error "$SUDO_DIRECTORY_REMOVE_FAIL" "$dir";
+ return 1;
+ fi
+}
245 lib/git-util
@@ -0,0 +1,245 @@
+#!/usr/bin/env bash
+
+######################################################################
+# git-util
+#
+# Utilties for working with the git repositories.
+######################################################################
+
+GIT_REPOSITORY=".git";
+GIT_IGNORE=".gitignore";
+
+function init_git_log_file {
+ #ensure we always have a log file for git commands
+ if [ -z "$GIT_LOG_FILE" -a ! -z "$INSTALL_LOG_PATH" ]; then
+ GIT_LOG_FILE="$INSTALL_LOG_PATH/git.log";
+ if [ ! -e "$GIT_LOG_FILE" ]; then
+ mkdirp "$INSTALL_LOG_PATH" > /dev/null;
+ touch "$GIT_LOG_FILE";
+ fi
+ fi
+}
+
+function get_git_message_prefix {
+ _result="[$program_name]";
+}
+
+function get_git_commit_message {
+ local msg="$1";
+ get_git_message_prefix;
+ local prefix="$_result";
+ local date=`date "+%d-%m-%Y %T"`;
+ local message="$prefix [$date]";
+ #add a custom message where necessary
+ if [ ! -z "$msg" ]; then
+ message="$message $msg";
+ fi
+ _result="$message";
+}
+
+function git_ignore {
+ local path="$1";
+ local ignores=("${@:2}");
+ if [ -d "$path" -a -w "$path" ]; then
+ local file="$path/$GIT_IGNORE";
+ echo "" > "$file";
+ info "writing %s to %s" "$GIT_IGNORE" "$path";
+ local contents="";
+ for i in "${ignores[@]}"
+ do
+ echo "$i" >> "$file";
+ done
+ fi
+}
+
+function git_repository {
+ local path="$1";
+ if [ -e "$path" ]; then
+ expand_path "$path";
+ if [ -d "$_result" -a -d "$_result/$GIT_REPOSITORY" ]; then
+ return 0;
+ fi
+ fi
+ return 1;
+}
+
+function git_status {
+ init_git_log_file;
+ local path="$1";
+ expand_path "$path";
+ git_repository "$_result";
+ #only status if already a repo
+ if [ $? -eq 0 ]; then
+ info "git status %s" "$path";
+ cdir "$path" > /dev/null;
+ git status >> "$GIT_LOG_FILE" 2>&1;
+ return $?;
+ else
+ warn "%s is not a git repository" "$path";
+ return 1;
+ fi
+}
+
+function git_init {
+ init_git_log_file;
+ local path="$1";
+ expand_path "$path";
+ git_repository "$_result";
+ #only initialize if not already a repo
+ if [ $? -ne 0 ]; then
+ info "git init %s" "$path";
+ git init "$path" >> "$GIT_LOG_FILE" 2>&1;
+ return $?;
+ else
+ warn "%s is already initialized as a git repository" "$path";
+ return 1;
+ fi
+}
+
+function git_add {
+ init_git_log_file;
+ local path="$1";
+ expand_path "$path";
+ git_repository "$_result";
+ #only add on valid repo
+ if [ $? -eq 0 ]; then
+ info "git add %s" "$path";
+ cdir "$path" > /dev/null;
+ git add "." >> "$GIT_LOG_FILE" 2>&1;
+ return $?;
+ else
+ warn "%s is not a git repository" "$path";
+ return 1;
+ fi
+}
+
+function git_commit {
+ init_git_log_file;
+ local path="$1";
+ local msg="$2";
+ get_git_commit_message "$msg";
+ msg="$_result";
+ expand_path "$path";
+ git_repository "$_result";
+ #only commit if already a repo
+ if [ $? -eq 0 ]; then
+ info "git commit %s" "$msg";
+ cdir "$path" > /dev/null;
+ git commit -a -m "$msg" >> "$GIT_LOG_FILE" 2>&1;
+ return $?;
+ else
+ warn "%s is not a git repository" "$path";
+ return 1;
+ fi
+}
+
+function git_clone {
+ init_git_log_file;
+ local repo="$1";
+ info "cloning %s" "$repo";
+ git clone --recursive "$repo" >> "$GIT_LOG_FILE" 2>&1;
+ return $?;
+}
+
+function git_pull_url {
+ init_git_log_file;
+ local url="$1";
+ info "git pull %s" "$url";
+ git pull "$url" >> "$GIT_LOG_FILE" 2>&1;
+ return $?;
+}
+
+function git_pull {
+ init_git_log_file;
+ local repo="$1";
+ local remote="$2";
+ local ref="$3";
+
+ if [ -z "$remote" ]; then
+ remote="origin";
+ fi
+
+ if [ -z "$ref" ]; then
+ ref="master";
+ fi
+
+ cdir "$repo" && info "git pull %s %s" "$remote" "$ref";
+ if [ $? -eq 0 ]; then
+ git pull "$remote" "$ref" >> "$GIT_LOG_FILE" 2>&1;
+ if [ $? -ne 0 ]; then
+ warn "could not pull %s from %s at %s" "$ref" "$remote" "$repo";
+ fi
+ else
+ warn "could not cd for pull %s from %s at %s" "$ref" "$remote" "$repo";
+ fi
+ return $?;
+}
+
+function git_ls_remote_tags {
+ local repo="$1";
+ info "git ls-remote --tags %s" "$repo";
+ _result=`git ls-remote --tags "$repo"`;
+}
+
+function git_find_tag {
+ local tag="$1";
+ local data="$2";
+ for t in $data
+ do
+ if [ "$t" == "refs/tags/$tag" ]
+ then
+ return 0;
+ fi
+ done
+ return 1;
+}
+
+function get_current_branch_name {
+ local repo="$1";
+ cdir "$repo" > /dev/null;
+ local branch_name=$(git symbolic-ref -q HEAD);
+ branch_name=${branch_name##refs/heads/};
+ branch_name=${branch_name:-HEAD};
+ _result="$branch_name";
+}
+
+function git_submodule_update {
+ git submodule update;
+}
+
+function git_submodule_add {
+ init_git_log_file;
+ local repo="$1";
+ local subrepo="$2";
+ local path="$3";
+ expand_path "$repo";
+ git_repository "$_result";
+ #only add the submodule if already a repo
+ if [ $? -eq 0 ]; then
+ cdir "$repo" > /dev/null;
+ if [ $? -eq 0 ]; then
+ info "git submodule add %s -> %s" "'$subrepo'" "'$path'";
+ git submodule add "$subrepo" "$path" >> "$GIT_LOG_FILE" 2>&1;
+ #aggressively add additional sub-modules when adding a sub module
+ git submodule update --init --recursive >> "$GIT_LOG_FILE" 2>&1;
+ fi
+ return $?;
+ else
+ warn "%s is not a git repository" "$repo";
+ return 1;
+ fi
+}
+
+function git_switch_origin {
+ init_git_log_file;
+ local repo="$1";
+ local origin="$2";
+
+ cdir "$repo" > /dev/null;
+
+ #remove the old origin
+ git remote rm origin >> "$GIT_LOG_FILE" 2>&1;
+
+ #add the new origin
+ git remote add origin "$origin" >> "$GIT_LOG_FILE" 2>&1;
+}
41 lib/help
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+######################################################################
+# help
+#
+# Functions for program help output.
+######################################################################
+
+function program_help {
+ local nm=`basename $0`;
+ local help_file="$exedir/${nm}.help";
+ if [ ! -f "$help_file" ]; then
+ info "no program help available for %s" "$nm";
+ else
+ usage_description " ";
+ while read line
+ do
+ #echo "$line";
+ IFS=":";
+ declare -a parts=( $line );
+ unset IFS;
+
+ local description=${parts[${#parts[@]}-1]};
+
+ local msg="${parts[0]}";
+
+ #remove the last part for the description
+ unset parts[${#parts[@]}-1];
+
+ #remove the first message format part
+ unset parts[0];
+
+ #echo "GOT HELP MESSAGE PARTS : ${parts[@]}";
+
+ usage " $msg" "${parts[@]}";
+ usage_description " ";
+ usage_description " $description";
+ usage_description " ";
+ done < "$help_file"
+ fi
+}
70 lib/messages
@@ -0,0 +1,70 @@
+#!/usr/bin/env bash
+
+######################################################################
+# messages
+#
+# Variables containing program messages.
+######################################################################
+
+WELCOME="%s running on %s as %s";
+
+#cleaning
+CLEANING="cleaning %s";
+CLEAN_COMPLETE="clean complete";
+
+#tests
+TEST_PREFIX="[test]";
+TEST_FAIL="[fail]";
+TEST_PASS="[pass]";
+TEST_RUNNER_START="running tests in %s";
+TEST_RUN_START="%s started on %s expects %s";
+TEST_RUN_STATUS="%s program %s exited with code %s";
+TEST_RUN_FAIL="%s failed test %s with code %s expected %s";
+TEST_RUN_PASS="%s finished test on %s with code %s";
+
+#fs
+CHECK_DIRECTORY="checking if %s is a directory";
+CREATED_DIRECTORY="mkdir -p %s";
+DIRECTORY_CREATE_FAIL="could not create directory %s";
+CHANGED_DIRECTORY="pwd %s";
+DIRECTORY_CHANGE_FAIL="could not change working directory to %s";
+
+REMOVED_DIRECTORY="rm -rf %s";
+DIRECTORY_REMOVE_FAIL="could not delete directory %s";
+
+SUDO_REMOVED_DIRECTORY="sudo rm -rf %s";
+SUDO_DIRECTORY_REMOVE_FAIL="could not delete directory %s using sudo";
+
+COPY_SUCCESS="cp -rf %s > %s";
+COPY_ERROR="cp -rf %s > %s";
+
+MOVE_SUCCESS="mv %s > %s";
+MOVE_ERROR="mv %s > %s";
+
+SYM_LINK_SUCCESS="ln -s %s > %s";
+SYM_LINK_ERROR="ln -s %s > %s";
+
+PROGRAM_NOT_FOUND="%s not found";
+
+#install
+PLATFORM_INSTALL_CHECK="checking for %s install";
+PLATFORM_INSTALL_PASS="found %s install directory";
+PLATFORM_INSTALL_FAIL="unsupported platform %s";
+
+PROGRAM_INSTALL_CHECK="checking for %s install on %s";
+PROGRAM_INSTALL_RUN="%s installing %s from %s";
+
+INSTALL_SOURCE_PATH_MISSING="installation source path not specified";
+INSTALL_SOURCE_PATH_INVALID="installation source path is not valid";
+
+INSTALL_FULL_NAME_MISSING="installation full name not specified";
+INSTALL_SHORT_NAME_MISSING="installation short name not specified";
+
+#install program start up data
+INSTALL_START_MSG="installing %s from source %s";
+
+#archive
+EXTRACTING="tar xzf %s > %s";
+EXTRACTION_ERROR="could not extract archive %s";
+
+ARCHIVING="tar czf %s < %s";
49 lib/shared
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+
+######################################################################
+# shared
+#
+# Sources shared libraries common to all programs.
+######################################################################
+
+#whether to suppress the default welcome message
+SUPPRESS_WELCOME=0;
+
+#default program name
+program_name=`basename $0`;
+
+#custom program name set by running executable
+PNAME=${PROGRAM_NAME:-}
+if [ ! -z ${PNAME} ]; then
+ program_name="$PROGRAM_NAME";
+fi
+
+source "$libdir/constants";
+source "$libdir/exit-codes";
+source "$libdir/messages";
+source "$libdir/style";
+source "$libdir/sysout";
+source "$libdir/help";
+source "$libdir/utilities";
+source "$libdir/fs";
+source "$libdir/git-util";
+source "$libdir/archive-util";
+source "$libdir/clean-util";
+
+#set +e;
+
+#ensure we can't use unbound variables
+#set -o nounset;
+
+#set -o errexit;
+#set -o pipefail;
+
+#TODO: refactor this so a program can set a name other than the basename of the executing program
+function welcome_msg {
+ if [ "$SUPPRESS_WELCOME" = "1" ]; then
+ return 0;
+ fi
+ info "$WELCOME" "$program_name" "$OS_INSTALL" "`whoami`";
+}
+
+welcome_msg;
95 lib/style
@@ -0,0 +1,95 @@
+#!/usr/bin/env bash
+
+######################################################################
+# style
+#
+# Terminal output formatting library.
+######################################################################
+
+#Black 0;30 Dark Gray 1;30
+#Blue 0;34 Light Blue 1;34
+#Green 0;32 Light Green 1;32
+#Cyan 0;36 Light Cyan 1;36
+#Red 0;31 Light Red 1;31
+#Purple 0;35 Light Purple 1;35
+#Brown 0;33 Yellow 1;33
+#Light Gray 0;37 White 1;37
+
+# The ANSI sequence: {ESC}[{attr};{bg};{256colors};{fg}m
+
+# {ESC} or \033 represents the ANSI escape-sequence. {attr} represents the outputs attributes (properties such as blinking and bold text), {fg} is the # foreground color, {bg} is the background color, m means the sequence ends.
+
+# blink green = "\033[01;38;5;160m$1\033[0m";
+
+function style_terminator {
+ _result="\033[0m";
+}
+
+function default_style {
+ _result="";
+}
+
+function normal {
+ _result="\033[0m$1\033[0m";
+}
+
+function bold {
+ _result="\033[1m$1\033[0m";
+}
+
+function start_red {
+ _result="\033[0;37;0;31m";
+}
+
+function red {
+ _result="\033[0;37;0;31m$1\033[0m";
+}
+
+function boldred {
+ _result="\033[1;31m$1\033[0m";
+}
+
+function underline {
+ _result="\033[4m$1\033[0m";
+}
+
+function cyan {
+ _result="\033[0;36m$1\033[0m";
+}
+
+function start_purple {
+ _result="\033[0;35m";
+}
+
+function purple {
+ _result="\033[0;35m$1\033[0m";
+}
+
+function boldpurple {
+ _result="\033[1;35m$1\033[0m";
+}
+
+function start_blue {
+ _result="\033[0;34m";
+}
+
+function boldblue {
+ _result="\033[1;34m$1\033[0m";
+}
+
+function blue {
+ _result="\033[0;34m$1\033[0m";
+}
+
+#
+function green_on_red {
+ _result="\033[0;41m$1\033[0m";
+}
+
+function gray {
+ _result="\033[0;37m$1\033[0m";
+}
+
+function lightcyan {
+ _result="\033[1;36m$1\033[0m";
+}
288 lib/sysout
@@ -0,0 +1,288 @@
+#!/usr/bin/env bash
+
+######################################################################
+# sysout
+#
+# Library functions for system output and program exit.
+######################################################################
+
+######################################################################
+# Colours a message string formatting each replacement as bold.
+#
+# $1 The name of the colour function to call.
+# $2 The function to call to highlight each replacement parameter.
+# $3 The printf format string.
+# $4-@ The remaining string replacements to be highlighted.
+######################################################################
+function colorize {
+ #function used to start the main color
+ local start_function="$1";
+ #function used to highlight each replacement parameter
+ local highlight_function="$2";
+ local message="$3";
+ local replacements=("${@:3}");
+ local output=( "$message" );
+ local c=0;
+ for i in "${replacements[@]}"
+ do
+ if [ $c -ne 0 ]; then
+ #highlight each replacement parameter
+ eval "$highlight_function" "'$i'";
+ local res="$_result";
+ eval "$start_function";
+ #concatenate together
+ res="$res$_result";
+ #and push back on to the output data
+ output=( "${output[@]}" "$res" );
+ fi
+ c=$[$c+1];
+ done
+ #get the overall start
+ eval "$start_function";
+ local start="$_result";
+
+ #always end with a style terminator
+ style_terminator;
+ local end="$_result";
+
+ #perform the replacement on the message template string
+ _result=$(printf "${output[@]}");
+
+ #wrap the replaced message with the start and end highlighting
+ local full="$start${_result[@]}$end";
+
+ #return the output
+ _result="$full";
+ #echo "got FULL RESULT: $full";
+ #echo -e "$full";
+ #echo "this is a normal message";
+}
+
+######################################################################
+# Performs replacement without performing any highlighting
+# appropriate for output to a non-terminal.
+#
+# $1 The printf format string.
+# $2-@ The remaining string replacements to be highlighted.
+######################################################################
+function sprintf {
+ _result=$(printf "${@}");
+}
+
+#TODO : integrate this logic so no highlighting is performed when not a terminal
+#if [ -t 1 ] ; then echo terminal; fi
+#(if [ -t 1 ] ; then echo terminal; fi) | echo
+
+#quits a program with a message and exit code
+function quit {
+
+ #trap - INT TERM EXIT;
+
+ local code=$1 || 1;
+ local params=("${@:2}");
+
+ #echo "GOT QUIT PARAMS ${params[@]}"
+ error "${params[@]}";
+
+ exit $code;
+}
+
+#prints a message with the default output formatting
+function print {
+ local msg="$1";
+ print_prefix;
+ echo -e "$msg";
+}
+
+function print_prefix {
+ local prefix="[$program_name]";
+ if [ -t 1 ]; then
+ if [ "$prefix" != "" ]; then
+ gray "$prefix";
+ echo -ne "$_result";
+ echo -ne " ";
+ fi
+ else
+ echo -n "$prefix ";
+ fi
+}
+
+#exits a program with a success message
+function success {
+ local status="[ok]";
+ local prefix="$status";
+ local msg="";
+ if [ -t 1 ]; then
+ #get the message prefix
+ bold "$status";
+ prefix="$_result";
+
+ #highlight the message and parameters
+ msgs=( "default_style" "bold" "${@}" );
+ colorize "${msgs[@]}";
+ msg="$_result";
+ else
+ sprintf "${@}";
+ msg="$_result";
+ fi
+
+ #output everything
+ print_prefix;
+ echo -e "$prefix $msg";
+
+ exit $SUCCESS;
+}
+
+#outputs an info message
+function info {
+ local status="[info]";
+ local prefix="$status";
+ local msg="";
+ if [ -t 1 ]; then
+ #get the message prefix
+ bold "$status";
+ prefix="$_result";
+
+ #highlight the message and parameters
+ msgs=( "default_style" "bold" "${@}" );
+ colorize "${msgs[@]}";
+ msg="$_result";
+ else
+ sprintf "${@}";
+ msg="$_result";
+ fi
+
+ #output everything
+ print_prefix;
+ echo -e "$prefix $msg";
+}
+
+#outputs an important info message
+function important {
+ local status="[info]";
+ local prefix="$status";
+ local msg="";
+ if [ -t 1 ]; then
+ #get the message prefix
+ bold "$status";
+ prefix="$_result";
+
+ #highlight the message and parameters
+ msgs=( "start_blue" "boldblue" "${@}" );
+ colorize "${msgs[@]}";
+ msg="$_result";
+ else
+ sprintf "${@}";
+ msg="$_result";
+ fi
+
+ #output everything
+ print_prefix;
+ echo -e "$prefix $msg";
+}
+
+#outputs a usage message
+function usage {
+ local status="[usage]";
+ local prefix="$status";
+ local msg="";
+ if [ -t 1 ]; then
+ #get the message prefix
+ bold "$status";
+ prefix="$_result";
+
+ #highlight the message and parameters
+ msgs=( "default_style" "bold" "${@}" );
+ colorize "${msgs[@]}";
+ msg="$_result";
+ else
+ sprintf "${@}";
+ msg="$_result";
+ fi
+
+ #output everything
+ print_prefix;
+ echo -e "$prefix $msg";
+}
+
+#output a usage description with no formatting
+function usage_description {
+ local status="[usage]";
+ local prefix="$status";
+ local msg="";
+ if [ -t 1 ]; then
+ #get the message prefix
+ bold "$status";
+ prefix="$_result";
+
+ #no highlight for usage descriptions
+ msgs=( "normal" "normal" "${@}" );
+ colorize "${msgs[@]}";
+ msg="$_result";
+ else
+ sprintf "${@}";
+ msg="$_result";
+ fi
+
+ #get the message prefix
+ #bold "[usage]";
+ #local prefix="$_result";
+
+ #highlight the message and parameters
+ #msgs=( "default_style" "default_style" "${@}" );
+ #colorize "${msgs[@]}";
+ #local msg="$_result";
+
+ #output everything
+ print_prefix;
+ echo -e "$prefix $msg";
+}
+
+#outputs a warning message
+function warn {
+
+ local status="[warn]";
+ local prefix="$status";
+ local msg="";
+ if [ -t 1 ]; then
+ #get the message prefix
+ boldpurple "$status";
+ prefix="$_result";
+
+ #highlight the message and parameters
+ msgs=( "start_purple" "boldpurple" "${@}" );
+ colorize "${msgs[@]}";
+ msg="$_result";
+ else
+ sprintf "${@}";
+ msg="$_result";
+ fi
+
+ #output everything
+ print_prefix;
+ echo -e "$prefix $msg";
+}
+
+#outputs an error message
+function error {
+ local status="[not ok]";
+ local prefix="$status";
+ local msg="";
+ if [ -t 1 ]; then
+ #get the message prefix
+ boldred "$status";
+ prefix="$_result";
+
+ #highlight the message and parameters
+ msgs=( "start_red" "boldred" "${@}" );
+ colorize "${msgs[@]}";
+ msg="$_result";
+ else
+ sprintf "${@}";
+ msg="$_result";
+ fi
+
+ #output everything
+ print_prefix;
+ echo -e "$prefix $msg";
+}
48 lib/utilities
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+
+######################################################################
+# util
+#
+# Common utility library functions.
+######################################################################
+
+function verifyshell {
+ shell=`basename $SHELL`
+ if [ "$shell" != "$TSHELL" ]; then
+ quit "$ERR_WRONG_SHELL" "incorrect shell %s expecting %s" "$SHELL" "$TSHELL";
+ fi
+}
+
+#verifies that the specified executable is installed and available in PATH
+function verify_exe {
+ _result=0;
+ type -P "$1" &>/dev/null || _result=1;
+}
+
+function verify_program {
+ local exe=$1;
+ info "checking for %s" "$exe";
+ verify_exe "$exe";
+ if [ $_result -ne 0 ]; then
+ error "$PROGRAM_NOT_FOUND" "$exe";
+ _result=1;
+ fi
+}
+
+######################################################################
+# verify_program_list
+#
+# Accepts an array of program names and verifies that they are
+# installed. If a program is not found this program will exit
+# with a non-zero exit code.
+######################################################################
+function verify_program_list {
+ local exes=( "$@" );
+ for exe in "${exes[@]}"
+ do
+ verify_program "$exe";
+ if [ "$_result" -eq 1 ]; then
+ quit "$ERR_MISSING_PROGRAM" "missing program %s" "$exe";
+ fi
+ done
+}
18 test/fail-copy-file
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+
+#get absolute path to running script
+name=`basename $0`;
+abspath=$(cd ${BASH_SOURCE[0]%/*} && echo $PWD/${0##*/});
+exedir=`dirname "$abspath"`;
+libdir="$exedir/../lib";
+
+#bring in the shared libraries
+source "$libdir/shared";
+
+#attempt to copy the test runner to the /etc directory - should fail
+expand_path "$exedir/../runner";
+copy "$_result" "/etc";
+
+if [ $? -ne 0 ]; then
+ quit 1 "failed to copy file";
+fi
25 test/fail-expand-path
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+#get absolute path to running script
+name=`basename $0`;
+abspath=$(cd ${BASH_SOURCE[0]%/*} && echo $PWD/${0##*/});
+exedir=`dirname "$abspath"`;
+libdir="$exedir/../lib";
+
+#bring in the shared libraries
+source "$libdir/shared";
+
+function test_expansion {
+ local relative="$1";
+ expand_path "$relative";
+ local expanded="$_result";
+ if [ "$expanded" != "$relative" ]; then
+ info "expanded %s to %s" "$relative" "$expanded";
+ return 0;
+ fi
+ return 1;
+}
+
+#attempt to expand a non-existent directory
+test_expansion "../non-existent";
+exit $?;
28 test/fail-find-git-tag
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+
+#get absolute path to running script
+name=`basename $0`;
+abspath=$(cd ${BASH_SOURCE[0]%/*} && echo $PWD/${0##*/});
+exedir=`dirname "$abspath"`;
+libdir="$exedir/../lib";
+
+#bring in the shared libraries
+source "$libdir/shared";
+
+function test_expansion {
+ local relative="$1";
+ expand_path "$relative";
+ local expanded="$_result";
+ if [ "$expanded" != "$relative" ]; then
+ info "expanded %s to %s" "$relative" "$expanded";
+ fi
+}
+
+git_ls_remote_tags "git@github.com:stax/server.git";
+git_find_tag "non-existent-tag" "$_result";
+
+if [ $? -eq 1 ]; then
+ exit 1;
+fi
+
+exit 0;
18 test/fail-symlink-file
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+
+#get absolute path to running script
+name=`basename $0`;
+abspath=$(cd ${BASH_SOURCE[0]%/*} && echo $PWD/${0##*/});
+exedir=`dirname "$abspath"`;
+libdir="$exedir/../lib";
+
+#bring in the shared libraries
+source "$libdir/shared";
+
+#attempt to symlink the test runner to the /etc directory
+expand_path "$exedir/../runner";
+symlink "$_result" "/etc/runner-symlink";
+
+if [ $? -ne 0 ]; then
+ quit 1 "failed to symlink file";
+fi
14 test/fail-verify-programs
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+
+#get absolute path to running script
+name=`basename $0`;
+abspath=$(cd ${BASH_SOURCE[0]%/*} && echo $PWD/${0##*/});
+exedir=`dirname "$abspath"`;
+libdir="$exedir/../lib";
+
+#bring in the shared libraries
+source "$libdir/shared";
+
+#verify all stack programs are installed
+stack_programs=( 'ls' 'mv' 'rm' 'fubar' 'foo' 'bar' );
+verify_program_list "${stack_programs[@]}";
17 test/fail-verify-shell
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+
+#get absolute path to running script
+name=`basename $0`;
+abspath=$(cd ${BASH_SOURCE[0]%/*} && echo $PWD/${0##*/});
+exedir=`dirname "$abspath"`;
+libdir="$exedir/../lib";
+
+#bring in the shared libraries
+source "$libdir/shared";
+
+#mimic use of an incorrect shell
+SHELL="zsh";
+
+verifyshell;
+
+quit 1 "incorrect shell $TSHELL";
51 test/lib/dir
@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+
+function test_runner_dir {
+
+ #TODO: test $1 is a directory
+ local dir=$1;
+
+ info "$TEST_RUNNER_START" "$dir";
+
+ for f in $1/*
+ do
+ local nm=`basename $f`;
+ local expects='== 0';
+ local type=`expr "$nm" : '\(fail\)'`;
+
+ if [ "$type" = "fail" ]; then
+ local expects=">= 1";
+ fi
+
+ if [ -x "$f" ]; then
+ info "$TEST_RUN_START" "$TEST_PREFIX" "$nm" "$expects";
+
+ #execute the test
+ "$f";
+ #get the exit code
+ local rescode=$?;
+
+ #fail: expecting a non-zero exit status but exited with zero
+ if [ "$type" = "fail" -a $rescode -eq 0 ]; then
+ error "$TEST_RUN_FAIL" "$TEST_FAIL" "$nm" "$rescode" "$expects";
+ fi
+
+ #pass: expecting a non-zero exit status
+ if [ "$type" = "fail" -a $rescode -ne 0 ]; then
+ info "$TEST_RUN_PASS" "$TEST_PASS" "$nm" "$rescode";
+ fi
+
+ #expecting a zero status and was zero
+ if [ "$type" = "" -a $rescode -eq 0 ]; then
+ info "$TEST_RUN_PASS" "$TEST_PASS" "$nm" "$rescode";
+ fi
+
+ #expecting a zero status and was zero
+ if [ "$type" = "" -a $rescode -ne 0 ]; then
+ error "$TEST_RUN_FAIL" "$TEST_FAIL" "$nm" "$rescode" "$expects";
+ fi
+ else
+ warn "skipping test %s file is not executable" "$nm";
+ fi
+ done
+}
16 test/test-copy-file
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+
+#get absolute path to running script
+name=`basename $0`;
+abspath=$(cd ${BASH_SOURCE[0]%/*} && echo $PWD/${0##*/});
+exedir=`dirname "$abspath"`;
+libdir="$exedir/../lib";
+
+#bring in the shared libraries
+source "$libdir/shared";
+
+#attempt to copy the test runner to the temp directory
+expand_path "$exedir/../runner";
+copy "$_result" "/private/tmp";
+
+success "$program_name passed test";
27 test/test-expand-path
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+
+#get absolute path to running script
+name=`basename $0`;
+abspath=$(cd ${BASH_SOURCE[0]%/*} && echo $PWD/${0##*/});
+exedir=`dirname "$abspath"`;
+libdir="$exedir/../lib";
+
+#bring in the shared libraries
+source "$libdir/shared";
+
+function test_expansion {
+ local relative="$1";
+ expand_path "$relative";
+ local expanded="$_result";
+ if [ "$expanded" != "$relative" ]; then
+ info "expanded %s to %s" "$relative" "$expanded";
+ fi
+}
+
+#expand a relative directory
+test_expansion "$exedir/../";
+
+#expand a file
+test_expansion "$exedir/../runner";
+
+success "expand path test complete";
27 test/test-find-git-tag
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+
+#get absolute path to running script
+name=`basename $0`;
+abspath=$(cd ${BASH_SOURCE[0]%/*} && echo $PWD/${0##*/});
+exedir=`dirname "$abspath"`;
+libdir="$exedir/../lib";
+
+#bring in the shared libraries
+source "$libdir/shared";
+
+function test_expansion {
+ local relative="$1";
+ expand_path "$relative";
+ local expanded="$_result";
+ if [ "$expanded" != "$relative" ]; then
+ info "expanded %s to %s" "$relative" "$expanded";
+ fi
+}
+
+git_ls_remote_tags "git@github.com:stax/server.git";
+git_find_tag "prototype" "$_result";
+if [ $? -eq 0 ]; then
+ success "find git tag test complete";
+fi
+
+exit 1;
16 test/test-symlink-file
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+
+#get absolute path to running script
+name=`basename $0`;
+abspath=$(cd ${BASH_SOURCE[0]%/*} && echo $PWD/${0##*/});
+exedir=`dirname "$abspath"`;
+libdir="$exedir/../lib";
+
+#bring in the shared libraries
+source "$libdir/shared";
+
+#attempt to symlink the test runner to the temp directory
+expand_path "$exedir/../runner";
+symlink "$_result" "/private/tmp/runner-symlink";
+
+success "$program_name passed test";
15 test/test-verify-programs
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+#get absolute path to running script
+name=`basename $0`;
+abspath=$(cd ${BASH_SOURCE[0]%/*} && echo $PWD/${0##*/});
+exedir=`dirname "$abspath"`;
+libdir="$exedir/../lib";
+
+#bring in the shared libraries
+source "$libdir/shared"
+
+#verify all stack programs are installed
+#stack_programs=( 'git' 'openssl' 'nginx' 'node' 'npm' 'couchdb' 'redis-server' 'redis-cli' );
+stack_programs=( 'git' 'ls' 'rm' );
+verify_program_list "${stack_programs[@]}";
14 test/test-verify-shell
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+
+#get absolute path to running script
+name=`basename $0`;
+abspath=$(cd ${BASH_SOURCE[0]%/*} && echo $PWD/${0##*/});
+exedir=`dirname "$abspath"`;
+libdir="$exedir/../lib";
+
+#bring in the shared libraries
+source "$libdir/shared";
+
+verifyshell;
+
+success "shell verified as $TSHELL";
Please sign in to comment.
Something went wrong with that request. Please try again.