Skip to content

Instantly share code, notes, and snippets.

@Oddly
Created May 22, 2025 19:56
Show Gist options
  • Save Oddly/d2a26a1949bf580f8df71563895e322d to your computer and use it in GitHub Desktop.
Save Oddly/d2a26a1949bf580f8df71563895e322d to your computer and use it in GitHub Desktop.
Gitea automatic bash update script
#!/bin/bash
# Function to get version number from semantic version string
version_to_number() {
echo "$1" | awk -F. '{ printf("%d%03d%03d", $1,$2,$3); }'
}
# Get the latest release version from GitHub
latest_version=$(curl -s https://api.github.com/repos/go-gitea/gitea/releases/latest | grep 'tag_name' | cut -d '"' -f 4)
# Remove the 'v' prefix from version string
latest_version="${latest_version#v}"
# Get the currently installed Gitea version
current_version=$(/usr/local/bin/gitea --version 2>&1)
current_version=$(echo "$current_version" | grep -oP '(\d+\.\d+\.\d+)')
echo "Latest version: $latest_version"
echo "Installed version: $current_version"
# Compare versions
if [ $(version_to_number $latest_version) -gt $(version_to_number $current_version) ]; then
echo "A newer version of Gitea is available."
# Define download URL
download_url="https://github.com/go-gitea/gitea/releases/download/v${latest_version}/gitea-${latest_version}-linux-amd64"
# Download and replace the current binary
echo "Downloading Gitea version $latest_version..."
curl -L $download_url -o /tmp/gitea-latest
echo "Replacing old version..."
sudo mv /tmp/gitea-latest /usr/local/bin/gitea
sudo chmod +x /usr/local/bin/gitea
echo "Starting Gitea again"
systemctl restart gitea
echo "Gitea updated successfully to version $latest_version"
else
echo "Gitea is already up to date."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment