Skip to content

Instantly share code, notes, and snippets.

@vwbusguy
Last active January 15, 2025 19:09
Show Gist options
  • Save vwbusguy/01451f938e293eb2e0d5811e1efd4162 to your computer and use it in GitHub Desktop.
Save vwbusguy/01451f938e293eb2e0d5811e1efd4162 to your computer and use it in GitHub Desktop.
forgejo-update
#!/bin/bash
DLOAD_DIR=/opt
gitea_help () {
echo -e "Usage: gitea-upgrade <version>\n\nSee https://codeberg.org/forgejo/forgejo/releases for current versions.\n";
echo $1;
}
case $(uname -m) in
x86_64 | amd64)
arch="amd64"
;;
aarch64 | arm64)
arch="arm64"
;;
*)
gitea_help "The architecture of $(uname -m) doesn't appear to be supported.";
exit 2;
;;
esac
: ${version:=$1}
: ${version:=$(curl https://forgejo.org/releases/rss.xml 2>/dev/null | xpath -q -e '/rss/channel/item/title[not(contains(text(),"rc")) and not(contains(text(),"beta")) and not(contains(text(),"alpha"))]/text()' | sort -rV | head -1 | sed 's,v,,g')}
if [ -f ${DLOAD_DIR}/forgejo-${version}-linux-${arch} ] && [ "$(readlink -f /usr/local/bin/gitea)" == ${DLOAD_DIR}/forgejo-${version}-linux-${arch} ] ; then
gitea_help "Already at the latest version: $version.";
exit 0;
fi;
cd ${DLOAD_DIR};
[ -f ${DLOAD_DIR}/forgejo-${version}-linux-${arch} ] || wget $(curl https://codeberg.org/forgejo/forgejo/releases/tag/v${version} 2>/dev/null | grep -1 -P "forgejo-${version}-linux-${arch}\"" | grep http | sed "s,.*href=\",,g;s,\".*,,g") -O forgejo-${version}-linux-${arch};
if [ $? -ne 0 ]; then
gitea_help "Could not fetch version ${version}. Either codeberg is down or version tag is wrong";
exit 1;
fi;
chmod +x ${DLOAD_DIR}/forgejo-${version}-linux-${arch};
chcon -v -t bin_t ${DLOAD_DIR}/forgejo-${version}-linux-${arch};
ln -sf ${DLOAD_DIR}/forgejo-${version}-linux-${arch} /usr/local/bin/gitea;
systemctl restart gitea;
echo "Gitea was successfully updated to ${version}. Check \`journalctl -f -u gitea\` for details.";
@vwbusguy
Copy link
Author

Updated it to support parsing recent markup changes on release pages on codeberg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment