Files
minideb/namibase/rootfs/usr/local/bin/bitnami-pkg
T
2016-09-02 14:48:09 +01:00

124 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
set -e
print_usage() {
echo "Usage: bitnami-pkg <COMMAND> <PACKAGE>-<VERSION> [OPTIONS] -- [ARGS]"
echo ""
echo "Download and install Stacksmith packages"
echo ""
echo "Commands:"
echo " install Download and install a package."
echo " unpack Download and unpack a package."
echo ""
echo "Options:"
echo " -b, --bucket Package release bucket (default: stacksmith)."
echo " -c, --checksum SHA256 verification checksum."
echo " -h, --help Show this help message and exit."
echo ""
echo "Examples:"
echo " - Unpack package"
echo " \$ bitnami-pkg unpack nginx-1.9.10-0"
echo ""
echo " - Verify and Install package"
echo " \$ bitnami-pkg install nginx-1.9.10-0 --checksum 15565d06b18c2e3710fc08e579ddb3d0e39aa663264a0f7404f0743cb4cdb58d"
echo ""
echo " - Install package with arguments"
echo " \$ bitnami-pkg install mariadb-10.1.11-0 -- --password bitnami"
echo ""
echo " - Install package from testing"
echo " \$ bitnami-pkg install mariadb-10.1.11-0 --bucket testing"
echo ""
}
# break up command line for easy parsing and check legal options
ARGS=$(busybox getopt -o b:c:h -l "bucket:,checksum:,help" -n "bitnami-pkg" -- "$@")
if [ $? -ne 0 ];
then
exit 1
fi
eval set -- "$ARGS";
while true; do
case "$1" in
-b|--bucket)
shift
if [ -n "$1" ]; then
RELEASE_BUCKET=$1
shift
fi
;;
-c|--checksum)
shift
if [ -n "$1" ]; then
PACKAGE_SHA256=$1
shift
fi
;;
-h|--help)
print_usage
exit 0
;;
--)
shift
break
;;
esac
done
# weed out unrecognized commands
case "$1" in
install|unpack)
;;
*)
echo "ERROR: Unrecognized command: $1"
echo ""
print_usage
exit 1
;;
esac
# install/unpack command need to be supplied a package name
if [ $# -lt 2 ]; then
print_usage
exit 1
fi
INSTALL_ROOT=/tmp/bitnami/pkg/install
CACHE_ROOT=/tmp/bitnami/pkg/cache
PACKAGE="$2-linux-x64"
PACKAGE_ARGS=${@:3}
PACKAGE_NAME=$(echo $PACKAGE | sed 's/-[0-9].*//')
RELEASE_BUCKET=${RELEASE_BUCKET:-stacksmith}
mkdir -p $INSTALL_ROOT
cd $INSTALL_ROOT
echo "===> Downloading $PACKAGE package"
if [ -f $CACHE_ROOT/$PACKAGE.tar.gz ]; then
echo "===> $CACHE_ROOT/$PACKAGE_NAME.tar.gz already exists, skipping download."
cp $CACHE_ROOT/$PACKAGE.tar.gz .
else
# display cURL progress bar when a tty is attached
if tty -s; then
CURL_ARGS="-#"
else
CURL_ARGS="-sS"
fi
curl $CURL_ARGS -LO https://downloads.bitnami.com/files/$RELEASE_BUCKET/$PACKAGE.tar.gz
fi
if [ "$PACKAGE_SHA256" ]; then
echo "===> Verifying package integrity"
echo "$PACKAGE_SHA256 $PACKAGE.tar.gz" | sha256sum -c -
fi
tar xzf $PACKAGE.tar.gz
case "$1" in
install) echo "===> Installing $PACKAGE" ;;
unpack) echo "===> Unpacking $PACKAGE" ;;
esac
nami $1 $PACKAGE $PACKAGE_ARGS
rm -rf $INSTALL_ROOT