Ventoy icon indicating copy to clipboard operation
Ventoy copied to clipboard

change interpreter to bash

Open xgqt opened this issue 5 years ago • 5 comments

the script only works with bash (checked with mksh - fails)

xgqt avatar Apr 28 '20 19:04 xgqt

Isn't it better to fix the bashisms instead?

--- Ventoy2Disk.sh	2020-05-22 18:05:11.742572393 -0300
+++ Ventoy2Disk.sh	2020-05-22 18:17:51.386209377 -0300
@@ -47,7 +47,7 @@
 
 if [ -z "$SUDO_USER" ]; then
     if [ "$USER" != "root" ]; then
-        vterr "EUID is $EUID root permission is required."
+        vterr "EUID is $(id -u) root permission is required."
         echo ''
         cd $OLDDIR
         exit 1
@@ -145,7 +145,8 @@
     vtwarn "All the data on the disk $DISK will be lost!!!"
     echo ""
 
-    read -p 'Continue? (y/n)'  Answer
+    echo -n "Continue? (y/n)? "
+    read Answer
     if [ "$Answer" != "y" ]; then
         if [ "$Answer" != "Y" ]; then
             exit 0
@@ -154,7 +155,8 @@
 
     echo ""
     vtwarn "All the data on the disk $DISK will be lost!!!"
-    read -p 'Double-check. Continue? (y/n)'  Answer
+    echo -n "Double-check. Continue? (y/n) "
+    read Answer
     if [ "$Answer" != "y" ]; then
         if [ "$Answer" != "Y" ]; then
             exit 0
@@ -229,7 +231,8 @@
     vtinfo "Upgrade operation is safe, all the data in the 1st partition (iso files and other) will be unchanged!"
     echo ""
 
-    read -p "Update Ventoy  $oldver ===> $curver   Continue? (y/n)"  Answer
+    echo -n "Update Ventoy  $oldver ===> $curver   Continue? (y/n) "
+    read Answer
     if [ "$Answer" != "y" ]; then
         if [ "$Answer" != "Y" ]; then
             cd $OLDDIR

naoliv avatar May 22 '20 21:05 naoliv

yeah, I'd say that would be better. I just wasn't sure if I could do it without side effects. 😅 and demanding the right(intended) interpreter would be a first sure thing after all. ^^

HoroTW avatar May 23 '20 21:05 HoroTW

Hi, From Ventoy-1.0.12 I integrated a busybox ash in the package. So now the main process is not depend on the shell envrioment in the system. You can make a try. I tested it on CentOS with mksh and it worked fine.

ventoy avatar May 31 '20 05:05 ventoy

$ ventoy
/usr/bin/ventoy: 2: /usr/bin/ventoy: pushd: not found
$ cat /etc/lsb-release
LSB_VERSION=1.4
DISTRIB_ID=Arch
DISTRIB_RELEASE=rolling
DISTRIB_DESCRIPTION="Arch Linux"
$ pacman -Qi ventoy
Name            : ventoy-bin
Version         : 1.0.13-1
Description     : A new multiboot USB solution (Binary)
Architecture    : x86_64
URL             : http://www.ventoy.net/
Licenses        : GPL3
Groups          : None
Provides        : ventoy
Depends On      : bash  util-linux  xz  exfat-utils
Optional Deps   : None
Required By     : None
Optional For    : None
Conflicts With  : ventoy
Replaces        : None
Installed Size  : 4.45 MiB
Packager        : Unknown Packager
Build Date      : Sun 14 Jun 2020 03:32:08 PM PDT
Install Date    : Sun 14 Jun 2020 03:32:12 PM PDT
Install Reason  : Explicitly installed
Install Script  : No
Validated By    : None
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 May 24 07:28 /bin/sh -> dash
$ grep /bin/sh /bin/ventoy /opt/ventoy/{,tool/}*.sh
/bin/ventoy:#!/bin/sh
/opt/ventoy/CreatePersistentImg.sh:#!/bin/sh
/opt/ventoy/Ventoy2Disk.sh:#!/bin/sh
/opt/ventoy/tool/ventoy_lib.sh:#!/bin/sh
/opt/ventoy/tool/VentoyWorker.sh:#!/bin/sh
$ checkbashisms $(file $(pacman -Qlq ventoy) | grep shell | cut -f1 -d':')
possible bashism in /opt/ventoy/tool/VentoyWorker.sh line 138 (read with option other than -r):
    read -p 'Continue? (y/n)'  Answer
possible bashism in /opt/ventoy/tool/VentoyWorker.sh line 147 (read with option other than -r):
    read -p 'Double-check. Continue? (y/n)'  Answer
possible bashism in /opt/ventoy/tool/VentoyWorker.sh line 258 (read with option other than -r):
    read -p "Update Ventoy  $oldver ===> $curver   Continue? (y/n)"  Answer
possible bashism in /opt/ventoy/tool/VentoyWorker.sh line 275 (echo -e):
        echo -en '\x80' | dd of=$DISK conv=fsync bs=1 count=1 seek=446 status=none
possible bashism in /opt/ventoy/tool/VentoyWorker.sh line 276 (echo -e):
        echo -en '\x00' | dd of=$DISK conv=fsync bs=1 count=1 seek=462 status=none
possible bashism in /opt/ventoy/tool/ventoy_lib.sh line 26 (echo -e):
    echo -e "\033[32m$*\033[0m"
possible bashism in /opt/ventoy/tool/ventoy_lib.sh line 30 (echo -e):
    echo -e "\033[33m$*\033[0m"
possible bashism in /opt/ventoy/tool/ventoy_lib.sh line 35 (echo -e):
    echo -e "\033[31m$*\033[0m"
possible bashism in /opt/ventoy/tool/ventoy_lib.sh line 192 (echo -e):
        echo -en '\xEF' | dd of=$DISK conv=fsync bs=1 count=1 seek=466 > /dev/null 2>&1
possible bashism in /usr/bin/ventoy line 2 ((push|pop)d):
pushd /opt/ventoy
possible bashism in /usr/bin/ventoy line 4 ((push|pop)d):
popd

GregoryHinton avatar Jun 14 '20 23:06 GregoryHinton

$ sudo su
# for f in $(file $(pacman -Qlq ventoy) | grep shell | cut -f1 -d':'); do 
>     sed 's:/bin/sh:/bin/bash:' $f >$f.NEW && mv $f $f.OLD && mv $f.NEW $f && chmod +x $f
> done
# exit
$ ventoy
/opt/ventoy /home/greg

***********************************************************
*                Ventoy2Disk Script                       *
*             longpanda  [email protected]                 *
***********************************************************

Usage:  Ventoy2Disk.sh CMD [ OPTION ] /dev/sdX
  CMD:
   -i  install ventoy to sdX (fail if disk already installed with ventoy)
   -u  update ventoy in sdX
   -I  force install ventoy to sdX (no matter installed or not)

  OPTION: (optional)
   -s  enable secure boot support (default is disabled)

GregoryHinton avatar Jun 14 '20 23:06 GregoryHinton