Last active
January 15, 2025 19:09
-
-
Save vwbusguy/01451f938e293eb2e0d5811e1efd4162 to your computer and use it in GitHub Desktop.
forgejo-update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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."; |
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
This assumes that there is a gitea service pointed at /usr/local/bin/gitea. If you're currently running gitea, this script will effectively migrate your Gitea to the latest Forgejo. If you're already running Forgejo, it will upgrade it, if an upgrade is available. Adjust the DLOAD_DIR according to your environment.
As always - use at your own risk.