s243a

Puppylinux script fixmenus

Oct 13th, 2014
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.39 KB | None | 0 0
  1. The following script is located at: /usr/sbin
  2. find out more here: http://www.pearltrees.com/s243a/fixmenus-puppylinux-script/id12764017
  3.  
  4.  
  5. #!/bin/sh
  6. #v2.14 Puppy now has XDG menus.
  7. #this script builds the menus from template files.
  8. #Any templates can be placed into /etc/xdg/templates, and the file must be
  9. #named to show its final destination. For example, the template for JWM:
  10. # _root_.jwmrc
  11. #...the '_' will be converted to a '/', so the generated JWM config file is:
  12. # /root/.jwmrc
  13. # 5jan2008: fbpanel,lxpanel support developed by plinej.
  14. #100404 BK added 'variconlinks' for my fbpanel pkg.
  15. #100427 when called via /etc/rc.d/rc.update, HOME is '/' (needed by some of the menu generating apps).
  16. #120207 translation of some SSS strings. refer /usr/share/sss/menu_strings/
  17. #120208 fix in case this script gets called with LANG=C
  18. #120209 this script now called from /usr/sbin/quicksetup, whenever locale is changed.
  19. #120216 sss translation file now uses simple sed expressions.
  20. #120524 bug fix.
  21. #121124 ensure that all [ ] are escaped. see also /usr/sbin/fixdesk, lang2initrd.
  22. #121125 revert 121124.
  23. #121126 restore 121124, plus escape '.' chars in regex.
  24.  
  25. #100427
  26. [ ! "$HOME" ] && HOME='/root'
  27. [ "$HOME" = "/" ] && HOME='/root'
  28. export HOME
  29.  
  30. if [ "$LANG" = "C" ];then #120208
  31.  LANG="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  32.  export LANG
  33. fi
  34. LANG1="`echo -n $LANG | cut -f 1 -d '_'`"  #120207 ex: de
  35.  
  36. TEMPLATES="`ls -1 /etc/xdg/templates | tr '\n' ' '`"
  37.  
  38. for ONETPL in $TEMPLATES #ex: _root_.jwmrc
  39. do
  40.  [ "$ONETPL" = "README.txt" ] && continue
  41.  ONEDEST="`echo -n "$ONETPL" | sed -e 's/_/\//g'`"
  42.  ONESRC="/etc/xdg/templates/$ONETPL"
  43.  echo "Generating $ONEDEST..."
  44.  
  45.  [ -f $ONEDEST ] && mv -f $ONEDEST ${ONEDEST}-previous
  46.  
  47.  cat $ONESRC |
  48.  while read ONELINE
  49.  do
  50.   EXECMENU="`echo -n "$ONELINE" | grep -o 'PUPPYMENU.*' | cut -f 2-5 -d ' '`"
  51.   if [ "$EXECMENU" = "" ];then
  52.    echo "$ONELINE" >> $ONEDEST
  53.   else
  54.    ${EXECMENU} >> ${ONEDEST}
  55.   fi
  56.  done
  57.  
  58.  #120207 translate some strings... 120216...
  59.  if [ "$LANG1" != "en" ];then
  60.   if [ -f /usr/share/sss/menu_strings/menu_strings.${LANG1} ];then
  61.    sPTN="/^\[${ONETPL}\]/,/^$/p" #this is a multi-line block find expression.
  62.    CODEBLOCK="`sed -n "$sPTN" /usr/share/sss/menu_strings/menu_strings.${LANG1} | sed -e '/^#/d' -e '/%%/d' -e '/^$/d' -e '/^\[/d'`" #extracts just the relevant block of lines.
  63.    if [ "$CODEBLOCK" ];then
  64.     echo "$CODEBLOCK" > /tmp/fixmenus-translationblock
  65.     #121124 ensure that all [ ] are escaped... 121125 revert... 121126 restore, plus escape '.' chars...
  66.     sed -i -e 's%\[%\\[%g' -e 's$\]$\\]$g' -e 's%\\\\\[%\\[%g' -e 's%\\\\\]%\\]%g' /tmp/fixmenus-translationblock
  67.     sed -i -e 's%\.%\\.%g' -e 's%\\\\\.%\\.%g' /tmp/fixmenus-translationblock #note: 2nd ptn gets rid of prior escape char, so there remains just one.
  68.     sed -i -f /tmp/fixmenus-translationblock ${ONEDEST}
  69.    fi
  70.   fi
  71.  fi
  72.  
  73. done
  74.  
  75. #w001 support for fbpanel, lxpanel, openbox, fluxbox, pekwm...
  76. [ `which variconlinks` ] && variconlinks #100404 for my fbpanel pkg.
  77. [ `which tempicons` ] && tempicons
  78. [ `which fbpanel_menu_refresh` ] && fbpanel_menu_refresh
  79. [ `which lxpanel_menu_refresh` ] && lxpanel_menu_refresh
  80. [ `which jwm2fluxbox` ] && jwm2fluxbox  ##current fluxbox_menu_refresh doesn't support menu icons while this does
  81. [ `which obmenu-refresh` ] && obmenu-refresh
  82. [ `which jwm2pekwm` ] && jwm2pekwm
  83.  
  84. ###END###
Advertisement
Add Comment
Please, Sign In to add comment