-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-gogs.sh
94 lines (64 loc) · 2.77 KB
/
setup-gogs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
apt-get update
if [ "$(id -u)" != "0" ]; then
echo "you should run this script with root!!! "
exit 1
else
# Golang installation
# Download Go and extract the compressed file:
donwload="go$VERSION.linux-amd64.tar.gz"
echo "$dowload is being downloaded !!!!"
wget https://storage.googleapis.com/golang/$dowload -O /tmp/go.tar.gz
tar -C "$HOME" -xzf /tmp/go.tar.gz
mv "$HOME/go" "$HOME/.go"# Set the GOPATH environment variable to specify the location of our workspace.
touch "$HOME/.${shell_profile}"
{
echo '# GoLang'
echo 'export GOROOT=$HOME/.go'
echo 'export PATH=$PATH:$GOROOT/bin'
echo 'export GOPATH=$HOME/go'
echo 'export PATH=$PATH:$GOPATH/bin'
} >> "$HOME/.${shell_profile}"
mkdir -p $HOME/go/{src,pkg,bin}
rm -f /tmp/go.tar.gz
# git installation
sudo apt-get install -y git
adduser --disabled-login --gecos 'Gogs' git # When you install Go and Gogs, it will be under the user git.
# Gogs installation
echo "" >>/etc/hosts
echo "$1 $2" >>/etc/hosts
hostnamectl set-hostname $2
echo "$2" > /proc/sys/kernel/hostname
apt-get install -y wget nginx git-core mysql-client mysql-server # Install nginx from the repository:
cd /home/git
wget --no-check-certificate https://dl.gogs.io/0.11.4/linux_amd64.tar.gz
tar -xvf linux_amd64.tar.gz && rm -f linux_amd64.tar.gz
echo "CREATE USER 'gogs'@'localhost' IDENTIFIED BY $3;" >>/home/git/gogs/scripts/mysql.sql
echo "GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'localhost';" >>/home/git/gogs/scripts/mysql.sql
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/*
cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/ # Download and install Gogs
sed -i 's|mysqld.service|mysqld.service mysql.service|' /etc/systemd/system/gogs.service
systemctl daemon-reload
systemctl enable gogs.service
systemctl start gogs.service
# Set nginx as the reverse proxy for Gogs. Using sudo, create a new file named /etc/nginx/sites-available/gogs
echo 'server {
listen IP:80;
server_name DOMAIN;
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/IP/$1/" /etc/nginx/sites-available/gogs.conf
sed -i "s/DOMAIN/$2/" /etc/nginx/sites-available/gogs.conf
service nginx restart
echo "installation completed"
systemctl enable gogs.service
systemctl start gogs.service
fi