-
Notifications
You must be signed in to change notification settings - Fork 6
/
install.sh
146 lines (122 loc) · 4.06 KB
/
install.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
repositoryUrl="https://github.com/AktivCo/Rutoken-VPN-Community-Edition-Server.git"
branch=public
PROJECT_NAME=Rutoken-VPN-Community-Edition-Server
ROOT_PROJECT_PATH=/opt/$PROJECT_NAME
if [[ "$(id -u)" != 0 ]]; then
echo "Error! Please run as root or with sudo"
exit 1
fi
/bin/egrep -i "^ubuntu:" /etc/group
if [ $? -eq 0 ]; then
echo "Group \"ubuntu\" exists"
else
echo "To continue installation we have to add new group that is called \"ubuntu\" into your system. Do you agree?"
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) exit;;
esac
done
fi
/bin/egrep -i "^ubuntu:" /etc/passwd
if [ $? -eq 0 ]; then
echo "User \"ubuntu\" exists"
else
echo "To continue installation we have to add new user that is called \"ubuntu\" into your system and add him to a group that is called \"ubuntu\" too. Do you agree?"
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) exit;;
esac
done
fi
grep -q "^ubuntu:" /etc/group || groupadd "ubuntu"
grep -q "^ubuntu:" /etc/passwd || useradd "ubuntu" -N -G users --create-home -s /bin/bash
usermod -a -G "ubuntu" "ubuntu" || exit 2
usermod -a -G "sudo" "ubuntu"
if [ -n "$1" ]; then repositoryUrl="$1" ; fi
if [ -n "$2" ]; then branch="$2" ; fi
sed -i s/\GRUB_CMDLINE_LINUX=\"\/GRUB_CMDLINE_LINUX=\"net.ifnames=0\ \/ /etc/default/grub
update-grub
apt-get update
killall -9 unattended-upgr
killall -9 apt-get
apt-get install -y git python3-pip curl openvpn wget supervisor nginx
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
apt-get update
apt-get install -y nodejs
apt-get install -y redis-server
apt-get install -y ifupdown net-tools
cd /opt
git clone $repositoryUrl
cd $ROOT_PROJECT_PATH
git checkout $branch
python3 -m pip install django==3.2
python3 -m pip install requests==2.25.1
python3 -m pip install ldap3==2.9
python3 -m pip install celery==4.4.2
python3 -m pip install redis==3.5.3
python3 -m pip install gunicorn==19.4.5
mkdir db
python3 manage.py makemigrations vpnserver
python3 manage.py migrate
export NG_CLI_ANALYTICS=off
npm install && npm run webpack:opensource
mkdir /etc/openvpn
cd $ROOT_PROJECT_PATH
chown -R ubuntu:ubuntu $ROOT_PROJECT_PATH
cat > /etc/nginx/sites-enabled/default <<EOF
server {
listen 80;
location /static {
include /etc/nginx/mime.types;
alias $ROOT_PROJECT_PATH/vpnserver/static/;
}
location /media {
alias /var/log/openvpn;
}
location / {
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_pass http://localhost:8000;
proxy_redirect default;
}
}
EOF
cat > /etc/supervisor/conf.d/celery.conf <<EOF
[program:celery]
command=celery -A vpnserver worker --loglevel=info
directory=$ROOT_PROJECT_PATH/
user=ubuntu
numprocs=1
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600
killasgroup=true
priority=998
environment=OPENVPN_BIN=/usr/sbin/openvpn, OPENVPN="/etc/openvpn",OPENSSL=/usr/bin/openssl,OPENSSL_CONF="$ROOT_PROJECT_PATH/Vpn/config/openssl.cnf",LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8,LC_LANG=en_US.UTF-8
EOF
cat > /etc/supervisor/conf.d/gunicorn.conf <<EOF
[program:gunicorn]
command=gunicorn Vpn.wsgi --bind 127.0.0.1:8000 --chdir $ROOT_PROJECT_PATH/
process_name=%(process_num)s
user=ubuntu
numprocs=1
redirect_stderr=true
autostart=true
autorestart=true
startsecs=5
environment=OPENVPN_BIN=/usr/sbin/openvpn, OPENVPN="/etc/openvpn",OPENSSL=/usr/bin/openssl,OPENSSL_CONF="$ROOT_PROJECT_PATH/Vpn/config/openssl.cnf", LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8,LC_LANG=en_US.UTF-8
EOF
update-rc.d supervisor enable
update-rc.d supervisor defaults
touch /etc/iptables.rules
mkdir -p /etc/openvpn/ccd
if [ $(cat /proc/sys/net/ipv4/ip_forward) = "0" ]; then echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf; fi
echo 'Defaults env_keep += "OPENVPN OPENSSL OPENSSL_CONF"' | (EDITOR="tee -a" visudo)
echo "ubuntu ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
sed -i s/\IS_DEMO_MODE\ =\ True\/IS_DEMO_MODE\ =\ False\/ $ROOT_PROJECT_PATH/Vpn/settings.py
sudo init 6