-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto.sh
99 lines (88 loc) · 4.66 KB
/
auto.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
#!/bin/bash
rm /etc/motd
echo 'net.ipv6.conf.all.disable_ipv6 = 1' >> /etc/sysctl.conf
sysctl -p
sed -i 's/GRUB_TIMEOUT=5/GRUB_TIMEOUT=0/g' /etc/default/grub
update-grub
echo -e "set linenumbers\nset mouse\nset softwrap" >> /etc/nanorc
cat >> /root/.bashrc << EOF
alias up='apt update && apt upgrade -y'
alias cl='apt autoremove && apt autoclean'
alias cls='clear'
alias rst='systemctl restart'
alias sta='systemctl status'
alias ..='. .bashrc'
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
EOF
echo -e "\n\e[32;7m【 检查HOSTNAME 】\e[0m"
echo $HOSTNAME | egrep -q '^[a-z]{2,3}\.[bopt]{4}\.[bopt]{3}$'
if [ $? -eq 0 ]
then
echo -e ' \e[36;7m '$HOSTNAME' \e[0m'
else
echo -e -n '\e[33;1m请输入hostname:\e[0m '
read input
echo -e ''$input'' | egrep -q '^[a-z]{2,3}\.[bopt]{4}\.[bopt]{3}$'
if [ $? -eq 0 ]
then
hostnamectl set-hostname $input
echo -e ' \e[36;7m '$input' \e[0m \e[31;5m须重启生效!请重启后再次运行本脚本。 \e[0m'
exit 1
else
echo -e '\e[31;5m 输入有误,请重新运行本脚本! \e[0m'
exit 1
fi
fi
echo -e "\n\e[32;7m【 下载证书 】\e[0m"
if echo $HOSTNAME | egrep -q '^[o-z]{2}'; then
wget -t3 -P /usr/local/etc https://github.com/grhooo/private/raw/main/cer/1/ptbt.{crt,key}
elif echo $HOSTNAME | egrep -q '^[i-t]{2}'; then
wget -t3 -P /usr/local/etc https://github.com/grhooo/private/raw/main/cer/2/ptbt.{crt,key}
elif echo $HOSTNAME | egrep -q '^[a-o]{2}'; then
wget -t3 -P /usr/local/etc https://github.com/grhooo/private/raw/main/cer/3/ptbt.{crt,key}
else
echo -e '\e[31;5m 请手动下载证书至/usr/local/etc \e[0m'
fi
echo -e "\n\e[32;7m【 安装caddy 】\e[0m"
apt install -y caddy
## wget -t3 -O /usr/share/caddy/index.html https://github.com/grhooo/private/raw/main/index.html
ln -s /usr/share/caddy /root/_caddyshare
echo -e "$HOSTNAME\ntls /usr/local/etc/ptbt.crt /usr/local/etc/ptbt.key\nroot * /usr/share/caddy\nfile_server" > /etc/caddy/Caddyfile
echo -e "\e[32;7m【 安装verysimple 】\e[0m"
mkdir -p /usr/local/etc/verysimple
ln -s /usr/local/etc/verysimple /root/_verysimple
wget -t3 https://github.com/e1732a364fed/v2ray_simple/releases/latest/download/verysimple_linux_amd64.tar.xz
tar -xJf verysimple_linux_amd64.tar.xz -C /usr/local/etc/verysimple
rm verysimple_linux_amd64.tar.xz
echo -e "[Unit]\nAfter=network.service\n\n[Service]\nExecStart=/usr/local/etc/verysimple/verysimple -c /usr/local/etc/verysimple/server.toml\n\n[Install]\nWantedBy=default.target" > /etc/systemd/system/verysimple.service
chmod 664 /etc/systemd/system/verysimple.service
echo -e '[app]\nloglevel = 6\n[[listen]]\nprotocol = "vlesss"\nuuid = "1587875e-bf9a-40f6-b19b-42b7104ead4e"\nport = 12345\ninsecure = false\nfallback = ":80"\ncert = "/usr/local/etc/ptbt.crt"\nkey = "/usr/local/etc/ptbt.key"\n#lazy = true\n[[dial]]\nprotocol = "direct"' > /usr/local/etc/verysimple/server.toml
systemctl daemon-reload
systemctl enable verysimple
systemctl start verysimple
systemctl restart caddy
echo -e "\n\e[32;7m【 修改ssh端口 】\e[0m"
sed -i -e 's/X11Forwarding yes/X11Forwarding no/m' -e 's/UsePAM yes/UsePAM no/m' -e 's/#AddressFamily any/AddressFamily inet/m' /etc/ssh/sshd_config
if grep -q '^Port\s.*' /etc/ssh/sshd_config; then
sed -i 's/^Port\s.*/Port 27184/m' /etc/ssh/sshd_config
else
sed -i 's/#Port 22/Port 27184/m' /etc/ssh/sshd_config
fi
echo -e "\n\e[32;7m【 设置定时任务 】\e[0m"
timedatectl set-timezone Asia/Shanghai
if echo $HOSTNAME | egrep -q '^[i-t]{2}'; then
echo -e '00 7 * * * cd `mktemp -d` && /bin/wget -t3 https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/rules.zip && /bin/unzip rules.zip && /bin/zip -j9 geo.zip *.dat && /bin/mv geo.zip /usr/share/caddy && /bin/rm -rf /tmp/tmp.*\n15 */8 * * * /bin/wget -t3 -O /usr/share/caddy/best.txt https://raw.githubusercontent.com/XIU2/TrackersListCollection/master/best.txt\n10 9-18/9 * * * /bin/wget -t3 -O /usr/share/caddy/tvbox.json https://raw.githubusercontent.com/2hacc/TVBox/main/tvbox.json' > /var/spool/cron/crontabs/root
else
echo -n
fi
echo -e "\n\e[32;7m【 安装AdGuardHome 】\e[0m"
curl -s -S -L https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | bash -s -- -c edge
/opt/AdGuardHome/AdGuardHome -s stop
sed -i -e 's/domain-name-servers, //g' -e '/dhcp6/d' /etc/dhcp/dhclient.conf
echo 'nameserver 127.0.0.1' > /etc/resolv.conf
echo -e "\n\e[32;7m【 caddy/verysimple运行情况 】\e[0m"
systemctl list-unit-files | egrep '^UNIT|caddy.s|verysimple'
IP=$(hostname -I) && echo -e "\n\e[34;1m AdGuardHome设置页面:http://${IP%% *}:3000\e[0m"
echo -e '\e[33;1mAdGuardHome配置文件:\e[0m\e[32;1m/opt/AdGuardHome/AdGuardHome.yaml\e[0m'