forked from ShadowCorpIndustries/SpotLight
-
Notifications
You must be signed in to change notification settings - Fork 11
/
autoinstall.sh
180 lines (156 loc) · 4.2 KB
/
autoinstall.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
java_install() {
sudo apt-get install -y openjdk-8-jdk
sudo update-java-alternatives -s java-1.8.0-openjdk-amd64
sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/java-8-openjdk-amd64/bin/javac
sudo update-alternatives --set javaws /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/javaws
}
nodejs_install() {
echo "Installing NodeJS..."
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
sudo apt-get install -y nodejs
echo "NodeJS installed"
}
npm_install() {
echo "Installing NPM..."
sudo npm install -g pm2
echo "NPM installed"
}
git_install() {
echo "Installing Git..."
sudo apt-get install -y git
echo "Git installed"
}
ufw_install() {
echo "Installing UFW..."
sudo apt-get install -y ufw
echo "UFW installed"
}
nginx_install() {
echo "Installing NGINX..."
sudo apt-get install -y nginx
echo "NGINX installed"
}
certbot_install() {
echo "Installing Certbot..."
sudo apt-get install -y certbot python3-certbot-nginx
echo "Certbot installed"
}
pm2_install() {
echo "Installing PM2..."
sudo npm install -g pm2
echo "PM2 installed"
}
# check if user is root
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# set production or development mode
echo "Do you want to install L3MON in production mode or development mode?"
echo "1. Production"
echo "2. Development"
read -p "Enter your choice [1-2]: " choice
case $choice in
1)
echo "Installing in production mode"
ENVIRONMENT="production"
;;
2)
echo "Installing in development mode"
ENVIRONMENT="development"
;;
*)
echo "Invalid choice"
exit 1
;;
esac
# update and upgrade
echo "Updating and upgrading..."
sudo apt-get update && sudo apt-get upgrade -y
echo "Update and upgrade done"
# check if java is installed
if [ -z "$(dpkg -l | grep openjdk-8-jre-headless)" ]; then
echo "Java is not installed"
java_install
fi
# check if nodejs is installed
if [ -z "$(command -v node)" ]; then
echo "Nodejs is not installed" 1>&2
nodejs_install
fi
# check if npm is installed
if [ -z "$(command -v npm)" ]; then
echo "Npm is not installed" 1>&2
npm_install
fi
# check if pm2 is installed
if [ -z "$(command -v pm2)" ]; then
echo "PM2 is not installed" 1>&2
pm2_install
fi
# check if git is installed
if [ -z "$(command -v git)" ]; then
echo "Git is not installed" 1>&2
git_install
fi
# check if ufw is installed
if [ -z "$(command -v ufw)" ]; then
echo "Ufw is not installed" 1>&2
ufw_install
fi
# check if nginx is installed
if [ -z "$(command -v nginx)" ]; then
echo "Nginx is not installed" 1>&2
nginx_install
fi
# check if certbot is installed
if [ -z "$(command -v certbot)" ]; then
echo "Certbot is not installed" 1>&2
certbot_install
fi
# clone the repo
echo "Cloning the repo..."
git clone https://github.com/karima940/L3MON.git
echo "Cloning the repo done"
# install the dependencies
echo "Installing the dependencies..."
npm i --prefix ./L3MON/server
echo "Installing the dependencies done"
# setup nginx
echo "Setting up nginx..."
read -p "Enter your domain name ( Example: yourdomain.com, example.io ): " DOMAIN
sudo sed -i 's/example.com/'$DOMAIN'/g' ./L3MON/conf.d/l3mon.conf
sudo cp ./L3MON/conf.d/l3mon.conf /etc/nginx/conf.d/l3mon.conf
sudo nginx -t
sudo systemctl reload nginx
echo "Nginx setup done"
# setup pm2
echo "Setting up pm2..."
cd ./L3MON/server
pm2 start index.js --name l3mon
pm2 save
echo "PM2 setup done"
sudo pm2 status
# sudo pm2 save
# sudo pm2 startup
# sudo pm2 save
echo "PM2 setup done"
# setup ufw firewall
echo "Setting up ufw firewall..."
sudo ufw enable
sudo ufw allow "Nginx Full"
sudo ufw delete allow "Nginx HTTP"
sudo ufw allow ssh
sudo ufw allow 22222/tcp
sudo ufw status
echo "Ufw firewall setup done"
# setup certbot
echo "Setting up certbot..."
if [ "$ENVIRONMENT" = "production" ]; then
echo "Setting up certbot production server"
sudo certbot --nginx -d $DOMAIN -d l3mon.$DOMAIN
else
echo "Setting up certbot staging server"
sudo certbot --nginx -d $DOMAIN -d l3mon.$DOMAIN --agree-tos --staging --register-unsafely-without-email --no-redirect
fi