diff --git a/tools/wget_release b/tools/wget_release new file mode 100755 index 0000000..9a932aa --- /dev/null +++ b/tools/wget_release @@ -0,0 +1,43 @@ +#!/bin/bash + +REPO_TYPE=$1 +REPO_NAME=$2 +DESTINATION=${3:-.} + +function usage { + local BASECMD=$(basename "$0") + echo 'usage: [DESTINATION]' + echo 'example:' + echo -e '\t# REPO_TYPE=github' + echo -e "\t$BASECMD github Dolibarr/dolibarr\n" + echo -e '\t# REPO_TYPE=artcode' + echo -e "\t$BASECMD artcode pvincent/debian-gnome\n" + echo -e '\t# With destination' + echo -e "\t$BASECMD artcode pvincent/debian-gnome /tmp # folder" + echo -e "\t$BASECMD artcode pvincent/debian-gnome /tmp/release.tgz # file" + exit -1 +} + +function get-github { + local BASE="https://github.com" + local release=$(curl -s $BASE/${REPO_NAME}/releases/latest | grep -oe "releases/tag/.*\"" | cut -d '/' -f3 | cut -d '"' -f1 ) + local url="$BASE/${REPO_NAME}/archive/refs/tags/${release}.tar.gz" + if [[ -d $DESTINATION ]]; then + DESTINATION="$DESTINATION/$(echo $REPO_NAME | cut -d '/' -f2 )-${release}.tgz" + fi + >&2 wget $url -O $DESTINATION + echo $DESTINATION +} + +[[ $# -lt 2 ]] && usage + +case $REPO_TYPE in + github ) + get-github + ;; + * ) + echo "repository type <${REPO_TYPE}> not yet supported!" && exit 1 + ;; +esac + +