From e1daac32c5b7ca0d902c16135d361aa5303f5124 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 27 Jan 2013 15:00:27 +0100 Subject: o Creating an initial version of install-file. --- libexec/app-install-file | 170 +++++++++-------------------------------------- 1 file changed, 33 insertions(+), 137 deletions(-) (limited to 'libexec/app-install-file') diff --git a/libexec/app-install-file b/libexec/app-install-file index a0d929a..1e3edb8 100755 --- a/libexec/app-install-file +++ b/libexec/app-install-file @@ -8,127 +8,53 @@ APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END -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 +usage() { + echo "usage: $0 -v -f " + exit 1 } -if [ $# -lt 2 ] +version= +file= + +while getopts "v:f:" opt +do + case $opt in + v) + version=$OPTARG + shift 2 + OPTIND=1 + ;; + f) + file=$OPTARG + shift 2 + OPTIND=1 + ;; + esac +done + +if [[ -z $version || -z $file || $# != 0 ]] then - method_install_usage + usage fi -case "$resolver" in - maven) - ;; - 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 versions/$resolved_version ] +if [ -d versions/$version ] then - echo "Version $resolved_version is already installed" + echo "Version $version is already installed" exit 1 fi -mkdir -p versions/$resolved_version +mkdir -p versions/$version echo "Unpacking..." -unzip -q -d versions/$resolved_version $zip_file +unzip -q -d versions/$version $file -if [ ! -d versions/$resolved_version/root ] +if [ ! -d versions/$version/root ] then echo "Invalid zip file, did not contain a ./root directory." >&2 exit 1 fi -echo "Changing current symlink" -rm -f current -ln -s versions/$resolved_version/root current - +# TODO: This should go away if [ -d current/bin ] then ( @@ -137,38 +63,8 @@ then ) fi -( - cd versions/$resolved_version - if [ -d scripts ] - then - find scripts | xargs chmod +x - fi +app-run-hook -v "$version" -h pre-install - 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_VERSION=$resolved_version \ - ../scripts/postinstall - set -e - ret=`echo $?` - if [ "$ret" != 0 ] - then - echo "Postinstall failed!" - exit 1 - fi - echo "Postinstall completed successfully" - fi -) +app-set-version -v "$version" -# 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 +app-run-hook -v "$version" -h post-install -- cgit v1.2.3