From ae36cad1836a6d3d7afaebf0ec2ff1b4240172e8 Mon Sep 17 00:00:00 2001 From: Phil Clifford Date: Tue, 7 May 2024 08:54:45 +0100 Subject: [PATCH] Add initial support for Glab (#947) * Add initial support for Glab * use urlencoded path instead of id * Add get gitlab releases (#8) * added get_gitlab_releases() * failed to filter for supported ARCHS * fix typo --------- Co-authored-by: Martin Wimpress <304639+flexiondotorg@users.noreply.github.com> --- .github/gitlab.png | Bin 0 -> 1584 bytes 01-main/manifest | 1 + 01-main/packages/.shellcheckrc | 1 + 01-main/packages/glab | 23 +++++++++++ deb-get | 73 +++++++++++++++++++++------------ 5 files changed, 72 insertions(+), 26 deletions(-) create mode 100644 .github/gitlab.png create mode 100644 01-main/packages/.shellcheckrc create mode 100644 01-main/packages/glab diff --git a/.github/gitlab.png b/.github/gitlab.png new file mode 100644 index 0000000000000000000000000000000000000000..0810e9ada497d2e4092d5b5ad7b0745628168372 GIT binary patch literal 1584 zcmc&yYfw{H5I#2`0U-#Ylv*r^LGpR^4H_Y=qG#gya8yE8f#;hAm27VAdCk#s zNqz@lw-W%PF#xb+0KB*BbX%wg03<9VD1w6$hJ4oz`mCFcgQ{exNrSimY6MW70_PLq zOf_HB;ta1zmSV^<`Ui&cH20p(K#rX0UrVf^=^n)K>RGk zE1`N1>;(=g8PrrmybfxrAezQ}Db%3h)WYFly80BvYlt9E!J*Hl!db*C1LAp9 zZ3R_ZNyWdS;zEcQ68EA-@M<7l1o2%E7eQP~z|+=2ybR(w5Z?=N*zU~Y0kbaFS$s&uy0iX1nDF*~jE zr?7jGs4W)9-Q-t)-C*l=LQmGkcT_|Ly?IHueY7m@#hdA5Y+BPA zX)6ULMrJ#ia+8kDh889atSHy8yo|3`R&M*4c83H?NNa+4?vwy7_2!DG)n2&<{e>0E zZjkWDPe(-W1JK;8etBA;1iq&1?)zot*zhX#4%x{`)7w4Sl;SH4u%z(fj!01!MPe7b zC30XT@M>x_=9=_L6Y1s$Z|!uK^fEFpU#sh-*EiRFW_{v#uAb`Id7lSoL!R*1sqOV` zU2fla*qWVcc@lBK9!m?KIGryZ6dLZgd^M5X0$c38!naDD<*k>rWXy4cW3N?TU#dN( zqa+=;^-EJ0)MvI2b;uI$Qgme!Nf$g2dz*^ayJNMR-2?qUbagcdAd!Tw@y%T^*M1g< z={Ytu#Ku0)a}QZ=_PF;>t6#jL>pL@2?LErDF^^CIx5VD-g1{xdR5IaKB`M(@;ge*) zinhIG7qrQJuW_EgwEW(CNH{Iz*W_H{E*@U7@`u;sqe(~8(kI82%5)jL{M4dS}ShfSF@1yiB$znRx) zQOFMpW}XQzw-~&xUguz!m7A2rVsvh8x8oevZCEgUU56kAe(gLTb{N|1NN5F*d#}2+29W Q1{HunPO#rapO}I_0YP-L&;S4c literal 0 HcmV?d00001 diff --git a/01-main/manifest b/01-main/manifest index 80c8d3d51..8744f9f0f 100644 --- a/01-main/manifest +++ b/01-main/manifest @@ -88,6 +88,7 @@ git-delta github-desktop gitkraken gitter +glab glow google-chat-electron google-chrome-beta diff --git a/01-main/packages/.shellcheckrc b/01-main/packages/.shellcheckrc new file mode 100644 index 000000000..95d9fde64 --- /dev/null +++ b/01-main/packages/.shellcheckrc @@ -0,0 +1 @@ +disable=SC2034,SC2148 \ No newline at end of file diff --git a/01-main/packages/glab b/01-main/packages/glab new file mode 100644 index 000000000..72b7aee03 --- /dev/null +++ b/01-main/packages/glab @@ -0,0 +1,23 @@ + +DEFVER=1 +#get_gitlab_releases "34675721" +#get_gitlab_releases "gitlab-org%2Fcli" +# PROJ="gitlab-org/cli" +# PROJ=${PROJ/\//%2F} +#ARCHS_SUPPORTED="amd64 arm64 armhf +get_gitlab_releases "gitlab-org%2Fcli" "latest" + +if [ "${ACTION}" != "prettylist" ]; then + URL=$(jq <${CACHE_FILE} -r '.[] |select(.name|contains("x86_64.deb"))| .direct_asset_url') + #URL=$(jq <${CACHE_FILE} --arg arch ${HOST_CPU/armhf/arm} -r '.[] |select(.name|contains($arch))|select(.name|contains(".deb"))| .direct_asset_url') + + #URL= $(jq <${CACHE_FILE} -r '.[] | .direct_asset_url' | grep ".*${HOST_CPU}\.deb" + #URL="${URL//\"}" + + VERSION_PUBLISHED="${URL##*/releases/v}" + VERSION_PUBLISHED=${VERSION_PUBLISHED%%/*} +fi + +PRETTY_NAME="Glab" +WEBSITE="https://gitlab.com/gitlab-org/cli" +SUMMARY="A GitLab CLI tool bringing GitLab to your command line" \ No newline at end of file diff --git a/deb-get b/deb-get index e7ea7e824..f79539d65 100755 --- a/deb-get +++ b/deb-get @@ -172,6 +172,29 @@ function get_github_releases() { fi } +function get_gitlab_releases() { + METHOD="gitlab" + CACHE_FILE="${CACHE_DIR}/${APP}.json" + # Cache gitlab releases json for 1 hour to try and prevent API rate limits + # + # Do not process gitlab releases while generating a pretty list or upgrading + # if $1 is org/app or user/repo it must be urlencoded + # the gitlab api can take a release or use permalink/latest to get the latest release + # So for gitlab sourced apps that use this release model users can use 99-local to pin a version + # + + if [[ ' install update fix-installed ' =~ " ${ACTION} " ]]; then + if [ ! -e "${CACHE_FILE}" ] || [ -n "$(find "${CACHE_FILE}" -mmin +"${DEBGET_CACHE_RTN:-60}")" ]; then + fancy_message info "Updating ${CACHE_FILE}" + RELEASE=${2/%latest/permalink/latest} + + local URL="https://gitlab.com/api/v4/projects/${1}/releases/${RELEASE}/assets/links" + wgetcmdarray=(wget -q --no-use-server-timestamps "${URL}" -O "${CACHE_FILE}") + + ${ELEVATE} "${wgetcmdarray[@]}" || ( fancy_message warn "Updating ${CACHE_FILE} failed." ) + fi + fi +} function get_website() { METHOD="website" CACHE_FILE="${CACHE_DIR}/${APP}.html" @@ -348,7 +371,7 @@ function remove_deb() { # Remove repos/PPA/key even if the app is not installed. case "${METHOD}" in - direct|github|website) + direct|github|gitlab|website) if [ -f "${CACHE_DIR}/${FILE}" ]; then fancy_message info "Removing ${CACHE_DIR}/${FILE}" ${ELEVATE} rm "${CACHE_DIR}/${FILE}" 2>/dev/null @@ -370,7 +393,7 @@ function version_deb() { function info_deb() { local INSTALLED="${VERSION_INSTALLED:-No}" case "${METHOD}" in - (direct|github|website) + (direct|github|gitlab|website) printf '%s\n' "${PRETTY_NAME}" printf ' %s:\t%s\n' Package "${APP}" Repository "${APP_SRC}" Updater deb-get Installed "${INSTALLED}" Published "${VERSION_PUBLISHED}" Architecture "${ARCHS_SUPPORTED}" Download "${URL}" Website "${WEBSITE}" Summary "${SUMMARY}";; (apt) @@ -466,7 +489,7 @@ function validate_deb() { fi fi - if { { [[ ' github website ' =~ " ${METHOD} " ]] && [ -s "${CACHE_FILE}" ]; } || [ "${METHOD}" == direct ]; } && + if { { [[ ' github website gitlab ' =~ " ${METHOD} " ]] && [ -s "${CACHE_FILE}" ]; } || [ "${METHOD}" == direct ]; } && ! [[ ' prettylist remove purge ' =~ " ${ACTION} " ]] && { [ -z "${URL}" ] || [ -z "${VERSION_PUBLISHED}" ]; } && { [ -z "${ARCHS_SUPPORTED}" ] || [[ " ${ARCHS_SUPPORTED} " =~ " ${HOST_ARCH} " ]]; } && @@ -568,16 +591,16 @@ cat <<"EOMSG" | :------: | :------------- | :------------ | EOMSG for FULL_APP in "${APPS[@]}"; do - if validate_deb "${FULL_APP}"; then - if [ "${APP_SRC}" == "${REPO}" ] || { [ "${REPO}" == "01-main" ] && [ "${APP_SRC}" == "00-builtin" ]; }; then - case "${METHOD}" in - apt) ICON="debian.png";; - github) ICON="github.png";; - ppa) ICON="launchpad.png";; - *) ICON="direct.png";; - esac - echo "| [](${WEBSITE}) | "'`'"${APP}"'`'" | ${SUMMARY} |" - fi + validate_deb "${FULL_APP}" + if [ "${APP_SRC}" == "${REPO}" ] || { [ "${REPO}" == "01-main" ] && [ "${APP_SRC}" == "00-builtin" ]; }; then + case "${METHOD}" in + apt) ICON="debian.png";; + github) ICON="github.png";; + gitlab) ICON="gitlab.png";; + ppa) ICON="launchpad.png";; + *) ICON="direct.png";; + esac + echo "| [](${WEBSITE}) | "'`'"${APP}"'`'" | ${SUMMARY} |" fi done } @@ -597,12 +620,11 @@ function update_debs() { local STATUS="" update_apt for APP in "${INSTALLED_APPS[@]}"; do - if validate_deb "${APPNAME2FULL[$APP]}"; then - if [ "${METHOD}" == "direct" ] || [ "${METHOD}" == "github" ] || [ "${METHOD}" == "website" ]; then - STATUS=$(dpkg-query -Wf '${Status}' "${APP}") - if [ "${STATUS}" == "install ok installed" ] && dpkg --compare-versions "${VERSION_PUBLISHED}" gt "${VERSION_INSTALLED}"; then - fancy_message info "${APP} (${VERSION_INSTALLED}) has an update pending. ${VERSION_PUBLISHED} is available." - fi + validate_deb "${APPNAME2FULL[$APP]}" + if [ "${METHOD}" == "direct" ] || [ "${METHOD}" == "github" ] || [ "${METHOD}" == "gitlab" ] || [ "${METHOD}" == "website" ]; then + STATUS=$(dpkg-query -Wf '${Status}' "${APP}") + if [ "${STATUS}" == "install ok installed" ] && dpkg --compare-versions "${VERSION_PUBLISHED}" gt "${VERSION_INSTALLED}"; then + fancy_message info "${APP} (${VERSION_INSTALLED}) has an update pending. ${VERSION_PUBLISHED} is available." fi fi done @@ -612,12 +634,11 @@ function upgrade_debs() { local STATUS="" upgrade_apt for APP in "${INSTALLED_APPS[@]}"; do - if validate_deb "${APPNAME2FULL[$APP]}"; then - if [ "${METHOD}" == "direct" ] || [ "${METHOD}" == "github" ] || [ "${METHOD}" == "website" ]; then - STATUS=$(dpkg-query -Wf '${Status}' "${APP}") - if [ "${STATUS}" == "install ok installed" ]; then - install_deb "${URL}" - fi + validate_deb "${APPNAME2FULL[$APP]}" + if [ "${METHOD}" == "direct" ] || [ "${METHOD}" == "github" ]|| [ "${METHOD}" == "gitlab" ] || [ "${METHOD}" == "website" ]; then + STATUS=$(dpkg-query -Wf '${Status}' "${APP}") + if [ "${STATUS}" == "install ok installed" ]; then + install_deb "${URL}" fi fi done @@ -1386,7 +1407,7 @@ function dg_action_install() { fi case "${METHOD}" in - direct|github|website) install_deb "${URL}";; + direct|github|gitlab|website) install_deb "${URL}";; apt) install_apt;; ppa) install_ppa;; esac