aboutsummaryrefslogtreecommitdiff
path: root/bin/app-init
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-01-26 23:58:22 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2013-01-26 23:58:22 +0100
commit110ffae47db27a49bbc43f86ba3737bccc1b3085 (patch)
treed74934b12e2904b8aff5fe87421a6501b8ea5c8e /bin/app-init
parentca27d6f6d9ccc35bf55db3d360d1d464d5e206e7 (diff)
downloadapp.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.tar.gz
app.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.tar.bz2
app.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.tar.xz
app.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.zip
o Rewriting most of this stuff to make it feel more like git.
Diffstat (limited to 'bin/app-init')
-rwxr-xr-xbin/app-init79
1 files changed, 79 insertions, 0 deletions
diff --git a/bin/app-init b/bin/app-init
new file mode 100755
index 0000000..e758916
--- /dev/null
+++ b/bin/app-init
@@ -0,0 +1,79 @@
+#!/bin/bash -e
+
+set -u
+
+if [[ $APPSH_HOME == "" ]]
+then
+ APPSH_HOME=`dirname "$0"`
+ APPSH_HOME=`cd "$APPSH_HOME/.." && pwd`
+fi
+
+. $APPSH_HOME/lib/common
+
+usage() {
+ echo "usage: $0 -d dir <resolver> <resolver args>"
+ exit 1
+}
+
+fatal() {
+ echo "$0: $@"
+ exit 1
+}
+
+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
+
+# TODO: install a trap handler and rm -rf "$dir"
+
+resolver=`grep_path "/app-resolver-$resolver_name$" "$PATH:$APPSH_HOME/libexec" | head -n 1`
+
+if [ -z "$resolver" ]
+then
+ echo "No such resolver: $resolver_name" 2>&1
+ exit 1
+fi
+
+mkdir -- "$dir" "$dir/.app"
+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