mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-19 04:49:13 +08:00
core: 修复 alpine 在 digitalocean 上的各种网络问题
This commit is contained in:
parent
e51774d4d8
commit
2fcc131ecb
@ -23,14 +23,14 @@ fi
|
|||||||
# 检测是否有 dhcpv4
|
# 检测是否有 dhcpv4
|
||||||
has_ipv4=false
|
has_ipv4=false
|
||||||
dhcpv4=false
|
dhcpv4=false
|
||||||
ip -4 addr show scope global | grep inet && dhcpv4=true && has_ipv4=true
|
ip -4 addr show scope global dev eth0 | grep inet && dhcpv4=true && has_ipv4=true
|
||||||
|
|
||||||
# 检测是否有 slaac
|
# 检测是否有 slaac
|
||||||
has_ipv6=false
|
has_ipv6=false
|
||||||
slaac=false
|
slaac=false
|
||||||
for i in $(seq 10 -1 0); do
|
for i in $(seq 10 -1 0); do
|
||||||
echo waiting slaac for ${i}s
|
echo waiting slaac for ${i}s
|
||||||
ip -6 addr show scope global | grep inet6 && slaac=true && has_ipv6=true && break
|
ip -6 addr show scope global dev eth0 | grep inet6 && slaac=true && has_ipv6=true && break
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -91,3 +91,10 @@ if $ipv6_has_internet && ! grep ':' /etc/resolv.conf; then
|
|||||||
echo "nameserver $ipv6_dns1" >>/etc/resolv.conf
|
echo "nameserver $ipv6_dns1" >>/etc/resolv.conf
|
||||||
echo "nameserver $ipv6_dns2" >>/etc/resolv.conf
|
echo "nameserver $ipv6_dns2" >>/etc/resolv.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 传参给 trans.start
|
||||||
|
has_ipv4=true && echo 1>/dev/has_dhcpv4 || echo 0 >/sys/has_dhcpv4
|
||||||
|
echo $ipv4_addr >/dev/ipv4_addr
|
||||||
|
echo $ipv4_gateway >/dev/ipv4_gateway
|
||||||
|
echo $ipv6_addr >/dev/ipv6_addr
|
||||||
|
echo $ipv6_gateway >/dev/ipv6_gateway
|
||||||
|
54
trans.sh
54
trans.sh
@ -214,6 +214,10 @@ clear_previous() {
|
|||||||
} 2>/dev/null || true
|
} 2>/dev/null || true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_netconf() {
|
||||||
|
[ -e /dev/$1 ] && cat /dev/$1
|
||||||
|
}
|
||||||
|
|
||||||
install_alpine() {
|
install_alpine() {
|
||||||
# 还原改动,不然本脚本会被复制到新系统
|
# 还原改动,不然本脚本会被复制到新系统
|
||||||
rm -f /etc/local.d/trans.start
|
rm -f /etc/local.d/trans.start
|
||||||
@ -237,24 +241,45 @@ install_alpine() {
|
|||||||
# 坑1 udhcpc下,ip -4 addr 无法知道是否是 dhcp
|
# 坑1 udhcpc下,ip -4 addr 无法知道是否是 dhcp
|
||||||
# 坑2 udhcpc不支持dhcpv6
|
# 坑2 udhcpc不支持dhcpv6
|
||||||
# 坑3 安装 dhcpcd,会强制使用dhcpv6,即使ra m=0,解决方法是配置文件设置auto
|
# 坑3 安装 dhcpcd,会强制使用dhcpv6,即使ra m=0,解决方法是配置文件设置auto
|
||||||
rc-update add networking boot
|
|
||||||
|
# 生成 lo 配置
|
||||||
|
cat <<EOF >/etc/network/interfaces
|
||||||
|
auto lo
|
||||||
|
iface lo inet loopback
|
||||||
|
EOF
|
||||||
|
|
||||||
# 生成 ipv4 配置
|
# 生成 ipv4 配置
|
||||||
if udhcpc -i eth0 -f -q -n; then
|
echo >>/etc/network/interfaces
|
||||||
# 生成dhcpv4配置
|
# dhcpv4
|
||||||
setup-interfaces -a
|
if [ "$(get_netconf has_dhcpv4)" = 1 ]; then
|
||||||
|
cat <<EOF >/etc/network/interfaces
|
||||||
|
auto eth0
|
||||||
|
iface eth0 inet dhcp
|
||||||
|
EOF
|
||||||
else
|
else
|
||||||
# 如果当前有ipv4地址,则会生成静态配置
|
# static
|
||||||
# 如果当前没有ipv4地址,则会生成dhcpv4配置
|
ipv4_addr=$(get_netconf ipv4_addr)
|
||||||
echo | setup-interfaces
|
ipv4_gateway=$(get_netconf ipv4_gateway)
|
||||||
|
if [ -n "$ipv4_addr" ]; then
|
||||||
|
cat <<EOF >>/etc/network/interfaces
|
||||||
|
auto eth0
|
||||||
|
iface eth0 inet4 static
|
||||||
|
address $ipv4_addr
|
||||||
|
gateway $ipv4_gateway
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 生成 ipv6 配置
|
# 生成 ipv6 配置
|
||||||
|
echo >>/etc/network/interfaces
|
||||||
apk add ndisc6
|
apk add ndisc6
|
||||||
ra=$(rdisc6 eth0)
|
is_slaac=false
|
||||||
echo "$ra" | cat -n
|
is_dhcpv6=false
|
||||||
echo "$ra" | grep 'Autonomous address conf' | grep Yes && is_slaac=true || is_slaac=false
|
if ra=$(rdisc6 eth0); then
|
||||||
echo "$ra" | grep 'Stateful address conf' | grep Yes && is_dhcpv6=true || is_dhcpv6=false
|
echo "$ra" | cat -n
|
||||||
|
echo "$ra" | grep 'Autonomous address conf' | grep Yes && is_slaac=true
|
||||||
|
echo "$ra" | grep 'Stateful address conf' | grep Yes && is_dhcpv6=true
|
||||||
|
fi
|
||||||
|
|
||||||
# 删除临时安装的软件,不然会带到新系统
|
# 删除临时安装的软件,不然会带到新系统
|
||||||
# shellcheck disable=SC2046
|
# shellcheck disable=SC2046
|
||||||
@ -270,8 +295,8 @@ install_alpine() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if ! $is_slaac && ! $is_dhcpv6; then
|
if ! $is_slaac && ! $is_dhcpv6; then
|
||||||
ipv6_addr=$(ip -6 addr show scope global dev eth0 | grep inet6 | head -1 | awk '{print $2}')
|
ipv6_addr=$(get_netconf ipv6_addr)
|
||||||
ipv6_gateway=$(ip -6 route show default dev eth0 | awk '{print $3}')
|
ipv6_gateway=$(get_netconf ipv6_gateway)
|
||||||
if [ -n "$ipv6_addr" ]; then
|
if [ -n "$ipv6_addr" ]; then
|
||||||
cat <<EOF >>/etc/network/interfaces
|
cat <<EOF >>/etc/network/interfaces
|
||||||
iface eth0 inet6 static
|
iface eth0 inet6 static
|
||||||
@ -280,7 +305,10 @@ iface eth0 inet6 static
|
|||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
ip addr
|
||||||
cat -n /etc/network/interfaces
|
cat -n /etc/network/interfaces
|
||||||
|
rc-update add networking boot
|
||||||
|
|
||||||
# 设置
|
# 设置
|
||||||
setup-keymap us us
|
setup-keymap us us
|
||||||
|
Loading…
x
Reference in New Issue
Block a user