home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #a central place to process a keyword in menus.
- #called by /etc/rc.d/rc.update,
- #pinstall.sh scripts in fvwm95-, jwm-, icewm-, 0rootfs_skeleton- Unleashed pkgs,
- #/usr/sbin/createpuppyonline, /usr/sbin/pupget.
-
- #thanks to papaschtroumpf for help speeding up the menu processing.
-
- #G2 Notes:
- #path-prefix does not need to include subdir .icewm
- #eg. to change /root/.icewm/menu, set path-prefix to /root
- #sed finds <space or tab>prog<space> or <space or tab>#prog<space>
- #is there a char for any whitespace, like \s ??
- #is the keyword delimited by certain chars? ... like "\"Foo333\ "?
- #eg. if the keyword is Foo1 then
- #it will find Foo1, Foo11, XFoo123 ... <anything>Foo1<anything>
-
- #USAGE:
- #two passed params expected (third is optional):
- # fixmenus <path-root-prefix> +|-<keyword>
- #for example:
- # fixmenus /mnt/home/puppy/puppy-unleashed/rootfs-complete/root0 +Gnumeric
- # ...means activate menu entries with Gnumeric keyword.
- #the path-prefix is prepended to these paths:
- # /.jwmrc
- # /.fvwm95rc
- # /.index.html
- #that last one is a place-holder for /usr/share/doc/index.html
- #the path-prefix may also be relative to current directory.
-
- #allow for an optional third param, to select just one menu to fix...
- #values are fvwm95, jwm, icewm, index
-
- DESTROOT="$1"
- AKEYWORD="`echo -n "$2" | cut -b 2-99`"
- if [ "`echo -n "$2" | cut -b 1`" = '-' ];then
- MENUTODO="remove"
- else
- if [ "`echo -n "$2" | cut -b 1`" = '+' ];then
- MENUTODO="add"
- else
- MENUTODO="add"
- AKEYWORD="$2" #no + or - prefix.
- fi
- fi
- ONEMENU="fvwm95 jwm icewm index"
- if [ $3 ];then
- ONEMENU="$3"
- fi
-
- if [ "$MENUTODO" = "add" ];then #uncomment menu entry with keyword.
-
- if [ ! "`echo "$ONEMENU" | grep "fvwm95"`" = "" ];then
- if [ -f $DESTROOT/.fvwm95rc ];then
- APATTERN="s/#+ \"$AKEYWORD/+ \"$AKEYWORD/g"
- echo -e "Updating keyword \"$AKEYWORD\" in Fvwm95 window manager menu..."
- cat $DESTROOT/.fvwm95rc | sed -e "$APATTERN" > /tmp/DOTfvwm95rc
- sync
- cp -f /tmp/DOTfvwm95rc $DESTROOT/.fvwm95rc #make ready for next keyword.
- fi
- fi
-
- if [ ! "`echo "$ONEMENU" | grep "jwm"`" = "" ];then
- #JWM is more difficult...
- if [ -f $DESTROOT/.jwmrc ];then
- echo -e "Updating keyword \"$AKEYWORD\" in JWM menu..."
- BPATTERN="s/^<!-- \+\(<Program label=\"$AKEYWORD.\+\)-->/\1/" #looking format label="PackageName
- sed -e "$BPATTERN" $DESTROOT/.jwmrc > /tmp/DOTjwmrc
- sync
- cp -f /tmp/DOTjwmrc $DESTROOT/.jwmrc
- fi
- fi
-
- if [ ! "`echo "$ONEMENU" | grep "icewm"`" = "" ];then
- if [ -f $DESTROOT/.icewm/menu ];then
- APATTERN="s/\t#prog \"$AKEYWORD/\tprog \"$AKEYWORD/g"
- APATTERN2="s/ #prog \"$AKEYWORD/ prog \"$AKEYWORD/g"
- APATTERN3="s/^#prog \"$AKEYWORD/prog \"$AKEYWORD/g"
- echo -e "Updating keyword \"$AKEYWORD\" in Icewm window manager menu..."
- cat $DESTROOT/.icewm/menu | sed -e "$APATTERN" -e "$APATTERN2" -e "$APATTERN3" > /tmp/DOTicemenu
- sync
- cp -f /tmp/DOTicemenu $DESTROOT/.icewm/menu #make ready for next keyword.
- fi
- fi
-
- if [ ! "`echo "$ONEMENU" | grep "index"`" = "" ];then
- #also do the help index...
- #this is different as index.html is not in /root, its in /usr.
- #it has to be copied to $DESTROOT/.index.html before calling fixmenus, copied back after.
- if [ -f $DESTROOT/.index.html ];then
- echo -e "Updating keyword \"$AKEYWORD\" in main help page..."
- CPATTERN="s/^<!--\(.\+$AKEYWORD.\+\)-->/\1/"
- sed -e "$CPATTERN" $DESTROOT/.index.html > /tmp/DOTindex.html
- sync
- cp -f /tmp/DOTindex.html $DESTROOT/.index.html
- fi
- fi
-
- sync
- exit
- fi
-
- if [ "$MENUTODO" = "remove" ];then #comment-out menu entry with keyword.
-
- if [ ! "`echo "$ONEMENU" | grep "fvwm95"`" = "" ];then
- if [ -f $DESTROOT/.fvwm95rc ];then
- APATTERN="s/^+ \"$AKEYWORD/#+ \"$AKEYWORD/g"
- cat $DESTROOT/.fvwm95rc | sed -e "$APATTERN" > /tmp/DOTfvwm95rc
- sync
- cp -f /tmp/DOTfvwm95rc $DESTROOT/.fvwm95rc
- fi
- fi
-
- if [ ! "`echo "$ONEMENU" | grep "jwm"`" = "" ];then
- #JWM is more difficult...
- if [ -f $DESTROOT/.jwmrc ];then
- BPATTERN="s/\(^<Program label=\"$AKEYWORD.\+\)/<!-- \1 -->/g"
- cat $DESTROOT/.jwmrc | sed -e "$BPATTERN" > /tmp/DOTjwmrc
- sync
- cp -f /tmp/DOTjwmrc $DESTROOT/.jwmrc
- fi
- fi
-
- if [ ! "`echo "$ONEMENU" | grep "icewm"`" = "" ];then
- if [ -f $DESTROOT/.icewm/menu ];then
- APATTERN="s/\tprog \"$AKEYWORD/\t#prog \"$AKEYWORD/g"
- APATTERN2="s/ prog \"$AKEYWORD/ #prog \"$AKEYWORD/g"
- APATTERN3="s/^prog \"$AKEYWORD/#prog \"$AKEYWORD/g"
- cat $DESTROOT/.icewm/menu | sed -e "$APATTERN" -e "$APATTERN2" -e "$APATTERN3" > /tmp/DOTicemenu
- sync
- cp -f /tmp/DOTicemenu $DESTROOT/.icewm/menu
- fi
- fi
-
- if [ ! "`echo "$ONEMENU" | grep "index"`" = "" ];then
- #also do the help index...
- if [ -f $DESTROOT/.index.html ];then
- NUMLINES=`wc -l $DESTROOT/.index.html | tr -s " " | cut -f 2 -d " "`
- echo -n "" > /tmp/DOCindex.html
- REDUCELIST="`cat $DESTROOT/.index.html`"
- while [ ! $NUMLINES -eq 0 ];do
- HEAD1ST="`echo "$REDUCELIST" | head -n 1`"
- NUMLINES=`expr $NUMLINES - 1`
- REDUCELIST="`echo -n "$REDUCELIST" | tail -n $NUMLINES`"
- if [ "`echo "$HEAD1ST" | grep "<\!\-\- "`" = "" ];then #check already commented out.
- BPATTERN=">${AKEYWORD}" #looking for format >ProgName
- if [ "`echo "$HEAD1ST" | grep "$BPATTERN"`" = "" ];then
- echo "$HEAD1ST" >> /tmp/DOCindex.html
- else
- echo -n '<!-- ' >> /tmp/DOCindex.html
- echo -n "$HEAD1ST" >> /tmp/DOCindex.html
- echo ' -->' >> /tmp/DOCindex.html
- fi
- else
- echo "$HEAD1ST" >> /tmp/DOCindex.html
- fi
- sync
- done
- cp -f /tmp/DOCindex.html $DESTROOT/.index.html
- fi
- fi
-
- fi
-
-