Unverified Commit b12db062 authored by Anderson Torres's avatar Anderson Torres Committed by GitHub
Browse files

Merge pull request #199103 from atorres1985-contrib/ventoy

ventoy-bin: fix plugson
parents 6b10854c 5d9a2f1c
Loading
Loading
Loading
Loading
+301 −0
Original line number Diff line number Diff line
Author: DuckSoft <realducksoft@gmail.com>
A shameless merge of many patches floating around; indeed it was made by reading
and applying them manually.

I just cannot stand such a dirty package. 
Let me do some optimisations.
diff -Naur ventoy-1.0.81-old/CreatePersistentImg.sh ventoy-1.0.81-new/CreatePersistentImg.sh
--- ventoy-1.0.81-old/CreatePersistentImg.sh	2022-10-25 08:26:21.000000000 -0300
+++ ventoy-1.0.81-new/CreatePersistentImg.sh	2022-11-02 10:29:07.355891607 -0300
@@ -119,17 +119,13 @@
 sync
 
If you are interested to improve this patch, welcome to mail me.
 if [ -n "$config" ]; then
-    if [ -d ./persist_tmp_mnt ]; then
-        rm -rf ./persist_tmp_mnt
-    fi
-    
-    mkdir ./persist_tmp_mnt
-    if mount $freeloop ./persist_tmp_mnt; then
-        echo '/ union' > ./persist_tmp_mnt/$config
+    path_to_persist_mnt="`mktemp -d`"
+    if mount $freeloop "$path_to_persist_mnt"; then
+        echo '/ union' > "$path_to_persist_mnt"/$config
         sync
-        umount ./persist_tmp_mnt
+        umount "$path_to_persist_mnt"
     fi
-    rm -rf ./persist_tmp_mnt
+    rm -rf "$path_to_persist_mnt"
 fi
 
 if [ ! -z "$passphrase" ]; then
diff -Naur ventoy-1.0.81-old/tool/ventoy_lib.sh ventoy-1.0.81-new/tool/ventoy_lib.sh
--- ventoy-1.0.81-old/tool/ventoy_lib.sh	2022-10-25 08:26:21.000000000 -0300
+++ ventoy-1.0.81-new/tool/ventoy_lib.sh	2022-11-02 09:46:29.764568349 -0300
@@ -6,6 +6,8 @@
 VENTOY_SECTOR_SIZE=512
 VENTOY_SECTOR_NUM=65536
 
diff -rup old/tool/ventoy_lib.sh new/tool/ventoy_lib.sh
--- tool/ventoy_lib.sh	2021-12-02 16:59:42.148650182 +0100
+++ tool/ventoy_lib.sh	2021-12-02 17:01:17.214720518 +0100
@@ -29,7 +29,7 @@ vterr() {
+LOGFILE="/var/log/ventoy.log"
+
 ventoy_false() {
     [ "1" = "2" ]
 }
@@ -29,7 +31,7 @@
 }
 
 vtdebug() {
-    echo "$*" >> ./log.txt
+    echo "$*" >>/var/log/ventoy.log
+    echo "$*" >> $LOGFILE
 }
 
 vtoy_gen_uuid() {
@@ -52,30 +52,6 @@ vtoy_gen_uuid() {
@@ -51,31 +53,7 @@
 }
 
 check_tool_work_ok() {
     
-    
-    if echo 1 | hexdump > /dev/null; then
-        vtdebug "hexdump test ok ..."
-    else
@@ -45,34 +77,89 @@ diff -rup old/tool/ventoy_lib.sh new/tool/ventoy_lib.sh
-        return
-    fi
-    
+
     vtdebug "tool check success ..."
     ventoy_true
 }
@@ -311,7 +287,7 @@ format_ventoy_disk_mbr() {
@@ -311,7 +289,7 @@
     else
     vtdebug "format disk by fdisk ..."
     
-fdisk $DISK >>./log.txt 2>&1 <<EOF
+fdisk $DISK >>/var/log/ventoy.log 2>&1 <<EOF
+fdisk $DISK >>$LOGFILE 2>&1 <<EOF
 o
 n
 p
diff -rup old/tool/VentoyWorker.sh new/tool/VentoyWorker.sh
--- tool/VentoyWorker.sh	2021-12-02 16:59:31.485642239 +0100
+++ tool/VentoyWorker.sh	2021-12-02 17:02:00.326752183 +0100
@@ -105,7 +105,7 @@ vtdebug "MODE=$MODE FORCE=$FORCE RESERVE
diff -Naur ventoy-1.0.81-old/tool/VentoyWorker.sh ventoy-1.0.81-new/tool/VentoyWorker.sh
--- ventoy-1.0.81-old/tool/VentoyWorker.sh	2022-10-25 08:26:21.000000000 -0300
+++ ventoy-1.0.81-new/tool/VentoyWorker.sh	2022-11-02 10:33:25.813135227 -0300
@@ -106,7 +106,7 @@
 if check_tool_work_ok; then
     vtdebug "check tool work ok"
 else
-    vterr "Some tools can not run on current system. Please check log.txt for details."
+    vterr "Some tools can not run on current system. Please check /var/log/ventoy.log for details."
+    vterr "Some tools can not run on current system. Please check $LOGFILE for details."
     exit 1
 fi
 
diff -rup old/Ventoy2Disk.sh new/Ventoy2Disk.sh
--- Ventoy2Disk.sh	2021-12-02 16:59:05.205622608 +0100
+++ Ventoy2Disk.sh	2021-12-02 17:03:29.037816991 +0100
@@ -32,48 +32,4 @@ echo "      https://www.ventoy.net"
@@ -159,19 +159,6 @@
     exit 1
 fi
 
-
-#check tmp_mnt directory
-if [ -d ./tmp_mnt ]; then
-    vtdebug "There is a tmp_mnt directory, now delete it."
-    umount ./tmp_mnt >/dev/null 2>&1
-    rm -rf ./tmp_mnt
-    if [ -d ./tmp_mnt ]; then
-        vterr "tmp_mnt directory exists, please delete it first."
-        exit 1
-    fi
-fi
-
-
 if [ "$MODE" = "install" -a -z "$NONDESTRUCTIVE" ]; then
     vtdebug "install Ventoy ..."
 
@@ -567,16 +554,16 @@
     PART1_TYPE=$(dd if=$DISK bs=1 count=1 skip=450 status=none | hexdump -n1 -e  '1/1 "%02X"')
 
     #reserve disk uuid
-    rm -f ./diskuuid.bin
-    dd status=none conv=fsync if=${DISK} skip=384 bs=1 count=16 of=./diskuuid.bin
+    path_to_diskuuid="`mktemp`"
+    dd status=none conv=fsync if=${DISK} skip=384 bs=1 count=16 of="$path_to_diskuuid"
 
     dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=440
-    dd status=none conv=fsync if=./diskuuid.bin of=$DISK bs=1 count=16 seek=384
-    rm -f ./diskuuid.bin
+    dd status=none conv=fsync if="$path_to_diskuuid" of=$DISK bs=1 count=16 seek=384
+    rm -f "$path_to_diskuuid"
 
     #reserve data
-    rm -f ./rsvdata.bin
-    dd status=none conv=fsync if=${DISK} skip=2040 bs=512 count=8 of=./rsvdata.bin
+    path_to_rsvdata="`mktemp`"
+    dd status=none conv=fsync if=${DISK} skip=2040 bs=512 count=8 of="$path_to_rsvdata"
 
     if [ "$PART1_TYPE" = "EE" ]; then
         vtdebug "This is GPT partition style ..."
@@ -598,8 +585,8 @@
         xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
     fi
 
-    dd status=none conv=fsync if=./rsvdata.bin seek=2040 bs=512 count=8 of=${DISK}
-    rm -f ./rsvdata.bin
+    dd status=none conv=fsync if="$path_to_rsvdata" seek=2040 bs=512 count=8 of=${DISK}
+    rm -f "$path_to_rsvdata"
 
     check_umount_disk "$DISK"
     
diff -Naur ventoy-1.0.81-old/Ventoy2Disk.sh ventoy-1.0.81-new/Ventoy2Disk.sh
--- ventoy-1.0.81-old/Ventoy2Disk.sh	2022-10-25 08:26:21.000000000 -0300
+++ ventoy-1.0.81-new/Ventoy2Disk.sh	2022-11-02 09:50:17.649369332 -0300
@@ -32,48 +32,4 @@
 echo '**********************************************'
 echo ''
 
@@ -122,22 +209,14 @@ diff -rup old/Ventoy2Disk.sh new/Ventoy2Disk.sh
-    fi
-fi
+./tool/VentoyWorker.sh $*
diff -rup old/VentoyPlugson.sh new/VentoyPlugson.sh
--- VentoyPlugson.sh	2021-12-02 17:54:36.055868878 +0100
+++ VentoyPlugson.sh	2021-12-02 18:04:40.919633986 +0100
@@ -25,8 +19,6 @@ if echo $machine | egrep -q 'aarch64|arm
     TOOLDIR=aarch64
 elif echo $machine | egrep -q 'x86_64|amd64'; then
     TOOLDIR=x86_64
-elif echo $machine | egrep -q 'mips64'; then
-    TOOLDIR=mips64el
 elif echo $machine | egrep -q 'i[3-6]86'; then
     TOOLDIR=i386
 else
@@ -35,38 +27,6 @@ else
diff -Naur ventoy-1.0.81-old/VentoyPlugson.sh ventoy-1.0.81-new/VentoyPlugson.sh
--- ventoy-1.0.81-old/VentoyPlugson.sh	2022-10-25 08:26:21.000000000 -0300
+++ ventoy-1.0.81-new/VentoyPlugson.sh	2022-11-02 09:51:36.758360872 -0300
@@ -43,39 +43,6 @@
     exit 1
 fi
 
 
-
-if ! [ -f "$OLDDIR/tool/plugson.tar.xz" ]; then
-    echo "Please run under the correct directory!" 
-    exit 1
@@ -173,7 +252,7 @@ diff -rup old/VentoyPlugson.sh new/VentoyPlugson.sh
 PATH=./tool/$TOOLDIR:$PATH
 
 HOST="127.0.0.1"
@@ -208,11 +168,3 @@ if [ -f /proc/$wID/maps ]; then
@@ -217,11 +184,3 @@
 
     wait $wID
 fi
@@ -185,10 +264,10 @@ diff -rup old/VentoyPlugson.sh new/VentoyPlugson.sh
-        cd "$OLDDIR"
-    fi
-fi
diff -rup old/VentoyWeb.sh new/VentoyWeb.sh
--- VentoyWeb.sh	2021-12-02 16:58:51.885612627 +0100
+++ VentoyWeb.sh	2021-12-02 17:04:43.437871014 +0100
@@ -15,12 +15,6 @@ print_err() {
diff -Naur ventoy-1.0.81-old/VentoyWeb.sh ventoy-1.0.81-new/VentoyWeb.sh
--- ventoy-1.0.81-old/VentoyWeb.sh	2022-10-25 08:26:21.000000000 -0300
+++ ventoy-1.0.81-new/VentoyWeb.sh	2022-11-02 09:53:13.773791254 -0300
@@ -15,12 +15,6 @@
     echo ""
 }
 
@@ -201,14 +280,22 @@ diff -rup old/VentoyWeb.sh new/VentoyWeb.sh
 OLDDIR=$(pwd)
 
 if uname -m | egrep -q 'aarch64|arm64'; then
@@ -85,8 +79,8 @@ if ps -ef | grep "V2DServer.*$HOST.*$POR
@@ -85,8 +79,8 @@
     exit 1
 fi
 
-LOGFILE=log.txt
-#delete the log.txt if it's more than 8MB
+LOGFILE=/var/log/ventoy.log
+#delete the ventoy.log if it's more than 8MB
+#delete the logfile if it's more than 8MB
 if [ -f $LOGFILE ]; then
     logsize=$(stat -c '%s' $LOGFILE)
     if [ $logsize -gt 8388608 ]; then
@@ -94,7 +88,6 @@
     fi
 fi
 
-
 if [ -f ./tool/$TOOLDIR/V2DServer.xz ]; then
     xz -d ./tool/$TOOLDIR/V2DServer.xz
     chmod +x ./tool/$TOOLDIR/V2DServer
+0 −5
Original line number Diff line number Diff line
--- VentoyPlugson.sh
+++ VentoyPlugson.sh
@@ -27,0 +28,2 @@ elif echo $machine | egrep -q 'x86_64|am
+elif echo $machine | egrep -q 'mips64'; then
+    TOOLDIR=mips64el
+0 −54
Original line number Diff line number Diff line
--- CreatePersistentImg.sh
+++ CreatePersistentImg.sh
@@ -110,7 +110,3 @@ if [ -n "$config" ]; then
-    if [ -d ./persist_tmp_mnt ]; then
-        rm -rf ./persist_tmp_mnt
-    fi
-    
-    mkdir ./persist_tmp_mnt
-    if mount $freeloop ./persist_tmp_mnt; then
-        echo '/ union' > ./persist_tmp_mnt/$config
+    path_to_persist_mnt="`mktemp -d`"
+    if mount $freeloop "$path_to_persist_mnt"; then
+        echo '/ union' > "$path_to_persist_mnt"/$config
@@ -118 +114 @@ if [ -n "$config" ]; then
-        umount ./persist_tmp_mnt
+        umount "$path_to_persist_mnt"
@@ -120 +116 @@ if [ -n "$config" ]; then
-    rm -rf ./persist_tmp_mnt
+    rm -rf "$path_to_persist_mnt"
--- tool/VentoyWorker.sh
+++ tool/VentoyWorker.sh
@@ -162,12 +161,0 @@ fi
-#check tmp_mnt directory
-if [ -d ./tmp_mnt ]; then
-    vtdebug "There is a tmp_mnt directory, now delete it."
-    umount ./tmp_mnt >/dev/null 2>&1
-    rm -rf ./tmp_mnt
-    if [ -d ./tmp_mnt ]; then
-        vterr "tmp_mnt directory exists, please delete it first."
-        exit 1
-    fi
-fi
-
-
@@ -569,2 +557,2 @@ else
-    rm -f ./diskuuid.bin
-    dd status=none conv=fsync if=${DISK} skip=384 bs=1 count=16 of=./diskuuid.bin
+    path_to_diskuuid="`mktemp`"
+    dd status=none conv=fsync if=${DISK} skip=384 bs=1 count=16 of="$path_to_diskuuid"
@@ -573,2 +561,2 @@ else
-    dd status=none conv=fsync if=./diskuuid.bin of=$DISK bs=1 count=16 seek=384
-    rm -f ./diskuuid.bin
+    dd status=none conv=fsync if="$path_to_diskuuid" of=$DISK bs=1 count=16 seek=384
+    rm -f "$path_to_diskuuid"
@@ -577,2 +565,2 @@ else
-    rm -f ./rsvdata.bin
-    dd status=none conv=fsync if=${DISK} skip=2040 bs=512 count=8 of=./rsvdata.bin
+    path_to_rsvdata="`mktemp`"
+    dd status=none conv=fsync if=${DISK} skip=2040 bs=512 count=8 of="$path_to_rsvdata"
@@ -600,2 +588,2 @@ else
-    dd status=none conv=fsync if=./rsvdata.bin seek=2040 bs=512 count=8 of=${DISK}
-    rm -f ./rsvdata.bin
+    dd status=none conv=fsync if="$path_to_rsvdata" seek=2040 bs=512 count=8 of=${DISK}
+    rm -f "$path_to_rsvdata"
+18 −20
Original line number Diff line number Diff line
@@ -47,25 +47,23 @@ let
    mipsel-linux = "mips64el";
  }.${stdenv.hostPlatform.system}
    or (throw "Unsupported platform ${stdenv.hostPlatform.system}");

  inherit (lib) optional optionalString;
in
stdenv.mkDerivation (finalAttrs: {
  pname = "ventoy-bin";
  version = "1.0.81";

  src = fetchurl {
    url = "https://github.com/ventoy/Ventoy/releases/download/v${finalAttrs.version}/ventoy-${finalAttrs.version}-linux.tar.gz";
  src = let
    inherit (finalAttrs) version;
  in fetchurl {
    url = "https://github.com/ventoy/Ventoy/releases/download/v${version}/ventoy-${version}-linux.tar.gz";
    hash = "sha256-15y05g+F+oEFYUUy7SE57GZ1RSHqdZnk2iOPsy1L0GI=";
  };

  patches = [
    ./000-sanitize.patch
    ./001-add-mips64.diff
    ./002-fix-for-read-only-file-system.diff
    ./000-nixos-sanitization.patch
  ];

  patchFlags = [ "-p0" ];

  postPatch = ''
    # Fix permissions.
    find -type f -name \*.sh -exec chmod a+x '{}' \;
@@ -79,8 +77,8 @@ stdenv.mkDerivation (finalAttrs: {
    autoPatchelfHook
    makeWrapper
  ]
  ++ lib.optional (withQt5 || withGtk3) copyDesktopItems
  ++ lib.optional withQt5 wrapQtAppsHook;
  ++ optional (withQt5 || withGtk3) copyDesktopItems
  ++ optional withQt5 wrapQtAppsHook;

  buildInputs = [
    bash
@@ -97,12 +95,12 @@ stdenv.mkDerivation (finalAttrs: {
    which
    xz
  ]
  ++ lib.optional withCryptsetup cryptsetup
  ++ lib.optional withExt4 e2fsprogs
  ++ lib.optional withGtk3 gtk3
  ++ lib.optional withNtfs ntfs3g
  ++ lib.optional withXfs xfsprogs
  ++ lib.optional withQt5 qtbase;
  ++ optional withCryptsetup cryptsetup
  ++ optional withExt4 e2fsprogs
  ++ optional withGtk3 gtk3
  ++ optional withNtfs ntfs3g
  ++ optional withXfs xfsprogs
  ++ optional withQt5 qtbase;

  desktopItems = [
    (makeDesktopItem {
@@ -163,7 +161,7 @@ stdenv.mkDerivation (finalAttrs: {
  ''
  # VentoGUI uses the `ventoy_gui_type` file to determine the type of GUI.
  # See: https://github.com/ventoy/Ventoy/blob/v1.0.78/LinuxGUI/Ventoy2Disk/ventoy_gui.c#L1096
  + lib.optionalString (withGtk3 || withQt5) ''
  + optionalString (withGtk3 || withQt5) ''
    echo "${defaultGuiType}" > "$VENTOY_PATH/ventoy_gui_type"
    makeWrapper "$VENTOY_PATH/VentoyGUI.$ARCH" "$out/bin/ventoy-gui" \
                --prefix PATH : "${lib.makeBinPath finalAttrs.buildInputs}" \
@@ -171,13 +169,13 @@ stdenv.mkDerivation (finalAttrs: {
    mkdir "$out"/share/{applications,pixmaps}
    ln -s "$VENTOY_PATH"/WebUI/static/img/VentoyLogo.png "$out"/share/pixmaps/
  ''
  + lib.optionalString (!withGtk3) ''
  + optionalString (!withGtk3) ''
    rm "$VENTOY_PATH"/tool/{"$ARCH"/Ventoy2Disk.gtk3,VentoyGTK.glade}
  ''
  + lib.optionalString (!withQt5) ''
  + optionalString (!withQt5) ''
    rm "$VENTOY_PATH/tool/$ARCH/Ventoy2Disk.qt5"
  ''
  + lib.optionalString (!withGtk3 && !withQt5) ''
  + optionalString (!withGtk3 && !withQt5) ''
    rm "$VENTOY_PATH"/VentoyGUI.*
  '' +
  ''