Skip to content

Instantly share code, notes, and snippets.

@Andelnyr
Forked from jniltinho/install_gogs_ubuntu.sh
Created May 15, 2020 03:58
Show Gist options
  • Select an option

  • Save Andelnyr/366b61c4d3b748b7b4071b7961e15c6c to your computer and use it in GitHub Desktop.

Select an option

Save Andelnyr/366b61c4d3b748b7b4071b7961e15c6c to your computer and use it in GitHub Desktop.
Install Gogs on Debian or Ubuntu
#!/bin/bash
## Install Gogs v0.9.113 + Nginx Webserver + Mysql
## On Debian, Ubuntu 64Bits
## Author: Nilton OS -- www.linuxpro.com.br
## Version: 3.2
### Tested on Ubuntu 16.04 LTS 64Bits
### Tested on Debian 8.7 64Bits
echo 'install_gogs_ubuntu.sh'
echo 'Support Ubuntu/Debian'
echo 'Installs Gogs 0.9.113'
echo 'Requires Ubuntu 16.04+, Debian 8+'
# Check if user has root privileges
if [[ $EUID -ne 0 ]]; then
echo "You must run the script as root or using sudo"
exit 1
fi
GET_OS=$(cat /etc/os-release | head -n1 | cut -d'=' -f2 | awk '{ print tolower($1) }'| tr -d '"')
### Vars
GOGS_LINK="https://dl.gogs.io"
GOGS_FILE=gogs_v0.9.113_linux_amd64.tar.gz
if [[ $GET_OS == 'debian' || $GET_OS == 'ubuntu' ]]; then
apt-get update
apt-get install -y wget nginx supervisor git-core mysql-client mysql-server
adduser --disabled-login --gecos 'Gogs' git
fi
cd /home/git
wget --no-check-certificate $GOGS_LINK/$GOGS_FILE
tar -xvf $GOGS_FILE && rm -f $GOGS_FILE
echo "Enter Mysql root password"
echo "--------------------"
mysql -p < /home/git/gogs/scripts/mysql.sql
chmod +x /home/git/gogs/gogs
mkdir -p /home/git/gogs/log
chown -R git:git /home/git/gogs
chown -R git:git /home/git/gogs/*
## Start Gogs App
if [[ $GET_OS == 'debian' || $GET_OS == 'ubuntu' ]]; then
echo '[program:gogs]
directory=/home/git/gogs/
command=/home/git/gogs/gogs web
autostart=true
autorestart=true
startsecs=20
stdout_logfile=/home/git/gogs/log/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/home/git/gogs/log/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
environment = HOME="/home/git", USER="git"
user = git' >> /etc/supervisor/conf.d/gogs.conf
service supervisor restart
fi
echo ""
echo "Setup Webserver Nginx"
echo "--------------------"
echo 'server {
listen YOUR_SERVER_IP:80;
server_name YOUR_SERVER_FQDN;
proxy_set_header X-Real-IP $remote_addr; # pass on real client IP
location / {
proxy_pass http://localhost:3000;
}
}' > /etc/nginx/sites-available/gogs.conf
ln -s /etc/nginx/sites-available/gogs.conf /etc/nginx/sites-enabled/gogs.conf
sed -i "s/YOUR_SERVER_IP/$SERVER_IP/" /etc/nginx/sites-available/gogs.conf
sed -i "s/YOUR_SERVER_FQDN/$SERVER_FQDN/" /etc/nginx/sites-available/gogs.conf
service nginx restart
echo ""
echo "Gogs Server App run on port 3000, Nginx on port 80"
echo "Access http://$SERVER_FQDN to continue the installation"
echo ""
echo "Screencast Install: http://blog.linuxpro.com.br/2015/08/14/instalando-gogs-no-ubuntu/"
## Links
## http://gogs.io/docs/installation/install_from_source.html
## http://gogs.io/
## https://github.com/gogits/gogs/
## https://github.com/gogits/gogs/blob/master/conf/app.ini
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment