-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathovpnfile-edit
94 lines (78 loc) · 3.15 KB
/
ovpnfile-edit
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
#!/bin/bash
# -*- coding: UTF-8 -*-
# 备份原软件源列表
cp /etc/apt/sources.list /etc/apt/sources.list.backup
# 替换软件源为阿里云镜像
cat <<EOT > /etc/apt/sources.list
## 默认禁用源码镜像以提高速度,如需启用请自行取消注释
deb http://mirrors.aliyun.com/debian bullseye main contrib non-free
# deb-src http://mirrors.aliyun.com/debian bullseye main contrib non-free
deb http://mirrors.aliyun.com/debian bullseye-updates main contrib non-free
# deb-src http://mirrors.aliyun.com/debian bullseye-updates main contrib non-free
deb http://mirrors.aliyun.com/debian bullseye-backports main contrib non-free
# deb-src http://mirrors.aliyun.com/debian bullseye-backports main contrib non-free
deb http://mirrors.aliyun.com/debian-security bullseye-security main contrib non-free
# deb-src http://mirrors.aliyun.com/debian-security bullseye-security main contrib non-free
EOT
apt install ntp
# 修改系统时间 时区
cat <<EOT > /etc/systemd/system/ntp-sync.service
[Unit]
Description=NTP Synchronization
After=network.target
[Service]
ExecStart=/usr/sbin/ntpd -g -u ntp:ntp -p /var/run/ntpd.pid
Restart=always
[Install]
WantedBy=multi-user.target
EOT
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
systemctl enable ntp-sync.service && systemctl start ntp-sync.service
function replace_ip() {
local file="$1"
local ip="$2"
local file_path="/root/${file}"
if [ -f "$file_path" ]; then
echo "修改 $file 文件 ..."
elif [ ! -f "$file_path" ]; then
echo "$file 文件不存在,开始下载 ..."
curl -sSL "https://git.lyvw.top:4433/https://raw.githubusercontent.com/YoYulyvW/tese/master/${file}" -o "$file_path"
fi
if ! grep -q "^net.ipv4.ip_forward=1$" /etc/sysctl.conf; then
sed -i "s/^#net.ipv4.ip_forward.*/net.ipv4.ip_forward=1/g" /etc/sysctl.conf
sysctl -q -p
echo "设置 net.ipv4.ip_forward=1"
fi
sed -i "s/192\.168\.[0-9]\{1,3\}/${ip}/g" "$file_path"
sed -i 's|https://github.com|https://git.lyvw.top:4433/https://github.com|g' "$file_path"
sed -i 's|v3.1.4/EasyRSA-3.1.4.tgz|v3.2.0/EasyRSA-3.2.0.tgz|g' "$file_path"
echo "已经成功修改 $file 文件"
echo
}
# 获取用户输入的IP地址
echo
echo "脚本内默认为192.168.254.0/24"
echo "请输入要修改的IP地址(前3位)例:192.168.250"
read -p " [留空回车使用默认值]: " ip_addr
if [ -n "$ip_addr" ]; then
if [[ "$ip_addr" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
ip_addr=$(echo "$ip_addr" | cut -d "." -f 1-3)
else
echo "输入的IP地址不合法,使用默认值!"
ip_addr="192.168.254"
fi
else
ip_addr="192.168.254"
fi
# 查找并替换openvpn-install.sh文件中的IP地址
replace_ip "openvpn-install.sh" "$ip_addr"
# 查找并替换openvpn-install-v6.sh文件中的IP地址
replace_ip "openvpn-install-v6.sh" "$ip_addr"
#echo "已经修改ip为:${ip_addr}.x"
if dpkg -l docker-ce | grep -q "^ii"; then
echo "Docker已安装"
else
echo "Docker未安装,开始安装"
curl -sSL https://git.lyvw.top:4433/https://raw.githubusercontent.com/YoYulyvW/tese/master/get-docker | sh
fi
echo