install.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. #!/bin/bash
  2. # Check root
  3. if [[ $EUID -ne 0 ]]; then
  4. echo "This script must be run as root!"
  5. exit 1
  6. fi
  7. if [ "$(systemd-detect-virt)" == "openvz" ]; then
  8. echo "OpenVZ is not supported!"
  9. exit 1
  10. fi
  11. # Get domain
  12. clear
  13. echo -e "Install variant :"
  14. echo -e " [1] Xray - Faster (443)"
  15. echo -e " [2] V2Ray - Support no-TLS (443 & 80)"
  16. echo -e ""
  17. until [[ ${variant} =~ ^[1-2]$ ]]; do
  18. read -rp "Select an option [1-2]: " variant
  19. done
  20. echo -e ""
  21. read -p "Please enter your domain : " domain
  22. echo -e ""
  23. ip=$(wget -qO- ipv4.icanhazip.com)
  24. domain_ip=$(ping "${domain}" -c 1 | sed '1{s/[^(]*(//;s/).*//;q}')
  25. if [[ ${domain_ip} == "${ip}" ]]; then
  26. echo -e "IP matched with the server. The installation will continue."
  27. sleep 2
  28. clear
  29. else
  30. echo -e "IP does not match with the server. Make sure to point A record to your server."
  31. echo -e ""
  32. exit 1
  33. fi
  34. # Update & Upgrade
  35. apt update
  36. apt upgrade -y
  37. # Remove unused dependencies
  38. apt autoremove -y
  39. # Set timezone
  40. ln -sf /usr/share/zoneinfo/Asia/Kuala_Lumpur /etc/localtime
  41. # Disable IPv6
  42. sysctl -w net.ipv6.conf.all.disable_ipv6=1
  43. sysctl -w net.ipv6.conf.default.disable_ipv6=1
  44. sysctl -w net.ipv6.conf.lo.disable_ipv6=1
  45. echo -e "net.ipv6.conf.all.disable_ipv6 = 1
  46. net.ipv6.conf.default.disable_ipv6 = 1
  47. net.ipv6.conf.lo.disable_ipv6 = 1" >> /etc/sysctl.conf
  48. # Install BBR+FQ
  49. echo -e "net.core.default_qdisc=fq
  50. net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
  51. sysctl -p
  52. # Configure UFW
  53. apt install -y ufw
  54. sed -i 's/DEFAULT_FORWARD_POLICY="DROP"/DEFAULT_FORWARD_POLICY="ACCEPT"/g' /etc/default/ufw
  55. sed -i "s/IPV6=yes/IPV6=no/g" /etc/default/ufw
  56. ufw allow 22
  57. ufw allow 85
  58. ufw allow 465
  59. ufw allow 8080
  60. ufw allow 1194
  61. ufw allow 80
  62. ufw allow 443
  63. ufw allow 51820
  64. ufw allow 7300
  65. ufw allow 8000
  66. ufw allow 3128
  67. ufw reload
  68. echo -e "y" | ufw enable
  69. # Install tools
  70. apt install -y net-tools vnstat unzip curl screen
  71. # Install screenfetch
  72. wget -qO /usr/bin/screenfetch "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/screenfetch.sh"
  73. chmod +x /usr/bin/screenfetch
  74. echo -e "clear
  75. screenfetch
  76. echo" >> .profile
  77. # Configure SSH
  78. echo -e "AllowUsers root" >> /etc/ssh/sshd_config
  79. wget -qO /etc/issue.net "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/issue.net"
  80. sed -i "s/#Banner none/Banner \/etc\/issue.net/g" /etc/ssh/sshd_config
  81. service ssh restart
  82. # Install Dropbear
  83. apt install -y dropbear
  84. sed -i "s/NO_START=1/NO_START=0/g" /etc/default/dropbear
  85. sed -i "s/DROPBEAR_PORT=22/DROPBEAR_PORT=85/g" /etc/default/dropbear
  86. echo -e "/bin/false" >> /etc/shells
  87. wget -qO /etc/dropbear_issue.net "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/dropbear_issue.net"
  88. sed -i 's|DROPBEAR_BANNER=""|DROPBEAR_BANNER="/etc/dropbear_issue.net"|g' /etc/default/dropbear
  89. service dropbear restart
  90. # Install Stunnel
  91. apt install -y stunnel4
  92. sed -i "s/ENABLED=0/ENABLED=1/g" /etc/default/stunnel4
  93. openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -sha256 -subj "/CN=Iriszz/emailAddress=aiman.iriszz@gmail.com/O=Void VPN/OU=Void VPN Premium/C=MY" -keyout /etc/stunnel/stunnel.pem -out /etc/stunnel/stunnel.pem
  94. wget -qO /etc/stunnel/stunnel.conf "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/stunnel.conf"
  95. service stunnel4 restart
  96. # Install Squid3
  97. apt install -y squid3
  98. wget -qO /etc/squid/squid.conf "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/squid.conf"
  99. sed -i "s/xx/$domain/g" /etc/squid/squid.conf
  100. sed -i "s/ip/$ip/g" /etc/squid/squid.conf
  101. service squid restart
  102. # Install OpenVPN
  103. apt install -y openvpn
  104. wget -q "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/openvpn/EasyRSA-3.0.8.tgz"
  105. tar xvf EasyRSA-3.0.8.tgz
  106. rm EasyRSA-3.0.8.tgz
  107. mv EasyRSA-3.0.8 /etc/openvpn/easy-rsa
  108. cp /etc/openvpn/easy-rsa/vars.example /etc/openvpn/easy-rsa/vars
  109. sed -i 's/#set_var EASYRSA_REQ_COUNTRY\t"US"/set_var EASYRSA_REQ_COUNTRY\t"MY"/g' /etc/openvpn/easy-rsa/vars
  110. sed -i 's/#set_var EASYRSA_REQ_PROVINCE\t"California"/set_var EASYRSA_REQ_PROVINCE\t"Kedah"/g' /etc/openvpn/easy-rsa/vars
  111. sed -i 's/#set_var EASYRSA_REQ_CITY\t"San Francisco"/set_var EASYRSA_REQ_CITY\t"Bandar Baharu"/g' /etc/openvpn/easy-rsa/vars
  112. sed -i 's/#set_var EASYRSA_REQ_ORG\t"Copyleft Certificate Co"/set_var EASYRSA_REQ_ORG\t\t"Void VPN"/g' /etc/openvpn/easy-rsa/vars
  113. sed -i 's/#set_var EASYRSA_REQ_EMAIL\t"me@example.net"/set_var EASYRSA_REQ_EMAIL\t"aiman.iriszz@gmail.com"/g' /etc/openvpn/easy-rsa/vars
  114. sed -i 's/#set_var EASYRSA_REQ_OU\t\t"My Organizational Unit"/set_var EASYRSA_REQ_OU\t\t"Void VPN Premium"/g' /etc/openvpn/easy-rsa/vars
  115. sed -i 's/#set_var EASYRSA_CA_EXPIRE\t3650/set_var EASYRSA_CA_EXPIRE\t3650/g' /etc/openvpn/easy-rsa/vars
  116. sed -i 's/#set_var EASYRSA_CERT_EXPIRE\t825/set_var EASYRSA_CERT_EXPIRE\t3650/g' /etc/openvpn/easy-rsa/vars
  117. sed -i 's/#set_var EASYRSA_REQ_CN\t\t"ChangeMe"/set_var EASYRSA_REQ_CN\t\t"Void VPN"/g' /etc/openvpn/easy-rsa/vars
  118. cd /etc/openvpn/easy-rsa
  119. ./easyrsa --batch init-pki
  120. ./easyrsa --batch build-ca nopass
  121. ./easyrsa gen-dh
  122. ./easyrsa build-server-full server nopass
  123. cd
  124. mkdir /etc/openvpn/key
  125. cp /etc/openvpn/easy-rsa/pki/issued/server.crt /etc/openvpn/key/
  126. cp /etc/openvpn/easy-rsa/pki/ca.crt /etc/openvpn/key/
  127. cp /etc/openvpn/easy-rsa/pki/dh.pem /etc/openvpn/key/
  128. cp /etc/openvpn/easy-rsa/pki/private/server.key /etc/openvpn/key/
  129. wget -qO /etc/openvpn/server-udp.conf "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/openvpn/server-udp.conf"
  130. wget -qO /etc/openvpn/server-tcp.conf "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/openvpn/server-tcp.conf"
  131. sed -i "s/#AUTOSTART="all"/AUTOSTART="all"/g" /etc/default/openvpn
  132. echo -e "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
  133. sysctl -p
  134. echo -e "\n# START OPENVPN RULES
  135. # NAT table rules
  136. *nat
  137. :POSTROUTING ACCEPT [0:0]
  138. # Allow traffic from OpenVPN client to eth0
  139. -I POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
  140. -I POSTROUTING -s 10.9.0.0/24 -o eth0 -j MASQUERADE
  141. COMMIT
  142. # END OPENVPN RULES" >> /etc/ufw/before.rules
  143. ufw reload
  144. systemctl start openvpn@server-udp
  145. systemctl start openvpn@server-tcp
  146. systemctl enable openvpn@server-udp
  147. systemctl enable openvpn@server-tcp
  148. # Configure OpenVPN client configuration
  149. mkdir -p /iriszz/openvpn
  150. wget -qO /iriszz/openvpn/client-udp.ovpn "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/openvpn/client-udp.ovpn"
  151. wget -qO /iriszz/openvpn/client-tcp.ovpn "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/openvpn/client-tcp.ovpn"
  152. sed -i "s/xx/$ip/g" /iriszz/openvpn/client-udp.ovpn
  153. sed -i "s/xx/$ip/g" /iriszz/openvpn/client-tcp.ovpn
  154. echo -e "\n<ca>" >> /iriszz/openvpn/client-tcp.ovpn
  155. cat "/etc/openvpn/key/ca.crt" >> /iriszz/openvpn/client-tcp.ovpn
  156. echo -e "</ca>" >> /iriszz/openvpn/client-tcp.ovpn
  157. echo -e "\n<ca>" >> /iriszz/openvpn/client-udp.ovpn
  158. cat "/etc/openvpn/key/ca.crt" >> /iriszz/openvpn/client-udp.ovpn
  159. echo -e "</ca>" >> /iriszz/openvpn/client-udp.ovpn
  160. # Install variant
  161. if [ "$variant" == 1 ]; then
  162. # Install Xray
  163. apt-get install -y lsb-release gnupg2 wget lsof tar unzip curl libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev jq nginx uuid-runtime
  164. curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh | bash -s -- install
  165. echo $domain > /usr/local/etc/xray/domain
  166. wget -qO /usr/local/etc/xray/config.json "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/xray/xray.json"
  167. wget -qO /etc/nginx/conf.d/${domain}.conf "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/xray/web.conf"
  168. sed -i "s/xxx/${domain}/g" /etc/nginx/conf.d/${domain}.conf
  169. wget -qO web.tar.gz "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/web.tar.gz"
  170. rm -rf /var/www/html/*
  171. tar xzf web.tar.gz -C /var/www/html
  172. rm -f web.tar.gz
  173. mkdir /iriszz/xray
  174. curl -L get.acme.sh | bash
  175. /root/.acme.sh/acme.sh --set-default-ca --server letsencrypt
  176. sed -i "6s/^/#/" /etc/nginx/conf.d/${domain}.conf
  177. sed -i "6a\\\troot /var/www/html/;" /etc/nginx/conf.d/${domain}.conf
  178. systemctl restart nginx
  179. /root/.acme.sh/acme.sh --issue -d "${domain}" --webroot "/var/www/html/" -k ec-256 --force
  180. /root/.acme.sh/acme.sh --installcert -d "${domain}" --fullchainpath /iriszz/xray/xray.crt --keypath /iriszz/xray/xray.key --reloadcmd "systemctl restart xray" --ecc --force
  181. sed -i "7d" /etc/nginx/conf.d/${domain}.conf
  182. sed -i "6s/#//" /etc/nginx/conf.d/${domain}.conf
  183. chown -R nobody.nogroup /iriszz/xray/xray.crt
  184. chown -R nobody.nogroup /iriszz/xray/xray.key
  185. touch /iriszz/xray/xray-clients.txt
  186. sed -i "s/\tinclude \/etc\/nginx\/sites-enabled\/\*;/\t# include \/etc\/nginx\/sites-enabled\/\*;asd/g" /etc/nginx/nginx.conf
  187. mkdir /etc/systemd/system/nginx.service.d
  188. printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" | tee /etc/systemd/system/nginx.service.d/override.conf
  189. systemctl daemon-reload
  190. systemctl restart nginx
  191. systemctl restart xray
  192. elif [[ "$variant" == 2 ]]; then
  193. # Install V2Ray
  194. apt-get install -y jq uuid-runtime socat
  195. bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
  196. echo $domain > /usr/local/etc/v2ray/domain
  197. wget -qO /usr/local/etc/v2ray/ws-tls.json "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/v2ray/v2ray-ws-tls.json"
  198. wget -qO /usr/local/etc/v2ray/ws.json "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/v2ray/v2ray-ws.json"
  199. sed -i "s/xx/${domain}/g" /usr/local/etc/v2ray/ws-tls.json
  200. sed -i "s/xx/${domain}/g" /usr/local/etc/v2ray/ws.json
  201. mkdir /iriszz/v2ray
  202. curl -L get.acme.sh | bash
  203. /root/.acme.sh/acme.sh --set-default-ca --server letsencrypt
  204. /root/.acme.sh/acme.sh --issue -d "${domain}" --standalone -k ec-256 --force
  205. /root/.acme.sh/acme.sh --installcert -d "${domain}" --fullchainpath /iriszz/v2ray/v2ray.crt --keypath /iriszz/v2ray/v2ray.key --ecc --force
  206. chown -R nobody.nogroup /iriszz/v2ray/v2ray.crt
  207. chown -R nobody.nogroup /iriszz/v2ray/v2ray.key
  208. touch /iriszz/v2ray/v2ray-clients.txt
  209. systemctl enable v2ray@ws-tls
  210. systemctl enable v2ray@ws
  211. systemctl start v2ray@ws-tls
  212. systemctl start v2ray@ws
  213. fi
  214. # Install WireGuard
  215. echo -e "deb http://ftp.debian.org/debian buster-backports main" >> /etc/apt/sources.list.d/buster-backports.list
  216. apt update
  217. apt install -y wireguard iptables resolvconf qrencode
  218. server_priv_key=$(wg genkey)
  219. server_pub_key=$(echo "${server_priv_key}" | wg pubkey)
  220. echo -e "ip=${ip}
  221. server_priv_key=${server_priv_key}
  222. server_pub_key=${server_pub_key}" > /etc/wireguard/params
  223. source /etc/wireguard/params
  224. echo -e "[Interface]
  225. Address = 10.66.66.1/24
  226. ListenPort = 51820
  227. PrivateKey = ${server_priv_key}
  228. PostUp = iptables -A FORWARD -i eth0 -o wg0 -j ACCEPT; iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  229. PostDown = iptables -D FORWARD -i eth0 -o wg0 -j ACCEPT; iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE" >> /etc/wireguard/wg0.conf
  230. systemctl start "wg-quick@wg0"
  231. systemctl enable "wg-quick@wg0"
  232. mkdir /iriszz/wireguard
  233. touch /iriszz/wireguard/wireguard-clients.txt
  234. # Install OHP
  235. wget -qO /usr/bin/ohpserver "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/ohpserver"
  236. chmod +x /usr/bin/ohpserver
  237. screen -AmdS ohp-dropbear ohpserver -port 3128 -proxy 127.0.0.1:8080 -tunnel 127.0.0.1:85
  238. screen -AmdS ohp-openvpn ohpserver -port 8000 -proxy 127.0.0.1:8080 -tunnel 127.0.0.1:1194
  239. # Install BadVPN UDPGw
  240. cd
  241. apt install -y cmake
  242. wget -qO badvpn.zip "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/badvpn.zip"
  243. unzip badvpn.zip
  244. cd badvpn-master
  245. mkdir build-badvpn
  246. cd build-badvpn
  247. cmake .. -DBUILD_NOTHING_BY_DEFAULT=1 -DBUILD_UDPGW=1
  248. make install
  249. cd
  250. rm -r badvpn-master
  251. rm badvpn.zip
  252. screen -AmdS badvpn badvpn-udpgw --listen-addr 127.0.0.1:7300
  253. # Install Speedtest cli
  254. curl -s https://install.speedtest.net/app/cli/install.deb.sh | bash
  255. apt install speedtest
  256. # Install fail2ban
  257. apt install -y fail2ban
  258. service fail2ban restart
  259. # Install DDoS Deflate
  260. apt install -y dnsutils tcpdump dsniff grepcidr
  261. wget -qO ddos.zip "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/ddos-deflate.zip"
  262. unzip ddos.zip
  263. cd ddos-deflate
  264. chmod +x install.sh
  265. ./install.sh
  266. cd
  267. rm -rf ddos.zip ddos-deflate
  268. # Configure script
  269. wget -qO /usr/bin/menu "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/menu/menu.sh"
  270. wget -qO /usr/bin/ssh-vpn-script "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/menu/ssh-vpn-script.sh"
  271. if [[ "$variant" == 1 ]]; then
  272. wget -qO /usr/bin/menu "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/menu/menu-xray.sh"
  273. wget -qO /usr/bin/xray-script "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/menu/xray-script.sh"
  274. chmod +x /usr/bin/xray-script
  275. elif [[ "$variant" == 2 ]]; then
  276. wget -qO /usr/bin/menu "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/menu/menu-v2ray.sh"
  277. wget -qO /usr/bin/v2ray-script "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/menu/v2ray-script.sh"
  278. chmod +x /usr/bin/v2ray-script
  279. fi
  280. wget -qO /usr/bin/wireguard-script "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/menu/wireguard-script.sh"
  281. wget -qO /usr/bin/script-info "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/menu/script-info.sh"
  282. wget -qO /usr/bin/script-1 "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/cron/script-1.sh"
  283. if [[ "$variant" == 1 ]]; then
  284. wget -qO /usr/bin/script-2 "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/cron/script-2-xray.sh"
  285. elif [[ "$variant" == 2 ]]; then
  286. wget -qO /usr/bin/script-2 "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/cron/script-2-v2ray.sh"
  287. fi
  288. wget -qO /usr/bin/script-3 "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/cron/script-3.sh"
  289. chmod +x /usr/bin/{menu,ssh-vpn-script,wireguard-script,script-info,script-1,script-2,script-3}
  290. # Configure rc.local
  291. wget -qO /etc/rc.local "https://raw.githubusercontent.com/iriszz-official/autoscript/main/FILES/rc.local"
  292. chmod +x /etc/rc.local
  293. # Configure crontab
  294. echo "0 0 * * * root reboot" >> /etc/crontab
  295. echo "55 23 * * * root script-2" >> /etc/crontab
  296. # Configure block all connections
  297. echo off >> /iriszz/block-status
  298. # Cleanup and reboot
  299. rm -f /root/install.sh
  300. cp /dev/null /root/.bash_history
  301. clear
  302. echo -e ""
  303. echo -e "Script executed succesfully."
  304. echo -e ""
  305. read -n 1 -r -s -p $"Press enter to reboot..."
  306. echo -e ""
  307. reboot