home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / fixmenus < prev    next >
Encoding:
Text File  |  2005-09-15  |  5.6 KB  |  165 lines

  1. #!/bin/sh
  2. #a central place to process a keyword in menus.
  3. #called by /etc/rc.d/rc.update,
  4. #pinstall.sh scripts in fvwm95-, jwm-, icewm-, 0rootfs_skeleton- Unleashed pkgs,
  5. #/usr/sbin/createpuppyonline, /usr/sbin/pupget.
  6.  
  7. #thanks to papaschtroumpf for help speeding up the menu processing.
  8.  
  9. #G2 Notes:
  10. #path-prefix does not need to include subdir .icewm
  11. #eg. to change /root/.icewm/menu, set path-prefix to /root
  12. #sed finds <space or tab>prog<space> or <space or tab>#prog<space>
  13. #is there a char for any whitespace, like \s ??
  14. #is the keyword delimited by certain chars? ... like "\"Foo333\ "?
  15. #eg. if the keyword is Foo1 then
  16. #it will find Foo1, Foo11, XFoo123 ... <anything>Foo1<anything>
  17.  
  18. #USAGE:
  19. #two passed params expected (third is optional):
  20. # fixmenus <path-root-prefix> +|-<keyword>
  21. #for example:
  22. # fixmenus /mnt/home/puppy/puppy-unleashed/rootfs-complete/root0 +Gnumeric
  23. # ...means activate menu entries with Gnumeric keyword.
  24. #the path-prefix is prepended to these paths:
  25. # /.jwmrc
  26. # /.fvwm95rc
  27. # /.index.html
  28. #that last one is a place-holder for /usr/share/doc/index.html
  29. #the path-prefix may also be relative to current directory.
  30.  
  31. #allow for an optional third param, to select just one menu to fix...
  32. #values are fvwm95, jwm, icewm, index
  33.  
  34. DESTROOT="$1"
  35. AKEYWORD="`echo -n "$2" | cut -b 2-99`"
  36. if [ "`echo -n "$2" | cut -b 1`" = '-' ];then
  37.  MENUTODO="remove"
  38. else
  39.  if [ "`echo -n "$2" | cut -b 1`" = '+' ];then
  40.   MENUTODO="add"
  41.  else
  42.   MENUTODO="add"
  43.   AKEYWORD="$2" #no + or - prefix.
  44.  fi
  45. fi
  46. ONEMENU="fvwm95 jwm icewm index"
  47. if [ $3 ];then
  48.  ONEMENU="$3"
  49. fi
  50.  
  51. if [ "$MENUTODO" = "add" ];then #uncomment menu entry with keyword.
  52.  
  53.  if [ ! "`echo "$ONEMENU" | grep "fvwm95"`" = "" ];then
  54.    if [ -f $DESTROOT/.fvwm95rc ];then
  55.     APATTERN="s/#+ \"$AKEYWORD/+ \"$AKEYWORD/g"
  56.     echo -e "Updating keyword \"$AKEYWORD\" in Fvwm95 window manager menu..."
  57.     cat $DESTROOT/.fvwm95rc | sed -e "$APATTERN" > /tmp/DOTfvwm95rc
  58.     sync
  59.     cp -f /tmp/DOTfvwm95rc $DESTROOT/.fvwm95rc #make ready for next keyword.
  60.    fi
  61.  fi
  62.  
  63.  if [ ! "`echo "$ONEMENU" | grep "jwm"`" = "" ];then
  64.    #JWM is more difficult...
  65.    if [ -f $DESTROOT/.jwmrc ];then
  66.     echo -e "Updating keyword \"$AKEYWORD\" in JWM menu..."
  67.     BPATTERN="s/^<!-- \+\(<Program label=\"$AKEYWORD.\+\)-->/\1/" #looking format label="PackageName
  68.     sed -e "$BPATTERN" $DESTROOT/.jwmrc > /tmp/DOTjwmrc
  69.     sync
  70.     cp -f /tmp/DOTjwmrc $DESTROOT/.jwmrc
  71.    fi
  72.  fi
  73.  
  74.  if [ ! "`echo "$ONEMENU" | grep "icewm"`" = "" ];then
  75.    if [ -f $DESTROOT/.icewm/menu ];then
  76.     APATTERN="s/\t#prog \"$AKEYWORD/\tprog \"$AKEYWORD/g"
  77.     APATTERN2="s/ #prog \"$AKEYWORD/ prog \"$AKEYWORD/g"
  78.     APATTERN3="s/^#prog \"$AKEYWORD/prog \"$AKEYWORD/g"
  79.     echo -e "Updating keyword \"$AKEYWORD\" in Icewm window manager menu..."
  80.     cat $DESTROOT/.icewm/menu | sed -e "$APATTERN" -e "$APATTERN2" -e "$APATTERN3" > /tmp/DOTicemenu
  81.     sync
  82.     cp -f /tmp/DOTicemenu $DESTROOT/.icewm/menu #make ready for next keyword.
  83.    fi
  84.  fi
  85.  
  86.  if [ ! "`echo "$ONEMENU" | grep "index"`" = "" ];then
  87.    #also do the help index...
  88.    #this is different as index.html is not in /root, its in /usr.
  89.    #it has to be copied to $DESTROOT/.index.html before calling fixmenus, copied back after.
  90.    if [ -f $DESTROOT/.index.html ];then
  91.     echo -e "Updating keyword \"$AKEYWORD\" in main help page..."
  92.     CPATTERN="s/^<!--\(.\+$AKEYWORD.\+\)-->/\1/"
  93.     sed -e "$CPATTERN" $DESTROOT/.index.html > /tmp/DOTindex.html
  94.     sync
  95.     cp -f /tmp/DOTindex.html $DESTROOT/.index.html
  96.    fi
  97.  fi
  98.  
  99.  sync
  100.  exit
  101. fi
  102.  
  103. if [ "$MENUTODO" = "remove" ];then #comment-out menu entry with keyword.
  104.  
  105.  if [ ! "`echo "$ONEMENU" | grep "fvwm95"`" = "" ];then
  106.       if [ -f $DESTROOT/.fvwm95rc ];then
  107.        APATTERN="s/^+ \"$AKEYWORD/#+ \"$AKEYWORD/g"
  108.        cat $DESTROOT/.fvwm95rc | sed -e "$APATTERN" > /tmp/DOTfvwm95rc
  109.        sync
  110.        cp -f /tmp/DOTfvwm95rc $DESTROOT/.fvwm95rc
  111.       fi
  112.  fi
  113.  
  114.  if [ ! "`echo "$ONEMENU" | grep "jwm"`" = "" ];then
  115.       #JWM is more difficult...
  116.       if [ -f $DESTROOT/.jwmrc ];then
  117.        BPATTERN="s/\(^<Program label=\"$AKEYWORD.\+\)/<!-- \1 -->/g"
  118.        cat $DESTROOT/.jwmrc | sed -e "$BPATTERN" > /tmp/DOTjwmrc
  119.        sync
  120.        cp -f /tmp/DOTjwmrc $DESTROOT/.jwmrc
  121.       fi
  122.  fi
  123.  
  124.  if [ ! "`echo "$ONEMENU" | grep "icewm"`" = "" ];then
  125.       if [ -f $DESTROOT/.icewm/menu ];then
  126.        APATTERN="s/\tprog \"$AKEYWORD/\t#prog \"$AKEYWORD/g"
  127.        APATTERN2="s/ prog \"$AKEYWORD/ #prog \"$AKEYWORD/g"
  128.        APATTERN3="s/^prog \"$AKEYWORD/#prog \"$AKEYWORD/g"
  129.        cat $DESTROOT/.icewm/menu | sed -e "$APATTERN" -e "$APATTERN2" -e "$APATTERN3" > /tmp/DOTicemenu
  130.        sync
  131.        cp -f /tmp/DOTicemenu $DESTROOT/.icewm/menu
  132.       fi
  133.  fi
  134.  
  135.  if [ ! "`echo "$ONEMENU" | grep "index"`" = "" ];then
  136.       #also do the help index...
  137.       if [ -f $DESTROOT/.index.html ];then
  138.        NUMLINES=`wc -l $DESTROOT/.index.html | tr -s " " | cut -f 2 -d " "`
  139.        echo -n "" > /tmp/DOCindex.html
  140.        REDUCELIST="`cat $DESTROOT/.index.html`"
  141.        while [ ! $NUMLINES -eq 0 ];do
  142.         HEAD1ST="`echo "$REDUCELIST" | head -n 1`"
  143.         NUMLINES=`expr $NUMLINES - 1`
  144.         REDUCELIST="`echo -n "$REDUCELIST" | tail -n $NUMLINES`"
  145.         if [ "`echo "$HEAD1ST" | grep "<\!\-\- "`" = "" ];then #check already commented out.
  146.          BPATTERN=">${AKEYWORD}" #looking for format >ProgName
  147.          if [ "`echo "$HEAD1ST" | grep "$BPATTERN"`" = "" ];then
  148.           echo "$HEAD1ST" >> /tmp/DOCindex.html
  149.          else
  150.           echo -n '<!-- ' >> /tmp/DOCindex.html
  151.           echo -n "$HEAD1ST" >> /tmp/DOCindex.html
  152.           echo ' -->'  >> /tmp/DOCindex.html
  153.          fi
  154.         else
  155.          echo "$HEAD1ST" >> /tmp/DOCindex.html
  156.         fi
  157.         sync
  158.        done
  159.        cp -f /tmp/DOCindex.html $DESTROOT/.index.html
  160.       fi
  161.  fi
  162.  
  163. fi
  164.  
  165.