| Author |
Message |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Sun 10 Oct 2010, 22:47 Post subject:
bashbox: multicall bash script Subject description: a bashified equivalent of busybox |
|
I have previously posted about a bash library - here
...and have posted several bash scripts in the past
Now I am combining them into a single script that works like busybox.
here is a list of currently implemented functions
If you have a function to add that isn't implemented please post it
addgroupgui() { #uses main_dialog() -> #addgroup [-g GID] [user_name] group_name
bashbox() { #todo make this more robust
blockads() { #tweaks /etc/hosts to ban certain sites
brokenlinks() { #find broken links in given input dir or pwd if not given
createlinks() { #make executable links for functions matching "()_{"
for x in `grep "() {" bashbox |cut -d"(" -f1 |grep -v " " |grep -v "#"` do ln -s bashbox $x; done
fixflash() { #mask your flash version as 10.1 rXXXXXX
getflash() { #install latest flash
getflash9() { #flash9 is smaller, fewer deps and still updated
getinput() { #DIALOG box to return user input to stdout
google() { #searches google for $@ or if blank uses $DIALOG
launcher() { #gtkdialog basic launcher program
main_dialog() { #parses template of vars to gen and eval a dialog then return the results
maindialogtemplate() {
percentbar() { #usage: "$0" XX% name=filename fgcolor=XXX bgcolor=XXX height=XXX width=XXX [vertical]
pget() { #download $1 to HOME/my-documents with axel
pickdate() { #choose a date - optional input: $1="text" $2=day $3=month $4=year
picktime() { #output a time - optional input: $1="text" $2=hours $3=minutes $4=seconds
pickfile() { #DIALOG box to return a user chosen file to stdout
pickXcolor() { #DIALOG box to return a user chosen X color to stdout
reset_mixers() { #from /usr/sbin/alsaconf... was called from rc.local0.
setDIALOG() { #sets $DIALOG to Xdialog if in X or dialog if in console
setjwmbg() { #TODO tweaks ... include $HOME/.jwmbg in the jwmrc template
setXCOLORS() { #sets $XCOLORS from ...rgb.txt
webcam2avi() { #capture your webcam to HOME/webcam.avi - requires ffmpeg & rxvt
X2avi() { #capture your desktop to HOME/x11-session.avi - ffmpeg needs x11grab
Xsetvolume() { #set volume with slider
Xshowimage() { #quick view of image
TODO partview2, mkinitrd, extractinitrd,...suggestions?
more TODO:
1)optimize/integrate puppy bash scripts/functions - replace with links
2)split off functions to compressed file that auto extracts on 1st run
3)make separate documentation file
4)more guis using main_dialog (integrated from my bbgui program)
5)suggestions?
About
1) each function tries to use other functions if possible - rather than duplicate code
2) functions are in alphabetical order to quickly find them
3) functions/comments are set up so that "folding" makes it easy to develop
Examples not yet implemented: | Code: | #optional description - TODO add $3 for compression type lzma, gz, etc
mkinitrd() { #creates initrd.gz from directory -usage: mkinitrd dir file
[ $2 == "" ] && echo usage: $0 directory /path/initrd.cpio.gz && exit 1
[ ! -d $1 ] && echo First argument must be a directory && exit 1
rm $2
cd $1
find . | cpio -o -H newc | gzip > $2
}
extractinitrd() { #extracts initrd.gz to directory -usage: extractinitrd dir file
[ $2 == "" ] && echo usage: $0 directory /path/initrd.cpio.gz && exit 1
[ ! -d $1 ] && echo First argument must be a directory && exit 1
cd $1
zcat $2 |cpio -id
} | posting here instead of additional softeware because I still consider it alpha/beta quality due to missing checks for bad input corner cases - please report any necessary fixes or additional functions
| Description |
|

Download |
| Filename |
bashbox-0.4.2.pet |
| Filesize |
6.21 KB |
| Downloaded |
370 Time(s) |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Last edited by technosaurus on Tue 15 Mar 2011, 12:07; edited 2 times in total
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Sun 10 Oct 2010, 23:18 Post subject:
|
|
some screenshots of the guis
and the example code:
| Code: | addgroupgui() { #uses main_dialog() -> #addgroup [-g GID] [user_name] group_name
DESCRIPTION="addgroup is a busybox builtin that allows you to manage groups on your system."
CBTT1="-S"
CBV1="Create a system group"
EBV1="user"
EBTT1="Enter the group"
NL1="F"
CBTT2="-g"
CBV2="Use a group ID"
EBV2="GID"
EBTT2="Enter the group ID"
MAX="2"
BBCOMMAND=addgroup
`main_dialog`
} |
Note: should move all functions to external file except bashbox and createlinks (they contain the "() {" that gets parsed for, so moving the rest out will simplify things ... and allow other scripts to include it using " . /usr/share/bashbox/bbfxns")
| Description |
|
| Filesize |
19.92 KB |
| Viewed |
1926 Time(s) |

|
| Description |
|
| Filesize |
15.1 KB |
| Viewed |
1788 Time(s) |

|
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
Lobster
Official Crustacean

Joined: 04 May 2005 Posts: 15109 Location: Paradox Realm
|
Posted: Mon 11 Oct 2010, 02:10 Post subject:
|
|
Hope to see this in Saluki (and used extensively) and other Puppys
Any code samples are great as a basis to hack from
I looked at the create an xpm file - that worked
- I may have a use for it
but don't quite get it
Could you provide sample gui code please?
things like
webcam2avi()
X2avi()
are of immense interest and potential
- just remember I can barely program a DVD recorder
and only just about realise what a function is
anyways:
Mic2mp3/mic2ogg
SendEmail
JoinIRCchannel
Check4DevX
CompileCode
would be a initial suggestions
If you look at early versions of precord (in wary I believe)
it was only two lines of code
that would be worth including
Many thanks
_________________ Puppy WIKI
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Mon 11 Oct 2010, 22:53 Post subject:
|
|
I just split off the functions and added Zigbert's external menu and Pprocess2 (as pprocess so that it doesn't conflict)
while I was at it I added 2 parameters to make the output more sane (ps -a / ps -u : to get just the running programs / running programs with more parameters)
I am trying to get the best parts of Zigbert's almost-hidden libraries in here and split them out into usable parts as I go.
Not sure the best gui style for the ffmpeg programs (X/webcam2avi) - maybe just set the directory and filename and open another dialog to play/convert etc...? ... crap I may need to add woo-ff to it, but I lost my latest version when I finally decided to wipe my last ntfs partition and the forum thread was deleted.... maybe I can port ffconvert instead
Edit:forgot to mention - added documentation in /usr/share/bashbox/bbdoc.sh - but I forgot to add this line to the end:
defaulttexteditor $0
| Description |
|

Download |
| Filename |
bashbox-0.4.9.pet |
| Filesize |
11.06 KB |
| Downloaded |
334 Time(s) |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Tue 12 Oct 2010, 00:01 Post subject:
|
|
added ffconvert-1.1-development-version (no code reductions yet)
added menu entries for pprocess and ffconvert
clicking on the documentation file (or running it will now open it in the defaulttexteditor)
| Description |
|

Download |
| Filename |
bashbox-0.5.0.pet |
| Filesize |
21.35 KB |
| Downloaded |
344 Time(s) |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
Flash
Official Dog Handler

Joined: 04 May 2005 Posts: 9843 Location: Arizona USA
|
Posted: Tue 12 Oct 2010, 00:42 Post subject:
|
|
Is Tree something that could be incorporated? I'm not sure what you're doing, so if that's a silly question just ignore it.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Tue 12 Oct 2010, 01:31 Post subject:
|
|
that one is in C but I rewrote it in bash (display only)
maybe it is better to echo to a file and then use less in case you have a really large tree? ... also ../ and ./ cornercases (needs full path or it only goes down one dir)
| Code: | #!/bin/sh
DIR=$1
[ $2 ] && SPACING=$2 || SPACING="|"
DIRSPACING="|"
while [ "${#DIRSPACING}" -lt "${#SPACING}" ]
do
DIRSPACING=${DIRSPACING}-
done
for x in `ls $DIR`; do
[ -d $DIR/$x ] && echo "$DIRSPACING-{"$x && tree $DIR/$x "$SPACING " || echo "$SPACING\`-"$x
done |
| Description |
|
| Filesize |
4.85 KB |
| Viewed |
1708 Time(s) |

|
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
Flash
Official Dog Handler

Joined: 04 May 2005 Posts: 9843 Location: Arizona USA
|
Posted: Tue 12 Oct 2010, 08:43 Post subject:
|
|
I use Tree to list the contents of the directory where all my mp3 books are. My mp3_books directory is arranged as in a library, with subdirectories of authors, and each author subdirectory containing subdirectories of mp3 books by that author. Finally, each mp3 book directory contains the mp3 audio files.
When I use Tree, I don't want it to display the actual files the books contain, only the directories. Mp3 audio books can contain hundreds of mp3 files, typically. Displaying those files wastes all the space on the screen for no purpose.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Tue 12 Oct 2010, 10:07 Post subject:
|
|
like this?
| Code: | tree(){ #display a graphical representation of a file tree from $1 with optional first character $2
DIR=$1
[ $2 ] && SPACING=$2 || SPACING="F"
DIRSPACING="D"
while [ "${#DIRSPACING}" -lt "${#SPACING}" ]
do
DIRSPACING=${DIRSPACING}-
done
for x in `ls $DIR`; do
[ -d $DIR/$x ] && echo "$DIRSPACING-{"$x && $0 $DIR/$x "$SPACING " || echo "$SPACING\`-"$x
done
}
dir_tree(){ #display a graphical representation of a directory tree from $1 with optional first character $2
DIR=$1
[ $2 ] && SPACING=$2 || SPACING="D"
for x in `ls $DIR`; do
[ -d $DIR/$x ] && echo "$SPACING\`-{"$x && $0 $DIR/$x "$SPACING "
done
} |
rather than using a file output within the function to be able to view large output you can just do something like this:
tree $DIR >/tmp/tree && COMMAND /tmp/tree
where COMMAND could be more, less, defaulttexteditor...
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Last edited by technosaurus on Tue 12 Oct 2010, 13:51; edited 2 times in total
|
|
Back to top
|
|
 |
Flash
Official Dog Handler

Joined: 04 May 2005 Posts: 9843 Location: Arizona USA
|
Posted: Tue 12 Oct 2010, 13:25 Post subject:
|
|
Well, I'm embarrassed to admit that I don't know how to try that out. I'll be happy to try it if you'll tell me how.
Here's an old post that shows what I mean. Each of the books in that list contains hundreds of mp3 files. Obviously, showing all the mp3 files would make the list all but useless for my purpose, which is to choose a book to listen to.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Tue 12 Oct 2010, 13:46 Post subject:
|
|
just save this into a script to test the dir_tree portion
| Code: | #!/bin/sh
DIR=$1
[ $2 ] && SPACING=$2 || SPACING="|"
for x in `ls $DIR`; do
[ -d $DIR/$x ] && echo "$SPACING\`-{"$x && $0 $DIR/$x "$SPACING "
done |
I haven't tested it myself since I'm not on a linux machine at the moment.
Edit: btw I think this could be considered an example of recursion in bash.
Here is a simplified one-liner for dirtree | Code: | #!/bin/sh
for x in `ls $1`; do [ -d $1/$x ] && echo "$2\`--{"$x && $0 $1/$x "$2 "; done | and for tree | Code: | #!/bin/sh
for x in `ls $1`; do [ -d $1/$x ] && echo "D$2\`-{"$x && $0 $1/$x "$2 |" || echo "F$2\`-<"$x; done | example usage:
tree . > tempfile & Xdialog --tailbox tempfile 0 0
I ported a tiny mp3 player to busybox that you may like - here is the thread http://www.murga-linux.com/puppy/viewtopic.php?t=59417
TODO - randomizer, Trash functions
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
Flash
Official Dog Handler

Joined: 04 May 2005 Posts: 9843 Location: Arizona USA
|
Posted: Tue 12 Oct 2010, 23:27 Post subject:
|
|
I opened a rxvt window in the mp3_books directory (by pressing the ` key to the left of the 1 key while in the mp3_books directory), copied the code above, pasted it into the rxvt window - and nothing happened. I suppose I should have first installed the bashbox .pet above? How do I open a bashbox console in the mp3_books directory?
Edit: The last line of code worked in rxvt, but not well.
Here's what it looked like: | Code: | # #!/bin/sh
# for x in `ls $1`; do [ -d $1/$x ] && echo "D$2\`-{"$x && $0 $1/$x "$2 |" || echo "F$2\`-<"$x; done
F`-<Benchley,
F`-<Peter
F`-<Borneman,
F`-<Walter
F`-<Carey,
F`-<Peter
F`-<Collins,
F`-<Gail
F`-<Conroy,
F`-<Pat
F`-<Fallada,
F`-<Hans
F`-<Farmer,
F`-<Philip
F`-<Jose
F`-<Farnsworth,
F`-<Christopher
F`-<Ferguson,
F`-<Niall
F`-<Grandin,
F`-<Greg
F`-<Hoeg,
F`-<Peter
F`-<Keillor,
F`-<Garrison
F`-<Matthiessen,
F`-<Peter
F`-<Pickard,
F`-<Nancy
F`-<Preston,
F`-<Douglas
F`-<Preston,
F`-<Douglas
F`-<and
F`-<Child,
F`-<Lincoln
F`-<Runyon,
F`-<Brent
F`-<Scottoline,
F`-<Lisa
F`-<Silko,
F`-<Leslie
F`-<Marmon
F`-<Steinhauer,
F`-<Olen
F`-<Thomas,
F`-<Evan
F`-<Truss,
F`-<Lynn
F`-<White,
F`-<Randy
F`-<Wayne
F`-<Zahn,
F`-<Timothy
# |
I tried to make minimp3 work but couldn't see how. I'm just a .pet, point-and-click man at heart.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Wed 13 Oct 2010, 09:19 Post subject:
|
|
they have to be run as scripts to work, because they recursively call themselves ($0 $1 & $2 are the inputs to the script), but your output indicates that you also need support for spaces in file names... next up auto-renaming function
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 5241 Location: Valåmoen, Norway
|
Posted: Wed 13 Oct 2010, 15:27 Post subject:
|
|
technosaurus
| Quote: | I added pprocess to my bashbox script - it went fairly smoothly & I even added a couple of parameters for different formatting, but still need to add the locales. (I am trying to consolidate as many functions as possible into a single script to ease development) Once we get everything together we can probably do some significant code reduction through code reuse (another bonus would be a unified look and feel).
Let me know what you think....or any other goodies you'd like to see added. Is there a reason you have separate files for your functions? |
Bashbox is an interesting attempt for further perfection. My personal experience with my lib-apps has some down-sides.
- I tried using the external-menu script in the latest Pmusic, but because of slow bash and gtkdialog, I ended up to hardcode the menus. A general menu-script will be most often slower than a built-from-scratch-script.
- Pfind, Pburn and Picker all uses Pfilesearch. My 'good' idea was to split the search-engine for wider use. The down-side is seen in Pburn when search-settings affect global file-search.
- Full effect of Bashbox, requires that Barry includes it in Woof. Else your script gets Bashbox as a dependency (it will anyway depend on it if used outside Puppy). This is the ever-lasting discussing of Perfection or Diversity.
- Please get me right. As I said, I think this is an interesting attempt. I hope you succeed....... Regardless, these script will be wonderful example of Bash code to 'steal' for other projects.
The use of a unique function-file is just my way of coding. The smaller projects like Pprocess would probably be cleaner if including functions in the main-file. Since all my projects has the same logistic, it is easy for me to navigate in my own code. In more complex code like Pburn and Pmusic it would be a coding hell to collect all functions in one file.
Sigmund
_________________ Stardust resources
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Wed 13 Oct 2010, 19:26 Post subject:
|
|
| zigbert wrote: | it would be a coding hell to collect all functions in one file.
Sigmund |
I always did it that way too until I figured out "folding", now it is my #1 requirement in an editor. To fold in geany just use Alt+D, F to fold and Alt+D, U to unfold (or use the Document menu)... sure beats having 20 tabs open and makes it easier to do a search for code
| Description |
the editing experience with folding |
| Filesize |
47.3 KB |
| Viewed |
1530 Time(s) |

|
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
|