mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-18 20:39:14 +08:00
core: 不重要的优化
This commit is contained in:
parent
ca70bbb3fa
commit
4b9f8d9bd6
@ -20,14 +20,14 @@ runcmd:
|
|||||||
# opensuse tumbleweed cloud-init 直接创建并写入 /etc/ssh/sshd_config,造成默认配置丢失
|
# opensuse tumbleweed cloud-init 直接创建并写入 /etc/ssh/sshd_config,造成默认配置丢失
|
||||||
# 下面这行删除 clout-init 创建的 sshd_config
|
# 下面这行删除 clout-init 创建的 sshd_config
|
||||||
- test $(wc -l </etc/ssh/sshd_config) -le 1 && cat /etc/ssh/sshd_config >>/etc/ssh/sshd_config.d/50-cloud-init.conf && rm -f /etc/ssh/sshd_config
|
- test $(wc -l </etc/ssh/sshd_config) -le 1 && cat /etc/ssh/sshd_config >>/etc/ssh/sshd_config.d/50-cloud-init.conf && rm -f /etc/ssh/sshd_config
|
||||||
- echo "PermitRootLogin yes" >/etc/ssh/sshd_config.d/01-permitrootlogin.conf || sed -Ei 's/^#?PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
|
- echo "PermitRootLogin yes" >/etc/ssh/sshd_config.d/01-permitrootlogin.conf 2>/dev/null || sed -Ei 's/^#?PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
|
||||||
- echo "Port @SSH_PORT@" >/etc/ssh/sshd_config.d/01-change-ssh-port.conf || sed -Ei 's/^#?Port .*/Port @SSH_PORT@/' /etc/ssh/sshd_config
|
- echo "Port @SSH_PORT@" >/etc/ssh/sshd_config.d/01-change-ssh-port.conf || sed -Ei 's/^#?Port .*/Port @SSH_PORT@/' /etc/ssh/sshd_config
|
||||||
# 已创建的 ssh 连接会沿用旧的配置(未开启密码登录),这时即使输入正确的密码,也会提示 Access Denied
|
# 已创建的 ssh 连接会沿用旧的配置(未开启密码登录),这时即使输入正确的密码,也会提示 Access Denied
|
||||||
# systemctl restart sshd 只会重启监听进程,不会关闭已创建的连接(子进程)
|
# systemctl restart sshd 只会重启监听进程,不会关闭已创建的连接(子进程)
|
||||||
- pkill sshd || true
|
- pkill sshd || true
|
||||||
# daemon-reload 会刷新 /run/systemd/generator/ssh.socket.d/addresses.conf
|
# daemon-reload 会刷新 /run/systemd/generator/ssh.socket.d/addresses.conf
|
||||||
- systemctl daemon-reload
|
- systemctl daemon-reload
|
||||||
- for s in ssh.socket ssh.service sshd.socket sshd.service; do systemctl is-enabled $s && systemctl restart $s && break; done
|
- for s in ssh.socket ssh.service sshd.socket sshd.service; do systemctl is-enabled $s 2>/dev/null && systemctl restart $s && break; done
|
||||||
# 删除有密码的行
|
# 删除有密码的行
|
||||||
- sed -i -e '/^[[:space:]]*password:/d' -e '/[[:space:]]*root:/d' /etc/cloud/cloud.cfg.d/99_fallback.cfg
|
- sed -i -e '/^[[:space:]]*password:/d' -e '/[[:space:]]*root:/d' /etc/cloud/cloud.cfg.d/99_fallback.cfg
|
||||||
- touch /etc/cloud/cloud-init.disabled
|
- touch /etc/cloud/cloud-init.disabled
|
||||||
|
79
reinstall.sh
79
reinstall.sh
@ -429,11 +429,16 @@ assert_not_in_container() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# 使用 | del_br ,但返回 del_br 之前返回值
|
# 使用 | del_br ,但返回 del_br 之前返回值
|
||||||
# ash 不支持 PIPESTATUS[n]
|
|
||||||
run_with_del_cr() {
|
run_with_del_cr() {
|
||||||
res=$("$@") && ret=0 || ret=$?
|
if false; then
|
||||||
echo "$res" | del_cr
|
# ash 不支持 PIPESTATUS[n]
|
||||||
return $ret
|
res=$("$@") && ret=0 || ret=$?
|
||||||
|
echo "$res" | del_cr
|
||||||
|
return $ret
|
||||||
|
else
|
||||||
|
"$@" | del_cr
|
||||||
|
return ${PIPESTATUS[0]}
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
run_with_del_cr_template() {
|
run_with_del_cr_template() {
|
||||||
@ -513,10 +518,10 @@ _wmic() {
|
|||||||
# shellcheck disable=SC2046
|
# shellcheck disable=SC2046
|
||||||
powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass \
|
powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass \
|
||||||
-File "$(cygpath -w "$tmp/wmic.ps1")" \
|
-File "$(cygpath -w "$tmp/wmic.ps1")" \
|
||||||
-Namespace $namespace \
|
-Namespace "$namespace" \
|
||||||
-Class $class \
|
-Class "$class" \
|
||||||
$([ -n "$filter" ] && echo "-Filter $filter") \
|
$([ -n "$filter" ] && echo -Filter "$filter") \
|
||||||
$([ -n "$props" ] && echo "-Properties $props")
|
$([ -n "$props" ] && echo -Properties "$props")
|
||||||
}
|
}
|
||||||
|
|
||||||
is_virt() {
|
is_virt() {
|
||||||
@ -881,7 +886,7 @@ get_windows_iso_links() {
|
|||||||
echo
|
echo
|
||||||
|
|
||||||
if [ -z "$page" ] || { [ -z "$label_msdn" ] && [ -z "$label_vlsc" ]; }; then
|
if [ -z "$page" ] || { [ -z "$label_msdn" ] && [ -z "$label_vlsc" ]; }; then
|
||||||
error_and_exit "Not support find this iso. Check --image-name or set --iso manually."
|
error_and_exit "Not support find this iso. Check if --image-name is wrong. If not, set --iso manually."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
curl -L "$page_url" | grep -ioP 'https://.*?.(iso|img)' >$tmp/win.list
|
curl -L "$page_url" | grep -ioP 'https://.*?.(iso|img)' >$tmp/win.list
|
||||||
@ -939,7 +944,7 @@ get_windows_iso_link() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
error_and_exit "Could not find windows iso."
|
error_and_exit "Could not find iso for this windows edition or language."
|
||||||
}
|
}
|
||||||
|
|
||||||
setos() {
|
setos() {
|
||||||
@ -1369,42 +1374,35 @@ Continue with DD?
|
|||||||
# ci
|
# ci
|
||||||
if is_in_china; then
|
if is_in_china; then
|
||||||
case $distro in
|
case $distro in
|
||||||
"centos") ci_mirror="https://mirror.nju.edu.cn/centos-cloud/centos" ;;
|
centos) ci_mirror="https://mirror.nju.edu.cn/centos-cloud/centos" ;;
|
||||||
"almalinux") ci_mirror="https://mirror.nju.edu.cn/almalinux/$releasever/cloud/$basearch/images" ;;
|
almalinux) ci_mirror="https://mirror.nju.edu.cn/almalinux/$releasever/cloud/$basearch/images" ;;
|
||||||
"rocky") ci_mirror="https://mirror.nju.edu.cn/rocky/$releasever/images/$basearch" ;;
|
rocky) ci_mirror="https://mirror.nju.edu.cn/rocky/$releasever/images/$basearch" ;;
|
||||||
"fedora") ci_mirror="https://mirror.nju.edu.cn/fedora/releases/$releasever/Cloud/$basearch/images" ;;
|
fedora) ci_mirror="https://mirror.nju.edu.cn/fedora/releases/$releasever/Cloud/$basearch/images" ;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
case $distro in
|
case $distro in
|
||||||
"centos") ci_mirror="https://cloud.centos.org/centos" ;;
|
centos) ci_mirror="https://cloud.centos.org/centos" ;;
|
||||||
"almalinux") ci_mirror="https://repo.almalinux.org/almalinux/$releasever/cloud/$basearch/images" ;;
|
almalinux) ci_mirror="https://repo.almalinux.org/almalinux/$releasever/cloud/$basearch/images" ;;
|
||||||
"rocky") ci_mirror="https://download.rockylinux.org/pub/rocky/$releasever/images/$basearch" ;;
|
rocky) ci_mirror="https://download.rockylinux.org/pub/rocky/$releasever/images/$basearch" ;;
|
||||||
"fedora") ci_mirror="https://dl.fedoraproject.org/pub/fedora/linux/releases/$releasever/Cloud/$basearch/images" ;;
|
fedora) ci_mirror="https://dl.fedoraproject.org/pub/fedora/linux/releases/$releasever/Cloud/$basearch/images" ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
case $distro in
|
case $distro in
|
||||||
"centos")
|
centos)
|
||||||
case $releasever in
|
case $releasever in
|
||||||
"7")
|
7)
|
||||||
# CentOS-7-aarch64-GenericCloud.qcow2c 是旧版本
|
# CentOS-7-aarch64-GenericCloud.qcow2c 是旧版本
|
||||||
ver=-2211
|
ver=-2211
|
||||||
ci_image=$ci_mirror/$releasever/images/CentOS-$releasever-$basearch-GenericCloud$ver.qcow2c
|
ci_image=$ci_mirror/$releasever/images/CentOS-$releasever-$basearch-GenericCloud$ver.qcow2c
|
||||||
;;
|
;;
|
||||||
"9") ci_image=$ci_mirror/$releasever-stream/$basearch/images/CentOS-Stream-GenericCloud-$releasever-latest.$basearch.qcow2 ;;
|
*) ci_image=$ci_mirror/$releasever-stream/$basearch/images/CentOS-Stream-GenericCloud-$releasever-latest.$basearch.qcow2 ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
"almalinux") ci_image=$ci_mirror/AlmaLinux-$releasever-GenericCloud-latest.$basearch.qcow2 ;;
|
almalinux) ci_image=$ci_mirror/AlmaLinux-$releasever-GenericCloud-latest.$basearch.qcow2 ;;
|
||||||
"rocky") ci_image=$ci_mirror/Rocky-$releasever-GenericCloud-Base.latest.$basearch.qcow2 ;;
|
rocky) ci_image=$ci_mirror/Rocky-$releasever-GenericCloud-Base.latest.$basearch.qcow2 ;;
|
||||||
"fedora")
|
fedora)
|
||||||
# Fedora-Cloud-Base-39-1.5.x86_64.qcow2
|
filename=$(curl -L $ci_mirror | grep -oP "Fedora-Cloud-Base-Generic.*?.qcow2" |
|
||||||
# Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2
|
sort -uV | tail -1 | grep .)
|
||||||
page=$(curl -L $ci_mirror)
|
|
||||||
# 40
|
|
||||||
filename=$(grep -oP "Fedora-Cloud-Base-Generic.*?.qcow2" <<<"$page" | head -1)
|
|
||||||
# 38/39
|
|
||||||
if [ -z "$filename" ]; then
|
|
||||||
filename=$(grep -oP "Fedora-Cloud-Base-$releasever.*?.qcow2" <<<"$page" | head -1)
|
|
||||||
fi
|
|
||||||
ci_image=$ci_mirror/$filename
|
ci_image=$ci_mirror/$filename
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -1413,10 +1411,10 @@ Continue with DD?
|
|||||||
else
|
else
|
||||||
# 传统安装
|
# 传统安装
|
||||||
case $distro in
|
case $distro in
|
||||||
"centos") mirrorlist="https://mirrors.centos.org/mirrorlist?repo=centos-baseos-$releasever-stream&arch=$basearch" ;;
|
centos) mirrorlist="https://mirrors.centos.org/mirrorlist?repo=centos-baseos-$releasever-stream&arch=$basearch" ;;
|
||||||
"almalinux") mirrorlist="https://mirrors.almalinux.org/mirrorlist/$releasever/baseos" ;;
|
almalinux) mirrorlist="https://mirrors.almalinux.org/mirrorlist/$releasever/baseos" ;;
|
||||||
"rocky") mirrorlist="https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=BaseOS-$releasever" ;;
|
rocky) mirrorlist="https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=BaseOS-$releasever" ;;
|
||||||
"fedora") mirrorlist="https://mirrors.fedoraproject.org/mirrorlist?arch=$basearch&repo=fedora-$releasever" ;;
|
fedora) mirrorlist="https://mirrors.fedoraproject.org/mirrorlist?arch=$basearch&repo=fedora-$releasever" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# rocky/centos9 需要删除第一行注释, almalinux 需要替换$basearch
|
# rocky/centos9 需要删除第一行注释, almalinux 需要替换$basearch
|
||||||
@ -1638,7 +1636,6 @@ install_pkg() {
|
|||||||
alpine) pkg_mgr=apk ;;
|
alpine) pkg_mgr=apk ;;
|
||||||
arch) pkg_mgr=pacman ;;
|
arch) pkg_mgr=pacman ;;
|
||||||
gentoo) pkg_mgr=emerge ;;
|
gentoo) pkg_mgr=emerge ;;
|
||||||
openwrt) pkg_mgr=opkg ;;
|
|
||||||
nixos) pkg_mgr=nix-env ;;
|
nixos) pkg_mgr=nix-env ;;
|
||||||
esac
|
esac
|
||||||
[ -n "$pkg_mgr" ] && return
|
[ -n "$pkg_mgr" ] && return
|
||||||
@ -1646,7 +1643,7 @@ install_pkg() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# 查找方法 2
|
# 查找方法 2
|
||||||
for mgr in dnf yum apt-get pacman zypper emerge apk opkg nix-env; do
|
for mgr in dnf yum apt-get pacman zypper emerge apk nix-env; do
|
||||||
is_have_cmd $mgr && pkg_mgr=$mgr && return
|
is_have_cmd $mgr && pkg_mgr=$mgr && return
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -1778,10 +1775,6 @@ install_pkg() {
|
|||||||
[ -z "$apt_updated" ] && apt-get update && apt_updated=1
|
[ -z "$apt_updated" ] && apt-get update && apt_updated=1
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get install -y $pkg
|
DEBIAN_FRONTEND=noninteractive apt-get install -y $pkg
|
||||||
;;
|
;;
|
||||||
opkg)
|
|
||||||
[ -z "$opkg_updated" ] && opkg update && opkg_updated=1
|
|
||||||
opkg install $pkg
|
|
||||||
;;
|
|
||||||
nix-env)
|
nix-env)
|
||||||
# 不指定 channel 会很慢,而且很占内存
|
# 不指定 channel 会很慢,而且很占内存
|
||||||
[ -z "$nix_updated" ] && nix-channel --update && nix_updated=1
|
[ -z "$nix_updated" ] && nix-channel --update && nix_updated=1
|
||||||
|
13
trans.sh
13
trans.sh
@ -1219,9 +1219,13 @@ install_alpine() {
|
|||||||
# 避免占用 Live OS 内存
|
# 避免占用 Live OS 内存
|
||||||
|
|
||||||
# 网络
|
# 网络
|
||||||
# 坑1 udhcpc下,ip -4 addr 无法知道是否是 dhcp
|
# udhcpc
|
||||||
# 坑2 udhcpc不支持dhcpv6
|
# 坑1 ip -4 addr 无法知道是否是 dhcp
|
||||||
# 坑3 dhcpcd的slaac默认开了隐私保护,造成ip和后台面板不一致
|
# 坑2 networking 服务不会运行 udhcpc6
|
||||||
|
# 坑3 h3c 移动云电脑 udhcpc6 无法获取 dhcpv6
|
||||||
|
|
||||||
|
# dhcpcd
|
||||||
|
# 坑1 slaac默认开了隐私保护,造成ip和后台面板不一致
|
||||||
|
|
||||||
# slaac方案1: udhcpc + rdnssd
|
# slaac方案1: udhcpc + rdnssd
|
||||||
# slaac方案2: dhcpcd + 关闭隐私保护
|
# slaac方案2: dhcpcd + 关闭隐私保护
|
||||||
@ -1440,7 +1444,7 @@ install_nixos() {
|
|||||||
# TODO: 准确匹配网卡,添加 udev 或者直接配置 networkd 匹配 mac
|
# TODO: 准确匹配网卡,添加 udev 或者直接配置 networkd 匹配 mac
|
||||||
create_nixos_network_config /tmp/nixos_network_config.nix
|
create_nixos_network_config /tmp/nixos_network_config.nix
|
||||||
|
|
||||||
add_space 2 <<EOF | del_empty_lines | add_newline both |
|
del_empty_lines <<EOF | add_space 2 | add_newline both |
|
||||||
############### Add by reinstall.sh ###############
|
############### Add by reinstall.sh ###############
|
||||||
$nix_bootloader
|
$nix_bootloader
|
||||||
$nix_swap
|
$nix_swap
|
||||||
@ -2180,6 +2184,7 @@ create_cloud_init_network_config() {
|
|||||||
# 旧版 cloud-init 有 bug
|
# 旧版 cloud-init 有 bug
|
||||||
# 有的版本会只从第一种配置中读取 dns,有的从第二种读取
|
# 有的版本会只从第一种配置中读取 dns,有的从第二种读取
|
||||||
# 因此写两种配置
|
# 因此写两种配置
|
||||||
|
# https://github.com/canonical/cloud-init/commit/1b8030e0c7fd6fbff7e38ad1e3e6266ae50c83a5
|
||||||
for cur in $(get_current_dns 4); do
|
for cur in $(get_current_dns 4); do
|
||||||
yq -i ".network.config[$config_id].subnets[$subnet_id].dns_nameservers += [\"$cur\"]" $ci_file
|
yq -i ".network.config[$config_id].subnets[$subnet_id].dns_nameservers += [\"$cur\"]" $ci_file
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user