-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-manager.sh
More file actions
executable file
·218 lines (196 loc) · 4.71 KB
/
app-manager.sh
File metadata and controls
executable file
·218 lines (196 loc) · 4.71 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash -i
red='\033[0;31m'
clear='\033[0m'
function welcome() {
clear
echo -e "============================================="
echo -e "== Welcome to Application Manager Wizard =="
echo -e "---------------------------------------------"
echo -e "== For Ubuntu 20.04 on Digital Ocean =="
echo -e "============================================="
echo -e "=="
}
function goodbye() {
echo -e "=="
echo -e "== Congratulations"
echo -e "== Operation succesfully."
echo -e "=="
echo -e "=="
echo -e "============================================="
echo -e "== Made with ${red}❤️${clear} from ©Factman =="
echo -e "============================================="
}
function setupAliases() {
if alias | grep -q appman; then
echo ""
else
printf "\n\n#########################\n## App Manager Aliases ##\n#########################\nalias appman=\"~/.app-manager.sh\"\nalias appmanager=\"~/.app-manager.sh\"\n\n" >>~/.bashrc
source ~/.bashrc
fi
}
function setFirewall() {
echo "=="
echo -e "== > Setting Up a Basic Firewall..."
echo "=="
ufw allow OpenSSH
ufw enable
echo "=="
}
function aptUpdate() {
echo "=="
echo -e "== > Updating apt libraries..."
echo "=="
sudo apt -y update
echo "=="
}
function setupNginx() {
aptUpdate
echo "=="
echo -e "== > Installing Nginx..."
echo "=="
sudo apt install nginx
sudo sed -i "s/# server_names_hash_bucket_size/server_names_hash_bucket_size/" /etc/nginx/nginx.conf
sudo nginx -t
sudo systemctl restart nginx
echo "=="
}
function enablingHTTPS() {
setFirewall
echo "=="
echo -e "== > Installing let's encrypt..."
echo "=="
sudo apt -y install certbot python3-certbot-nginx
echo "=="
echo "=="
echo -e "== > Updating the firewall..."
sudo ufw allow 'Nginx Full'
echo "=="
}
function enablingHTTP() {
setFirewall
echo "=="
echo -e "== > Updating the firewall..."
sudo ufw allow 'Nginx HTTP'
echo "=="
}
function installNVM() {
echo "=="
echo -e "== > Installing NVM..."
echo "=="
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
source ~/.bashrc
source ~/.profile
echo "=="
echo "=="
echo -e "== > Installed NVM: v$(nvm -v)"
echo "=="
}
function installNodeJS() {
echo "=="
echo -e "== > Installing NodeJS v$1..."
echo "=="
nvm install $1
nvm use node
echo "=="
echo "=="
echo -e "== > Installed Node: $(node -v)"
echo -e "== > Installed NPM: v$(npm -v)"
echo "=="
}
function installPM2() {
source ~/.bashrc
source ~/.profile
echo "=="
echo -e "== > Installing PM2..."
echo "=="
npm install -g pm2
echo "=="
echo "=="
pm2Save=$(pm2 startup)
pm2ver=$(pm2 -v)
echo "== sudo ${pm2Save##*"sudo "}"
echo "=="
echo -e "== > IMPORTANT: You must run the code above to complete installation."
echo "=="
echo "=="
echo -e "== > Installed PM2: v$(pm2 -v)"
echo "=="
source ~/.bashrc
source ~/.profile
}
function output() {
echo "=="
echo -e -n "== $1: "
read $2
}
function checkInput() {
case $1 in
n | N | no | No | NO) echo "n" ;;
y | Y | yes | Yes | YES) echo "y" ;;
*) echo $2 ;;
esac
}
function init() {
# Installation Options
echo "=="
echo -e "== Press (Y) for Yes & (N) for No"
output "Install Nginx (Yes)" installNginx
output "Enable HTTPS with Let's Encrypt (Yes)" enableHttps
output "Install NVM/NodeJS/NPM (Yes)" installNode
if [[ $(checkInput "$installNode" "y") = "y" ]]; then
output "Node version (lts)" nodeVersion
fi
output "Install PM2 (Yes)" installPM
# installing Nginx
if [[ $(checkInput "$installNginx" "y") = "y" ]]; then
setupNginx
if [[ $(checkInput "$enableHttps" "y") = "y" ]]; then
enablingHTTPS
else
enablingHTTP
fi
fi
# installing NVM/Node/NPM
if [[ $(checkInput "$installNode" "y") = "y" ]]; then
installNVM
if [[ -z $nodeVersion ]]; then
installNodeJS "lts"
else
installNodeJS "$nodeVersion"
fi
fi
# installing PM2
if [[ $(checkInput "$installPM" "y") = "y" ]]; then
installPM2
fi
}
function updateSystem() {
echo "=="
echo -e "== > Updating Server..."
echo "=="
apt -y update
echo "=="
echo "=="
echo -e "== > Upgrading Server..."
echo "=="
apt -y upgrade
echo "=="
echo "=="
}
# Layout start here
setupAliases
if [[ $1 = "install" ]]; then
welcome
echo "== Installation in progress..."
init
elif [[ $1 = "update" ]]; then
output "Update Server? (Yes)" updateServer
if [[ $(checkInput "$updateServer" "y") = "y" ]]; then
updateSystem
fi
fi
# Layout end here
goodbye