This repository has been archived on 2024-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
thelinuxlist/scripts/giteaupdate.sh

96 lines
2.4 KiB
Bash

#!/usr/bin/env bash
# Trap Ctrl+C to exit gracefully
trap 'exit 130' INT
# Function to prompt user for confirmation
prompt_confirmation() {
while true; do
read -r -p "Would you like to update Gitea? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
return 0
;;
[nN][oO]|[nN])
return 1
;;
*)
echo "That wasn't an option..."
;;
esac
done
}
# 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
if prompt_confirmation; then
check_connectivity
update_gitea
else
echo "Gitea update aborted."
fi
exit 0