-#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
- 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
-
-testEF=$(echo -en '\xEF' | ./tool/hexdump -n 1 -e '1/1 "%02X"')
-if [ "$testEF" != "EF" ]; then
- vtdebug "testEF=##${testEF}##"
- vterr "There is something wrong with the interpreter !"
- 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 swapon -s | grep -q "^${DISK}[0-9]"; then
- swapon -s | grep "^${DISK}[0-9]" | awk '{print $1}' | while read line; do
- vtdebug "Trying to swapoff $line ..."
- swapoff $line
- done
-fi
-
-
-if grep "$DISK" /proc/mounts; then
- vterr "$DISK is already mounted, please umount it first!"
- cd $OLDDIR
- exit 1
-fi
-
-if swapon -s | grep -q "^${DISK}[0-9]"; then
- vterr "$DISK is used as swap, please swapoff it first!"
- cd $OLDDIR
- exit 1
-fi
-
-
-if [ "$MODE" = "install" ]; then
- vtdebug "install ventoy ..."
-
- if parted -v > /dev/null 2>&1; then
- PARTTOOL='parted'
- elif fdisk -v >/dev/null 2>&1; then
- PARTTOOL='fdisk'
- else
- vterr "Both parted and fdisk are not found in the sysstem, Ventoy can't create new partition."
- 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