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 Sat 18 Jan 2020, 09: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 3 of 4 [52 Posts]   Goto page: Previous 1, 2, 3, 4 Next
Author Message
rg66


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

PostPosted: Wed 04 Oct 2017, 16:46    Post subject:  

belham2 wrote:
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


Sorry belham2, I meant the code will also work with the unsquashfs command.

I've updated pac-tools with the new progress bar (attached below, just remove fake .gz and make sure it's executable) put it in /usr/bin. You can select as many sfs's as you want (as long as /tmp has enough space to extract them) and right click > repack-extract packages > extract. You can also put the new dir2sfs in /sbin and right click multiple folders > Convert to sfs. The right click options are in X-series and Carolina.

Slacko64 (700-r3) probably doesn't have yad so the script will fail. Also check if it has the script command, if not, download slackware util-linux from the repo.

Edit: pac-tools had a few typo's do to a sed accident Shocked, I've uploaded a new one, see below.
pac-tools.gz
Description  remove fake .gz
gz

 Download 
Filename  pac-tools.gz 
Filesize  5.16 KB 
Downloaded  171 Time(s) 

_________________
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
X-series repo

Last edited by rg66 on Fri 06 Oct 2017, 01:12; edited 1 time in total
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4249
Location: holland

PostPosted: Wed 04 Oct 2017, 17:47    Post subject:  

Hi Belham, here's sfs2dir, basically the same as the last dir2sfs from rg66, but the other way around.
Unsquashes to directory name, same as the name of .sfs (but without the .sfs extension)

Code:
#!/bin/bash

[ ! -f "$1" ] && exit
DIR="${1%.*}"

if [ "$(echo "$1" | wc -w)" -gt 1 ]; then
  yad --window-icon="application-x-squashfs-image" --title="Rename File" --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 [ -d "$DIR" ];then
  yad --window-icon="application-x-squashfs-image" --title="Overwrite" --text="<b>$(basename $DIR)</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 -rf "$DIR" ;;
    *) exit ;;
  esac
fi

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

rm -f typescript
sync


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


Joined: 18 May 2008
Posts: 4872
Location: Blue Springs, MO

PostPosted: Thu 12 Oct 2017, 00:00    Post subject:  

goingnuts and I did a progress bar implementation for tar here ... could probably be adapted
_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
slavvo67

Joined: 12 Oct 2012
Posts: 1617
Location: The other Mr. 305

PostPosted: Sat 23 Dec 2017, 11:12    Post subject:  

So if you don't have the script command, I guess you're out of luck?
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14714
Location: Gatineau (Qc), Canada

PostPosted: Sat 23 Dec 2017, 13:52    Post subject:  

Hi all.

I still think you guys are foillowing the principle: "Why do simple when you can do
complicated!" A couple of lines of poetry are in order, I think:
Quote:
"As I see you guys go,
My love for console grows."

Really! Smile

As a reminder:
http://murga-linux.com/puppy/viewtopic.php?p=969545&sort=lastpost#969545

Where is the world heading?! Laughing

Merrry Christmas to all.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
phat7

Joined: 05 Jun 2015
Posts: 164

PostPosted: Sun 24 Dec 2017, 01:20    Post subject:  

slavvo67 wrote:
So if you don't have the script command, I guess you're out of luck?
No, you are lucky. You can ignore all this.
musher0 has a point.
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2572
Location: In The Way

PostPosted: Mon 21 Oct 2019, 15:10    Post subject:  

Hi all

This was just what I was looking for!

Up until this point the other versions didn't allow me to have several working at the same time, not sure why.

I have made some modifications and the yad version is my preferred version.

stemsee
xscreenshot-20191021T200553.png
 Description   
 Filesize   6.56 KB
 Viewed   196 Time(s)

xscreenshot-20191021T200553.png

Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2572
Location: In The Way

PostPosted: Mon 21 Oct 2019, 16:08    Post subject:  

The only problem I have is that with --auto-close we don't see the progress bar reach the end. Without --auto-close we have to manually close the yad gui. either by getting focus and pressing Esc key, or using the Stop button.

It would be great to get the 100 exported so some monitoring loop could kill the yad when 100 has been detected, but I couldn't do it.

stemsee
dir2sfs.gz
Description  rename to dir2sfs
gz

 Download 
Filename  dir2sfs.gz 
Filesize  1.74 KB 
Downloaded  47 Time(s) 
Back to top
View user's profile Send private message MSN Messenger 
rockedge


Joined: 11 Apr 2012
Posts: 1447
Location: Connecticut, United States

PostPosted: Mon 21 Oct 2019, 19:06    Post subject:  

@stemsee

I tried out the script on WeeDog (Void Linux) and it works perfectly.
Back to top
View user's profile Send private message Visit poster's website 
stemsee

Joined: 27 Jun 2013
Posts: 2572
Location: In The Way

PostPosted: Tue 22 Oct 2019, 05:03    Post subject:  

Thanks for confirming report @rockedge
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2572
Location: In The Way

PostPosted: Tue 22 Oct 2019, 05:56    Post subject:  

Now I made the script give defaults for overwrite and compression options. And in case of using Stop to interrupt, the partially created sfs is removed.
Code:
if [ -f "$1.sfs" ];then
  DO=$(yad --window-icon="application-x-squashfs-image" --title="Overwrite" --text="<b>$(basename $1).sfs</b> already exists.\n Would you like to overwrite or rename it?\n" \
  --text-align="center" --borders="10" --buttons-layout="center" --button="gtk-yes:1" --button="gtk-no:0" --center --timeout 2)

  case $DO in
    0|252) exit ;;
    70|1) rm -f "$1.sfs" "$1.sfs-md5.txt" ;;
  esac
fi
Code:
--button="GZIP:0" --button="XZ:1" --button="XZ-HC:2" --center --timeout 2
[[ $? == "" ]] && $?="1"
case $? in
  0) COMP="-comp gzip" ;;
  1) COMP="-comp xz" ;;
  2) COMP="-comp xz -b 1024k -Xbcj x86" ;;
  *) exit ;;
esac
Code:
if [ $? -ne 0 ]; then
  rm -f "$1.sfs"
  killall mksquashfs
  kill $PID
  rm -f typescript
  exit
fi


However killall mksquashfs is not ideal in case you have more than one mksquashfs job running! We need to target the specific mksquashfs process id! Or by getting the time each process started we can use ps -e | grep mksquashfs, time running to determine which process to kill.

EDIT: Maybe we can assign the pid for each mksquashfs process.
Code:
echo "$((RANDOM))" >/tmp/$1

Code:
cat  /tmp/$1 > /proc/sys/kernel/ns_last_pid; mksquashfs

Code:
kill $(cat /tmp/$1)
dir2sfs.gz
Description  rename to dir2sfs, copy to /usr/local/bin, make executable cli 'chmod 755 /usr/local/bin/dir2sfs'
gz

 Download 
Filename  dir2sfs.gz 
Filesize  1.76 KB 
Downloaded  43 Time(s) 
Back to top
View user's profile Send private message MSN Messenger 
rufwoof


Joined: 24 Feb 2014
Posts: 3710

PostPosted: Tue 22 Oct 2019, 10:44    Post subject:  

I'd suggest including lz4 compression also. Very fast (but relatively poor compression). lz4 -Xhc tends to be more like gzip for compression, but is slower (relatively speaking), so not really worth including that IMO when gzip is available (unless you want very fast decompression also), just the standard lz4 ... for its speed. lzo -Xcompression-level 1 is a alternative, not as quick, but relatively quick ... and more commonly available (lzop is in busybox for instance).

Re killing. I know you can get a process name for a pid using the comm= parameter

# ps -p 2523 -o comm=
geany

maybe something along those lines might be used??

_________________
( ͡° ͜ʖ ͡°) :wq
Fatdog multi-session usb

echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2572
Location: In The Way

PostPosted: Tue 22 Oct 2019, 18:46    Post subject:  

Hi rufwoof

can you provide a scripted example of your ps * comm= command? I could not use it as is.

Added lz4.

I found a way to catch the mksquashfs pid by time, but I cannot now get the script to kill it.

Code:
time=$(date | awk '{print $4}')  # unique time label

( sleep 1; ps -e | grep mksquashfs | tail -1 | awk '{print $1}' >/tmp/$time; exit ) & # delay and catch the last mksquashfs pid and store in file

(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"  --borders="10" \
--text-align="center" --button="gtk-stop:0" \
--buttons-layout="center" --auto-close

if [[ $? -eq 0 ]]; then
  pd=$(cat /tmp/$time) # read file for pid
  kill $pd
  rm -f "$1.sfs"
  rm -f "$1.sfs-md5.txt"
  rm -f typescript
  exit
fi
Back to top
View user's profile Send private message MSN Messenger 
rufwoof


Joined: 24 Feb 2014
Posts: 3710

PostPosted: Tue 22 Oct 2019, 19:20    Post subject:  

Maybe its different under Fatdog (proper/full Linux) ??

For instance if I run galculator and put it into the background, it shows pid 4550 was used. If I then run ps -p 4550 -o comm= ... then it returns the name i.e. galculator.
Quote:
# galculator &
[1] 4550
# ps -p 4550 -o comm=
galculator
#

Does that do similar for you?

If you use args= instead, then it shows both the command and arguments. Starting geany /mnt/sdb1/menu.lst for instance
Quote:
# geany /mnt/sdb1/menu.lst &
[1] 4899
# ps -p 4899 -o comm=
geany
# ps -p 4899 -o args=
geany /mnt/sdb1/menu.lst
#


Another approach might be to bring the relevant backgrounded task to the foreground and kill that (i.e. normal fg, bg, jobs commands)

# jobs
[1]+ Running geany /mnt/sdb1/menu.lst &
#
# fg %1
... and geany becomes the active window/task

or kill %1 ... to kill it.

With mksquashfs it does use multi-cores, but running mksquashfs /usr usr.sfs & and then I can run jobs and see its [2] and fg %2 brings that to the front and I can ctrl-c end it and all cores (child) tasks also closed. When doing that interactively however you get the mksquashfs progress bars ticking away between running the commands unless you direct that to /dev/null.

You can select jobs by the first few characters of the string

galculator &
fg %gal

or via a string within the command line, so if you were mksquashfs /usr ... and mksquashfs /lib64 ... then you could foreground (or kill) the mksquashfs /lib one by using fg %?lib ... i.e. ?lib matches the substring lib contained within the command line.

_________________
( ͡° ͜ʖ ͡°) :wq
Fatdog multi-session usb

echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh

Last edited by rufwoof on Tue 22 Oct 2019, 20:31; edited 1 time in total
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2572
Location: In The Way

PostPosted: Tue 22 Oct 2019, 20:20    Post subject:  

Cracked it!

I got it working with specific mksquashfs process IDs. And lz4 option.

Probably there is a better way.

stemsee
dir2sfs.gz
Description  fake .gz
gz

 Download 
Filename  dir2sfs.gz 
Filesize  2 KB 
Downloaded  37 Time(s) 
Back to top
View user's profile Send private message MSN Messenger 
Display posts from previous:   Sort by:   
Page 3 of 4 [52 Posts]   Goto page: Previous 1, 2, 3, 4 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.0787s ][ Queries: 13 (0.0173s) ][ GZIP on ]