thelinuxlist/scripts/unattended/giteaupdate.sh

71 lines
1.9 KiB
Bash

#!/usr/bin/env bash
# Function to check network connectivity
check_connectivity() {
echo "Checking necessary domains for connectivity..."
for domain in "github.com" "api.github.com" "dl.gitea.io" "raw.githubusercontent.com"; do
if ! ping -c1 "$domain" &>"/dev/null"; then
echo "Unable to access $domain. Update cannot proceed."
exit 1
fi
done
}
# Function to perform the update
update_gitea() {
echo "Updating Gitea..."
# Check if curl is installed
if ! command -v curl &>/dev/null; then
echo "Installing curl..."
sudo apt install -y curl || { echo "Failed to install curl. Exiting."; exit 1; }
fi
# Get latest Gitea version
VER=$(curl --silent "https://api.github.com/repos/go-gitea/gitea/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sed 's|[v,]||g')
# Determine architecture
case "$(uname -m)" in
i386)
arch="386"
;;
x86_64)
arch="amd64"
;;
armv6l)
arch="arm-6"
;;
armv7l)
arch="arm-7"
;;
*)
echo "Unsupported architecture"
exit 1
;;
esac
# Download and install Gitea binary
gitea_url="https://dl.gitea.io/gitea/$VER/gitea-$VER-linux-$arch"
echo "Downloading Gitea from: $gitea_url"
sudo curl -fsSL -o "/tmp/gitea" "$gitea_url"
sudo mv /tmp/gitea /usr/local/bin
sudo chmod +x /usr/local/bin/gitea
# Restart Gitea service
echo "Restarting Gitea service..."
sudo systemctl restart gitea
# Allow port through firewall
echo "Allowing port 3000 through firewall..."
sudo ufw allow 3000
echo "Gitea has been updated successfully!"
}
# Main script
# Automate confirmation by assuming yes to the prompt
check_connectivity
update_gitea
exit 0