core: 不重要的优化

This commit is contained in:
bin456789 2024-07-09 23:37:51 +08:00
parent 214a1b1bfb
commit 77ca441e64
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
4 changed files with 63 additions and 43 deletions

View File

@ -11,7 +11,7 @@ Reinstall server with one-click [中文](README.md)
## Highlights ## Highlights
- Support installation of 13 common Linux distributions. - Support installation of 16 common Linux distributions.
- Support for installing Windows using the official original ISO. The script can automatically search for the ISO and drivers. - Support for installing Windows using the official original ISO. The script can automatically search for the ISO and drivers.
- Support reinstallation in any direction, meaning `Linux to Linux`, `Linux to Win`, `Win to Win`, `Win to Linux`. - Support reinstallation in any direction, meaning `Linux to Linux`, `Linux to Win`, `Win to Win`, `Win to Linux`.
- Specifically tailored for low-spec machines, addressing insufficient memory that prevents network installation. - Specifically tailored for low-spec machines, addressing insufficient memory that prevents network installation.

View File

@ -11,7 +11,7 @@
## 亮点 ## 亮点
- 支持安装 13 种常见 Linux 发行版 - 支持安装 16 种常见 Linux 发行版
- 支持用官方原版 iso 安装 Windows并且脚本会自动查找 iso 和驱动 - 支持用官方原版 iso 安装 Windows并且脚本会自动查找 iso 和驱动
- 支持任意方向重装,也就是支持 `Linux to Linux`、`Linux to Win`、`Win to Win`、`Win to Linux` - 支持任意方向重装,也就是支持 `Linux to Linux`、`Linux to Win`、`Win to Win`、`Win to Linux`
- 专门适配低配小鸡,解决内存过少导致无法进行网络安装 - 专门适配低配小鸡,解决内存过少导致无法进行网络安装

View File

@ -93,12 +93,12 @@ curl() {
return return
else else
ret=$? ret=$?
if [ $ret -eq 22 ]; then # 403 404 错误,或者达到重试次数
# 403 404 错误 if [ $ret -eq 22 ] || [ $i -eq 5 ]; then
return $ret return $ret
fi fi
fi
sleep 1 sleep 1
fi
done done
} }
@ -1298,34 +1298,30 @@ install_pkg() {
esac esac
} }
is_need_epel_repo() { # 系统 package名称 repo名称
# centos/alma/rocky/fedora/anolis epel-release epel
# oracle linux oracle-epel-release ol9_developer_EPEL
# opencloudos epol-release EPOL
check_is_need_epel() {
is_need_epel() {
case "$pkg" in case "$pkg" in
dpkg) [ "$pkg_mgr" = yum ] || [ "$pkg_mgr" = dnf ] ;; dpkg) true ;;
jq) [ "$pkg_mgr" = yum ] ;; # el7/ol7 jq) is_have_cmd yum && ! is_have_cmd dnf ;; # el7/ol7 的 jq 在 epel 仓库
*) false ;; *) false ;;
esac esac
} }
add_epel_repo() { try_find_epel_name() {
# epel 名称可能是 epel 或 ol9_developer_EPEL epel=$($pkg_mgr repolist --all | awk '{print $1}' | grep -Ei '(epel|epol)$')
# 如果没启用 }
if ! $pkg_mgr repolist | awk '{print $1}' | grep -qi 'epel$'; then
# 删除 epel repo因为可能安装了但未启用
rm -rf /etc/yum.repos.d/*epel*.repo
epel_release="$($pkg_mgr list | grep 'epel-release' | awk '{print $1}' | cut -d. -f1 | head -1)"
# 如果已安装 if is_need_epel; then
if rpm -q $epel_release; then if ! try_find_epel_name; then
# 检查是否为最新 epel_release="$($pkg_mgr list | grep -E '(epel|epol)-release' | awk '{print $1}' | cut -d. -f1 | head -1)"
if $pkg_mgr check-update $epel_release; then
$pkg_mgr reinstall -y $epel_release
else
$pkg_mgr update -y $epel_release
fi
else
# 如果未安装
$pkg_mgr install -y $epel_release $pkg_mgr install -y $epel_release
try_find_epel_name
fi fi
enable_epel="--enablerepo=$epel"
fi fi
} }
@ -1337,8 +1333,14 @@ install_pkg() {
echo "Installing package '$text'..." echo "Installing package '$text'..."
case $pkg_mgr in case $pkg_mgr in
dnf) dnf install -y --setopt=install_weak_deps=False $pkg ;; dnf)
yum) yum install -y $pkg ;; check_is_need_epel
dnf install $enable_epel -y --setopt=install_weak_deps=False $pkg
;;
yum)
check_is_need_epel
yum install $enable_epel -y $pkg
;;
emerge) emerge --oneshot $pkg ;; emerge) emerge --oneshot $pkg ;;
pacman) pacman -Syu --noconfirm --needed $pkg ;; pacman) pacman -Syu --noconfirm --needed $pkg ;;
zypper) zypper install -y $pkg ;; zypper) zypper install -y $pkg ;;
@ -1381,9 +1383,6 @@ install_pkg() {
error_and_exit "Can't find compatible package manager. Please manually install $cmd." error_and_exit "Can't find compatible package manager. Please manually install $cmd."
fi fi
cmd_to_pkg cmd_to_pkg
if is_need_epel_repo; then
add_epel_repo
fi
install_pkg_real install_pkg_real
fi fi
done done
@ -2002,7 +2001,7 @@ build_finalos_cmdline() {
} }
build_extra_cmdline() { build_extra_cmdline() {
for key in confhome hold cloud_image main_disk; do for key in confhome hold force cloud_image main_disk; do
value=${!key} value=${!key}
if [ -n "$value" ]; then if [ -n "$value" ]; then
extra_cmdline+=" extra.$key='$value'" extra_cmdline+=" extra.$key='$value'"
@ -2695,7 +2694,7 @@ else
fi fi
# 整理参数 # 整理参数
if ! opts=$(getopt -n $0 -o "" --long ci,debug,hold:,sleep:,iso:,image-name:,img:,lang:,commit: -- "$@"); then if ! opts=$(getopt -n $0 -o "" --long ci,debug,hold:,sleep:,iso:,image-name:,img:,lang:,commit:,force: -- "$@"); then
usage_and_exit usage_and_exit
fi fi
@ -2722,6 +2721,13 @@ while true; do
fi fi
shift 2 shift 2
;; ;;
--force)
force=$2
if ! { [ "$force" = bios ] || [ "$force" = efi ]; }; then
error_and_exit "Invalid --force value: $force."
fi
shift 2
;;
--img) --img)
img=$2 img=$2
shift 2 shift 2
@ -3088,10 +3094,11 @@ if is_use_grub; then
get_function_content load_grubenv_if_not_loaded >$target_cfg get_function_content load_grubenv_if_not_loaded >$target_cfg
# 原系统为 openeuler 云镜像,需要添加 --unrestricted否则要输入密码
del_empty_lines <<EOF | tee -a $target_cfg del_empty_lines <<EOF | tee -a $target_cfg
set timeout_style=menu set timeout_style=menu
set timeout=5 set timeout=5
menuentry "$(get_entry_name)" { menuentry "$(get_entry_name)" --unrestricted {
$(! is_in_windows && echo 'insmod lvm') $(! is_in_windows && echo 'insmod lvm')
$(is_os_in_btrfs && echo 'set btrfs_relative_path=n') $(is_os_in_btrfs && echo 'set btrfs_relative_path=n')
insmod all_video insmod all_video

View File

@ -8,6 +8,7 @@ set -eE
# debian 安装版、ubuntu 安装版、redhat 安装版不使用该密码 # debian 安装版、ubuntu 安装版、redhat 安装版不使用该密码
PASSWORD=123@@@ PASSWORD=123@@@
EFI_UUID=C12A7328-F81F-11D2-BA4B-00A0C93EC93B
TRUE=0 TRUE=0
FALSE=1 FALSE=1
@ -38,7 +39,7 @@ trap_err() {
error() { error() {
color='\e[31m' color='\e[31m'
plain='\e[0m' plain='\e[0m'
echo -e "${color}Error: $*${plain}" echo -e "${color}Error: $*${plain}" >&2
} }
error_and_exit() { error_and_exit() {
@ -73,8 +74,16 @@ apk() {
wget() { wget() {
echo "$@" | grep -o 'http[^ ]*' >&2 echo "$@" | grep -o 'http[^ ]*' >&2
for i in $(seq 5); do for i in $(seq 5); do
command wget "$@" && return if command wget "$@"; then
return
else
ret=$?
# 错误,或者达到重试次数
if [ $i -eq 5 ]; then
return $ret
fi
sleep 1 sleep 1
fi
done done
} }
@ -182,7 +191,11 @@ update_part() {
} }
is_efi() { is_efi() {
if [ -n "$force" ]; then
[ "$force" = efi ]
else
[ -d /sys/firmware/efi/ ] [ -d /sys/firmware/efi/ ]
fi
} }
is_use_cloud_image() { is_use_cloud_image() {
@ -595,7 +608,6 @@ grep_efi_index() {
add_fallback_efi_to_nvram() { add_fallback_efi_to_nvram() {
apk add lsblk efibootmgr apk add lsblk efibootmgr
EFI_UUID=C12A7328-F81F-11D2-BA4B-00A0C93EC93B
efi_row=$(lsblk /dev/$xda -ro NAME,PARTTYPE,PARTUUID | grep -i "$EFI_UUID") efi_row=$(lsblk /dev/$xda -ro NAME,PARTTYPE,PARTUUID | grep -i "$EFI_UUID")
efi_part_uuid=$(echo "$efi_row" | awk '{print $3}') efi_part_uuid=$(echo "$efi_row" | awk '{print $3}')
efi_part_name=$(echo "$efi_row" | awk '{print $1}') efi_part_name=$(echo "$efi_row" | awk '{print $1}')
@ -3396,7 +3408,8 @@ install_windows() {
else else
# 或者用 ms-sys # 或者用 ms-sys
apk add grub-bios apk add grub-bios
grub-install --boot-directory=/os/boot /dev/$xda # efi 下,强制安装 mbr 引导,需要添加 --target i386-pc
grub-install --target i386-pc --boot-directory=/os/boot /dev/$xda
cat <<EOF >/os/boot/grub/grub.cfg cat <<EOF >/os/boot/grub/grub.cfg
set timeout=5 set timeout=5
menuentry "reinstall" { menuentry "reinstall" {