forked from nilofari700/FreeIRAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.sh
461 lines (397 loc) · 16.2 KB
/
dev.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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
#!/bin/bash
# FreeIRAN v.1.2.0 Beta
# Brave hearts unite for a Free Iran, lighting the path to a brighter future with unwavering determination.
# ErfanNamira
# https://github.com/ErfanNamira/FreeIRAN
# Check for sudo privileges
if [[ $EUID -ne 0 ]]; then
if [[ $(sudo -n true 2>/dev/null) ]]; then
echo "This script will be run with sudo privileges."
else
echo "This script must be run with sudo privileges."
exit 1
fi
fi
# 1. Function to perform system updates and cleanup
system_update() {
sudo apt update -y
sudo apt upgrade -y
sudo apt autoremove -y
sudo apt autoclean -y
sudo apt clean -y
dialog --msgbox "System updates and cleanup completed." 10 60
}
# 2. Function to install essential packages
install_essential_packages() {
packages=("curl" "nano" "certbot" "cron" "ufw" "htop" "net-tools" "zip" "unzip")
package_installed() {
dpkg -l | grep -q "^ii $1"
}
for pkg in "${packages[@]}"; do
if ! package_installed "$pkg"; then
sudo apt install -y "$pkg"
fi
done
}
# 3. Function to install Speedtest
install_speedtest() {
dialog --title "Install Speedtest" --yesno "Do you want to install Speedtest?" 10 60
response=$?
if [ $response -eq 0 ]; then
curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash
sudo apt-get -y install speedtest
dialog --msgbox "Speedtest has been installed successfully. You can now run it by entering 'speedtest' in the terminal." 10 40
else
dialog --msgbox "Skipping installation of Speedtest." 10 40
fi
}
# 4. Function to create a swap file
create_swap_file() {
if [ -f /swapfile ]; then
dialog --title "Swap File" --msgbox "A swap file already exists. Skipping swap file creation." 10 60
else
dialog --title "Swap File" --inputbox "Enter the size of the swap file (e.g., 2G for 2 gigabytes):" 10 60 2> swap_size.txt
swap_size=$(cat swap_size.txt)
if [[ "$swap_size" =~ ^[0-9]+[GgMm]$ ]]; then
sudo fallocate -l "$swap_size" /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10
sudo sysctl vm.vfs_cache_pressure=50
echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf
echo "vm.vfs_cache_pressure=50" | sudo tee -a /etc/sysctl.conf
dialog --msgbox "Swap file created successfully with a size of $swap_size." 10 60
else
dialog --msgbox "Invalid swap file size. Please provide a valid size (e.g., 2G for 2 gigabytes)." 10 60
fi
fi
}
# 5. Function to enable BBR
enable_bbr() {
dialog --title "Enable BBR" --yesno "Do you want to enable BBR? Enabling BBR while Hybla is enabled can lead to conflicts. Are you sure you want to proceed?" 12 60
response=$?
if [ $response -eq 0 ]; then
echo "net.core.default_qdisc = fq" | sudo tee -a /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control = bbr" | sudo tee -a /etc/sysctl.conf
dialog --msgbox "BBR enabled successfully." 10 40
else
dialog --msgbox "BBR configuration skipped." 10 40
fi
}
# 6. Function to enable Hybla
enable_hybla() {
dialog --title "Enable Hybla" --yesno "Do you want to enable Hybla? Enabling Hybla while BBR is enabled can lead to conflicts. Are you sure you want to proceed?" 12 60
response=$?
if [ $response -eq 0 ]; then
# Add lines to /etc/security/limits.conf
echo "* soft nofile 51200" | sudo tee -a /etc/security/limits.conf
echo "* hard nofile 51200" | sudo tee -a /etc/security/limits.conf
# Run ulimit command
ulimit -n 51200
# Add lines to /etc/ufw/sysctl.conf
echo "fs.file-max = 51200" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.core.rmem_max = 67108864" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.core.wmem_max = 67108864" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.core.netdev_max_backlog = 250000" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.core.somaxconn = 4096" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.ipv4.tcp_syncookies = 1" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.ipv4.tcp_tw_reuse = 1" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.ipv4.tcp_tw_recycle = 0" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.ipv4.tcp_fin_timeout = 30" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.ipv4.tcp_keepalive_time = 1200" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.ipv4.ip_local_port_range = 10000 65000" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog = 8192" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.ipv4.tcp_max_tw_buckets = 5000" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.ipv4.tcp_fastopen = 3" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.ipv4.tcp_mem = 25600 51200 102400" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.ipv4.tcp_rmem = 4096 87380 67108864" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.ipv4.tcp_wmem = 4096 65536 67108864" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.ipv4.tcp_mtu_probing = 1" | sudo tee -a /etc/ufw/sysctl.conf
echo "net.ipv4.tcp_congestion_control = hybla" | sudo tee -a /etc/ufw/sysctl.conf
dialog --msgbox "Hybla enabled successfully." 10 60
else
dialog --msgbox "Hybla configuration skipped." 10 60
fi
}
# 7. Function to enable and configure Cron
enable_and_configure_cron() {
dialog --title "Enable and Configure Cron" --yesno "Would you like to enable and configure Cron? This will schedule automatic updates and system restarts every night at 01:00 +3:30 GMT." 10 60
response=$?
if [ $response -eq 0 ]; then
echo "00 22 * * * /usr/bin/apt-get update && /usr/bin/apt-get upgrade -y && /usr/bin/apt-get autoremove -y && /usr/bin/apt-get autoclean -y && /usr/bin/apt-get clean -y" | sudo tee -a /etc/crontab
echo "30 22 * * * /sbin/shutdown -r" | sudo tee -a /etc/crontab
dialog --msgbox "Cron enabled and configured successfully." 10 40
else
dialog --msgbox "Cron configuration skipped." 10 40
fi
}
# 8. Function to install Multiprotocol VPN Panel
install_vpn_panel() {
dialog --title "Install Multiprotocol VPN Panel" --menu "Select a VPN Panel to Install:" 15 60 6 \
"1" "X-UI | Alireza" \
"2" "X-UI | MHSanaei" \
"3" "X-UI | vaxilu" \
"4" "X-UI | FranzKafkaYu" \
"5" "X-UI En | FranzKafkaYu" \
"6" "reality-ezpz | aleskxyz" 2> vpn_choice.txt
vpn_choice=$(cat vpn_choice.txt)
case $vpn_choice in
"1")
bash <(curl -Ls https://raw.githubusercontent.com/alireza0/x-ui/master/install.sh)
;;
"2")
bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh)
;;
"3")
bash <(curl -Ls https://raw.githubusercontent.com/vaxilu/x-ui/master/install.sh)
;;
"4")
bash <(curl -Ls https://raw.githubusercontent.com/FranzKafkaYu/x-ui/master/install.sh)
;;
"5")
bash <(curl -Ls https://raw.githubusercontent.com/FranzKafkaYu/x-ui/master/install_en.sh)
;;
"6")
bash <(curl -sL https://raw.githubusercontent.com/aleskxyz/reality-ezpz/master/reality-ezpz.sh)
;;
*)
dialog --msgbox "Invalid choice. No VPN Panel installed." 10 40
return
;;
esac
# Wait for the user to press Enter
read -p "Please press Enter to continue."
# Return to the menu
}
# 9. Function to obtain SSL certificates
obtain_ssl_certificates() {
apt install -y certbot
dialog --title "Obtain SSL Certificates" --yesno "Do you want to Get SSL Certificates?" 10 60
response=$?
if [ $response -eq 0 ]; then
dialog --title "SSL Certificate Information" --inputbox "Enter your email:" 10 60 2> email.txt
email=$(cat email.txt)
dialog --title "SSL Certificate Information" --inputbox "Enter your domain (e.g., sub.domain.com):" 10 60 2> domain.txt
domain=$(cat domain.txt)
if [ -n "$email" ] && [ -n "$domain" ]; then
sudo certbot certonly --standalone --preferred-challenges http --agree-tos --email "$email" -d "$domain"
# Wait for the user to press Enter
read -p "Please Press Enter to continue"
dialog --msgbox "SSL certificates obtained successfully for $domain in /etc/letsencrypt/live." 10 60
else
dialog --msgbox "Both email and domain are required to obtain SSL certificates." 10 60
fi
else
dialog --msgbox "Skipping SSL certificate acquisition." 10 40
fi
# Return to the menu
}
# 10. Function to set up Pi-Hole
setup_pi_hole() {
# Ask if you want to install Pi-Hole, a network-wide ad blocker
dialog --title "Install Pi-Hole" --yesno "Do you want to install Pi-Hole, the network-wide ad blocker?" 10 60
response=$?
if [ $response -eq 0 ]; then
curl -sSL https://install.pi-hole.net | bash
dialog --title "Change Pi-Hole Web Interface Password" --yesno "Do you want to change the Pi-Hole web interface password?" 10 60
response=$?
if [ $response -eq 0 ]; then
pihole -a -p
dialog --msgbox "Pi-Hole web interface password changed successfully." 10 60
else
dialog --msgbox "Skipping Pi-Hole web interface password change." 10 40
fi
if [ -f /etc/lighttpd/lighttpd.conf ]; then
dialog --title "Change Lighttpd Port" --yesno "If you have installed Pi-Hole, then Lighttpd is listening on port 80 by default. Do you want to change the Lighttpd port?" 10 60
response=$?
if [ $response -eq 0 ]; then
sudo nano /etc/lighttpd/lighttpd.conf
dialog --msgbox "Lighttpd port changed." 10 60
else
dialog --msgbox "Skipping Lighttpd port change." 10 40
fi
fi
else
dialog --msgbox "Skipping Pi-Hole installation." 10 40
fi
}
# 11. Function to change SSH port
change_ssh_port() {
# Prompt the user for the new SSH port
dialog --title "Change SSH Port" --inputbox "Enter the new SSH port:" 10 60 2> ssh_port.txt
new_ssh_port=$(cat ssh_port.txt)
# Verify that a valid port number is provided
if [[ $new_ssh_port =~ ^[0-9]+$ ]]; then
# Remove the '#' comment from the 'Port' line in sshd_config (if present)
sudo sed -i "/^#*Port/s/^#*Port/Port/" /etc/ssh/sshd_config
# Update SSH port in sshd_config
sudo sed -i "s/^Port .*/Port $new_ssh_port/" /etc/ssh/sshd_config
# Reload SSH service to apply changes
sudo systemctl reload sshd
dialog --msgbox "SSH port changed to $new_ssh_port. Please ensure that you apply related firewall rules and update your SSH client configuration accordingly." 10 60
else
dialog --msgbox "Invalid port number. Please provide a valid port." 10 60
fi
}
# 12. Function to enable UFW
enable_ufw() {
# Set defaults
sudo ufw default deny incoming
sudo ufw default allow outgoing
# Prompt the user for the SSH port to allow
dialog --title "Enable UFW - SSH Port" --inputbox "Enter the SSH port to allow:" 10 60 2> ssh_port.txt
ssh_port=$(cat ssh_port.txt)
# Allow SSH port
if [ -n "$ssh_port" ]; then
sudo ufw allow "$ssh_port"/tcp
sudo ufw limit "$ssh_port"/tcp
fi
# Prompt the user for additional ports to open
dialog --title "Enable UFW - Additional Ports" --inputbox "Enter additional ports to open (comma-separated, e.g., 80,443):" 10 60 2> ufw_ports.txt
ufw_ports=$(cat ufw_ports.txt)
# Allow additional ports specified by the user
if [ -n "$ufw_ports" ]; then
IFS=',' read -ra ports_array <<< "$ufw_ports"
for port in "${ports_array[@]}"; do
sudo ufw allow "$port"
done
fi
# Enable UFW to start at boot
sudo ufw enable
sudo systemctl enable ufw
# Display completion message
dialog --msgbox "UFW enabled and configured successfully." 12 60
}
# 13. Function to install and configure WARP Proxy
install_configure_warp_proxy() {
dialog --title "Install & Configure WARP Proxy" --yesno "Do you want to install and configure WARP Proxy?" 10 60
response=$?
if [ $response -eq 0 ]; then
bash <(curl -fsSL git.io/warp.sh) proxy
# Wait for the user to press Enter
read -p "Please Press Enter to continue"
dialog --msgbox "WARP Proxy installed and configured successfully." 10 60
else
dialog --msgbox "Skipping installation and configuration of WARP Proxy." 10 60
fi
}
# 14. Function to deploy Erlang MTProto Proxy
deploy_erlang_mtproto_proxy() {
curl -L -o mtp_install.sh https://git.io/fj5ru && bash mtp_install.sh
# Wait for the user to press Enter
read -p "Please Press Enter to continue"
}
# 15. Function to setup Hysteria II
setup_hysteria_ii() {
bash <(curl -fsSL https://raw.githubusercontent.com/deathline94/Hysteria-Installer/main/hysteria.sh)
# Wait for the user to press Enter
read -p "Please Press Enter to continue"
}
# 16. Function to setup TUIC v5
setup_tuic_v5() {
bash <(curl -fsSL https://raw.githubusercontent.com/deathline94/tuic-v5-installer/main/tuic-installer.sh)
# Wait for the user to press Enter
read -p "Please Press Enter to continue"
}
# 17. Function to setup Reverse Tls Tunnel
setup_reverse_tls_tunnel() {
# Ask the user if they want to install Reverse Tls Tunnel
dialog --title "Setup Reverse Tls Tunnel" --yesno "Do you want to install Reverse Tls Tunnel developed by radkesvat?" 10 60
response=$?
if [ $response -eq 0 ]; then
# Download the script and make it executable
wget "https://raw.githubusercontent.com/radkesvat/ReverseTlsTunnel/master/install.sh" -O install.sh && chmod +x install.sh && bash install.sh
# Display instructions in the terminal
echo "ReverseTlsTunnel has been downloaded. Please run it in an Iran server with this command:"
echo "nohup ./RTT --iran --lport:443 --sni:splus.ir --password:123"
echo
echo "And run it in an Abroad server with:"
echo "nohup ./RTT --kharej --iran-ip:5.4.3.2 --iran-port:443 --toip:127.0.0.1 --toport:2083 --password:123 --sni:splus.ir"
# Wait for the user to press Enter
read -p "Please Press Enter to continue"
else
dialog --msgbox "Skipping installation of Reverse Tls Tunnel." 10 60
fi
}
# 18.Function to create a non-root SSH user
create_ssh_user() {
# Ask the user for the username
read -p "Enter the username for the new SSH user: " username
# Ask the user for the password (securely)
read -s -p "Enter the password for the new SSH user: " password
echo
# Create the user with the specified username
sudo useradd -m -s /bin/bash "$username"
# Set the user's password
echo "$username:$password" | sudo chpasswd
# Display a message with the created user details
echo "SSH user: $username"
echo "Password: $password"
# Wait for the user to press Enter
read -p "Please Press Enter to continue"
}
# 19.Function to reboot the system
reboot_system() {
dialog --title "Reboot System" --yesno "Do you want to reboot the system?" 10 60
response=$?
if [ $response -eq 0 ]; then
sudo reboot
else
dialog --msgbox "System reboot canceled." 10 40
fi
}
# 20.Function to exit the script
exit_script() {
clear # Clear the terminal screen for a clean exit
echo "Exiting the script. Goodbye!"
exit 0 # Exit with a status code of 0 (indicating successful termination)
}
# Main menu options using dialog
while true; do
choice=$(dialog --clear --backtitle "FreeIRAN v.1.2.0 - Main Menu" --title "Main Menu" --menu "Choose an option:" 18 60 15 \
1 "System Update and Cleanup" \
2 "Install Essential Packages" \
3 "Install Speedtest" \
4 "Create Swap File" \
5 "Enable BBR" \
6 "Enable Hybla" \
7 "Schedule Automatic Updates & ReStarts" \
8 "Install Multiprotocol VPN Panels" \
9 "Obtain SSL Certificates" \
10 "Setup Pi-Hole" \
11 "Change SSH Port" \
12 "Enable UFW" \
13 "Install & Configure WARP Proxy" \
14 "Deploy Erlang MTProto Proxy" \
15 "Setup Hysteria II" \
16 "Setup TUIC v5" \
17 "Setup Reverse Tls Tunnel" \
18 "Create SSH User" \
19 "Reboot System" \
20 "Exit Script" 3>&1 1>&2 2>&3)
case $choice in
1) system_update ;;
2) install_essential_packages ;;
3) install_speedtest ;;
4) create_swap_file ;;
5) enable_bbr ;;
6) enable_hybla ;;
7) enable_and_configure_cron ;;
8) install_vpn_panel ;;
9) obtain_ssl_certificates ;;
10) setup_pi_hole ;;
11) change_ssh_port ;;
12) enable_ufw ;;
13) install_configure_warp_proxy ;;
14) deploy_erlang_mtproto_proxy ;;
15) setup_hysteria_ii ;;
16) setup_tuic_v5 ;;
17) setup_reverse_tls_tunnel ;;
18) create_ssh_user ;;
19) reboot_system ;;
20) exit_script ;;
*) echo "Invalid option. Please try again." ;;
esac
done