-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-setup.sh
78 lines (66 loc) · 1.9 KB
/
server-setup.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
#!/bin/bash
# Check apt pakage managers
sudo useradd -m -s /bin/bash tunnel && echo "tunnel:SecurePassword" | sudo chpasswd
install_with_apt() {
sudo apt update
sudo apt install -y nginx python3 python3-pip
}
# Check yum pakage manager
install_with_yum() {
sudo yum update
sudo yum install epel-release -y
sudo yum install -y nginx python3 python3-pip
}
#Detect the package manager
install_software() {
local software_name="$package"
# Check if APT is available
if command -v apt > /dev/null; then
install_with_apt "$software_name"
# Check if YUM is available
elif command -v yum > /dev/null; then
install_with_yum "$software_name"
else
echo "Package manager not-found. Cannot install software."
fi
}
install_software "package_name"
cd server && pip3 install -r requirements.txt
sudo mkdir -p /root/.tunnel
pwd
sudo cp -r ../server /root/.tunnel
# Assign the server name from the argument
server_name="$1"
nginx_conf_dir="/etc/nginx/sites-available"
nginx_conf_file="${server_name}"
sudo rm -rf /etc/nginx/sites-enabled/default
sudo mkdir -p /etc/nginx/location_block
sudo touch /etc/nginx/location_block/tunnel
# Create an Nginx site configuration file
cat <<EOF > "${nginx_conf_dir}/${nginx_conf_file}"
server {
listen 80;
server_name ${server_name};
include /etc/nginx/location_block/tunnel;
}
EOF
# Create a symlink to enable the site
sudo ln -s "${nginx_conf_dir}/${nginx_conf_file}" "/etc/nginx/sites-enabled/"
# Reload Nginx to apply the new configuration
sudo systemctl restart nginx.service
# Create service file for tunnel App
cat <<EOF > "/etc/systemd/system/tunnel-app.service"
[Unit]
Description=Tunnel app
After=network.target
[Service]
User=root
WorkingDirectory=/root/.tunnel/server
ExecStart=python3 server.py
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable tunnel-app
sudo systemctl start tunnel-app
echo "Setup Done"