-
Notifications
You must be signed in to change notification settings - Fork 45
/
FreeIRAN.sh
171 lines (143 loc) · 6.17 KB
/
FreeIRAN.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
#!/bin/bash
# Script: FreeIRAN.sh
# Author: Namira
# Description: A simple bash script for setup Ubuntu Server.
# https://github.com/ErfanNamira/FreeIRAN
# Check for sudo privileges
if [ "$EUID" -ne 0 ]; then
echo "Please run this script with sudo or as root."
exit 1
fi
# Introductory message
cat <<EOM
FreeIRAN: A simple bash script for setting up Ubuntu Server
What does this script do? You can select to:
1. Update & Upgrade Server
2. Install essential packages
3. Install Speedtest
4. Create SWAP File
5. Enable BBR
6. Automatically update and restart the server every night at 01:00 GMT+3:30
7. Install X-UI (Alireza/MHSanaei)
8. Install Pi-Hole Adblocker
9. Install & set WARP Proxy
10. Install Erlang MTProto Proxy
11. Install Hysteria II
12. Install TUIC v5
Manually set the parameters yourself when prompted during the setup.
EOM
# Ask the user if they want to proceed
read -p "Do you want to proceed with the setup? (y/n): " proceed
if [[ $proceed != "y" && $proceed != "Y" ]]; then
echo "Setup aborted."
exit 0
fi
# Helper function to check if a package is installed
package_installed() {
dpkg -l | grep -q $1
}
# 1. Update & Upgrade Server
read -p "Do you want to update & upgrade the server? (y/n): " update_upgrade
if [[ $update_upgrade == "y" || $update_upgrade == "Y" ]]; then
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean && sudo apt clean
fi
# 2. Install essential packages
read -p "Do you want to install essential packages? (y/n): " install_packages
if [[ $install_packages == "y" || $install_packages == "Y" ]]; then
packages=("curl" "nano" "certbot" "cron" "ufw" "htop" "dialog" "net-tools")
for pkg in "${packages[@]}"; do
if ! package_installed $pkg; then
sudo apt install -y $pkg
fi
done
fi
# 3. Install Speedtest
read -p "Do you want to install Speedtest? (y/n): " install_speedtest
if [[ $install_speedtest == "y" || $install_speedtest == "Y" ]]; then
if ! package_installed "speedtest-cli"; then
curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash
sudo apt-get install -y speedtest-cli
fi
fi
# 4. Create SWAP File
read -p "Do you want to create a SWAP file? (y/n): " create_swap
if [[ $create_swap == "y" || $create_swap == "Y" ]]; then
read -p "Enter the SWAP file size (e.g., 1G for 1GB): " swap_size
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
echo "SWAP file of size $swap_size created and configured."
else
echo "No SWAP file will be created."
fi
# 5. Enable BBR
read -p "Do you want to enable BBR? (y/n): " enable_bbr
if [[ $enable_bbr == "y" || $enable_bbr == "Y" ]]; 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
fi
# 6. Enable and configure Cron
read -p "Do you want to set up automatic nightly updates and restarts? (y/n): " enable_cron
if [[ $enable_cron == "y" || $enable_cron == "Y" ]]; then
sudo systemctl enable cron
echo "Adding cron jobs..."
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
fi
# 7. Install Alireza X-UI
read -p "Do you want to install Alireza X-UI? (y/n): " install_xui
if [[ $install_xui == "y" || $install_xui == "Y" ]]; then
bash <(curl -Ls https://raw.githubusercontent.com/alireza0/x-ui/master/install.sh)
fi
# 8. Install MHSanaei X-UI
read -p "Do you want to install MHSanaei X-UI? (y/n): " install_xui2
if [[ $install_xui2 == "y" || $install_xui2 == "Y" ]]; then
bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh)
fi
# 9. Install Pi-Hole Adblocker
read -p "Do you want to install Pi-Hole Adblocker? (y/n): " install_pihole
if [[ $install_pihole == "y" || $install_pihole == "Y" ]]; then
curl -sSL https://install.pi-hole.net | bash
pihole -a -p
echo "nameserver 127.0.0.53" | sudo tee /etc/resolv.conf
fi
# 10. Install & set WARP Proxy
read -p "Do you want to install and set WARP Proxy? (y/n): " install_warp
if [[ $install_warp == "y" || $install_warp == "Y" ]]; then
bash <(curl -fsSL git.io/warp.sh) proxy
fi
# 11. Install Erlang MTProto Proxy
read -p "Do you want to install Erlang MTProto Proxy? (y/n): " install_mtproto
if [[ $install_mtproto == "y" || $install_mtproto == "Y" ]]; then
curl -L -o mtp_install.sh https://git.io/fj5ru && bash mtp_install.sh
fi
# 12. Install Hysteria II
read -p "Do you want to install Hysteria II? (y/n): " install_hysteria
if [[ $install_hysteria == "y" || $install_hysteria == "Y" ]]; then
bash <(curl -fsSL https://raw.githubusercontent.com/deathline94/Hysteria-Installer/main/hysteria.sh)
fi
# 13. Install TUIC v5
read -p "Do you want to install TUIC v5? (y/n): " install_tuic
if [[ $install_tuic == "y" || $install_tuic == "Y" ]]; then
bash <(curl -fsSL https://raw.githubusercontent.com/deathline94/tuic-v5-installer/main/tuic-installer.sh)
fi
# Reminder message
cat <<EOM
Setup completed. Don't forget to:
1. Add your desired adlists via the Pi-hole web interface.
2. Update the Pi-hole database with [pihole -g].
3. Obtain SSL Certificates with [sudo certbot certonly --standalone --preferred-challenges http --agree-tos --email [email protected] -d sub.domain.com].
4. Change the SSH Port with [sudo nano /etc/ssh/sshd_config].
5. Set up UFW.
6. Change WARP License Key [warp-cli set-license <your-warp-plus-license-key>]
7. Change Server DNS to use Pi-hole [sudo nano /etc/resolv.conf]
8. Restart your server with [sudo shutdown -r now].
EOM
# Exit script
exit 0