Improve install script (#842)
* Add checksum to install script This will allow someone to check if Babashka is correctly downloaded, e.g.: ``` $ ./install --dir /tmp --checksum 3cb19f158b9f1655e0165b6c4067d35faaa05882bbdb230616c91085b02b5bf4 Downloading https://github.com/babashka/babashka/releases/download/v0.4.1/babashka-0.4.1-linux-amd64.tar.gz to /tmp Failed checksum on babashka-0.4.1-linux-amd64.tar.gz Got: 3cb19f158b9f1655e0165b6c4067d35faaa05882bbdb230616c91085b02b5bf3 Expected: 3cb19f158b9f1655e0165b6c4067d35faaa05882bbdb230616c91085b02b5bf4 ``` There is no check by default. This makes this change backwards compatible (e.g.: if the machine doesn't have sha256sum, this change will not break installation). * Add --static to install script This will allow installation of static instead of dynamically binaries on Linux. * Add checksum to print_help * Add check that --checksum and --options should be provided together
This commit is contained in:
parent
e6a2fdbb45
commit
c39d4bc320
1 changed files with 52 additions and 16 deletions
68
install
68
install
|
|
@ -3,20 +3,28 @@
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
version=""
|
version=""
|
||||||
|
checksum=""
|
||||||
|
static_binary="false"
|
||||||
default_install_dir="/usr/local/bin"
|
default_install_dir="/usr/local/bin"
|
||||||
install_dir=$default_install_dir
|
install_dir="$default_install_dir"
|
||||||
default_download_dir="/tmp"
|
default_download_dir="/tmp"
|
||||||
download_dir=$default_download_dir
|
download_dir="$default_download_dir"
|
||||||
|
|
||||||
print_help() {
|
print_help() {
|
||||||
echo "Installs latest (or specific) version of babashka. Installation directory defaults to /usr/local/bin."
|
echo "Installs latest (or specific) version of babashka. Installation directory defaults to /usr/local/bin."
|
||||||
echo -e
|
echo -e
|
||||||
echo "Usage:"
|
echo "Usage:"
|
||||||
echo "install [--dir <dir>] [--download-dir <download-dir>] [--version <version>]"
|
echo "install [--dir <dir>] [--download-dir <download-dir>] [--version <version>] [--checksum <checksum>] [--static]"
|
||||||
echo -e
|
echo -e
|
||||||
echo "Defaults:"
|
echo "Defaults:"
|
||||||
echo " * Installation directory: ${default_install_dir}"
|
echo " * Installation directory: ${default_install_dir}"
|
||||||
echo " * Download directory: ${default_download_dir}"
|
echo " * Download directory: ${default_download_dir}"
|
||||||
|
if [[ -z "$checksum" ]]; then
|
||||||
|
echo " * Checksum: no"
|
||||||
|
else
|
||||||
|
echo " * Checksum: ${checksum}"
|
||||||
|
fi
|
||||||
|
echo " * Static binary: ${static_binary}"
|
||||||
echo " * Version: <Latest release on github>"
|
echo " * Version: <Latest release on github>"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
@ -25,14 +33,10 @@ if [[ $# -eq 1 ]]; then
|
||||||
install_dir=${1:-}
|
install_dir=${1:-}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while [[ $# -gt 1 ]]
|
while [[ $# -gt 0 ]]
|
||||||
do
|
do
|
||||||
key="$1"
|
key="$1"
|
||||||
if [[ -z "${2:-}" ]]; then
|
case "$key" in
|
||||||
print_help
|
|
||||||
fi
|
|
||||||
|
|
||||||
case $key in
|
|
||||||
--dir)
|
--dir)
|
||||||
install_dir="$2"
|
install_dir="$2"
|
||||||
shift
|
shift
|
||||||
|
|
@ -48,6 +52,15 @@ do
|
||||||
shift
|
shift
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--checksum)
|
||||||
|
checksum="$2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--static)
|
||||||
|
static_binary="true"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*) # unknown option
|
*) # unknown option
|
||||||
print_help
|
print_help
|
||||||
shift
|
shift
|
||||||
|
|
@ -55,6 +68,11 @@ do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [[ "$checksum" != "" ]] && [[ "$version" == "" ]]; then
|
||||||
|
>&2 echo "Options --checksum and --version should be provided together!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$version" == "" ]]; then
|
if [[ "$version" == "" ]]; then
|
||||||
version="$(curl -sL https://raw.githubusercontent.com/babashka/babashka/master/resources/BABASHKA_RELEASED_VERSION)"
|
version="$(curl -sL https://raw.githubusercontent.com/babashka/babashka/master/resources/BABASHKA_RELEASED_VERSION)"
|
||||||
fi
|
fi
|
||||||
|
|
@ -81,18 +99,36 @@ else
|
||||||
util="$(which tar) -zxf"
|
util="$(which tar) -zxf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
download_url="https://github.com/babashka/babashka/releases/download/v$version/babashka-$version-$platform-$arch."$ext
|
if [[ "$static_binary" == "true" ]]; then
|
||||||
|
if [[ "$platform" != "linux" ]]; then
|
||||||
|
>&2 echo "Static binaries are only available in Linux platform!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
filename="babashka-$version-$platform-$arch-static."$ext
|
||||||
|
else
|
||||||
|
filename="babashka-$version-$platform-$arch."$ext
|
||||||
|
fi
|
||||||
|
download_url="https://github.com/babashka/babashka/releases/download/v$version/$filename"
|
||||||
|
|
||||||
mkdir -p "$download_dir"
|
mkdir -p "$download_dir"
|
||||||
cd "$download_dir"
|
cd "$download_dir"
|
||||||
echo -e "Downloading $download_url to $download_dir"
|
echo -e "Downloading $download_url to $download_dir"
|
||||||
rm -rf "babashka-$version-$platform-$arch."$ext
|
|
||||||
rm -rf "bb"
|
|
||||||
curl -o "babashka-$version-$platform-$arch."$ext -sL $download_url
|
|
||||||
$util "babashka-$version-$platform-$arch."$ext
|
|
||||||
rm "babashka-$version-$platform-$arch."$ext
|
|
||||||
|
|
||||||
if [ "$download_dir" != "$install_dir" ]
|
rm -rf "$filename"
|
||||||
|
rm -rf "bb"
|
||||||
|
curl -o "$filename" -sL "$download_url"
|
||||||
|
if [[ -n "$checksum" ]]; then
|
||||||
|
if ! echo "$checksum $filename" | sha256sum --check --status; then
|
||||||
|
>&2 echo "Failed checksum on $filename"
|
||||||
|
>&2 echo "Got: $(sha256sum "$filename" | cut -d' ' -f1)"
|
||||||
|
>&2 echo "Expected: $checksum"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
$util "$filename"
|
||||||
|
rm "$filename"
|
||||||
|
|
||||||
|
if [[ "$download_dir" != "$install_dir" ]]
|
||||||
then
|
then
|
||||||
mkdir -p "$install_dir"
|
mkdir -p "$install_dir"
|
||||||
if [ -f "$install_dir/bb" ]; then
|
if [ -f "$install_dir/bb" ]; then
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue