mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-19 04:49:13 +08:00
core: 优化代码
This commit is contained in:
parent
30174545b0
commit
dcc5ae7131
27
reinstall.sh
27
reinstall.sh
@ -79,6 +79,7 @@ is_use_cloud_image() {
|
|||||||
is_use_dd() {
|
is_use_dd() {
|
||||||
[ "$distro" = dd ]
|
[ "$distro" = dd ]
|
||||||
}
|
}
|
||||||
|
|
||||||
is_os_in_btrfs() {
|
is_os_in_btrfs() {
|
||||||
mount | grep -w 'on / type btrfs'
|
mount | grep -w 'on / type btrfs'
|
||||||
}
|
}
|
||||||
@ -93,16 +94,17 @@ get_os_part() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cp_to_btrfs_root() {
|
cp_to_btrfs_root() {
|
||||||
files=$*
|
|
||||||
mount_dir=/tmp/reinstall-btrfs-root
|
mount_dir=/tmp/reinstall-btrfs-root
|
||||||
if ! grep -q $mount_dir /proc/mounts; then
|
if ! grep -q $mount_dir /proc/mounts; then
|
||||||
mkdir -p $mount_dir
|
mkdir -p $mount_dir
|
||||||
mount "$(get_os_part)" $mount_dir -t btrfs -o subvol=/
|
mount "$(get_os_part)" $mount_dir -t btrfs -o subvol=/
|
||||||
fi
|
fi
|
||||||
cp -rf $files /tmp/reinstall-btrfs-root
|
cp -rf "$@" /tmp/reinstall-btrfs-root
|
||||||
}
|
}
|
||||||
|
|
||||||
is_host_has_ipv4_and_ipv6() {
|
is_host_has_ipv4_and_ipv6() {
|
||||||
|
host=$1
|
||||||
|
|
||||||
install_pkg dig
|
install_pkg dig
|
||||||
# dig会显示cname结果,cname结果以.结尾,grep -v '\.$' 用于去除 cname 结果
|
# dig会显示cname结果,cname结果以.结尾,grep -v '\.$' 用于去除 cname 结果
|
||||||
res=$(dig +short $host A $host AAAA | grep -v '\.$')
|
res=$(dig +short $host A $host AAAA | grep -v '\.$')
|
||||||
@ -275,11 +277,11 @@ setos() {
|
|||||||
# cloud image
|
# cloud image
|
||||||
# TODO: Minimal 镜像
|
# TODO: Minimal 镜像
|
||||||
if is_in_china; then
|
if is_in_china; then
|
||||||
ci_mirror=https://mirror.nju.edu.cn/ubuntu-cloud-images/releases
|
ci_mirror=https://mirror.nju.edu.cn/ubuntu-cloud-images
|
||||||
else
|
else
|
||||||
ci_mirror=https://cloud-images.ubuntu.com/releases/$releasever/release
|
ci_mirror=https://cloud-images.ubuntu.com
|
||||||
fi
|
fi
|
||||||
eval ${step}_img=$ci_mirror/ubuntu-$releasever-server-cloudimg-$basearch_alt.img
|
eval ${step}_img=$ci_mirror/releases/$releasever/release/ubuntu-$releasever-server-cloudimg-$basearch_alt.img
|
||||||
else
|
else
|
||||||
# 传统安装
|
# 传统安装
|
||||||
if [ "$localtest" = 1 ]; then
|
if [ "$localtest" = 1 ]; then
|
||||||
@ -456,16 +458,11 @@ setos() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eval ${step}_distro=$distro
|
eval ${step}_distro=$distro
|
||||||
case "$distro" in
|
if is_distro_like_redhat $distro; then
|
||||||
ubuntu) setos_ubuntu ;;
|
setos_redhat
|
||||||
alpine) setos_alpine ;;
|
else
|
||||||
debian) setos_debian ;;
|
setos_$distro
|
||||||
arch) setos_arch ;;
|
fi
|
||||||
opensuse) setos_opensuse ;;
|
|
||||||
windows) setos_windows ;;
|
|
||||||
dd) setos_dd ;;
|
|
||||||
*) setos_redhat ;;
|
|
||||||
esac
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is_distro_like_redhat() {
|
is_distro_like_redhat() {
|
||||||
|
13
trans.sh
13
trans.sh
@ -1364,13 +1364,15 @@ install_redhat_ubuntu() {
|
|||||||
extra_cmdline="$extra_cmdline $(echo $var | sed -E "s/(extra\.[^=]*)=(.*)/\1='\2'/")"
|
extra_cmdline="$extra_cmdline $(echo $var | sed -E "s/(extra\.[^=]*)=(.*)/\1='\2'/")"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# 安装红帽系时,只有最后一个有安装界面显示
|
||||||
|
# https://anaconda-installer.readthedocs.io/en/latest/boot-options.html#console
|
||||||
|
console_cmdline=$(get_ttys console=)
|
||||||
grub_cfg=/os/boot/grub/grub.cfg
|
grub_cfg=/os/boot/grub/grub.cfg
|
||||||
|
|
||||||
# 新版grub不区分linux/linuxefi
|
# 新版grub不区分linux/linuxefi
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
if [ "$distro" = "ubuntu" ]; then
|
if [ "$distro" = "ubuntu" ]; then
|
||||||
download $iso /os/installer/ubuntu.iso
|
download $iso /os/installer/ubuntu.iso
|
||||||
console_cmdline=$(get_ttys console=)
|
|
||||||
|
|
||||||
apk add dmidecode
|
apk add dmidecode
|
||||||
dmi=$(dmidecode)
|
dmi=$(dmidecode)
|
||||||
@ -1411,7 +1413,7 @@ EOF
|
|||||||
set timeout=5
|
set timeout=5
|
||||||
menuentry "reinstall" {
|
menuentry "reinstall" {
|
||||||
search --no-floppy --label --set=root os
|
search --no-floppy --label --set=root os
|
||||||
linux /vmlinuz inst.stage2=hd:LABEL=installer:/install.img inst.ks=$ks $extra_cmdline
|
linux /vmlinuz inst.stage2=hd:LABEL=installer:/install.img inst.ks=$ks $extra_cmdline $console_cmdline
|
||||||
initrd /initrd.img
|
initrd /initrd.img
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
@ -1432,6 +1434,10 @@ if [ "$sleep" = 1 ]; then
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$distro" != "alpine" ]; then
|
||||||
|
mod_motd
|
||||||
|
fi
|
||||||
|
|
||||||
setup_tty_and_log
|
setup_tty_and_log
|
||||||
clear_previous
|
clear_previous
|
||||||
add_community_repo
|
add_community_repo
|
||||||
@ -1439,10 +1445,7 @@ add_community_repo
|
|||||||
# 找到主硬盘
|
# 找到主硬盘
|
||||||
# shellcheck disable=SC2010
|
# shellcheck disable=SC2010
|
||||||
xda=$(ls /dev/ | grep -Ex 'sda|hda|xda|vda|xvda|nvme0n1')
|
xda=$(ls /dev/ | grep -Ex 'sda|hda|xda|vda|xvda|nvme0n1')
|
||||||
|
|
||||||
# shellcheck disable=SC2154
|
|
||||||
if [ "$distro" != "alpine" ]; then
|
if [ "$distro" != "alpine" ]; then
|
||||||
mod_motd
|
|
||||||
setup_nginx_if_enough_ram
|
setup_nginx_if_enough_ram
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user