How To Automated Gitea Update

Gitea didn’t have a built-in script to auto-update itself, so we need to write simple bash script to do the job for us. Since the Gitea only single executable file, we can just grab the latest version from Github, then replace the current one.

Take a look at Gitea updater below gitea-upgrade.sh

#!/usr/bin/env bash
 
GITEA_PATH="$HOME"
# check current Gitea version installed
GITEA_VERSION=$($GITEA_PATH/gitea -v | cut -d ' ' -f 3)
# Get latest version from Github
GITEA_LATEST_VERSION=$(curl -s https://github.com/go-gitea/gitea/releases/latest | sed 's#.*tag/\(.*\)\".*#\1#' | sed 's/v//1')
 
if [ "$GITEA_VERSION" != "$GITEAVERSION" ]; then
    cd "$GITEA_PATH" || exit
    # backup current gitea
    cp "$GITEA_PATH/gitea" cp "$GITEA_PATH/gitea-$GITEA_VERSION"
    # delete the old version
    rm -f $GITEA_PATH/gitea
    # Download the latest version from Github
    wget "https://github.com/go-gitea/gitea/releases/download/v${GITEA_LATEST_VERSION}/gitea-${GITEA_LATEST_VERSION}-linux-amd64" -O "$GITEA_PATH/gitea"
    # set gitea as executeable
    chmod +x "$GITEA_PATH/gitea"
    # it's better to use systemd to handle this
    # kill current gitea process
    pkill gitea
    # run the gitea again
    nohup $GITEA_PATH/gitea web > /dev/null 2>&1 &
fi

check the comment for explanation, it’s not really fool-proof script, but it works for my internal usage for few years.

To automated the upgrade process, we’ll use crontab to handle the schedule. Let’s say we want to check the update every night, run crontab -e, the append

@daily /bin/bash /path/to/gitea-upgrade.sh

Leave a Reply