From 533ce1f34322a54035f50d70f101b5bb01797cf4 Mon Sep 17 00:00:00 2001 From: Michael Parker Date: Sun, 3 Nov 2019 22:29:44 -0500 Subject: [PATCH 1/2] add a scripts folder as a resource This specifically adds a the github_release_grabber I wrote for the tmodloader egg. --- scripts/github_release_grabber.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 scripts/github_release_grabber.sh diff --git a/scripts/github_release_grabber.sh b/scripts/github_release_grabber.sh new file mode 100644 index 00000000..d05120c8 --- /dev/null +++ b/scripts/github_release_grabber.sh @@ -0,0 +1,28 @@ +## this is a simple script to use the github API for release versions. +## this requires the egg has a variable for GITHUB_PACKAGE, VERSION and MATCH (match is to match the filename in some way) +## this supports using oauth/personal access tokens via GITHUB_USER and GITHUB_OAUTH_TOKEN (both are required.) +## if you are getting hit with GitHub API limit issues then you need to have the user and token set. + + +if [ -z "$GITHUB_USER" ] && [ -z "$GITHUB_OAUTH_TOKEN" ] ; then + echo -e "using anon api call" +else + echo -e "user and oauth token set" + alias curl='curl -u $GITHUB_USER:$GITHUB_OAUTH_TOKEN ' +fi + +## get release info and download links +LATEST_JSON=$(curl --silent "https://api.github.com/repos/$GITHUB_PACKAGE/releases/latest") +RELEASES=$(curl --silent "https://api.github.com/repos/$GITHUB_PACKAGE/releases") + +if [ -z "$VERSION" ] || [ "$VERSION" == "latest" ]; then + DOWNLOAD_LINK=$(echo $LATEST_JSON | jq .assets | jq -r .[].browser_download_url | grep -i ${MATCH}) +else + VERSION_CHECK=$(echo $RELEASES | jq -r --arg VERSION "$VERSION" '.[] | select(.tag_name==$VERSION) | .tag_name') + if [ "$VERSION" == "$VERSION_CHECK" ]; then + DOWNLOAD_LINK=$(echo $RELEASES | jq -r --arg VERSION "$VERSION" '.[] | select(.tag_name==$VERSION) | .assets[].browser_download_url' | grep -i ${MATCH}) + else + echo -e "defaulting to latest release" + DOWNLOAD_LINK=$(echo $LATEST_JSON | jq .assets | jq -r .[].browser_download_url) + fi +fi \ No newline at end of file From f5c7014231090048cb1eabb984562c8e3ea27e15 Mon Sep 17 00:00:00 2001 From: Michael Parker Date: Sun, 3 Nov 2019 22:34:43 -0500 Subject: [PATCH 2/2] add file unpacker This is to unpack files. --- scripts/file_unpacker.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 scripts/file_unpacker.sh diff --git a/scripts/file_unpacker.sh b/scripts/file_unpacker.sh new file mode 100644 index 00000000..42cb8bcc --- /dev/null +++ b/scripts/file_unpacker.sh @@ -0,0 +1,15 @@ +## only needs to have the file with a file passed into it to get the filetype. +## only supports tar.gz/xz and zip currently for unpacking. +## The value for ${DOWNLOAD_LINK##*/} is + +FILETYPE=$(file -F ',' ${DOWNLOAD_LINK##*/} | cut -d',' -f2 | cut -d' ' -f2) +if [ "$FILETYPE" == "gzip" ]; then + tar xzvf ${DOWNLOAD_LINK##*/} +elif [ "$FILETYPE" == "Zip" ]; then + unzip ${DOWNLOAD_LINK##*/} +elif [ "$FILETYPE" == "XZ" ]; then + tar xvf ${DOWNLOAD_LINK##*/} +else + echo -e "unknown filetype. Exeting" + exit 2 +fi \ No newline at end of file