66 lines
2.1 KiB
Bash
Executable File
66 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# dependencies, jq
|
|
# if you have run into github api anonymous access limits which happens during debugging/dev then add user and token here or sourced from a separate file
|
|
# . ~/githubapitoken
|
|
#GITHUB_USER=""
|
|
#GITHUB_TOKEN=""
|
|
|
|
[[ $(command -v jq &> /dev/null) ]] && echo jq is required, install via \'sudo apt install jq\' && exit
|
|
|
|
[[ ! $GITEA_DIR ]] && export GITEA_DIR="$(dirname "$(cd "$(dirname "$BASH_SOURCE")"; pwd -P)")"
|
|
source $GITEA_DIR/scripts/library
|
|
|
|
REPO=go-gitea/gitea
|
|
|
|
if [ "$GITHUB_TOKEN" != "" ]; then
|
|
echo using access token with script
|
|
echo $GITHUB_USER $GITHUB_TOKEN
|
|
fi
|
|
|
|
# ARCHIVE=tar.gz
|
|
# [ "$OS" == "windows" ] && ARCHIVE=zip
|
|
OS=$(get_OS)
|
|
ARCH=$(get_arch)
|
|
[[ ! $OS ]] && echo non supported OS $OS && exit
|
|
[[ ! $ARCH ]] && echo non supported architecture $ARCH && exit
|
|
echo Gitea Upgrade/Install for
|
|
echo Operating System $OS
|
|
echo Architecture $ARCH
|
|
RECORD=$(curl -u $GITHUB_USER:$GITHUB_TOKEN -s https://api.github.com/repos/$REPO/releases/latest)
|
|
NEW_VER=$(echo $RECORD | jq -r '.tag_name')
|
|
[ "$NEW_VER" ] && echo $NEW_VER is latest version available from https://github.com/c$REPO/releases
|
|
echo checking current gitea installed version
|
|
VER=$(version)
|
|
if [[ "$NEW_VER" == "v$VER" ]]; then
|
|
echo gitea is up to date, nothing to upgrade, v$VER
|
|
exit
|
|
else
|
|
[[ $VER ]] && echo updating v$VER to $NEW_VER || echo no current installed gitea binary, installing $NEW_VER
|
|
fi
|
|
|
|
URL=$(echo $RECORD | \
|
|
jq -r \
|
|
--arg os $OS \
|
|
--arg arch $ARCH \
|
|
--arg archnot "$ARCH." \
|
|
'.assets[] | select( .name | contains($os)) |
|
|
select (.name | contains($arch)) |
|
|
select (.name | contains($archnot) | not )
|
|
.browser_download_url' \
|
|
)
|
|
|
|
echo $URL
|
|
|
|
if [ $URL ]; then
|
|
echo "Downloading Gitea Binary at $URL"
|
|
wget --user=-u $GITHUB_USER --password=$GITHUB_TOKEN -q -O $GITEA_DIR/gitea.bin $URL
|
|
if ( [[ $? -eq 0 ]] && [[ "$NEW_VER" == *"$(version)"* ]] ); then
|
|
chmod +x $GITEA_DIR/gitea.bin
|
|
echo upgrade succeeded, $GITEA_DIR/gitea.bin version is $(version)
|
|
else
|
|
echo upgrade from $URL failed
|
|
fi
|
|
else
|
|
echo unabled to determine download url
|
|
fi
|