From feea11e2bb2bc5f42ceca64255900e3917d87f98 Mon Sep 17 00:00:00 2001 From: longpanda Date: Mon, 29 May 2023 00:11:21 +0800 Subject: [PATCH] Support unattended auto install for Deepin/UOS --- .../MOD_SRC/grub-2.04/grub-core/fs/squash4.c | 26 ++- .../ventoy/hook/deepin/disk_mount_hook.sh | 40 +++++ IMG/cpio/ventoy/hook/deepin/udev_disk_hook.sh | 151 ++++++++++++++++++ IMG/cpio/ventoy/hook/deepin/ventoy-hook.sh | 42 +++++ .../ventoy/hook/deepin/ventoy_autoinstall.sh | 122 ++++++++++++++ IMG/cpio/ventoy/ventoy_chain.sh | 8 +- 6 files changed, 368 insertions(+), 21 deletions(-) create mode 100644 IMG/cpio/ventoy/hook/deepin/disk_mount_hook.sh create mode 100644 IMG/cpio/ventoy/hook/deepin/udev_disk_hook.sh create mode 100644 IMG/cpio/ventoy/hook/deepin/ventoy-hook.sh create mode 100644 IMG/cpio/ventoy/hook/deepin/ventoy_autoinstall.sh diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/fs/squash4.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/fs/squash4.c index 5dbad6e1..06a4a3c0 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/fs/squash4.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/fs/squash4.c @@ -405,24 +405,16 @@ static grub_ssize_t zstd_decompress_wrap(char *inbuf, grub_size_t insize, grub_o { char *udata = NULL; int usize = data->blksz; + if (usize < 8192) + usize = 8192; - if (off == 0) - { - ZSTD_decompress(outbuf, len, inbuf, insize); - } - else - { - if (usize < 8192) - usize = 8192; - - udata = grub_malloc (usize); - if (!udata) - return -1; + udata = grub_malloc (usize); + if (!udata) + return -1; - ZSTD_decompress(udata, usize, inbuf, insize); - grub_memcpy(outbuf, udata + off, len); - grub_free(udata); - } + ZSTD_decompress(udata, usize, inbuf, insize); + grub_memcpy(outbuf, udata + off, len); + grub_free(udata); return len; } @@ -551,7 +543,7 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, break; case grub_cpu_to_le16_compile_time (SQUASH_TYPE_LONG_DIR): off = grub_le_to_cpu16 (dir->ino.long_dir.offset); - endoff = grub_le_to_cpu16 (dir->ino.long_dir.size) + off - 3; + endoff = grub_le_to_cpu32 (dir->ino.long_dir.size) + off - 3; chunk = grub_le_to_cpu32 (dir->ino.long_dir.chunk); break; default: diff --git a/IMG/cpio/ventoy/hook/deepin/disk_mount_hook.sh b/IMG/cpio/ventoy/hook/deepin/disk_mount_hook.sh new file mode 100644 index 00000000..4e00b8f1 --- /dev/null +++ b/IMG/cpio/ventoy/hook/deepin/disk_mount_hook.sh @@ -0,0 +1,40 @@ +#!/ventoy/busybox/sh +#************************************************************************************ +# Copyright (c) 2020, longpanda +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +#************************************************************************************ + +. /ventoy/hook/ventoy-hook-lib.sh + +vtlog "####### $0 $* ########" + +VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH + +wait_for_usb_disk_ready + +vtdiskname=$(get_ventoy_disk_name) +if [ "$vtdiskname" = "unknown" ]; then + vtlog "ventoy disk not found" + PATH=$VTPATH_OLD + exit 0 +fi + +vtlog "${vtdiskname#/dev/}2 found..." +$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/udev_disk_hook.sh "${vtdiskname#/dev/}2" + +if [ -f /ventoy/autoinstall ]; then + sh /ventoy/hook/default/auto_install_varexp.sh /ventoy/autoinstall +fi diff --git a/IMG/cpio/ventoy/hook/deepin/udev_disk_hook.sh b/IMG/cpio/ventoy/hook/deepin/udev_disk_hook.sh new file mode 100644 index 00000000..251f046b --- /dev/null +++ b/IMG/cpio/ventoy/hook/deepin/udev_disk_hook.sh @@ -0,0 +1,151 @@ +#!/ventoy/busybox/sh +#************************************************************************************ +# Copyright (c) 2020, longpanda +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +#************************************************************************************ + +. /ventoy/hook/ventoy-hook-lib.sh + +ventoy_os_install_dmsetup() { + + vtlog "ventoy_os_install_dmsetup $1 ..." + + vt_usb_disk=$1 + + # dump iso file location + $VTOY_PATH/tool/vtoydm -i -f $VTOY_PATH/ventoy_image_map -d ${vt_usb_disk} > $VTOY_PATH/iso_file_list + + # install dmsetup + LINE=$($GREP ' dmsetup.*\.udeb' $VTOY_PATH/iso_file_list) + if [ $? -eq 0 ]; then + install_udeb_from_line "$LINE" ${vt_usb_disk} + fi + + # install libdevmapper + LINE=$($GREP ' libdevmapper.*\.udeb' $VTOY_PATH/iso_file_list) + if [ $? -eq 0 ]; then + install_udeb_from_line "$LINE" ${vt_usb_disk} + fi + + # install md-modules + LINE=$($GREP -i ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list) + if [ $? -eq 0 ]; then + LINTCNT=$($GREP -i -c ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list) + if [ $LINTCNT -gt 1 ]; then + vtlog "more than one pkgs, need to filter..." + VER=$($BUSYBOX_PATH/uname -r) + + LINE=$($GREP -i ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list | $GREP -i $VER) + LINTCNT=$($GREP -i ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list | $GREP -i -c $VER) + if [ $LINTCNT -gt 1 ]; then + vtlog "Still more than one pkgs, use the first one..." + LINE=$($GREP -i ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list | $GREP -i -m1 $VER) + fi + fi + install_udeb_from_line "$LINE" ${vt_usb_disk} + fi + + # insmod md-mod if needed + if $GREP -q 'device-mapper' /proc/devices; then + vtlog "device mapper module is loaded" + else + vtlog "device mapper module is NOT loaded, now load it..." + + VER=$($BUSYBOX_PATH/uname -r) + KO=$($FIND /lib/modules/$VER/kernel/drivers/md -name "dm-mod*") + vtlog "KO=$KO" + + insmod $KO + fi + + vtlog "dmsetup install finish, now check it..." + if dmsetup info >> $VTLOG 2>&1; then + vtlog "dmsetup work ok" + else + vtlog "dmsetup not work, now try to load eglibc ..." + + # install eglibc (some ubuntu 32 bit version need it) + LINE=$($GREP 'libc6-.*\.udeb' $VTOY_PATH/iso_file_list) + if [ $? -eq 0 ]; then + install_udeb_from_line "$LINE" ${vt_usb_disk} + fi + + if dmsetup info >> $VTLOG 2>&1; then + vtlog "dmsetup work ok after retry" + else + vtlog "dmsetup still not work after retry" + fi + fi +} + +if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then + exit 0 +fi + +vtlog "==== $0 $* ====" + +dmsetup_path=$(ventoy_find_bin_path dmsetup) +if [ -z "$dmsetup_path" ]; then + ventoy_os_install_dmsetup "/dev/${1:0:-1}" +fi + +if ! $GREP -q 'device-mapper' /proc/devices; then + ventoy_os_install_dmsetup "/dev/${1:0:-1}" +fi + +ventoy_udev_disk_common_hook $* + +# +# Some distro default only accept usb partitions as install medium. +# So if ventoy is installed on a non-USB device, we just mount /cdrom here except +# for these has boot=live or boot=casper parameter in cmdline +# +VT_BUS_USB="" +if [ -n "$ID_BUS" ]; then + if echo $ID_BUS | $GREP -q -i usb; then + VT_BUS_USB="YES" + fi +else + if $BUSYBOX_PATH/ls -l /sys/class/block/${1:0:-1} | $GREP -q -i usb; then + VT_BUS_USB="YES" + fi +fi + +if [ -n "$VT_BUS_USB" ]; then + vtlog "$1 is USB device" + echo /dev/$1 > /ventoy/list-devices-usb-part +else + vtlog "$1 is NOT USB device (bus $ID_BUS)" + + if $EGREP -q 'boot=|casper' /proc/cmdline; then + vtlog "boot=, or casper, don't mount" + else + vtlog "No boot param, need to mount" + echo /dev/$1 > /ventoy/list-devices-usb-part + fi +fi + +#special process for Linx +if $BUSYBOX_PATH/uname -r | $GREP -q "^2\.6"; then + if $GREP -q "linx" /proc/version; then + blkdev_num=$($VTOY_PATH/tool/dmsetup ls | $GREP ventoy | $SED 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/') + vtDM=$(ventoy_find_dm_id ${blkdev_num}) + echo "/dev/$vtDM" > /ventoy/list-devices-usb-part + fi +fi + +# OK finish +set_ventoy_hook_finish diff --git a/IMG/cpio/ventoy/hook/deepin/ventoy-hook.sh b/IMG/cpio/ventoy/hook/deepin/ventoy-hook.sh new file mode 100644 index 00000000..9625c623 --- /dev/null +++ b/IMG/cpio/ventoy/hook/deepin/ventoy-hook.sh @@ -0,0 +1,42 @@ +#!/ventoy/busybox/sh +#************************************************************************************ +# Copyright (c) 2020, longpanda +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +#************************************************************************************ + + +if [ -e /init ] && $GREP -q '^mountroot$' /init; then + echo "Here before mountroot ..." >> $VTLOG + + $SED "/^mountroot$/i\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/deepin/disk_mount_hook.sh" -i /init + $SED "/^mountroot$/i\\export LIVEMEDIA=/dev/mapper/ventoy" -i /init + $SED "/^mountroot$/i\\export LIVE_MEDIA=/dev/mapper/ventoy" -i /init + + if $GREP -q 'live-media=' /proc/cmdline; then + if [ -f /scripts/casper ] && $GREP -q '^ *LIVEMEDIA=' /scripts/casper; then + $SED "s#^ *LIVEMEDIA=.*#LIVEMEDIA=/dev/mapper/ventoy#" -i /scripts/casper + fi + fi +else + echo "Here use udev hook ..." >> $VTLOG + ventoy_systemd_udevd_work_around + ventoy_add_udev_rule "$VTOY_PATH/hook/deepin/udev_disk_hook.sh %k" +fi + +if [ -f $VTOY_PATH/autoinstall ]; then + echo "Do auto install ..." >> $VTLOG + $SED '/maybe_break[[:space:]]*init/i\/ventoy/busybox/sh /ventoy/hook/deepin/ventoy_autoinstall.sh >>/ventoy/autoinstall.log 2>&1' -i /init +fi diff --git a/IMG/cpio/ventoy/hook/deepin/ventoy_autoinstall.sh b/IMG/cpio/ventoy/hook/deepin/ventoy_autoinstall.sh new file mode 100644 index 00000000..5e6f581c --- /dev/null +++ b/IMG/cpio/ventoy/hook/deepin/ventoy_autoinstall.sh @@ -0,0 +1,122 @@ +#!/ventoy/busybox/sh + +. /ventoy/hook/ventoy_hook_lib.sh + +change_var_value() { + local vfile=$1 + local vkey=$2 + local vVal=$3 + local quote=$4 + local vline + + if [ $quote -eq 0 ]; then + vline="$vkey = $vVal" + else + vline="$vkey = \"$vVal\"" + fi + + if grep -q -m1 "^$vkey[[:space:]]*=" $vfile; then + sed "s#^$vkey[[:space:]]*=.*#$vline#g" -i $vfile + else + echo "$vline" >> $vfile + fi +} + +setting_script_process() { + local sfile=$1 + local vItem + local vB64Item + + vItem=$(grep '^language[[:space:]]*=' /ventoy/autoinstall | awk '{print $3}') + if [ -n "$vItem" ]; then + change_var_value $sfile 'select_language_default_locale' "$vItem" 0 + fi + + vItem=$(grep '^timezone[[:space:]]*=' /ventoy/autoinstall | awk '{print $3}') + if [ -n "$vItem" ]; then + change_var_value $sfile 'timezone_default' "$vItem" 0 + fi + + vItem=$(grep '^hostname[[:space:]]*=' /ventoy/autoinstall | awk '{print $3}') + if [ -n "$vItem" ]; then + change_var_value $sfile 'system_info_default_hostname' "$vItem" 1 + change_var_value $sfile 'DI_HOSTNAME' "$vItem" 1 + fi + + vItem=$(grep '^root_password[[:space:]]*=' /ventoy/autoinstall | awk '{print $3}') + if [ -n "$vItem" ]; then + vB64Item=$(echo -n "$vItem" | base64) + change_var_value $sfile 'system_info_default_root_password' "$vB64Item" 1 + change_var_value $sfile 'DI_ROOTPASSWORD' "$vB64Item" 1 + fi + + vItem=$(grep '^default_username[[:space:]]*=' /ventoy/autoinstall | awk '{print $3}') + if [ -n "$vItem" ]; then + change_var_value $sfile 'system_info_default_username' "$vItem" 1 + change_var_value $sfile 'DI_USERNAME' "$vItem" 1 + fi + + vItem=$(grep '^default_password[[:space:]]*=' /ventoy/autoinstall | awk '{print $3}') + if [ -n "$vItem" ]; then + change_var_value $sfile 'system_info_default_password' "$vItem" 1 + change_var_value $sfile 'DI_PASSWORD' "$vItem" 1 + fi + + vItem=$(grep '^install_disk[[:space:]]*=' /ventoy/autoinstall | awk '{print $3}') + if [ -n "$vItem" ]; then + echo "DI_FULLDISK_MULTIDISK_DEVICE = $vItem" >> $sfile + echo "DI_ROOTDISK = $vItem" >> $sfile + echo "DI_BOOTLOADER = $vItem" >> $sfile + fi + + change_var_value $sfile 'skip_virtual_machine_page' 'true' 0 + change_var_value $sfile 'skip_select_language_page' 'true' 0 + change_var_value $sfile 'skip_select_language_page_on_first_boot' 'true' 0 + change_var_value $sfile 'skip_system_keyboard_page' 'true' 0 + change_var_value $sfile 'skip_system_info_page' 'true' 0 + change_var_value $sfile 'skip_qr_code_system_info_page' 'true' 0 + change_var_value $sfile 'skip_timezone_page' 'true' 0 + change_var_value $sfile 'skip_partition_page' 'true' 0 + change_var_value $sfile 'system_info_password_validate_required' '0' 0 + change_var_value $sfile 'system_info_password_strong_check' 'false' 0 + change_var_value $sfile 'partition_do_auto_part' 'true' 0 + change_var_value $sfile 'system_info_disable_license' 'true' 0 + change_var_value $sfile 'system_info_disable_experience' 'true' 0 + change_var_value $sfile 'system_info_disable_privacy_license' 'true' 0 + + #filesystem.squashfs search ini + #first_page_state=0,表示不跳过首页,展示首页让用户自己选择 + #first_page_state=1,表示跳过首页,并且自动点击一键安装 + #first_page_state=2,表示跳过首页,并且自动点击自定义安装 + #first_page_state=3,表示跳过首页,并且直接以全盘安装方式自动安装 + change_var_value $sfile 'first_page_state' '3' 0 +} + +update_settings() { + local script=$1 + local newscript + + echo "update_settings for $script ..." + + newscript=$(basename $script) + cp -a $script /ventoy/vini_${newscript} + setting_script_process /ventoy/vini_${newscript} + + rm -f $script + cp -a /ventoy/vini_${newscript} $script +} + +sh /ventoy/hook/common/auto_install_varexp.sh /ventoy/autoinstall + +update_settings /root/usr/share/deepin-installer/resources/default_settings.ini + +ls -1 /root/usr/share/deepin-installer/resources/override/ | while read line; do + update_settings /root/usr/share/deepin-installer/resources/override/$line +done + +ls -1 /root/usr/share/deepin-installer/resources/oem/ | while read line; do + update_settings /root/usr/share/deepin-installer/resources/oem/$line +done + + + diff --git a/IMG/cpio/ventoy/ventoy_chain.sh b/IMG/cpio/ventoy/ventoy_chain.sh index 5b6be59a..cae7c4fd 100644 --- a/IMG/cpio/ventoy/ventoy_chain.sh +++ b/IMG/cpio/ventoy/ventoy_chain.sh @@ -64,9 +64,9 @@ ventoy_get_os_type() { elif $GREP -q '[Uu]buntu' /proc/version; then echo 'debian'; return - # Deepin : do the same process with debian + # Deepin : elif $GREP -q '[Dd]eepin' /proc/version; then - echo 'debian'; return + echo 'deepin'; return # rhel5/CentOS5 and all other distributions based on them elif $GREP -q 'el5' /proc/version; then @@ -169,9 +169,9 @@ ventoy_get_os_type() { elif $GREP -q 'fuyu' /etc/os-release; then echo 'openEuler'; return elif $GREP -q 'deepin' /etc/os-release; then - echo 'debian'; return + echo 'deepin'; return elif $GREP -q 'chinauos' /etc/os-release; then - echo 'debian'; return + echo 'deepin'; return fi fi