]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - INSTALL/tool/VentoyWorker.sh
add class for submenu of 'Ventoy UEFI Utilities'
[Ventoy.git] / INSTALL / tool / VentoyWorker.sh
index 4b4fc300b999074bd39be9c0f97a074204fbd3ea..f12fbb7e0d3cbe588b880607dc2f5709fb3eebac 100644 (file)
@@ -9,15 +9,18 @@ print_usage() {
     echo '   -i  install ventoy to sdX (fail if disk already installed with ventoy)'
     echo '   -I  force install ventoy to sdX (no matter installed or not)'
     echo '   -u  update ventoy in sdX'
+    echo '   -l  list Ventoy information in sdX'
     echo ''
     echo '  OPTION: (optional)'
     echo '   -r SIZE_MB  preserve some space at the bottom of the disk (only for install)'
     echo '   -s          enable secure boot support (default is disabled)'
     echo '   -g          use GPT partition style, default is MBR (only for install)'
+    echo '   -L          Label of the 1st exfat partition (default is ventoy)'
     echo ''
 }
 
 
+VTNEW_LABEL='ventoy'
 RESERVE_SIZE_MB=0
 while [ -n "$1" ]; do
     if [ "$1" = "-i" ]; then
@@ -27,17 +30,22 @@ while [ -n "$1" ]; do
         FORCE="Y"
     elif [ "$1" = "-u" ]; then
         MODE="update"
+    elif [ "$1" = "-l" ]; then
+        MODE="list"
     elif [ "$1" = "-s" ]; then
         SECUREBOOT="YES"
     elif [ "$1" = "-g" ]; then
         VTGPT="YES"
+    elif [ "$1" = "-L" ]; then
+        shift
+        VTNEW_LABEL=$1
     elif [ "$1" = "-r" ]; then
         RESERVE_SPACE="YES"
         shift
         RESERVE_SIZE_MB=$1
     elif [ "$1" = "-V" ] || [ "$1" = "--version" ]; then
         exit 0
-    elif [ "$1" == "-h" ] || [ "$1" = "--help" ]; then
+    elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
         print_usage
         exit 0
     else
@@ -63,11 +71,15 @@ if ! [ -b "$DISK" ]; then
 fi
 
 if [ -e /sys/class/block/${DISK#/dev/}/start ]; then
-    vterr "$DISK is a partition, please use the whole disk"
+    vterr  "$DISK is a partition, please use the whole disk."
+    echo   "For example:"
+    vterr  "    sudo sh Ventoy2Disk.sh -i /dev/sdX1 <=== This is wrong"
+    vtinfo "    sudo sh Ventoy2Disk.sh -i /dev/sdX  <=== This is right"
+    echo ""
     exit 1
 fi
 
-if [ -n "$RESERVE_SPACE" ]; then
+if [ -n "$RESERVE_SPACE" -a "$MODE" = "install" ]; then
     if echo $RESERVE_SIZE_MB | grep -q '^[0-9][0-9]*$'; then
         vtdebug "User will reserve $RESERVE_SIZE_MB MB disk space"
     else
@@ -95,6 +107,36 @@ else
     exit 1
 fi
 
+if [ "$MODE" = "list" ]; then
+    version=$(get_disk_ventoy_version $DISK)
+    if [ $? -eq 0 ]; then
+        echo "Ventoy Version in Disk: $version"
+        
+        vtPart1Type=$(dd if=$DISK bs=1 count=1 skip=450 status=none | hexdump -n1 -e  '1/1 "%02X"')
+        if [ "$vtPart1Type" = "EE" ]; then            
+            echo "Disk Partition Style  : GPT"
+        else
+            echo "Disk Partition Style  : MBR"
+        fi
+        
+        vtPART2=$(get_disk_part_name $DISK 2)        
+        rm -rf ./tmpmntp2 && mkdir ./tmpmntp2
+        mount $vtPART2 ./tmpmntp2 > /dev/null 2>&1
+
+        if [ -e ./tmpmntp2/EFI/BOOT/MokManager.efi ]; then
+            echo "Secure Boot Support   : YES"
+        else
+            echo "Secure Boot Support   : NO"
+        fi        
+        umount ./tmpmntp2 > /dev/null 2>&1
+        rm -rf ./tmpmntp2
+    else
+        echo "Ventoy Version: NA"
+    fi
+    echo ""
+    exit 0
+fi
+
 #check mountpoint
 grep "^$DISK" /proc/mounts | while read mtline; do
     mtpnt=$(echo $mtline | awk '{print $2}')
@@ -244,7 +286,7 @@ if [ "$MODE" = "install" ]; then
     PART1=$(get_disk_part_name $DISK 1)  
     PART2=$(get_disk_part_name $DISK 2)  
 
-    $cmd -n ventoy -s $cluster_sectors ${PART1}
+    $cmd -n "$VTNEW_LABEL" -s $cluster_sectors ${PART1}
 
     vtinfo "writing data to disk ..."
     
@@ -336,7 +378,7 @@ else
     SHORT_PART2=${PART2#/dev/}
     part2_start=$(cat /sys/class/block/$SHORT_PART2/start)
     
-    PART1_TYPE=$(dd if=$DISK bs=1 count=1 skip=450 status=none | ./tool/hexdump -n1 -e  '1/1 "%02X"')
+    PART1_TYPE=$(dd if=$DISK bs=1 count=1 skip=450 status=none | hexdump -n1 -e  '1/1 "%02X"')
     
     if [ "$PART1_TYPE" = "EE" ]; then
         vtdebug "This is GPT partition style ..."        
@@ -346,8 +388,8 @@ else
         vtdebug "This is MBR partition style ..."
         dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=440
     
-        PART1_ACTIVE=$(dd if=$DISK bs=1 count=1 skip=446 status=none | ./tool/hexdump -n1 -e  '1/1 "%02X"')
-        PART2_ACTIVE=$(dd if=$DISK bs=1 count=1 skip=462 status=none | ./tool/hexdump -n1 -e  '1/1 "%02X"')
+        PART1_ACTIVE=$(dd if=$DISK bs=1 count=1 skip=446 status=none | hexdump -n1 -e  '1/1 "%02X"')
+        PART2_ACTIVE=$(dd if=$DISK bs=1 count=1 skip=462 status=none | hexdump -n1 -e  '1/1 "%02X"')
         
         vtdebug "PART1_ACTIVE=$PART1_ACTIVE  PART2_ACTIVE=$PART2_ACTIVE"
         if [ "$PART1_ACTIVE" = "00" ] && [ "$PART2_ACTIVE" = "80" ]; then