-
Notifications
You must be signed in to change notification settings - Fork 0
/
github_get_last_release
executable file
·40 lines (31 loc) · 1.75 KB
/
github_get_last_release
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
export PACKAGE_BIN=$(echo ${PACKAGE_BIN})
export SUDOCMD=$(echo ${SUDOCMD})
export CURDIR=$(echo ${CURDIR})
export RUNDIR=$(echo ${RUNDIR})
export PATH=${PACKAGE_BIN}:${PATH}
[[ -e ${PACKAGE_BIN} ]] || ${SUDOCMD} mkdir -vp ${PACKAGE_BIN} || exit 1
${SUDOCMD} chown -vR ${USER}:users ${PACKAGE_BIN} || exit 1
PACKAGE_PKG=${1}
[[ "${PACKAGE_PKG}" != "" ]] || exit 1
PACKAGE_KEY=${2}
[[ "${PACKAGE_KEY}" != "" ]] || exit 1
PACKAGE_NOT=${3}
PACKAGE_VER=$(mktemp)
wget --output-document=${PACKAGE_VER} https://api.github.com/repos/${PACKAGE_PKG}/releases/latest
PACKAGE_TAG=$(cat ${PACKAGE_VER} | grep -i '"tag_name"' | grep -oP '(v[^"]*)')
PACKAGE_URL=$(cat ${PACKAGE_VER} | jq ".assets[] | select (.name | contains(\"${PACKAGE_KEY}\")) | .browser_download_url" | tr -d '"')
PACKAGE_OUT=$(cat ${PACKAGE_VER} | jq ".assets[] | select (.name | contains(\"${PACKAGE_KEY}\")) | .name" | tr -d '"')
#if [[ "${PACKAGE_NOT}" != "" ]]
#then
# PACKAGE_URL=$(cat ${PACKAGE_VER} | jq ".assets[] | select (.name | contains(\"${PACKAGE_KEY}\")) | select(.name | contains(\"${PACKAGE_NOT}\") | not) | .browser_download_url" | tr -d '"')
# PACKAGE_OUT=$(cat ${PACKAGE_VER} | jq ".assets[] | select (.name | contains(\"${PACKAGE_KEY}\")) | select(.name | contains(\"${PACKAGE_NOT}\") | not) | .name" | tr -d '"')
#fi
if [[ "${PACKAGE_NOT}" != "" ]]
then
PACKAGE_URL=$(echo -e "${PACKAGE_URL}" | grep -v -P "${PACKAGE_NOT}")
PACKAGE_OUT=$(echo -e "${PACKAGE_OUT}" | grep -v -P "${PACKAGE_NOT}")
fi
wget --output-document=${PACKAGE_BIN}/${PACKAGE_OUT}-${PACKAGE_TAG} ${PACKAGE_URL}
${SUDOCMD} ln -svf ${PACKAGE_BIN}/${PACKAGE_OUT}-${PACKAGE_TAG} ${PACKAGE_BIN}/${PACKAGE_OUT}
${SUDOCMD} ln -svf ${PACKAGE_BIN}/${PACKAGE_OUT}-${PACKAGE_TAG} ${PACKAGE_BIN}/$(basename ${PACKAGE_PKG})