]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - INSTALL/Ventoy2Disk.sh
Fix the resolution issue when boot Windows/WinPE in UEFI mode.
[Ventoy.git] / INSTALL / Ventoy2Disk.sh
index 8e05b586e7b887fbdb0a3d56126bdae569de7f31..f08ab1090a26d040af9a09db88b283e00eb09c62 100644 (file)
 #!/bin/sh
 
-OLDDIR=$PWD
+OLDDIR=$(pwd)
 
 if ! [ -f ./tool/ventoy_lib.sh ]; then
-    cd ${0%Ventoy2Disk.sh}
+    if [ -f ${0%Ventoy2Disk.sh}/tool/ventoy_lib.sh ]; then
+        cd ${0%Ventoy2Disk.sh}    
+    fi
 fi
 
-. ./tool/ventoy_lib.sh
-
-print_usage() {
-    echo 'Usage:  VentoyInstaller.sh OPTION /dev/sdX'
-    echo '  OPTION:'
-    echo '   -i  install ventoy to sdX (fail if disk already installed with ventoy)'
-    echo '   -u  update ventoy in sdX'
-    echo '   -I  force install ventoy to sdX (no matter installed or not)'
-    echo ''
-}
-
-echo ''
-echo '***********************************************************'
-echo '*                Ventoy2Disk Script                       *'
-echo '*             longpanda  admin@ventoy.net                 *'
-echo '***********************************************************'
-echo ''
-
-vtdebug "############# Ventoy2Disk $0 ################"
+if [ -f ./ventoy/version ]; then
+    curver=$(cat ./ventoy/version) 
+fi
 
-if [ "$1" = "-i" ]; then
-    MODE="install"
-elif [ "$1" = "-I" ]; then
-    MODE="install"
-    FORCE="Y"
-elif [ "$1" = "-u" ]; then
-    MODE="update"
+if uname -m | grep -E -q 'aarch64|arm64'; then
+    export TOOLDIR=aarch64
+elif uname -m | grep -E -q 'x86_64|amd64'; then
+    export TOOLDIR=x86_64
+elif uname -m | grep -E -q 'mips64'; then
+    export TOOLDIR=mips64el
 else
-    print_usage
-    cd $OLDDIR
-    exit 1
+    export TOOLDIR=i386
 fi
+export PATH="./tool/$TOOLDIR:$PATH"
 
-if ! [ -b "$2" ]; then
-    print_usage
-    cd $OLDDIR
-    exit 1
-fi
 
-if [ -z "$SUDO_USER" ]; then
-    if [ "$USER" != "root" ]; then
-        vterr "EUID is $EUID root permission is required."
-        echo ''
-        cd $OLDDIR
-        exit 1
-    fi
-fi
+echo ''
+echo '**********************************************'
+echo "      Ventoy: $curver  $TOOLDIR"
+echo "      longpanda admin@ventoy.net"
+echo "      https://www.ventoy.net"
+echo '**********************************************'
+echo ''
 
-vtdebug "MODE=$MODE FORCE=$FORCE"
 
 if ! [ -f ./boot/boot.img ]; then
     if [ -d ./grub ]; then
-        vterr "Don't run me here, please download the released install package, and run there."
+        echo "Don't run Ventoy2Disk.sh here, please download the released install package, and run the script in it."
     else
-        vterr "Please run under the right directory!" 
-    fi
-    exit 1
-fi
-
-#decompress tool
-cd tool
-chmod +x ./xzcat
-for file in $(ls); do
-    if [ "$file" != "xzcat" ]; then
-        if [ "$file" != "ventoy_lib.sh" ]; then
-            ./xzcat $file > ${file%.xz}
-            chmod +x ${file%.xz}
-        fi
+        echo "Please run under the correct directory!" 
     fi
-done
-cd ../
-
-if ! check_tool_work_ok; then
-    vterr "Some tools can not run in current system. Please check log.txt for detail."
-    cd $OLDDIR
     exit 1
 fi
 
+echo "############# Ventoy2Disk $* [$TOOLDIR] ################" >> ./log.txt
+date >> ./log.txt
 
-DISK=$2
-
-if ! [ -b "$DISK" ]; then
-    vterr "Disk $DISK does not exist"
-    cd $OLDDIR
-    exit 1
-fi
-
-
-if [ -e /sys/class/block/${DISK#/dev/}/start ]; then
-    vterr "$DISK is a partition, please use the whole disk"
-    cd $OLDDIR
-    exit 1
-fi
-
-grep "^$DISK" /proc/mounts | while read mtline; do
-    mtpnt=$(echo $mtline | awk '{print $2}')
-    vtdebug "Trying to umount $mtpnt ..."
-    umount $mtpnt >/dev/null 2>&1
-done
-
-if grep "$DISK" /proc/mounts; then
-    vterr "$DISK is already mounted, please umount it first!"
-    cd $OLDDIR
-    exit 1
+#decompress tool
+echo "decompress tools" >> ./log.txt
+cd ./tool/$TOOLDIR
+
+ls *.xz > /dev/null 2>&1
+if [ $? -eq 0 ]; then
+    [ -f ./xzcat ] && chmod +x ./xzcat
+
+    for file in $(ls *.xz); do
+        echo "decompress $file" >> ./log.txt
+        xzcat $file > ${file%.xz}
+        [ -f ./${file%.xz} ] && chmod +x ./${file%.xz}
+        [ -f ./$file ] && rm -f ./$file
+    done
 fi
 
+cd ../../
+chmod +x -R ./tool/$TOOLDIR
 
-if [ "$MODE" = "install" ]; then
-    vtdebug "install ventoy ..."
-    
-    if ! fdisk -v >/dev/null 2>&1; then
-        vterr "fdisk is needed by ventoy installation, but is not found in the system."
-        cd $OLDDIR
-        exit 1
-    fi
-    
-    version=$(get_disk_ventoy_version $DISK)
-    if [ $? -eq 0 ]; then
-        if [ -z "$FORCE" ]; then
-            vtwarn "$DISK already contains a Ventoy with version $version"
-            vtwarn "Use -u option to do a safe upgrade operation."
-            vtwarn "OR if you really want to reinstall ventoy to $DISK, please use -I option."
-            vtwarn ""
-            cd $OLDDIR
-            exit 1
-        fi
-    fi
-    
-    disk_sector_num=$(cat /sys/block/${DISK#/dev/}/size)
-    disk_size_gb=$(expr $disk_sector_num / 2097152)
-
-    if [ $disk_sector_num -gt 4294967296 ]; then
-        vterr "$DISK is over 2TB size, MBR will not work on it."
-        cd $OLDDIR
-        exit 1
-    fi
-
-    #Print disk info
-    echo "Disk : $DISK"
-    parted -s $DISK p 2>&1 | grep Model
-    echo "Size : $disk_size_gb GB"
-    echo ''
-
-    vtwarn "Attention:"
-    vtwarn "You will install Ventoy to $DISK."
-    vtwarn "All the data on the disk $DISK will be lost!!!"
-    echo ""
-
-    read -p 'Continue? (y/n)'  Answer
-    if [ "$Answer" != "y" ]; then
-        if [ "$Answer" != "Y" ]; then
-            exit 0
-        fi
-    fi
-
-    echo ""
-    vtwarn "All the data on the disk $DISK will be lost!!!"
-    read -p 'Double-check. Continue? (y/n)'  Answer
-    if [ "$Answer" != "y" ]; then
-        if [ "$Answer" != "Y" ]; then
-            exit 0
-        fi
-    fi
-
-
-    if [ $disk_sector_num -le $VENTOY_SECTOR_NUM ]; then  
-        vterr "No enough space in disk $DISK"
-        exit 1
-    fi
-
-    if ! dd if=/dev/zero of=$DISK bs=1 count=512 status=none conv=fsync; then
-        vterr "Write data to $DISK failed, please check whether it's in use."
-        exit 1
-    fi
-
-    format_ventoy_disk $DISK
-
-    # format part1
-    if ventoy_is_linux64; then
-        cmd=./tool/mkexfatfs_64
-    else
-        cmd=./tool/mkexfatfs_32
-    fi
-
-    chmod +x ./tool/*
-
-    # DiskSize > 32GB  Cluster Size use 128KB
-    # DiskSize < 32GB  Cluster Size use 32KB
-    if [ $disk_size_gb -gt 32 ]; then
-        cluster_sectors=256
-    else
-        cluster_sectors=64
-    fi
-
-    $cmd -n ventoy -s $cluster_sectors ${DISK}1
-
-    chmod +x ./tool/vtoy_gen_uuid
 
-    dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=446
-    ./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
-    ./tool/xzcat ./ventoy/ventoy.disk.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start_sector
-    
-    #disk uuid
-    ./tool/vtoy_gen_uuid | dd status=none conv=fsync of=${DISK} seek=384 bs=1 count=16
-    
-    #disk signature
-    ./tool/vtoy_gen_uuid | dd status=none conv=fsync of=${DISK} skip=12 seek=440 bs=1 count=4
-
-    sync
-
-    echo ""
-    vtinfo "Install Ventoy to $DISK successfully finished."
-    echo ""
-    
+if [ -f /bin/bash ]; then
+    /bin/bash ./tool/VentoyWorker.sh $*
 else
-    vtdebug "update ventoy ..."
-    
-    oldver=$(get_disk_ventoy_version $DISK)
-    if [ $? -ne 0 ]; then
-        vtwarn "$DISK does not contain ventoy or data corupted"
-        echo ""
-        vtwarn "Please use -i option if you want to install ventoy to $DISK"
-        echo ""
-        cd $OLDDIR
-        exit 1
-    fi
-
-    curver=$(cat ./ventoy/version)
-
-    vtinfo "Upgrade operation is safe, all the data in the 1st partition (iso files and other) will be unchanged!"
-    echo ""
+    ash ./tool/VentoyWorker.sh $*
+fi
 
-    read -p "Update Ventoy  $oldver ===> $curver   Continue? (y/n)"  Answer
-    if [ "$Answer" != "y" ]; then
-        if [ "$Answer" != "Y" ]; then
-            cd $OLDDIR
-            exit 0
-        fi
+if [ -n "$OLDDIR" ]; then 
+    CURDIR=$(pwd)
+    if [ "$CURDIR" != "$OLDDIR" ]; then
+        cd "$OLDDIR"
     fi
-
-    PART2=$(get_disk_part_name $DISK 2)
-    
-    dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=440
-    
-    ./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1  
-
-    disk_sector_num=$(cat /sys/block/${DISK#/dev/}/size) 
-    part2_start=$(expr $disk_sector_num - $VENTOY_SECTOR_NUM)
-    ./tool/xzcat ./ventoy/ventoy.disk.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start
-
-    sync
-
-    echo ""
-    vtinfo "Update Ventoy to $DISK successfully finished."
-    echo ""
-    
 fi
-
-cd $OLDDIR
-