From 11c930f71db58201994265b71a8f76187f1dbda1 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 27 Jan 2013 12:58:25 +0100 Subject: o Adding a common header to all scripts. o Disabling un-used tests and apps for now. --- Makefile | 23 +- bin/X-app-instance | 502 ++++++++++++++++++++++++++++++++++++++++++ bin/app-conf | 12 +- bin/app-init | 10 +- bin/app-instance | 502 ------------------------------------------ bin/app-operate | 73 ------ bin/app-start | 11 + bin/app-stop | 11 + lib/header | 8 + libexec/app-cat-conf | 20 +- libexec/app-grep-path | 12 +- libexec/app-install-file | 12 +- libexec/app-operate | 50 +++++ libexec/app-resolver-maven | 12 +- test/X-app-help.bats | 38 ++++ test/X-app-install.bats | 50 +++++ test/X-app-list-versions.bats | 28 +++ test/X-app-list.bats | 102 +++++++++ test/X-help.bats | 17 ++ test/X-it-install-remove.bats | 45 ++++ test/app-help.bats | 38 ---- test/app-install.bats | 50 ----- test/app-list-versions.bats | 28 --- test/app-list.bats | 102 --------- test/help.bats | 17 -- test/it-install-remove.bats | 45 ---- 26 files changed, 920 insertions(+), 898 deletions(-) create mode 100755 bin/X-app-instance delete mode 100755 bin/app-instance delete mode 100755 bin/app-operate create mode 100755 bin/app-start create mode 100755 bin/app-stop create mode 100644 lib/header create mode 100755 libexec/app-operate create mode 100755 test/X-app-help.bats create mode 100755 test/X-app-install.bats create mode 100755 test/X-app-list-versions.bats create mode 100755 test/X-app-list.bats create mode 100755 test/X-help.bats create mode 100755 test/X-it-install-remove.bats delete mode 100755 test/app-help.bats delete mode 100755 test/app-install.bats delete mode 100755 test/app-list-versions.bats delete mode 100755 test/app-list.bats delete mode 100755 test/help.bats delete mode 100755 test/it-install-remove.bats diff --git a/Makefile b/Makefile index 2019e13..a3e5e42 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,33 @@ all: test -BATS=$(patsubst test/%,%,$(wildcard test/*.bats)) +BINS=$(wildcard bin/app-*) $(wildcard libexec/app-*) + +BATS=$(sort $(patsubst test/%,%,$(filter-out test/X-%,$(wildcard test/*.bats)))) TESTS=$(addprefix bats-,$(BATS)) bats-%: @echo === test/$(patsubst bats-%,%,$@) @bats test/$(patsubst bats-%,%,$@) -test: $(TESTS) +show-tests: @echo BATS=$(BATS) @echo TESTS=$(TESTS) + @echo $(addprefix set_header-,$(BINS)) +test: show-tests $(TESTS) .PHONY: test + +define set_header +set_header-$(1): + @count=`wc -l lib/header|cut -f 1 -d ' '`; \ + cat lib/header > x; \ + echo "# HEADER END" >> x; \ + sed '1,/HEADER END/d' $(1) >> x; \ + if [ `md5sum $(1)|cut -f 1 -d ' '` != `md5sum x|cut -f 1 -d ' '` ]; then echo Updated: $(1); cp x $(1); fi; \ + rm x +endef + +$(foreach f,$(BINS),$(eval $(call set_header,$(f)))) +set-headers: $(addprefix set_header-,$(BINS)) + +.PHONY: set-headers diff --git a/bin/X-app-instance b/bin/X-app-instance new file mode 100755 index 0000000..02e3c0f --- /dev/null +++ b/bin/X-app-instance @@ -0,0 +1,502 @@ +#!/bin/bash + +if [[ $APPSH_HOME == "" ]] +then + APPSH_HOME=`dirname "$0"` + APPSH_HOME=`cd "$APPSH_HOME/.." && pwd` +fi + +if [ -n "$APPSH_REPO" ] +then + repo="$APPSH_REPO" +else + repo="http://repo1.maven.org" +fi + +calculate_md5() { + local file="$1"; shift + + md5sum "$file" | cut -c 1-32 +} + +# TODO: support file:// repositories +# TODO: look in the local repository first +get() { + local url=$1 + local file=$2 + local exit + + curl -o $file $url -D curl.tmp + + exit=`grep "^HTTP/[0-9]\.[0-9] 200 .*" curl.tmp >/dev/null; echo $?` + head=`head -n 1 curl.tmp` + rm -f curl.tmp + if [ "$exit" != 0 ] + then + echo "Unable to download $url: $head" >&2 + exit 1 + fi +} + +resolve_snapshot() { + local groupId=$1; shift + local groupIdSlash=$1; shift + local artifactId=$1; shift + local version=$1; shift + + local metadata=$apps/.app/var/download/$groupId-$artifactId-$version-metadata.xml + local base_url=$repo/$groupIdSlash/$artifactId/$version + get $base_url/maven-metadata.xml $metadata + local resolved_version=`xmlstarlet sel -t -m '//snapshotVersion[extension[text()="zip"]]' -v value $metadata` + echo $resolved_version +} + +download_artifact() { + local file="$1"; shift + local url="$1"; shift + + echo "Downloading $url.md5" + get $url.md5 $file.md5 + local expected_md5="`cat $file.md5`" + + if [ -r $file ] + then + if [ "$expected_md5" == "`calculate_md5 $file`" ] + then + echo "Artifact already downloaded." + else + rm -f "$file" + fi + return 0 + fi + echo "Downloading artifact: $url" + get $url $file + + local actual_md5="`calculate_md5 $file`" + if [ "$expected_md5" == "$actual_md5" ] + then + echo "Artifact downloaded." + else + echo "Invalid checksum. Expected $expected_md5, got $actual_md5" >&2 + exit 1 + fi +} + +method_install_usage() { + if [ -n "$1" ] + then + echo "Error:" "$@" >&2 + fi + + echo "usage: install <-r resolver> -u " >&2 + echo "" >&2 + echo "Install package from a Maven repository:" >&2 + echo " $0 [-n name] [-i instance] instance install -r maven -u groupId:artifactId:version" >&2 + echo "" >&2 + echo "Install package from a file:" >&2 + echo " $0 [-n name] [-i instance] instance install -r file -u file [-v version]" >&2 + echo "The version defaults to the current timestamp" >&2 + exit 1 +} + +method_install() { + local name="$1"; shift + local instance="$1"; shift + local version + local resolver + local url + local groupId + local artifactId + local zip_file + + + if [ $# -eq 0 ] + then + method_install_usage + fi + + while getopts "n:i:v:r:u:" opt + do + case $opt in + n) + name=$OPTARG + ;; + i) + instance=$OPTARG + ;; + v) + version=$OPTARG + ;; + r) + resolver=$OPTARG + ;; + u) + url=$OPTARG + ;; + \?) + method_install_usage "Invalid option: -$OPTARG" + ;; + esac + done + + if [ -z "$name" ] + then + method_install_usage "Missing required argument: -i name." + fi + + if [ -z "$instance" ] + then + method_install_usage "Missing required argument: -i instance." + fi + + if [ -z "$resolver" ] + then + method_install_usage "Missing required option: -r resolver" + fi + + if [ -z "$url" ] + then + method_install_usage "Missing required option: -u url" + fi + + case "$resolver" in + maven) + url=`echo $url | tr ":" " "`; set -- $url + groupId=$1 + artifactId=$2 + version=$3 + + if [ -z "$groupId" -o -z "$artifactId" -o -z "$version" ] + then + method_install_usage "Invalid Maven url." + fi + + local groupIdSlash=$(echo $groupId | sed "s,\.,/,g") + if [ "`echo $version | sed -n s,.*-SNAPSHOT$,SNAPSHOT,p`" == "SNAPSHOT" ] + then + echo "Resolving version $version..." + local resolved_version=`resolve_snapshot $groupId $groupIdSlash $artifactId $version` + if [ -z "$resolved_version" ] + then + echo "Unable to resolve version." + exit 1 + fi + echo "Resolved version $version to $resolved_version" + else + resolved_version=$version + fi + + zip_file=$apps/.app/var/download/$groupId-$artifactId-$resolved_version.zip + artifact_url=$repo/$groupIdSlash/$artifactId/$version/$artifactId-$resolved_version.zip + + download_artifact "$zip_file" "$artifact_url" + ;; + file) + if [ ! -r "$url" ] + then + echo "Could not read file: $url" >&2 + exit 1 + fi + + # TODO: should the zip file be copied into download/ so that + # there's always a local copy? + zip_file=$url + + if [ -z "$version" ] + then + version=`TZ=UTC date +"%Y%m%d-%H%M%S"` + fi + + resolved_version=$version + ;; + *) + method_install_usage "Invalid resolver type: $resolver" + ;; + esac + + if [ -d $name/$instance/versions/$resolved_version ] + then + echo "Version $resolved_version is already installed" + exit 1 + fi + + if [ ! -d $name/$instance ] + then + echo "Creating instance '$instance' for '$name'" + mkdir -p $name/$instance + fi + + mkdir -p $name/$instance/versions/$resolved_version + + echo "Unpacking..." + unzip -q -d $name/$instance/versions/$resolved_version $zip_file + + if [ ! -d $name/$instance/versions/$resolved_version/root ] + then + echo "Invalid zip file, did not contain a ./root directory." >&2 + exit 1 + fi + + echo "Changing current symlink" + rm -f $apps/$name/$instance/current + ln -s versions/$resolved_version/root $apps/$name/$instance/current + + if [ -d $name/$instance/current/bin ] + then + ( + cd $name/$instance/current + find bin -type f | xargs chmod +x + ) + fi + + ( + cd $name/$instance/versions/$resolved_version + if [ -d scripts ] + then + find scripts | xargs chmod +x + fi + + if [ -x scripts/postinstall ] + then + echo "Running postinstall..." + cd root + set +e + env -i \ + PATH=/bin:/usr/bin \ + APPSH_APPS=$apps \ + APPSH_HOME=$APPSH_HOME \ + APPSH_NAME=$name \ + APPSH_INSTANCE=$instance \ + APPSH_VERSION=$resolved_version \ + ../scripts/postinstall + set -e + ret=`echo $?` + if [ "$ret" != 0 ] + then + echo "Postinstall failed!" + exit 1 + fi + echo "Postinstall completed successfully" + fi + ) + + if [ -r $apps/.app/var/list ] + then + sed "/^$name:$instance/d" $apps/.app/var/list > $apps/.app/var/list.new + fi + echo "$name:$instance:$version:$url" >> $apps/.app/var/list.new + mv $apps/.app/var/list.new $apps/.app/var/list +} + +method_set_current_usage() { + if [ -n "$1" ] + then + echo "Error:" "$@" >&2 + fi + + echo "usage: set-current -v version" >&2 + exit 1 +} + +method_set_current() { + local name="$1"; shift + local instance="$1"; shift + local version + + if [ $# -eq 0 ] + then + method_set_current_usage + fi + + while getopts "n:i:v:" opt + do + case $opt in + n) + name=$OPTARG + ;; + i) + instance=$OPTARG + ;; + v) + version=$OPTARG + ;; + \?) + method_set_current_usage "Invalid option: -$OPTARG" + ;; + esac + done + + if [ -z "$version" ] + then + echo "Missing required option -v version." >&2 + exit 1 + fi + + assert_is_instance method_set_current_usage "$name" "$instance" "no" + + if [ ! -d $apps/$name/$instance/versions/$version ] + then + echo "Invalid version: $version." + exit 1 + fi + + rm -f $apps/$name/$instance/current + ln -s versions/$version/root $apps/$name/$instance/current + + return 0 +} + +method_list_usage() { + if [ -n "$1" ] + then + echo "Error:" "$@" >&2 + fi + + echo "usage: list [-n name] [-P field]" >&2 + echo "" + echo "List all installed applications:" >&2 + echo " list" >&2 + echo "" + echo "List all applications with the selected fields with parseable output:" >&2 + echo " list -P instance -P version -n foo" >&2 + exit 1 +} + +method_list() { + local filter_name="$1"; shift + local filter_instance="$1"; shift + local mode="pretty" + local vars + local filter_name + + while getopts "P:n:i:" opt + do + case $opt in + P) + mode="parseable" + vars="$vars $OPTARG" + ;; + n) + filter_name=$OPTARG + ;; + i) + filter_instance=$OPTARG + ;; + \?) + method_list_usage "Invalid option: -$OPTARG" + ;; + esac + done + + if [ ! -r $apps/.app/var/list ] + then + return + fi + + if [ $mode = "pretty" ] + then + printf "%-20s %-20s %-20s\n" "Name" "Instance" "Version" + list_apps "$filter_name" "$filter_instance" name instance version | (IFS=:; while read name instance version + do + printf "%-20s %-20s %-20s\n" "$name" "$instance" "$version" + done) + else + list_apps "$filter_name" "$filter_instance" $vars + fi +} + +method_list_versions_usage() { + if [ -n "$1" ] + then + echo "Error:" "$@" >&2 + fi + + echo "usage: list-versions -n name -i instance [-P]" >&2 + exit 1 +} + +method_list_versions() { + local filter_name="$1"; shift + local instance="$1"; shift + local version + local mode="pretty" + + if [ $# -eq 0 ] + then + method_list_versions_usage + fi + + while getopts "n:i:P" opt + do + case $opt in + n) + name=$OPTARG + ;; + i) + instance=$OPTARG + ;; + v) + version=$OPTARG + ;; + P) + mode="parseable" + ;; + \?) + method_list_versions_usage "Invalid option: -$OPTARG" + ;; + esac + done + + assert_is_instance method_list_versions_usage "$name" "$instance" "no" + + if [ $mode = "pretty" ] + then + echo "Available versions for $name/$instance:" + fi + + find_versions $name $instance + + return 0 +} + +method_instance_usage() { + if [ -n "$1" ] + then + echo "Error:" $@ >&2 + fi + + echo "usage: $0 instance " >&2 + echo "" >&2 + echo "Available methods:" >&2 + echo " install - Installs an application" >&2 + echo " list - List all installed applications" >&2 + echo " list-versions - List all available versions for a single application" >&2 + echo " set-current - Set the current version" >&2 +} + +method_instance() { + local name="$1"; shift + local instance="$1"; shift + local method="$1" + + if [ $# -gt 0 ] + then + shift + fi + + case "$method" in + install) method_install "$name" "$instance" "$@" ;; + list) method_list "$name" "$instance" "$@" ;; + list-versions) method_list_versions "$name" "$instance" "$@" ;; + set-current) method_set_current "$name" "$instance" "$@" ;; + *) + if [ -z "$method" ] + then + method_instance_usage + else + method_instance_usage "Unknown method $method" + fi + ;; + esac + exit $? +} diff --git a/bin/app-conf b/bin/app-conf index b890d6d..3602a39 100755 --- a/bin/app-conf +++ b/bin/app-conf @@ -1,11 +1,9 @@ #!/bin/bash -# HEADER START -if [[ $APPSH_HOME == "" ]] -then - APPSH_HOME=`dirname "$0"` - APPSH_HOME=`cd "$APPSH_HOME/.." && pwd` -fi +set -e +set -u + +APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END @@ -125,7 +123,7 @@ case "$command" in exit 1 fi - conf_delete "$1" "$2" + conf_delete "$1" ;; *) if [ -z "$command" ] diff --git a/bin/app-init b/bin/app-init index e758916..cca82e1 100755 --- a/bin/app-init +++ b/bin/app-init @@ -1,14 +1,12 @@ -#!/bin/bash -e +#!/bin/bash +set -e set -u -if [[ $APPSH_HOME == "" ]] -then - APPSH_HOME=`dirname "$0"` - APPSH_HOME=`cd "$APPSH_HOME/.." && pwd` -fi +APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common +# HEADER END usage() { echo "usage: $0 -d dir " diff --git a/bin/app-instance b/bin/app-instance deleted file mode 100755 index 02e3c0f..0000000 --- a/bin/app-instance +++ /dev/null @@ -1,502 +0,0 @@ -#!/bin/bash - -if [[ $APPSH_HOME == "" ]] -then - APPSH_HOME=`dirname "$0"` - APPSH_HOME=`cd "$APPSH_HOME/.." && pwd` -fi - -if [ -n "$APPSH_REPO" ] -then - repo="$APPSH_REPO" -else - repo="http://repo1.maven.org" -fi - -calculate_md5() { - local file="$1"; shift - - md5sum "$file" | cut -c 1-32 -} - -# TODO: support file:// repositories -# TODO: look in the local repository first -get() { - local url=$1 - local file=$2 - local exit - - curl -o $file $url -D curl.tmp - - exit=`grep "^HTTP/[0-9]\.[0-9] 200 .*" curl.tmp >/dev/null; echo $?` - head=`head -n 1 curl.tmp` - rm -f curl.tmp - if [ "$exit" != 0 ] - then - echo "Unable to download $url: $head" >&2 - exit 1 - fi -} - -resolve_snapshot() { - local groupId=$1; shift - local groupIdSlash=$1; shift - local artifactId=$1; shift - local version=$1; shift - - local metadata=$apps/.app/var/download/$groupId-$artifactId-$version-metadata.xml - local base_url=$repo/$groupIdSlash/$artifactId/$version - get $base_url/maven-metadata.xml $metadata - local resolved_version=`xmlstarlet sel -t -m '//snapshotVersion[extension[text()="zip"]]' -v value $metadata` - echo $resolved_version -} - -download_artifact() { - local file="$1"; shift - local url="$1"; shift - - echo "Downloading $url.md5" - get $url.md5 $file.md5 - local expected_md5="`cat $file.md5`" - - if [ -r $file ] - then - if [ "$expected_md5" == "`calculate_md5 $file`" ] - then - echo "Artifact already downloaded." - else - rm -f "$file" - fi - return 0 - fi - echo "Downloading artifact: $url" - get $url $file - - local actual_md5="`calculate_md5 $file`" - if [ "$expected_md5" == "$actual_md5" ] - then - echo "Artifact downloaded." - else - echo "Invalid checksum. Expected $expected_md5, got $actual_md5" >&2 - exit 1 - fi -} - -method_install_usage() { - if [ -n "$1" ] - then - echo "Error:" "$@" >&2 - fi - - echo "usage: install <-r resolver> -u " >&2 - echo "" >&2 - echo "Install package from a Maven repository:" >&2 - echo " $0 [-n name] [-i instance] instance install -r maven -u groupId:artifactId:version" >&2 - echo "" >&2 - echo "Install package from a file:" >&2 - echo " $0 [-n name] [-i instance] instance install -r file -u file [-v version]" >&2 - echo "The version defaults to the current timestamp" >&2 - exit 1 -} - -method_install() { - local name="$1"; shift - local instance="$1"; shift - local version - local resolver - local url - local groupId - local artifactId - local zip_file - - - if [ $# -eq 0 ] - then - method_install_usage - fi - - while getopts "n:i:v:r:u:" opt - do - case $opt in - n) - name=$OPTARG - ;; - i) - instance=$OPTARG - ;; - v) - version=$OPTARG - ;; - r) - resolver=$OPTARG - ;; - u) - url=$OPTARG - ;; - \?) - method_install_usage "Invalid option: -$OPTARG" - ;; - esac - done - - if [ -z "$name" ] - then - method_install_usage "Missing required argument: -i name." - fi - - if [ -z "$instance" ] - then - method_install_usage "Missing required argument: -i instance." - fi - - if [ -z "$resolver" ] - then - method_install_usage "Missing required option: -r resolver" - fi - - if [ -z "$url" ] - then - method_install_usage "Missing required option: -u url" - fi - - case "$resolver" in - maven) - url=`echo $url | tr ":" " "`; set -- $url - groupId=$1 - artifactId=$2 - version=$3 - - if [ -z "$groupId" -o -z "$artifactId" -o -z "$version" ] - then - method_install_usage "Invalid Maven url." - fi - - local groupIdSlash=$(echo $groupId | sed "s,\.,/,g") - if [ "`echo $version | sed -n s,.*-SNAPSHOT$,SNAPSHOT,p`" == "SNAPSHOT" ] - then - echo "Resolving version $version..." - local resolved_version=`resolve_snapshot $groupId $groupIdSlash $artifactId $version` - if [ -z "$resolved_version" ] - then - echo "Unable to resolve version." - exit 1 - fi - echo "Resolved version $version to $resolved_version" - else - resolved_version=$version - fi - - zip_file=$apps/.app/var/download/$groupId-$artifactId-$resolved_version.zip - artifact_url=$repo/$groupIdSlash/$artifactId/$version/$artifactId-$resolved_version.zip - - download_artifact "$zip_file" "$artifact_url" - ;; - file) - if [ ! -r "$url" ] - then - echo "Could not read file: $url" >&2 - exit 1 - fi - - # TODO: should the zip file be copied into download/ so that - # there's always a local copy? - zip_file=$url - - if [ -z "$version" ] - then - version=`TZ=UTC date +"%Y%m%d-%H%M%S"` - fi - - resolved_version=$version - ;; - *) - method_install_usage "Invalid resolver type: $resolver" - ;; - esac - - if [ -d $name/$instance/versions/$resolved_version ] - then - echo "Version $resolved_version is already installed" - exit 1 - fi - - if [ ! -d $name/$instance ] - then - echo "Creating instance '$instance' for '$name'" - mkdir -p $name/$instance - fi - - mkdir -p $name/$instance/versions/$resolved_version - - echo "Unpacking..." - unzip -q -d $name/$instance/versions/$resolved_version $zip_file - - if [ ! -d $name/$instance/versions/$resolved_version/root ] - then - echo "Invalid zip file, did not contain a ./root directory." >&2 - exit 1 - fi - - echo "Changing current symlink" - rm -f $apps/$name/$instance/current - ln -s versions/$resolved_version/root $apps/$name/$instance/current - - if [ -d $name/$instance/current/bin ] - then - ( - cd $name/$instance/current - find bin -type f | xargs chmod +x - ) - fi - - ( - cd $name/$instance/versions/$resolved_version - if [ -d scripts ] - then - find scripts | xargs chmod +x - fi - - if [ -x scripts/postinstall ] - then - echo "Running postinstall..." - cd root - set +e - env -i \ - PATH=/bin:/usr/bin \ - APPSH_APPS=$apps \ - APPSH_HOME=$APPSH_HOME \ - APPSH_NAME=$name \ - APPSH_INSTANCE=$instance \ - APPSH_VERSION=$resolved_version \ - ../scripts/postinstall - set -e - ret=`echo $?` - if [ "$ret" != 0 ] - then - echo "Postinstall failed!" - exit 1 - fi - echo "Postinstall completed successfully" - fi - ) - - if [ -r $apps/.app/var/list ] - then - sed "/^$name:$instance/d" $apps/.app/var/list > $apps/.app/var/list.new - fi - echo "$name:$instance:$version:$url" >> $apps/.app/var/list.new - mv $apps/.app/var/list.new $apps/.app/var/list -} - -method_set_current_usage() { - if [ -n "$1" ] - then - echo "Error:" "$@" >&2 - fi - - echo "usage: set-current -v version" >&2 - exit 1 -} - -method_set_current() { - local name="$1"; shift - local instance="$1"; shift - local version - - if [ $# -eq 0 ] - then - method_set_current_usage - fi - - while getopts "n:i:v:" opt - do - case $opt in - n) - name=$OPTARG - ;; - i) - instance=$OPTARG - ;; - v) - version=$OPTARG - ;; - \?) - method_set_current_usage "Invalid option: -$OPTARG" - ;; - esac - done - - if [ -z "$version" ] - then - echo "Missing required option -v version." >&2 - exit 1 - fi - - assert_is_instance method_set_current_usage "$name" "$instance" "no" - - if [ ! -d $apps/$name/$instance/versions/$version ] - then - echo "Invalid version: $version." - exit 1 - fi - - rm -f $apps/$name/$instance/current - ln -s versions/$version/root $apps/$name/$instance/current - - return 0 -} - -method_list_usage() { - if [ -n "$1" ] - then - echo "Error:" "$@" >&2 - fi - - echo "usage: list [-n name] [-P field]" >&2 - echo "" - echo "List all installed applications:" >&2 - echo " list" >&2 - echo "" - echo "List all applications with the selected fields with parseable output:" >&2 - echo " list -P instance -P version -n foo" >&2 - exit 1 -} - -method_list() { - local filter_name="$1"; shift - local filter_instance="$1"; shift - local mode="pretty" - local vars - local filter_name - - while getopts "P:n:i:" opt - do - case $opt in - P) - mode="parseable" - vars="$vars $OPTARG" - ;; - n) - filter_name=$OPTARG - ;; - i) - filter_instance=$OPTARG - ;; - \?) - method_list_usage "Invalid option: -$OPTARG" - ;; - esac - done - - if [ ! -r $apps/.app/var/list ] - then - return - fi - - if [ $mode = "pretty" ] - then - printf "%-20s %-20s %-20s\n" "Name" "Instance" "Version" - list_apps "$filter_name" "$filter_instance" name instance version | (IFS=:; while read name instance version - do - printf "%-20s %-20s %-20s\n" "$name" "$instance" "$version" - done) - else - list_apps "$filter_name" "$filter_instance" $vars - fi -} - -method_list_versions_usage() { - if [ -n "$1" ] - then - echo "Error:" "$@" >&2 - fi - - echo "usage: list-versions -n name -i instance [-P]" >&2 - exit 1 -} - -method_list_versions() { - local filter_name="$1"; shift - local instance="$1"; shift - local version - local mode="pretty" - - if [ $# -eq 0 ] - then - method_list_versions_usage - fi - - while getopts "n:i:P" opt - do - case $opt in - n) - name=$OPTARG - ;; - i) - instance=$OPTARG - ;; - v) - version=$OPTARG - ;; - P) - mode="parseable" - ;; - \?) - method_list_versions_usage "Invalid option: -$OPTARG" - ;; - esac - done - - assert_is_instance method_list_versions_usage "$name" "$instance" "no" - - if [ $mode = "pretty" ] - then - echo "Available versions for $name/$instance:" - fi - - find_versions $name $instance - - return 0 -} - -method_instance_usage() { - if [ -n "$1" ] - then - echo "Error:" $@ >&2 - fi - - echo "usage: $0 instance " >&2 - echo "" >&2 - echo "Available methods:" >&2 - echo " install - Installs an application" >&2 - echo " list - List all installed applications" >&2 - echo " list-versions - List all available versions for a single application" >&2 - echo " set-current - Set the current version" >&2 -} - -method_instance() { - local name="$1"; shift - local instance="$1"; shift - local method="$1" - - if [ $# -gt 0 ] - then - shift - fi - - case "$method" in - install) method_install "$name" "$instance" "$@" ;; - list) method_list "$name" "$instance" "$@" ;; - list-versions) method_list_versions "$name" "$instance" "$@" ;; - set-current) method_set_current "$name" "$instance" "$@" ;; - *) - if [ -z "$method" ] - then - method_instance_usage - else - method_instance_usage "Unknown method $method" - fi - ;; - esac - exit $? -} diff --git a/bin/app-operate b/bin/app-operate deleted file mode 100755 index dc16780..0000000 --- a/bin/app-operate +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/bash - -if [[ $APPSH_HOME == "" ]] -then - APPSH_HOME=`dirname "$0"` - APPSH_HOME=`cd "$APPSH_HOME/.." && pwd` -fi - -operate_usage() { - if [ -n "$1" ] - then - echo "Error:" "$@" >&2 - fi - - echo "usage: $0 [operate method] -n name -i instance" >&2 - exit 1 -} - -method_operate_usage() { - if [ -n "$1" ] - then - echo "Error:" $@ >&2 - fi - - echo "usage: $0 operate " >&2 - echo "" >&2 - echo "Available operate methods:" >&2 - echo " start" >&2 - echo " stop" >&2 - echo " restart" >&2 - echo " status" >&2 -} - -method_operate() { - local name="$1"; shift - local instance="$1"; shift - local method="$1" - - if [ $# -gt 0 ] - then - shift - fi - - bin=`$APPSH_HOME/bin/app-cat-conf -f $apps/$name/$instance/current/etc/app.conf -g app -k method | cut -f 2 -d =` - - if [ -z "$bin" ] - then - bin=$APPSH_HOME/.app/lib/pid-method - fi - - if [ ! -x "$name/$instance/current/$bin" ] - then - echo "Invalid executable: $bin" >&2 - exit 1 - fi - - case "$method" in - start) run_app "$name" "$instance" "$bin" "start" "$@" ;; - stop) run_app "$name" "$instance" "$bin" "stop" "$@" ;; - status) run_app "$name" "$instance" "$bin" "status" "$@" ;; - restart) run_app "$name" "$instance" "$bin" "restart" "$@" ;; - run) run_app "$name" "$instance" "$bin" "run" "$@" ;; - *) - if [ -z "$method" ] - then - method_operate_usage - else - method_operate_usage "Unknown method $method" - fi - ;; - esac - exit $? -} diff --git a/bin/app-start b/bin/app-start new file mode 100755 index 0000000..be290ce --- /dev/null +++ b/bin/app-start @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e +set -u + +APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) + +. $APPSH_HOME/lib/common +# HEADER END + +exec $APPSH_HOME/libexec/app-operate "start" "$@" diff --git a/bin/app-stop b/bin/app-stop new file mode 100755 index 0000000..535af9e --- /dev/null +++ b/bin/app-stop @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e +set -u + +APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) + +. $APPSH_HOME/lib/common +# HEADER END + +exec $APPSH_HOME/libexec/app-operate "stop" "$@" diff --git a/lib/header b/lib/header new file mode 100644 index 0000000..805e06e --- /dev/null +++ b/lib/header @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e +set -u + +APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) + +. $APPSH_HOME/lib/common diff --git a/libexec/app-cat-conf b/libexec/app-cat-conf index 78d3c36..5da435e 100755 --- a/libexec/app-cat-conf +++ b/libexec/app-cat-conf @@ -1,16 +1,17 @@ #!/bin/bash -if [[ $APPSH_HOME == "" ]] -then - APPSH_HOME=`dirname "$0"` - APPSH_HOME=`cd "$APPSH_HOME/.." && pwd` -fi - set -e +set -u + +APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) + +. $APPSH_HOME/lib/common +# HEADER END key_expr="[a-zA-Z][_a-zA-Z0-9]*" file=.app/config +name="" while getopts "f:n:" opt do @@ -35,13 +36,10 @@ else filter="s,^\($name\)=\(.*\),\1=\2,p" fi -if [[ $APPSH_DEFAULT_CONFIG == "" ]] -then - APPSH_DEFAULT_CONFIG=$APPSH_HOME/lib/default-config -fi +APPSH_DEFAULT_CONFIG=${APPSH_DEFAULT_CONFIG-$APPSH_HOME/lib/default-config} # The awk script makes sure each key only appears once cat "$file" "$APPSH_DEFAULT_CONFIG" | \ - sed -n -e "$filter" $extra | \ + sed -n -e "$filter" | \ awk -F = ' (!($1 in a)){a[$1]; print }' | \ sort diff --git a/libexec/app-grep-path b/libexec/app-grep-path index f5e8287..fa6e5e5 100755 --- a/libexec/app-grep-path +++ b/libexec/app-grep-path @@ -1,13 +1,13 @@ #!/bin/bash -# A command line wrapper around get grep_path function +set -e +set -u -if [[ $APPSH_HOME == "" ]] -then - APPSH_HOME=`dirname "$0"` - APPSH_HOME=`cd "$APPSH_HOME/.." && pwd` -fi +APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common +# HEADER END + +# A command line wrapper around get grep_path function grep_path "$1" "$2" diff --git a/libexec/app-install-file b/libexec/app-install-file index 6c06aa7..a0d929a 100755 --- a/libexec/app-install-file +++ b/libexec/app-install-file @@ -1,10 +1,12 @@ #!/bin/bash -if [[ $APPSH_HOME == "" ]] -then - APPSH_HOME=`dirname "$0"` - APPSH_HOME=`cd "$APPSH_HOME/.." && pwd` -fi +set -e +set -u + +APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) + +. $APPSH_HOME/lib/common +# HEADER END calculate_md5() { local file="$1"; shift diff --git a/libexec/app-operate b/libexec/app-operate new file mode 100755 index 0000000..8e4ecac --- /dev/null +++ b/libexec/app-operate @@ -0,0 +1,50 @@ +#!/bin/bash + +set -e +set -u + +APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) + +. $APPSH_HOME/lib/common +# HEADER END + +method_operate() { + local name="$1"; shift + local instance="$1"; shift + local method="$1" + + if [ $# -gt 0 ] + then + shift + fi + + bin=`$APPSH_HOME/bin/app-cat-conf -f $apps/$name/$instance/current/etc/app.conf -g app -k method | cut -f 2 -d =` + + if [ -z "$bin" ] + then + bin=$APPSH_HOME/.app/lib/pid-method + fi + + if [ ! -x "$name/$instance/current/$bin" ] + then + echo "Invalid executable: $bin" >&2 + exit 1 + fi + + case "$method" in + start) run_app "$name" "$instance" "$bin" "start" "$@" ;; + stop) run_app "$name" "$instance" "$bin" "stop" "$@" ;; + status) run_app "$name" "$instance" "$bin" "status" "$@" ;; + restart) run_app "$name" "$instance" "$bin" "restart" "$@" ;; + run) run_app "$name" "$instance" "$bin" "run" "$@" ;; + *) + if [ -z "$method" ] + then + method_operate_usage + else + method_operate_usage "Unknown method $method" + fi + ;; + esac + exit $? +} diff --git a/libexec/app-resolver-maven b/libexec/app-resolver-maven index cb137fa..a347abb 100755 --- a/libexec/app-resolver-maven +++ b/libexec/app-resolver-maven @@ -1,12 +1,12 @@ -#!/bin/bash -e +#!/bin/bash +set -e set -u -if [[ $APPSH_HOME == "" ]] -then - APPSH_HOME=`dirname "$0"` - APPSH_HOME=`cd "$APPSH_HOME/.." && pwd` -fi +APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) + +. $APPSH_HOME/lib/common +# HEADER END usage() { message=${1-} diff --git a/test/X-app-help.bats b/test/X-app-help.bats new file mode 100755 index 0000000..4b94f23 --- /dev/null +++ b/test/X-app-help.bats @@ -0,0 +1,38 @@ +#!/usr/bin/env bats +# vim: set filetype=sh: + +load utils + +@test "./app instance" { + app instance; echo_lines + [ $status -eq $exit_usage_wrong ] + [ $(expr "${lines[0]}" : "usage: ./app instance .*") -ne 0 ] + [ ${#lines[*]} == 6 ] +} + +@test "./app instance install" { + app instance install; echo_lines + [ $status -eq $exit_usage ] + [ $(expr "${lines[0]}" : "usage: install .*") -ne 0 ] + [ ${#lines[*]} == 6 ] +} + +@test "./app instance list" { + app instance list; echo_lines + [ $status -eq 0 ] + [ ${#lines[*]} == 0 ] +} + +@test "./app instance list-versions" { + app instance list-versions; echo_lines + [ $status -eq $exit_usage ] + [ $(expr "${lines[0]}" : "usage: list-versions .*") -ne 0 ] + [ ${#lines[*]} == 1 ] +} + +@test "./app instance set-current" { + app instance "set-current"; echo_lines + [ $status -eq $exit_usage ] + [ $(expr "${lines[0]}" : "usage: set-current .*") -ne 0 ] + [ ${#lines[*]} == 1 ] +} diff --git a/test/X-app-install.bats b/test/X-app-install.bats new file mode 100755 index 0000000..18a84bc --- /dev/null +++ b/test/X-app-install.bats @@ -0,0 +1,50 @@ +#!/usr/bin/env bats +# vim: set filetype=sh: + +load utils + +# TODO: Add test for installing duplicate version + +@test "./app install app-a" { + mkzip "app-a" + app install \ + -r file \ + -u $BATS_TEST_DIRNAME/data/app-a.zip + + echo_lines + [ $status -eq 0 ] + [ "$output" = "Creating instance 'prod' for 'app-a' +Unpacking... +Changing current symlink +Running postinstall... +Hello World! +Creating logs directory +Postinstall completed successfully" ] + [ ${#lines[*]} == 7 ] +} + +@test "./app instance install install-test-env" { + mkzip "install-test-env" + app instance install \ + -r file \ + -u $BATS_TEST_DIRNAME/data/install-test-env.zip \ + -v 1.0 + echo_lines + [ $status -eq 0 ] + [ "$output" = "Creating instance 'prod' for 'install-test-env' +Unpacking... +Changing current symlink +Running postinstall... +APPSH_APPS=$APPSH_APPS +APPSH_HOME=$APPSH_HOME +APPSH_INSTANCE=prod +APPSH_NAME=install-test-env +APPSH_VERSION=1.0 +PATH=/bin:/usr/bin +PWD=$APPSH_APPS_CANONICAL/install-test-env/prod/versions/1.0/root +SHLVL=1 +_=/usr/bin/env +Postinstall completed successfully" ] + [ ${#lines[*]} == 14 ] +# PWD=$APPSH_APPS_CANONICAL/install-test-env/prod/versions/1.0 +} diff --git a/test/X-app-list-versions.bats b/test/X-app-list-versions.bats new file mode 100755 index 0000000..de543eb --- /dev/null +++ b/test/X-app-list-versions.bats @@ -0,0 +1,28 @@ +#!/usr/bin/env bats +# vim: set filetype=sh: + +load utils + +@test "./app instance list-versions" { + mkzip "app-a" + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 + [ $status -eq 0 ] + + app instance list-versions -n app-a -i env-a; echo_lines + [ $status -eq 0 ] + [ "$output" = "Available versions for app-a/env-a: +1.0 +1.1" ] + + expected="1.0 +1.1" + +set -x + app -n app-a instance -i env-a list-versions -P; [ "$output" = "$expected" ]; echo_lines; + app -n app-a instance list-versions -i env-a -P; [ "$output" = "$expected" ]; echo_lines; + app instance list-versions -n app-a -i env-a -P; [ "$output" = "$expected" ]; echo_lines; +} diff --git a/test/X-app-list.bats b/test/X-app-list.bats new file mode 100755 index 0000000..3092837 --- /dev/null +++ b/test/X-app-list.bats @@ -0,0 +1,102 @@ +#!/usr/bin/env bats +# vim: set filetype=sh: + +load utils + +@test "./app instance list - all apps" { + mkzip "app-a" + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 + [ $status -eq 0 ] + + app instance list; echo_lines + [ $status -eq 0 ] + [ "$output" = "Name Instance Version +app-a env-a 1.1 +app-a env-b 1.0 +app-b env-a 1.0 +app-b env-b 1.0 " ] + + app instance list -P name -P instance -P version; echo_lines + [ $status -eq 0 ] + [ "$output" = "app-a:env-a:1.1 +app-a:env-b:1.0 +app-b:env-a:1.0 +app-b:env-b:1.0" ] +} + +@test "./app instance list - -n filter" { + mkzip "app-a" + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 + [ $status -eq 0 ] + + app instance list -n foo; echo_lines + [ $status -eq 0 ] + [ "$output" = "Name Instance Version " ] + + app instance list -n app-a; echo_lines + [ $status -eq 0 ] + [ "$output" = "Name Instance Version +app-a env-a 1.1 +app-a env-b 1.0 " ] + + app instance list -n app-a -P name -P instance -P version; echo_lines + [ $status -eq 0 ] + [ "$output" = "app-a:env-a:1.1 +app-a:env-b:1.0" ] +} + +@test "./app instance list - -i filter" { + mkzip "app-a" + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 + [ $status -eq 0 ] + + app instance list -i foo; echo_lines + [ $status -eq 0 ] + [ "$output" = "Name Instance Version " ] + + app instance list -i env-a; echo_lines + [ $status -eq 0 ] + [ "$output" = "Name Instance Version +app-a env-a 1.1 +app-b env-a 1.0 " ] + + app instance list -i env-a -P name -P instance -P version; echo_lines + [ $status -eq 0 ] + [ "$output" = "app-a:env-a:1.1 +app-b:env-a:1.0" ] +} + +@test "./app instance list - -n + -i filter" { + mkzip "app-a" + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && + app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 + [ $status -eq 0 ] + + app instance list -n foo -i bar; echo_lines + [ $status -eq 0 ] + [ "$output" = "Name Instance Version " ] + + app instance list -n app-a -i env-a; echo_lines + [ $status -eq 0 ] + [ "$output" = "Name Instance Version +app-a env-a 1.1 " ] + + app instance list -n app-a -i env-a -P name -P instance -P version; echo_lines + [ $status -eq 0 ] + [ "$output" = "app-a:env-a:1.1" ] +} diff --git a/test/X-help.bats b/test/X-help.bats new file mode 100755 index 0000000..eba4eeb --- /dev/null +++ b/test/X-help.bats @@ -0,0 +1,17 @@ +#!/usr/bin/env bats +# vim: set filetype=sh: + +load utils + +@test "./app" { + app; echo_lines + [ $status -eq $exit_usage_wrong ] + [ $(expr "${lines[0]}" : "usage: ./app .*") -ne 0 ] +} + +@test "./app foo" { + app foo; echo_lines + [ $status -eq $exit_usage_wrong ] + [ "${lines[0]}" = "Error: No such method group: foo" ] + [ $(expr "${lines[1]}" : "usage: ./app .*") -ne 0 ] +} diff --git a/test/X-it-install-remove.bats b/test/X-it-install-remove.bats new file mode 100755 index 0000000..78f4532 --- /dev/null +++ b/test/X-it-install-remove.bats @@ -0,0 +1,45 @@ +#!/usr/bin/env bats +# vim: set filetype=sh: + +load utils + +@test "install remove roundtrip" { + mkzip "app-a" + name="app-a" + instance="prod" + a="-n $name -i $instance" + + describe "Installing $name/$instance" + app instance install \ + -r file \ + -u $BATS_TEST_DIRNAME/data/app-a.zip \ + -n $name -i $instance; echo_lines + [ $status -eq 0 ] + + can_not_read ".app/var/pid/$name-$instance.pid" + + describe "Setting property" + app -n $name -i $instance conf set env.TEST_PROPERTY awesome + [ $status -eq 0 ] + + describe "Starting $name/$instance" + app -n $name -i $instance operate start + echo_lines + [ $status -eq 0 ] + can_read .app/var/pid/$name-$instance.pid + + describe "Stopping $name/$instance" + app -n $name -i $instance operate stop + [ $status -eq 0 ] + echo_lines + can_not_read .app/var/pid/$name-$instance.pid + + can_read "$name/$instance/logs/$name.log" + can_read "$name/$instance/logs/$name.env" + can_read "$name/$instance/current/foo.conf" + + [ "`cat $name/$instance/logs/$name.env`" = "TEST_PROPERTY=awesome" ] + [ "`cat $name/$instance/current/foo.conf`" = "hello" ] + + # TODO: Remove the version +} diff --git a/test/app-help.bats b/test/app-help.bats deleted file mode 100755 index 4b94f23..0000000 --- a/test/app-help.bats +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bats -# vim: set filetype=sh: - -load utils - -@test "./app instance" { - app instance; echo_lines - [ $status -eq $exit_usage_wrong ] - [ $(expr "${lines[0]}" : "usage: ./app instance .*") -ne 0 ] - [ ${#lines[*]} == 6 ] -} - -@test "./app instance install" { - app instance install; echo_lines - [ $status -eq $exit_usage ] - [ $(expr "${lines[0]}" : "usage: install .*") -ne 0 ] - [ ${#lines[*]} == 6 ] -} - -@test "./app instance list" { - app instance list; echo_lines - [ $status -eq 0 ] - [ ${#lines[*]} == 0 ] -} - -@test "./app instance list-versions" { - app instance list-versions; echo_lines - [ $status -eq $exit_usage ] - [ $(expr "${lines[0]}" : "usage: list-versions .*") -ne 0 ] - [ ${#lines[*]} == 1 ] -} - -@test "./app instance set-current" { - app instance "set-current"; echo_lines - [ $status -eq $exit_usage ] - [ $(expr "${lines[0]}" : "usage: set-current .*") -ne 0 ] - [ ${#lines[*]} == 1 ] -} diff --git a/test/app-install.bats b/test/app-install.bats deleted file mode 100755 index 18a84bc..0000000 --- a/test/app-install.bats +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bats -# vim: set filetype=sh: - -load utils - -# TODO: Add test for installing duplicate version - -@test "./app install app-a" { - mkzip "app-a" - app install \ - -r file \ - -u $BATS_TEST_DIRNAME/data/app-a.zip - - echo_lines - [ $status -eq 0 ] - [ "$output" = "Creating instance 'prod' for 'app-a' -Unpacking... -Changing current symlink -Running postinstall... -Hello World! -Creating logs directory -Postinstall completed successfully" ] - [ ${#lines[*]} == 7 ] -} - -@test "./app instance install install-test-env" { - mkzip "install-test-env" - app instance install \ - -r file \ - -u $BATS_TEST_DIRNAME/data/install-test-env.zip \ - -v 1.0 - echo_lines - [ $status -eq 0 ] - [ "$output" = "Creating instance 'prod' for 'install-test-env' -Unpacking... -Changing current symlink -Running postinstall... -APPSH_APPS=$APPSH_APPS -APPSH_HOME=$APPSH_HOME -APPSH_INSTANCE=prod -APPSH_NAME=install-test-env -APPSH_VERSION=1.0 -PATH=/bin:/usr/bin -PWD=$APPSH_APPS_CANONICAL/install-test-env/prod/versions/1.0/root -SHLVL=1 -_=/usr/bin/env -Postinstall completed successfully" ] - [ ${#lines[*]} == 14 ] -# PWD=$APPSH_APPS_CANONICAL/install-test-env/prod/versions/1.0 -} diff --git a/test/app-list-versions.bats b/test/app-list-versions.bats deleted file mode 100755 index de543eb..0000000 --- a/test/app-list-versions.bats +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bats -# vim: set filetype=sh: - -load utils - -@test "./app instance list-versions" { - mkzip "app-a" - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 - [ $status -eq 0 ] - - app instance list-versions -n app-a -i env-a; echo_lines - [ $status -eq 0 ] - [ "$output" = "Available versions for app-a/env-a: -1.0 -1.1" ] - - expected="1.0 -1.1" - -set -x - app -n app-a instance -i env-a list-versions -P; [ "$output" = "$expected" ]; echo_lines; - app -n app-a instance list-versions -i env-a -P; [ "$output" = "$expected" ]; echo_lines; - app instance list-versions -n app-a -i env-a -P; [ "$output" = "$expected" ]; echo_lines; -} diff --git a/test/app-list.bats b/test/app-list.bats deleted file mode 100755 index 3092837..0000000 --- a/test/app-list.bats +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env bats -# vim: set filetype=sh: - -load utils - -@test "./app instance list - all apps" { - mkzip "app-a" - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 - [ $status -eq 0 ] - - app instance list; echo_lines - [ $status -eq 0 ] - [ "$output" = "Name Instance Version -app-a env-a 1.1 -app-a env-b 1.0 -app-b env-a 1.0 -app-b env-b 1.0 " ] - - app instance list -P name -P instance -P version; echo_lines - [ $status -eq 0 ] - [ "$output" = "app-a:env-a:1.1 -app-a:env-b:1.0 -app-b:env-a:1.0 -app-b:env-b:1.0" ] -} - -@test "./app instance list - -n filter" { - mkzip "app-a" - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 - [ $status -eq 0 ] - - app instance list -n foo; echo_lines - [ $status -eq 0 ] - [ "$output" = "Name Instance Version " ] - - app instance list -n app-a; echo_lines - [ $status -eq 0 ] - [ "$output" = "Name Instance Version -app-a env-a 1.1 -app-a env-b 1.0 " ] - - app instance list -n app-a -P name -P instance -P version; echo_lines - [ $status -eq 0 ] - [ "$output" = "app-a:env-a:1.1 -app-a:env-b:1.0" ] -} - -@test "./app instance list - -i filter" { - mkzip "app-a" - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 - [ $status -eq 0 ] - - app instance list -i foo; echo_lines - [ $status -eq 0 ] - [ "$output" = "Name Instance Version " ] - - app instance list -i env-a; echo_lines - [ $status -eq 0 ] - [ "$output" = "Name Instance Version -app-a env-a 1.1 -app-b env-a 1.0 " ] - - app instance list -i env-a -P name -P instance -P version; echo_lines - [ $status -eq 0 ] - [ "$output" = "app-a:env-a:1.1 -app-b:env-a:1.0" ] -} - -@test "./app instance list - -n + -i filter" { - mkzip "app-a" - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 - [ $status -eq 0 ] - - app instance list -n foo -i bar; echo_lines - [ $status -eq 0 ] - [ "$output" = "Name Instance Version " ] - - app instance list -n app-a -i env-a; echo_lines - [ $status -eq 0 ] - [ "$output" = "Name Instance Version -app-a env-a 1.1 " ] - - app instance list -n app-a -i env-a -P name -P instance -P version; echo_lines - [ $status -eq 0 ] - [ "$output" = "app-a:env-a:1.1" ] -} diff --git a/test/help.bats b/test/help.bats deleted file mode 100755 index eba4eeb..0000000 --- a/test/help.bats +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bats -# vim: set filetype=sh: - -load utils - -@test "./app" { - app; echo_lines - [ $status -eq $exit_usage_wrong ] - [ $(expr "${lines[0]}" : "usage: ./app .*") -ne 0 ] -} - -@test "./app foo" { - app foo; echo_lines - [ $status -eq $exit_usage_wrong ] - [ "${lines[0]}" = "Error: No such method group: foo" ] - [ $(expr "${lines[1]}" : "usage: ./app .*") -ne 0 ] -} diff --git a/test/it-install-remove.bats b/test/it-install-remove.bats deleted file mode 100755 index 78f4532..0000000 --- a/test/it-install-remove.bats +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bats -# vim: set filetype=sh: - -load utils - -@test "install remove roundtrip" { - mkzip "app-a" - name="app-a" - instance="prod" - a="-n $name -i $instance" - - describe "Installing $name/$instance" - app instance install \ - -r file \ - -u $BATS_TEST_DIRNAME/data/app-a.zip \ - -n $name -i $instance; echo_lines - [ $status -eq 0 ] - - can_not_read ".app/var/pid/$name-$instance.pid" - - describe "Setting property" - app -n $name -i $instance conf set env.TEST_PROPERTY awesome - [ $status -eq 0 ] - - describe "Starting $name/$instance" - app -n $name -i $instance operate start - echo_lines - [ $status -eq 0 ] - can_read .app/var/pid/$name-$instance.pid - - describe "Stopping $name/$instance" - app -n $name -i $instance operate stop - [ $status -eq 0 ] - echo_lines - can_not_read .app/var/pid/$name-$instance.pid - - can_read "$name/$instance/logs/$name.log" - can_read "$name/$instance/logs/$name.env" - can_read "$name/$instance/current/foo.conf" - - [ "`cat $name/$instance/logs/$name.env`" = "TEST_PROPERTY=awesome" ] - [ "`cat $name/$instance/current/foo.conf`" = "hello" ] - - # TODO: Remove the version -} -- cgit v1.2.3