Skip to content

Instantly share code, notes, and snippets.

@mladoux
Last active February 17, 2020 05:35
Show Gist options
  • Save mladoux/d398077288b608179745c0d4558ba1e2 to your computer and use it in GitHub Desktop.
Save mladoux/d398077288b608179745c0d4558ba1e2 to your computer and use it in GitHub Desktop.
Installs the latest version of gitea on a fresh ubuntu 18.04 server with an nginx front end. ( Needs to be run as root )
#!/bin/bash
# Download latest version of gitea
export LATEST=$(curl -s https://api.github.com/repos/go-gitea/gitea/releases/latest | grep 'browser_download_url' | cut -d\" -f4 | grep 'linux-amd64' | grep -v .asc | grep -v .xz | grep -v .sha256)
wget -O gitea $LATEST
# Create user
echo "Creating git user"
adduser \
--system \
--shell /bin/bash \
--gecos 'Git Version Control' \
--group \
--disabled-password \
--home /home/git \
git
id git > git-user-info.txt
id git
# Update software
apt update
apt -y dist-upgrade
apt -y install mariadb-server nginx
# Database Setup
echo "Set a database password:"
read DBPASS
echo "Creating Database"
echo "-----------------"
echo "User : gitea"
echo "Password : ${DBPASS}"
echo "Database : gitea"
cat > db.sql <<EOF_DB
CREATE DATABASE gitea;
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost' IDENTIFIED BY "${DBPASS}";
FLUSH PRIVILEGES;
EOF_DB
mysql < db.sql
# Install binary
chmod +x gitea
mv gitea /usr/local/bin/
mkdir -p /etc/gitea /var/lib/gitea/{custom,data,indexers,public,log}
chown git:git /var/lib/gitea/{data,indexers,log}
chmod 750 /var/lib/gitea/{data,indexers,log}
chown root:git /etc/gitea
chmod 770 /etc/gitea
# Setup for systemd autostarting on reboot
cat > /etc/systemd/system/gitea.service <<EOF_SERVICE
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
After=mysql.service
[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
# If you want to bind Gitea to a port below 1024 uncomment
# the two values below
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
EOF_SERVICE
systemctl daemon-reload
systemctl enable gitea
systemctl start gitea
# Set up nginx proxy server
echo "Setting up the nginx proxy, what domain name/ip address would you like the server"
echo "to listen to?"
read SITE_HOST
unlink /etc/nginx/sites-enabled/default
cat > /etc/nginx/sites-available/gitea.conf <<EOF_NGINX
upstream gitea {
server 127.0.0.1:3000;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name ${SITE_HOST};
root /var/lib/gitea/public;
access_log off;
error_log off;
location / {
try_files maintain.html \$uri \$uri/index.html @node;
}
location @node {
client_max_body_size 0;
proxy_pass http://localhost:3000;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header Host \$http_host;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_max_temp_file_size 0;
proxy_redirect off;
proxy_read_timeout 120;
}
}
EOF_NGINX
ln -s /etc/nginx/sites-available/gitea.conf /etc/nginx/sites-enabled/gitea
systemctl reload nginx
echo "All done! Please open your browser to http://${SITE_HOST} to finish configuration!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment