Skip to content

Instantly share code, notes, and snippets.

@febritecno
Created October 4, 2024 13:00
Show Gist options
  • Save febritecno/24e379488edb292b0a74441352d07f49 to your computer and use it in GitHub Desktop.
Save febritecno/24e379488edb292b0a74441352d07f49 to your computer and use it in GitHub Desktop.
Git tea installer
#!/bin/bash
# Update system packages
sudo apt update && sudo apt upgrade -y
# Install required dependencies
sudo apt install -y git curl sqlite3
# Create a user for Gitea
sudo adduser --system --group --disabled-password --shell /bin/bash --home /home/git --gecos 'Gitea User' git
# Create directory for Gitea
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R gitea:gitea /var/lib/gitea/
sudo chmod -R 750 /var/lib/gitea/
# Download and install Gitea
sudo wget -O /tmp/gitea https://dl.gitea.com/gitea/1.22.2/gitea-1.22.2-linux-amd64
sudo mv /tmp/gitea /usr/local/bin/gitea
sudo chmod +x /usr/local/bin/gitea
# Create Gitea service file
sudo tee /etc/systemd/system/gitea.service > /dev/null <<EOF
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
[Service]
RestartSec=2s
Type=simple
User=gitea
Group=gitea
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=gitea HOME=/home/gitea GITEA_WORK_DIR=/var/lib/gitea
[Install]
WantedBy=multi-user.target
EOF
# Create Gitea configuration file
sudo mkdir -p /etc/gitea
sudo tee /etc/gitea/app.ini > /dev/null <<EOF
APP_NAME = Gitea: Git with a cup of tea
RUN_USER = gitea
RUN_MODE = prod
[server]
HTTP_ADDR = 0.0.0.0
HTTP_PORT = 3000
ROOT_URL = http://localhost:3000/
[database]
DB_TYPE = sqlite3
PATH = /var/lib/gitea/data/gitea.db
[repository]
ROOT = /var/lib/gitea/data/gitea-repositories
[i18n]
LANGS = en-US
NAMES = English
[log]
MODE = file
LEVEL = info
ROOT_PATH = /var/lib/gitea/log
EOF
# Set proper permissions
sudo chown -R root:gitea /etc/gitea
sudo chown root:gitea /etc/gitea/app.ini
sudo chmod 750 /etc/gitea/
sudo chmod 660 /etc/gitea/app.ini
# Set Database sqlite
sqlite3 /var/lib/gitea/data/gitea.db ".databases"
chown gitea:gitea /var/lib/gitea/data/gitea.db
chmod 640 /var/lib/gitea/data/gitea.db
# Start and enable Gitea service
sudo systemctl daemon-reload
sudo systemctl enable --now gitea
echo "Gitea installation completed. Access it at http://your_server_ip:3000"
#sudo journalctl -u gitea -f
#sudo sqlite3 /var/lib/gitea/data/gitea.db ".databases"
#sudo chown gitea:gitea /var/lib/gitea/data/gitea.db
#sudo chmod 640 /var/lib/gitea/data/gitea.db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment