#!/bin/bash set -e set -u APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END usage_inner() { echo "usage: $usage_app -d dir " } while getopts "d:" opt do case $opt in d) dir=$OPTARG shift 2 OPTIND=1 ;; esac done if [ $# -lt 1 ] then usage fi resolver_name="$1"; shift if [ -z "$dir" ] then usage fi if [ -e "$dir" ] then fatal "Already initialized: $dir" 2>&1 fi resolver=`grep_path "/app-resolver-$resolver_name$" "$PATH" | head -n 1` if [ -z "$resolver" ] then echo "No such resolver: $resolver_name" 2>&1 exit 1 fi mkdir -p -- "$dir" "$dir/.app" ok=no clean_dir=`cd "$dir">/dev/null; pwd` trap '[[ $ok == yes ]] || rm -rf "$clean_dir"' EXIT cd "$dir" app-conf set app.resolver "$resolver_name" "$resolver" init "$@" "$resolver" resolve-version version=`app-conf get app.version` if [[ $version == "" ]] then echo "Unable to resolve version" 2>&1 exit fi echo "Resolved version to $version" "$resolver" download-version -v "$version" -f .app/latest.zip app-install-file -v "$version" -f .app/latest.zip ok=yes