another uci mounter


Forum: Programming and Scripting
Topic: another uci mounter
started by: mikshaw

Posted by mikshaw on Oct. 19 2006,19:04
I made this one simply for aesthetic reasons.  It fits nicely with dwm or wmii, since it uses dmenu or wmiimenu
Code Sample
# uci.dmenu, mikshaw 2006
# Uses dmenu (dwm.suckless.org) to display and [u]mount uci packages

PREFIX="/home/dsl/mydsl" # where are your uci files
DMENU='dmenu -font snap -normbg #000000 -normfg #666666 -selbg #222222 -selfg #888888' # wmiimenu works too
PACKAGELIST=`find $PREFIX/ -name "*.uci"` # find all *.uci files in $PREFIX

showmenu() {
for i in $PACKAGELIST; do
TMPNAME=`basename $i .uci` # shows only the package name for a clean, compact display
if grep "$i " /etc/mtab &>/dev/null; then
 echo "*$TMPNAME" # asterisk on mounted files
else
 echo "$TMPNAME"
fi
done | sort | $DMENU
}

PKG=`showmenu|sed 's/\*//'` # run showmenu() and remove asterisks from stdout
for i in $PACKAGELIST; do # find the selected item string in the list
if [ "`basename $i .uci`" == "$PKG" ]; then FNAME="$i"; break; fi
done
[ -r "$FNAME" ] && mydsl-load "$FNAME"


EDIT: changed it to display only the package name in dmenu, without the filename extension.

Posted by mikshaw on Oct. 20 2006,16:46
Code Sample
#!/bin/bash

# uci.dmenu, mikshaw 2006
# Uses dmenu (dwm.suckless.org) to display and [u]mount uci packages
#
# changelog (yyyy.mm.dd)
#  2006.10.20: Added optional check for mydsl boot code and mydsl commandline param
#              Exit if PACKAGELIST is empty
#              Added non-recursive search option
#  2006.10.19: Stripped prefix and suffix from packagename display

PREFIX="/home/dsl/mydsl" # where are your uci files
DMENU='dmenu -font snap -normbg #000000 -normfg #666666 -selbg #222222 -selfg #888888' # wmiimenu works too
NOR=""

for i in $@; do
case $1 in
h|-h|-help|--help)
cat << EOF
 Options:
   -b, b      Use "mydsl=" boot option, if available
   -n, n      No recursive search
   directory  Path to a MyDSL directory
EOF
exit 0
;;
b|-b)
# use "mydsl=" boot option for PREFIX (overrides the PREFIX variable above)
# based on Robert's mydsl code in /etc/init.d/dsl-config, minus the automounting
 source /etc/init.d/dsl-functions
 CMDLINE=`cat /proc/cmdline`
 MYDSL=`getbootparam mydsl`
 MYDSL_DEVICE="${MYDSL%%/*}"
 MYDSL_DIR="${MYDSL#*/}"
 if [ "$MYDSL_DEVICE" = "$MYDSL_DIR" ]; then MYDSL_DIR=""; fi
 find_mountpoint "$MYDSL_DEVICE"
 [ -d "$MOUNTPOINT/$MYDSL_DIR" ] && PREFIX="$MOUNTPOINT/$MYDSL_DIR"
 shift
;;
n|-n)
 NOR=1
 shift
;;
*)
 [ -d "$1" ] && PREFIX="$1"
 shift
;;
esac
done

if [ -n "$NOR" ]; then
FIND="ls $PREFIX/*.uci"
else
FIND="find $PREFIX/ -name *.uci"
fi
PACKAGELIST=`$FIND 2>/dev/null` # find all *.uci files in $PREFIX
#PACKAGELIST=`find $PREFIX/ -name "*.uci" 2>/dev/null` # find all *.uci files in $PREFIX
[ -z "$PACKAGELIST" ]  && exit

showmenu() {
for i in $PACKAGELIST; do
TMPNAME=`basename $i .uci` # shows only the package name for a clean, compact display
if grep "$i " /etc/mtab &>/dev/null; then
 echo "*$TMPNAME" # asterisk on mounted files
else
 echo "$TMPNAME"
fi
done | sort | $DMENU
}

PKG=`showmenu|sed 's/\*//'` # run showmenu() and remove asterisks from stdout
for i in $PACKAGELIST; do # find the selected item string in the list
if [ "`basename $i .uci`" == "$PKG" ]; then FNAME="$i"; break; fi
done
[ -r "$FNAME" ] && mydsl-load "$FNAME"

EDIT: added options for non-recursive search and use of "mydsl=" boot code

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.