dir2sfs - Yad version

Moderator: Forum moderators

Post Reply
User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

dir2sfs - Yad version

Post by stemsee »

Here is dir2sfs yad version. Contributors to this updated version include rg66, fredx181, misko_2083, stemsee, step, belham2, rufwoof and technosaurus.

topic on murga http://murga-linux.com/puppy/viewtopic.php?t=111674

dir2sfs.png
dir2sfs.png (86.47 KiB) Viewed 2203 times

Code: Select all

#!/bin/bash
#
[[ "`whoami`" != "root" ]] && exec sudo -E -S ${0} "$@"

[ ! -d "$1" ] && exit
if [ "$(echo "$1" | wc -w)" -gt 1 ]; then
  yad --window-icon="application-x-squashfs-image" --title="Rename Folder"  \
  --text="Remove blank spaces from\n<b>$(basename "$1")</b> \
and try again." --text-align="center" --borders="10" --width="220"  \
--no-buttons --timeout="3" --center
exit
fi

if [ -f "$1.sfs" ];then
  yad --window-icon="application-x-squashfs-image" --title="Overwrite"  \
  --text="<b>$(basename $1).sfs</b> already exists.\n Would you like to overwrite it?\n" \
  --text-align="center" --borders="10" --buttons-layout="center"  \
  --button="Yes:1" --button="No:0" --center --timeout-indicator=top  \
  --timeout 7
  case $? in
    0|252) exit ;;
    70|1) [[ -f "$1.sfs" ]] && rm -f $1.sfs
[[ -f "$1.sfs-md5.txt" ]] && rm -f "$1.sfs-md5.txt";;
  esac
fi
yad --window-icon="application-x-squashfs-image" \
--title "Choose Compression Type" \
--text="LZ4 is fastest; GZIP for older machines
XZ-HC is the highest compression; ZSTD is latest tech."  \
--text-align="center" --borders="10" --buttons-layout="center" \
--columns=2 --button="GZIP:0" --button="XZ:1" --button="XZ-HC:2" \
--button="LZ4:3" --button="LZ4-HC:4" --button="ZSTD:5" --center \
--timeout-indicator=top --timeout 7
case $? in
  0) COMP="-comp gzip" ;;
  1) COMP="-comp xz" ;;
  2) COMP="-comp xz -b 1024k -Xbcj x86" ;;
  3) COMP="-comp lz4" ;;
  4) COMP="-comp lz4 -Xhc" ;;
  5) COMP="-comp zstd" ;;
  *) COMP="-comp xz" ;;
esac

( sleep 0.5; pgrep -n mksquashfs >/tmp/$$ ) &
(script -q -c "stty rows 40 cols 100; mksquashfs "$1" "$1.sfs" $COMP" | \
while read -n 100 LINE; do echo $LINE | busybox strings | egrep '[0-9]\%' | \
awk '{print $NF}'; done ) | yad --progress --center --undecorated --on-top \
--skip-taskbar --progress-text="Building $1.sfs $COMP" --borders="10" \
--text-align="center" --button="Stop:1" \
--buttons-layout="center" --auto-close
case $? in
1) kill $(cat /tmp/$$)
[[ -f "$1.sfs" ]] && rm -f $1.sfs
[[ -f "$1.sfs-md5.txt" ]] && rm -f "$1.sfs-md5.txt";;
esac
[[ -f "$1.sfs" ]] && md5sum "$1.sfs" > "$1.sfs-md5.txt"
rm -f typescript
rm -f /tmp/$$
sync
dir2sfs.gz
(2.11 KiB) Downloaded 204 times

rename as dir2sfs and place in /usr/local/bin, then

Code: Select all

chmod 755 /usr/local/bin/dir2sfs
User avatar
Jasper
Posts: 1989
Joined: Wed Sep 07, 2022 1:20 pm
Has thanked: 843 times
Been thanked: 462 times

Re: dir2sfs

Post by Jasper »

@stemsee

Thanks for this script :thumbup:

My version in FossaPup64-95 appeared to have stopped functioning and I would receive error messages informing me that the directory was locked/unavailable (?)

For my build the file needs to be placed in

/sbin

**EDIT**

When I run the application the GUI remains on-screen for a few seconds before it counts down and gives little opportunity to make a selection.

Is it possible for the application not to execute until a user makes their decision?

Also, my progress bar seems to run right to left. To me that feels like a countdown instead of progress.

User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: dir2sfs

Post by stemsee »

Hi Jasper

Just remove "--timeout 7" ....

For the progress indicator to move from left to right there is the --bar=LABEL[:TYPE], type can be norm, rtl, pulse, or perm .... but when i tested --bar option the script hung! I am using the gtk2 yad version by step, I expect gtk3 version should be ok! Experiment and let us know.

cheers

User avatar
Jasper
Posts: 1989
Joined: Wed Sep 07, 2022 1:20 pm
Has thanked: 843 times
Been thanked: 462 times

Re: dir2sfs

Post by Jasper »

@stemsee

Thanks for getting back to me.

I did remove the Timeout entry and that allowed the dialog box to remain onscreen until I made my decision.

I could not locate the --bar term. However, when I did another test, the progress bar did run left to right :thumbup:

User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: dir2sfs

Post by stemsee »

Yes, the timeout indicator always runs right to left.

Im glad its resolved.

stemsee

User avatar
AntonioPt
Posts: 211
Joined: Wed Aug 11, 2021 7:41 pm
Has thanked: 92 times
Been thanked: 37 times

Re: dir2sfs

Post by AntonioPt »

Hello guys this script has a small but that i still don't how to fix it

so i run it, then i stop it in the middle of the operation, gui close right but mksquashfs still working in background

Why astronauts use Linux
Because you can't open windows in space

sonny
Posts: 725
Joined: Mon Feb 15, 2021 4:50 pm
Has thanked: 486 times
Been thanked: 173 times

Re: dir2sfs - Yad version

Post by sonny »

@radky, @stemsee
In BookwormPup64, the 'progress (%)' indicator no longer appears in the terminal.
You can only tell it's done when the text file pops up.

User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: dir2sfs

Post by stemsee »

AntonioPt wrote: Sat Jun 01, 2024 11:44 pm

Hello guys this script has a small but that i still don't how to fix it

so i run it, then i stop it in the middle of the operation, gui close right but mksquashfs still working in background

Code: Select all

kill $(cat /tmp/$$)

This is the line to work on. Maybe test your kill command or pkill. See if /tmp/$$ contains the correct process id. Maybe increase the sleepto 1 in this line

Code: Select all

( sleep 0.5; pgrep -n mksquashfs >/tmp/$$ ) &
Last edited by stemsee on Fri Jun 07, 2024 11:06 am, edited 2 times in total.
User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: dir2sfs - Yad version

Post by stemsee »

sonny wrote: Sun Jun 02, 2024 2:17 am

@radky, @stemsee
In BookwormPup64, the 'progress (%)' indicator no longer appears in the terminal.
You can only tell it's done when the text file pops up.

This is a GUI version of dir2sfs, depends on yad.

User avatar
AntonioPt
Posts: 211
Joined: Wed Aug 11, 2021 7:41 pm
Has thanked: 92 times
Been thanked: 37 times

Re: dir2sfs

Post by AntonioPt »

Gonna test it and see what is the Result thxx

stemsee wrote: Fri Jun 07, 2024 11:02 am
AntonioPt wrote: Sat Jun 01, 2024 11:44 pm

Hello guys this script has a small but that i still don't how to fix it

so i run it, then i stop it in the middle of the operation, gui close right but mksquashfs still working in background

Code: Select all

kill $(cat /tmp/$$)

This is the line to work on. Maybe test your kill command or pkill. See if /tmp/$$ contains the correct process id. Maybe increase the sleepto 1 in this line

Code: Select all

( sleep 0.5; pgrep -n mksquashfs >/tmp/$$ ) &

Why astronauts use Linux
Because you can't open windows in space

User avatar
AntonioPt
Posts: 211
Joined: Wed Aug 11, 2021 7:41 pm
Has thanked: 92 times
Been thanked: 37 times

Re: dir2sfs - Yad version

Post by AntonioPt »

hello @stemsee i add it more time and still nutting i all so add in the case killall mksquashfs

Why astronauts use Linux
Because you can't open windows in space

User avatar
AntonioPt
Posts: 211
Joined: Wed Aug 11, 2021 7:41 pm
Has thanked: 92 times
Been thanked: 37 times

Re: dir2sfs - Yad version

Post by AntonioPt »

Found the anser @stemsee

New code should look like this or at least in LunarPup its working since now i can grab real info

Code: Select all

( sleep 0.5; pgrep -n mksquashfs >/tmp/$$ ) &
(script -q -c "stty rows 40 cols 100; mksquashfs "$1" "$1.sfs" $COMP" | \
while read -n 100 LINE; do echo $LINE | busybox strings | egrep '[0-9]\%' | \
awk '{print $NF}'; done & ) | result=($( yad --progress --center --undecorated --on-top \
--skip-taskbar --progress-text="$(gettext 'Building') $1.sfs $COMP" --borders="10" \
--text-align="center" --button="$(gettext 'Stop'):1" \
--buttons-layout="center" --auto-close ))
ret=$?
#  kill $(cat /tmp/$$)
case $ret in
 1) killall mksquashfs
   [[ -f "$1.sfs" ]] && rm -f $1.sfs
   [[ -f "$1.sfs-md5.txt" ]] && rm -f "$1.sfs-md5.txt";;
esac

Why astronauts use Linux
Because you can't open windows in space

User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: dir2sfs - Yad version

Post by stemsee »

that's not the best solution, because you might have another mksquashfs in progress!

Does your system have pgrep installed?

User avatar
AntonioPt
Posts: 211
Joined: Wed Aug 11, 2021 7:41 pm
Has thanked: 92 times
Been thanked: 37 times

Re: dir2sfs - Yad version

Post by AntonioPt »

stemsee wrote: Sat Jun 08, 2024 12:49 pm

that's not the best solution, because you might have another mksquashfs in progress!

Does your system have pgrep installed?

Sorry just Saw your post now and yes i have pgrep.
By the way since this machine is too slow i just can Run one mksquashsf at time but tell me a better way then

Why astronauts use Linux
Because you can't open windows in space

User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: dir2sfs - Yad version

Post by stemsee »

yes, your machine is slow so the mksquashfs command takes much longer to begin, so increase the sleep value to 4 or more seconds, so that mksquashfs is actually squashing files and has a process id to grab. But the script will never be changed for general use to 'killall mksquashfs'....of course you can make that change locally.

User avatar
AntonioPt
Posts: 211
Joined: Wed Aug 11, 2021 7:41 pm
Has thanked: 92 times
Been thanked: 37 times

Re: dir2sfs - Yad version

Post by AntonioPt »

OK small update

from my final code i change killall mksquashfs to original code kill $(cat /tmp/$$) in order to kill only this mksquashfs process and thxx for the Tip @stemsee

Code: Select all

case $ret in
 1)   kill $(cat /tmp/$$)
   [[ -f "$1.sfs" ]] && rm -f $1.sfs
   [[ -f "$1.sfs-md5.txt" ]] && rm -f "$1.sfs-md5.txt";;
esac

Why astronauts use Linux
Because you can't open windows in space

Post Reply

Return to “Utilities”