#!/usr/bin/env bash trap 'exit 130' INT # Function to check if required domains are accessible check_domains() { echo "Checking necessary domains..." 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. Installation cannot proceed." exit 1 fi done } # Function to install Gitea install_gitea() { echo "Installing 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') # Install git echo "Installing git..." sudo apt-get install git -y || { echo "Failed to install git. Exiting."; exit 1; } # Create git user echo "Creating git user..." sudo adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git # Download and install Gitea binary echo "Downloading Gitea binary..." 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 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 # Create necessary directories and files echo "Setting up directories and files..." sudo mkdir -p /var/lib/gitea/{custom,data,log} sudo chown -R git:git /var/lib/gitea sudo chmod -R 750 /var/lib/gitea sudo mkdir -p /etc/gitea sudo chown root:git /etc/gitea sudo chmod 770 /etc/gitea # Configure systemd service echo "Configuring systemd service..." sudo curl -fsSL -o /etc/systemd/system/gitea.service https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service sudo systemctl daemon-reload sudo systemctl enable --now gitea # Allow port through firewall echo "Allowing port 3000 through firewall..." sudo ufw allow 3000 # Get public and internal IP addresses public_ip=$(curl -sS --connect-timeout 10 -m 60 https://ipv4.icanhazip.com/ || curl -sS --connect-timeout 10 -m 60 https://api.ipify.org ) internal_ip=$(ip addr | grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -E -v "^127\.|^255\.|^0\." | head -n 1) # Output installation information echo -e "==================================================================" echo "Gitea has been installed successfully!" echo "The Gitea web interface should be available at:" echo "http://$internal_ip:3000" echo "Or, if you are using a VPS, at:" echo "http://$public_ip:3000" echo "==================================================================" } # Main script # Automate installation by assuming yes to the prompt check_domains install_gitea exit 0