Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 18 Oct 2017, 11:14
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to put a progress bar in dir2sfs? (Solved)
Post new topic   Reply to topic View previous topic :: View next topic
Page 2 of 3 [33 Posts]   Goto page: Previous 1, 2, 3 Next
Author Message
belham2

Joined: 15 Aug 2016
Posts: 1145

PostPosted: Mon 02 Oct 2017, 07:16    Post subject:  

Hi rg66 & Fred,

Ok, kind of a dunce question: rg66, can I just copy your script, put it in a blank text file, name it whatever (i.e. "squashingit.sh"), then "chmod +x ..." it, then grab an icon for it, and save it to a handy place (desktop?). Thus I'll then be able to drag ANY directory I was getting ready to squash and place it on top of the script, and PRESTO..the script will come to life squashing that directory without me doing anything else?

Sorry if the above is a noob question; I just want to make sure I understand so i can use it. I've been unsquashing and especially squashing a lot of stuff this past week (modifying sfs files), and this script would save me the headache of pounding the long command I use into the terminal.

Only thing I wonder, is this script or can this script, be modified to compress at max "xz"? I use (what you taught me, Fred) this following command always when I am re-squashing a SFS and I am looking for smallest size possible:

Code:

# mksquash dir-example 'new-sfs-name' -all-root -noappend -comp xz -b 1048576 -Xbcj x86


.....and for x86_64, I just add "_64" to the "x86" above (hope I am doing that correct)


Thanks, guys, for any feedback.
Back to top
View user's profile Send private message 
rg66


Joined: 23 Jul 2012
Posts: 1125
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

PostPosted: Mon 02 Oct 2017, 07:33    Post subject:  

phat7 wrote:

Almost all
Code:
if [ ! -d "$t" ];then
   echo "error: no valid folder specified!"
   exit 0
 fi


Yep, definitely missed that one. Here's a new copy with option to over write existing sfs.

Code:
#!/bin/bash

t=`echo "$1" | sed "s/\/$//"`
z=`echo "$1" | sed "s/\/$//"`

[ ! -d "$t" ] && exit

if [ -f "$z.sfs" ];then
  yad --window-icon="application-x-squashfs-image" --title="Overwrite" --text="<b>$(basename $z).sfs</b> already exists.\n Would you like to overwrite it?\n" \
  --text-align="center" --borders="10" --buttons-layout="center" --button="gtk-yes:0" --button="gtk-no:1"
  case $? in
    0) rm -f "$z.sfs" "$z.sfs-md5.txt" ;;
    *) exit ;;
  esac
fi

yad --window-icon="application-x-squashfs-image" --title "Choose Compression Type" --text "Choose which algorthim to compress the sfs with.
Choosing XZ will give you a smaller iso but may
be slower than GZIP on very lowspec machines.
XZ-HC is a higher compression xz squashfile." --text-align="center" --borders="5" --buttons-layout="center" \
--button="GZIP:0" --button="XZ:1" --button="XZ-HC:2"
case $? in
  0) COMP="-comp gzip" ;;
  1) COMP="-comp xz" ;;
  2) COMP="-comp xz -b 1024k -Xbcj x86" ;;
  *) exit ;;
esac

script -q -c "stty rows 40 cols 100; mksquashfs "$t" "$z.sfs" $COMP" | while read -n 99 LINE ; do
PROG=`echo $LINE | egrep '[0-9]\%' | cut -f1 -d% | awk '{print $NF}'| grep -v '\.'`
echo "#$PROG%"
echo $PROG
done | yad --window-icon="application-x-squashfs-image" --progress --borders="10" --skip-taskbar --text="<b>Building $t.sfs</b>\n" \
--text-align="center" --width="250" --button="Stop!gtk-stop!Stop operation:1" --buttons-layout="center" --auto-close 
case $? in
0) while [ "`pidof mksquashfs`" ]; do
   sleep .2
   done ;;
*) killall mksquashfs
   rm -f typescript
   exit ;; 
esac

rm -f typescript
md5sum "$z.sfs" > "$z.sfs-md5.txt"
sync

_________________
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
X-series repo
Back to top
View user's profile Send private message 
rg66


Joined: 23 Jul 2012
Posts: 1125
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

PostPosted: Mon 02 Oct 2017, 08:26    Post subject:  

belham2 wrote:
Hi rg66 & Fred,

Ok, kind of a dunce question: rg66, can I just copy your script, put it in a blank text file, name it whatever (i.e. "squashingit.sh"), then "chmod +x ..." it, then grab an icon for it, and save it to a handy place (desktop?). Thus I'll then be able to drag ANY directory I was getting ready to squash and place it on top of the script, and PRESTO..the script will come to life squashing that directory without me doing anything else?

Sorry if the above is a noob question; I just want to make sure I understand so i can use it. I've been unsquashing and especially squashing a lot of stuff this past week (modifying sfs files), and this script would save me the headache of pounding the long command I use into the terminal.

Only thing I wonder, is this script or can this script, be modified to compress at max "xz"? I use (what you taught me, Fred) this following command always when I am re-squashing a SFS and I am looking for smallest size possible:

Code:

# mksquash dir-example 'new-sfs-name' -all-root -noappend -comp xz -b 1048576 -Xbcj x86


.....and for x86_64, I just add "_64" to the "x86" above (hope I am doing that correct)


Thanks, guys, for any feedback.


I'm testing with the script on the desktop and dragging dirs onto it so it definitely works in Xfce.

Changing
Code:
2) COMP="-comp xz -b 1024k -Xbcj x86" ;;

to
Code:
2) COMP="-all-root -noappend -comp xz -b 1048576 -Xbcj x86" ;;

should do the trick.

I don't think x86_64 is an option.

"Available filters: x86, arm, armthumb, powerpc, sparc, ia64"

I think ia64 is for Intel Itanium and x86 works for both 32 and 64bit

_________________
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
X-series repo
Back to top
View user's profile Send private message 
misko_2083


Joined: 08 Nov 2016
Posts: 19

PostPosted: Mon 02 Oct 2017, 11:11    Post subject:  

Quote:
Code:
script -q -c "stty rows 40 cols 100; mksquashfs "$t" "$z.sfs" $COMP" | while read -n 99 LINE ; do
PROG=`echo $LINE | egrep '[0-9]\%' | cut -f1 -d% | awk '{print $NF}'| grep -v '\.'`
echo "#$PROG%"
echo $PROG
done | yad --window-icon="application-x-squashfs-image" --progress --borders="10" --skip-taskbar --text="<b>Building $t.sfs</b>\n" \
--text-align="center" --width="250" --button="Stop!gtk-stop!Stop operation:1" --buttons-layout="center" --auto-close

^this part has so many pipes.
Not sure what is invert match at the end grep -v '\.' doing.
Awk can do all of that.
Code:
script -q -c "stty rows 40 cols 100; mksquashfs "$t" "$z.sfs" $COMP" |
awk '/\[*\]*[0-9]\%/{print "#",$NF;gsub("%","");print $NF; fflush(stdout)}' |
yad --window-icon="application-x-squashfs-image" --progress --borders="10" --skip-taskbar --text="<b>Building $t.sfs</b>\n" \
--text-align="center" --width="250" --button="Stop!gtk-stop!Stop operation:1" --buttons-layout="center" --auto-close
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 2515
Location: holland

PostPosted: Mon 02 Oct 2017, 12:42    Post subject:  

belham2 wrote:
mksquash dir-example 'new-sfs-name' -all-root -noappend -comp xz -b 1048576 -Xbcj x86


Hi Belham,
As far as I understand, the "-all-root" option makes all files owned by root.
If so, I wouldn't recommend that option, because there may be sometimes (executable) files that needs to have other ownership, e.g. messagebus.
Better leave ownership of files as they are, I'd say.
(specially when re-squashing filesystem of Dog based distributions as they have /home/<user> owned by 'normal' user)

Fred
Back to top
View user's profile Send private message 
belham2

Joined: 15 Aug 2016
Posts: 1145

PostPosted: Mon 02 Oct 2017, 17:23    Post subject:  

Thank you, rg66 and Fred Wink I only learn stuff when guys like you post in these threads. Otherwise I'm my own worse enemy, as whether Im supposed to or not, I'll try everything left & right under the sun with the result I usually end up getting so lost I don't remember where I started Rolling Eyes . Thanks again.
Back to top
View user's profile Send private message 
rg66


Joined: 23 Jul 2012
Posts: 1125
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

PostPosted: Tue 03 Oct 2017, 00:46    Post subject:  

misko_2083 wrote:
Quote:
Code:
script -q -c "stty rows 40 cols 100; mksquashfs "$t" "$z.sfs" $COMP" | while read -n 99 LINE ; do
PROG=`echo $LINE | egrep '[0-9]\%' | cut -f1 -d% | awk '{print $NF}'| grep -v '\.'`
echo "#$PROG%"
echo $PROG
done | yad --window-icon="application-x-squashfs-image" --progress --borders="10" --skip-taskbar --text="<b>Building $t.sfs</b>\n" \
--text-align="center" --width="250" --button="Stop!gtk-stop!Stop operation:1" --buttons-layout="center" --auto-close

^this part has so many pipes.
Not sure what is invert match at the end grep -v '\.' doing.
Awk can do all of that.
Code:
script -q -c "stty rows 40 cols 100; mksquashfs "$t" "$z.sfs" $COMP" |
awk '/\[*\]*[0-9]\%/{print "#",$NF;gsub("%","");print $NF; fflush(stdout)}' |
yad --window-icon="application-x-squashfs-image" --progress --borders="10" --skip-taskbar --text="<b>Building $t.sfs</b>\n" \
--text-align="center" --width="250" --button="Stop!gtk-stop!Stop operation:1" --buttons-layout="center" --auto-close


That's how the script was originally (from Saluki I think), if I remove "grep -v '\.'", it flashes 47% after it reaches 100. Can't get a working progress bar from your awk line.

_________________
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
X-series repo
Back to top
View user's profile Send private message 
misko_2083


Joined: 08 Nov 2016
Posts: 19

PostPosted: Tue 03 Oct 2017, 06:31    Post subject:  

rg66 wrote:
Quote:
That's how the script was originally (from Saluki I think), if I remove "grep -v '\.'", it flashes 47% after it reaches 100. Can't get a working progress bar from your awk line.

Oh I see it must work without terminal.
If I add flush to the script this is working for me:
Code:
script --return --flush --quiet --command \
"stty rows 40 cols 100; mksquashfs "$t" "$z.sfs" $COMP" |
awk '/\[*\]*[0-9]\%/{print "#",$NF;gsub("%","");print $NF; fflush(stdout)}' |
yad --window-icon="application-x-squashfs-image" --progress --borders="10" --skip-taskbar --text="<b>Building $t.sfs</b>\n" \
--text-align="center" --width="250" --button="Stop!gtk-stop!Stop operation:1" --buttons-layout="center" --auto-close

It did not flash 47% after 100, yad dialog closes because of --auto-close.
i used a different regular expression to search for strings. That could be it.
awk /\[*\]*[0-9]\%/ vs egrep '[0-9]\%'
The progress looks like this:
Code:
     file ..., uncompressed size 2755336 bytes

     [=========\                                             ]   481/12359
   3%

     file ..., uncompressed size 726904 bytes

     [==========\                                            ]   528/12359
   4%

     file ..., uncompressed size 577 bytes

     [==============\                                        ]   719/12359
   5%

* script --return
-e, --return
Return the exit code of the child process. Uses the same format
as bash termination on signal termination exit code is 128+n.
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 2515
Location: holland

PostPosted: Tue 03 Oct 2017, 15:23    Post subject:  

misko_2083 wrote:
If I add flush to the script this is working for me:
Code:
script --return --flush --quiet --command \
"stty rows 40 cols 100; mksquashfs "$t" "$z.sfs" $COMP" |
awk '/\[*\]*[0-9]\%/{print "#",$NF;gsub("%","");print $NF; fflush(stdout)}' |
yad --window-icon="application-x-squashfs-image" --progress --borders="10" --skip-taskbar --text="<b>Building $t.sfs</b>\n" \
--text-align="center" --width="250" --button="Stop!gtk-stop!Stop operation:1" --buttons-layout="center" --auto-close


Tried that, but no progress is showing for me.

@rg66
Maybe you noticed also that the progress sometimes jumps back for a split second to under 10%, although not a real problem, but found that piping first to strings (or busybox strings) solves it:

Code:
echo $LINE | busybox strings |egrep '[0-9]\%' | cut -f1 -d% |awk '{print $NF}'|grep -v '\.'


Fred
Back to top
View user's profile Send private message 
rg66


Joined: 23 Jul 2012
Posts: 1125
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

PostPosted: Wed 04 Oct 2017, 01:04    Post subject:  

@misko_2083

Also tried your code and couldn't get a progress bar.

@fredx181

Yes, I have noticed it jumping back to 10 or whatever percent. I'll add the "busybox strings", stuff like that bugs me. I've also gone back to Xdialog, yad --auto-close closes the window before it's finished squashing where as Xdialog stays open.

Cheers!

_________________
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
X-series repo
Back to top
View user's profile Send private message 
rg66


Joined: 23 Jul 2012
Posts: 1125
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

PostPosted: Wed 04 Oct 2017, 01:24    Post subject:  

The strings addition really sorts things out, nice one Fred. The line can be only "echo $LINE | strings | egrep '[0-9]\%' | awk '{print $NF}'; done" and you get:
Code:
10%
10%
10%
14%
16%
18%
19%
20%
33%
51%
78%
100%
100%
100%
100%
100%
100%
100%
Kbytes)
bytes)
bytes)


My script is now:
Code:
#!/bin/bash

t=`echo "$1" | sed "s/\/$//"`
z=`echo "$1" | sed "s/\/$//"`

[ ! -d "$t" ] && exit

if [ -f "$z.sfs" ];then
  yad --window-icon="application-x-squashfs-image" --title="Overwrite" --text="<b>$(basename $z).sfs</b> already exists.\n Would you like to overwrite it?\n" \
  --text-align="center" --borders="10" --buttons-layout="center" --button="gtk-yes:0" --button="gtk-no:1"
  case $? in
    0) rm -f "$z.sfs" "$z.sfs-md5.txt" ;;
    *) exit ;;
  esac
fi

yad --window-icon="application-x-squashfs-image" --title "Choose Compression Type" --text "Choose which algorthim to compress the sfs with.
Choosing XZ will give you a smaller sfs but may
be slower than GZIP on very lowspec machines.
XZ-HC is a higher compression XZ squashfile." --text-align="center" --borders="5" --buttons-layout="center" \
--button="GZIP:0" --button="XZ:1" --button="XZ-HC:2"
case $? in
  0) COMP="-comp gzip" ;;
  1) COMP="-comp xz" ;;
  2) COMP="-comp xz -b 1024k -Xbcj x86" ;;
  *) exit ;;
esac

(script -q -c "stty rows 40 cols 100; mksquashfs "$t" "$z.sfs" $COMP" | while read -n 99 LINE ; do
echo $LINE | strings | egrep '[0-9]\%' | awk '{print $NF}'; done
) | Xdialog --title "Building Squashfile " --gauge "Building $(basename $z).sfs\n\nPlease Wait..." 7 50 0
if [ $? -ne 0 ]; then
  killall mksquashfs
  rm -f typescript
  exit
fi

rm -f typescript
md5sum "$z.sfs" > "$z.sfs-md5.txt"
sync


This also works for unsquashfs as well Very Happy

_________________
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
X-series repo
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 2515
Location: holland

PostPosted: Wed 04 Oct 2017, 08:34    Post subject:  

rg66 wrote:
My script is now:
...
...


OK! Nice working, simple script now.
I'd say that "busybox strings" would be better because not every distro has "strings"
(btw, that might go for "script" also, anyway for info: it's part of package "bsdutils" in Ubuntu and Debian)

Fred
Back to top
View user's profile Send private message 
rg66


Joined: 23 Jul 2012
Posts: 1125
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

PostPosted: Wed 04 Oct 2017, 08:57    Post subject:  

fredx181 wrote:
.I'd say that "busybox strings" would be better because not every distro has "strings"
(btw, that might go for "script" also, anyway for info: it's part of package "bsdutils" in Ubuntu and Debian)

Fred


OK, will change to busybox strings. I had to get script from slackware util-linux pkg as it's not included in slacko.

I've also got rid of the t=, z= and just went with $1 as I don't see the point of those as the version check is gone.I must have nothing better to do than play with this script, lol.

_________________
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
X-series repo
Back to top
View user's profile Send private message 
rg66


Joined: 23 Jul 2012
Posts: 1125
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

PostPosted: Wed 04 Oct 2017, 12:56    Post subject:  

Definitely my last one. Reverting back to "read -n 50 LINE" captures a lot more lines.
Code:
#!/bin/bash

[ ! -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"
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="gtk-yes:0" --button="gtk-no:1"
  case $? in
    0) rm -f "$1.sfs" "$1.sfs-md5.txt" ;;
    *) exit ;;
  esac
fi

yad --window-icon="application-x-squashfs-image" --title "Choose Compression Type" \
--text="XZ will give you a smaller sfs but may
be slower than GZIP on older machines.
XZ-HC is a higher compression XZ sfs." --text-align="center" --borders="10" --buttons-layout="center" \
--button="GZIP:0" --button="XZ:1" --button="XZ-HC:2"
case $? in
  0) COMP="-comp gzip" ;;
  1) COMP="-comp xz" ;;
  2) COMP="-comp xz -b 1024k -Xbcj x86" ;;
  *) exit ;;
esac

(script -q -c "stty rows 40 cols 100; mksquashfs "$1" "$1.sfs" $COMP" | while read -n 50 LINE ; do
echo $LINE | busybox strings | egrep '[0-9]\%' | awk '{print $NF}'; done
) | Xdialog --title "Building Squashfile " --gauge "Building $(basename $1).sfs\n\nPlease Wait..." 7 50 0
if [ $? -ne 0 ]; then
  killall mksquashfs
  rm -f typescript
  exit
fi

rm -f typescript
md5sum "$1.sfs" > "$1.sfs-md5.txt"
sync


Edit: I've added a pop-up warning for folders with white spaces just in case. Confused

_________________
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
X-series repo
Back to top
View user's profile Send private message 
belham2

Joined: 15 Aug 2016
Posts: 1145

PostPosted: Wed 04 Oct 2017, 15:50    Post subject:  

rg66 wrote:
Definitely my last one. Reverting back to "read -n 50 LINE" captures a lot more lines.

Edit: I've added a pop-up warning for folders with white spaces just in case. Confused



Hi rg66,

Am in X-Slacko-4.4 now, been testing this latest iteration of the script above for the last hour. Works nice! I put it on the desktop, and every folder I've dropped onto it (from different partitions even) works & up pops the dialog box, and away she goes. Progress bar works good too. Nice job!

I just have one question: you wrote this above in an earlier message:

Code:
This also works for unsquashfs as well  Very Happy


Am I misunderstanding? I dropped one of the newly created .sfs files on the script to test the unsquashfs capabilitiy, and the script does nothing.

Was/Is the script meant to do unsquashing too just by dropping a .sfs on it? (I don't see unsquashfs commands in the script, so was trying to figure out what you meant when you wrote "this also works for unsquashfs as well...very happy".



P.S. Just found something weird...in Micko's latest Slacko64 (700-r3), on another machine at my desk here, the script does nothing. It won't launch at all, even though it is set up the same way with the same permissions as in X-Slacko-4.4. Weird, as it should easily run in 64-bit slacko because it's only a script after all, right? Surprised
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 2 of 3 [33 Posts]   Goto page: Previous 1, 2, 3 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1774s ][ Queries: 14 (0.0332s) ][ GZIP on ]