-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathubuntu-server-setup.sh
More file actions
executable file
·124 lines (106 loc) · 2.57 KB
/
ubuntu-server-setup.sh
File metadata and controls
executable file
·124 lines (106 loc) · 2.57 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
#!/bin/bash -i
red='\033[0;31m'
clear='\033[0m'
function welcome() {
clear
echo -e "============================================="
echo -e "== Welcome to Ubuntu Server Setup 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 "== Server setup completed successfully."
echo -e "=="
echo -e "== Use the following to connect via SSH on your local computer"
echo -e "== ssh $username@$(curl -s api.infoip.io/ip)"
echo -e "=="
echo -e "============================================="
echo -e "== Made with ${red}❤️${clear} from ©Factman =="
echo -e "============================================="
}
function addUser() {
echo "=="
echo -e "== > Creating a New User..."
echo "=="
echo -e "== > You will be asked a few questions"
echo -e "=="
adduser $username
usermod -aG sudo $username
echo "=="
}
function setFirewall() {
echo "=="
echo -e "== > Setting Up a Basic Firewall..."
echo "=="
ufw allow OpenSSH
ufw enable
echo "=="
}
function grantAccess() {
echo "=="
echo -e "== > Granting SSH access to the user..."
rsync --archive --chown=$username:$username ~/.ssh /home/$username
echo "=="
}
function switchAccount() {
echo "=="
echo -e "== > Switching from root to $username..."
echo "=="
su - $username
echo "=="
}
function installAppManager() {
echo "=="
echo -e "== > Installing App Manager..."
echo "=="
cd ~ && curl https://raw.githubusercontent.com/factman/Ubuntu-Server-Setup/main/app-manager.sh >./.app-manager.sh && chmod +x ./.app-manager.sh && ./.app-manager.sh install
}
function updateRestart() {
echo "=="
echo -e "== > Updating Server..."
echo "=="
apt -y update
echo "=="
echo "=="
echo -e "== > Upgrading Server..."
echo "=="
apt -y upgrade
echo "=="
echo "=="
}
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
}
# Layout start here
welcome
if [[ $UID -eq 0 ]]; then
# set $username
output "Enter Username" username
fi
# create a user account
if [[ -n $username ]]; then
addUser
setFirewall
grantAccess
switchAccount
fi
installAppManager
output "Update Server? (Yes)" updateServer
if [[ $(checkInput "$updateServer" "y") = "y" ]]; then
updateRestart
fi
# Layout end here
goodbye