2023-04-08 14:21:14 -07:00
|
|
|
#!/usr/bin/env bash
|
2024-03-20 20:49:27 -07:00
|
|
|
|
2023-08-04 01:30:15 -07:00
|
|
|
trap 'exit 130' INT
|
2024-03-20 20:49:27 -07:00
|
|
|
|
|
|
|
# Function to prompt user for installation
|
|
|
|
prompt_installation() {
|
|
|
|
while true; do
|
|
|
|
read -r -p "Would you like to install Gitea? [Y/n] " input
|
|
|
|
|
|
|
|
case $input in
|
2022-10-20 10:57:59 -07:00
|
|
|
[yY][eE][sS]|[yY])
|
2024-03-20 20:49:27 -07:00
|
|
|
return 0
|
|
|
|
;;
|
2022-10-20 10:57:59 -07:00
|
|
|
[nN][oO]|[nN])
|
2024-03-20 20:49:27 -07:00
|
|
|
return 1
|
|
|
|
;;
|
2022-10-20 10:57:59 -07:00
|
|
|
*)
|
2024-03-20 20:49:27 -07:00
|
|
|
echo "That wasn't an option..."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
2023-01-30 09:05:00 -08:00
|
|
|
|
2024-03-20 20:49:27 -07:00
|
|
|
# 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
|
|
|
|
}
|
2023-01-30 09:05:00 -08:00
|
|
|
|
2024-03-20 20:49:27 -07:00
|
|
|
# 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')
|
2023-01-30 09:05:00 -08:00
|
|
|
|
2024-03-20 20:49:27 -07:00
|
|
|
# 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
|
|
|
|
if prompt_installation; then
|
|
|
|
check_domains
|
|
|
|
install_gitea
|
|
|
|
else
|
|
|
|
echo "Gitea installation aborted."
|
2023-04-18 18:50:09 -07:00
|
|
|
fi
|
|
|
|
|
2024-03-20 20:49:27 -07:00
|
|
|
exit 0
|