-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.txt
168 lines (146 loc) · 4.09 KB
/
server.txt
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
#!/bin/bash
# Function to get user input and save it to a file
get_user_input() {
local file="$1"
if [ -f "$file" ]; then
cat "$file"
else
read -p "Enter: " ui
ui=$(tr -d '[:space:]' <<< "$ui")
echo "$ui" > "$file"
cat "$file"
fi
}
# Function to perform initial setup
initial_setup() {
if [ ! -x "$(command -v curl)" ]; then
echo "Updating..."
sudo apt-get update
sudo apt-get upgrade -y
# Install needed software
sudo apt-get install -y curl rsync radicale links mutt dovecot
fi
}
# Function to download config files
download_config_files() {
files=("httpd.conf" "relayd.conf" "acme-client.conf" ".muttrc" ".mailcap" "dovecot.conf")
for file in "${files[@]}"; do
if [ ! -f "$file" ]; then
wget "https://sive.rs/file/$file"
fi
done
if [ -f pf.conf ]; then
sudo mv pf.conf /etc/pf.conf
sudo pfctl -f /etc/pf.conf
fi
}
# Function to get domain name
get_domain_name() {
local domain_file="/root/my/domain"
if [ -f "$domain_file" ]; then
cat "$domain_file"
else
read -p "Your domain name? " ui
domain=$(tr -d '[:space:]' <<< "$ui" | tr '[:upper:]' '[:lower:]' | sed 's/^www\.//')
echo "$domain" > "$domain_file"
echo "$domain"
fi
}
# Function to get username
get_username() {
local user_file="/root/my/user"
if [ -f "$user_file" ]; then
cat "$user_file"
else
read -p "Your user name? (one lowercase word, no spaces): " ui
user=$(tr -d '[:space:]' <<< "$ui" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]//g')
echo "$user" > "$user_file"
echo "$user"
fi
}
# Function to check if email and login are correct
check_email_and_login() {
local user_file_ok="/root/my/userok"
if [ ! -f "$user_file_ok" ]; then
echo "Email and login will be $user@$domain"
read -p "Does that look right? (y/n) " ui
yn=$(tr -d '[:space:]' <<< "$ui" | tr '[:upper:]' '[:lower:]' | cut -c1-1)
if [ "$yn" != "y" ]; then
rm "$user_file" "$domain_file"
echo "Please run this script again."
exit 1
fi
touch "$user_file_ok"
fi
}
# Main script
if [ "$(id -u)" -ne 0 ] || [ "$(uname)" != "Linux" ]; then
echo "Must be run as root on Linux"
exit 1
fi
# INITIAL SETUP
initial_setup
# DOWNLOAD CONFIG FILES
download_config_files
# DOMAIN?
domain=$(get_domain_name)
# USERNAME?
user=$(get_username)
# DOMAIN AND USER OK?
check_email_and_login
# Function to configure mutt
configure_mutt() {
local muttrc_file=".muttrc"
if [ -f "$muttrc_file" ]; then
sed -i "s/YOURNAME/$user/g" "$muttrc_file"
fi
}
# Function to configure dovecot
configure_dovecot() {
local dovecot_file="dovecot.conf"
if [ -f "$dovecot_file" ]; then
sed -i "s/YOURNAME/$user/g" "$dovecot_file"
fi
}
# Function to configure acme-client
configure_acme_client() {
local acme_client_file="acme-client.conf"
if [ -f "$acme_client_file" ]; then
sed -i "s/YOURNAME/$user/g" "$acme_client_file"
sed -i "s/YOURDOMAIN/$domain/g" "$acme_client_file"
fi
}
# Function to configure relayd
configure_relayd() {
local relayd_file="relayd.conf"
if [ -f "$relayd_file" ]; then
sed -i "s/YOURNAME/$user/g" "$relayd_file"
sed -i "s/YOURDOMAIN/$domain/g" "$relayd_file"
fi
}
# Function to configure httpd
configure_httpd() {
local httpd_file="httpd.conf"
if [ -f "$httpd_file" ]; then
sed -i "s/YOURNAME/$user/g" "$httpd_file"
sed -i "s/YOURDOMAIN/$domain/g" "$httpd_file"
fi
}
# Function to configure ufw
configure_ufw() {
sudo ufw allow 22 # Allow SSH
sudo ufw allow 80 # Allow HTTP
sudo ufw allow 443 # Allow HTTPS
sudo ufw enable # Enable the firewall
}
# Configure applications
configure_mutt
configure_dovecot
configure_acme_client
configure_relayd
configure_httpd
configure_pf
configure_smtpd
# Display completion message
echo "Installation and configuration completed successfully!"
echo "Reboot your system to apply changes."