fixmenus 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/sh
  2. #v2.14 Puppy now has XDG menus.
  3. #this script builds the menus from template files.
  4. #Any templates can be placed into /etc/xdg/templates, and the file must be
  5. #named to show its final destination. For example, the template for JWM:
  6. # _root_.jwmrc
  7. #...the '_' will be converted to a '/', so the generated JWM config file is:
  8. # /root/.jwmrc
  9. # 5jan2008: fbpanel,lxpanel support developed by plinej.
  10. #100404 BK added 'variconlinks' for my fbpanel pkg.
  11. #100427 when called via /etc/rc.d/rc.update, HOME is '/' (needed by some of the menu generating apps).
  12. #120207 translation of some SSS strings. refer /usr/share/sss/menu_strings/
  13. #120208 fix in case this script gets called with LANG=C
  14. #120209 this script now called from /usr/sbin/quicksetup, whenever locale is changed.
  15. #120216 sss translation file now uses simple sed expressions.
  16. #120524 bug fix.
  17. #100427
  18. [ ! "$HOME" ] && HOME='/root'
  19. [ "$HOME" = "/" ] && HOME='/root'
  20. export HOME
  21. [ -f $HOME/.jwm/menuheights ] && . $HOME/.jwm/menuheights
  22. # remove csh shell files #precaution
  23. CSH=$(find /etc/profile.d -name *.csh)
  24. [ "$CSH" ] && rm /etc/profile.d/*.csh
  25. if [ "$LANG" = "C" ];then #120208
  26. LANG="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  27. export LANG
  28. fi
  29. LANG1="`echo -n $LANG | cut -f 1 -d '_'`" #120207 ex: de
  30. TEMPLATES="`ls -1 /etc/xdg/templates | tr '\n' ' '`"
  31. for ONETPL in $TEMPLATES #ex: _root_.jwmrc
  32. do
  33. [ "$ONETPL" = "README.txt" ] && continue
  34. ONEDEST="`echo -n "$ONETPL" | sed -e 's/_/\//g'`"
  35. ONESRC="/etc/xdg/templates/$ONETPL"
  36. echo "Generating $ONEDEST..."
  37. [ -f $ONEDEST ] && mv -f $ONEDEST ${ONEDEST}-previous
  38. cat $ONESRC |
  39. while read ONELINE
  40. do
  41. EXECMENU="`echo -n "$ONELINE" | grep -o 'PUPPYMENU.*' | cut -f 2-5 -d ' '`"
  42. if echo "$ONELINE" | grep -q "MENHEIGHT" ;then #131213 designed to be backward compatible
  43. [ "$MENHEIGHT" ] && echo $ONELINE | sed "s%MENHEIGHT%$MENHEIGHT%" >> $ONEDEST \
  44. || echo $ONELINE | sed "s%MENHEIGHT%24%" >> $ONEDEST
  45. elif [ "$EXECMENU" = "" ];then
  46. echo "$ONELINE" >> $ONEDEST
  47. else
  48. ${EXECMENU} ${MENHEIGHT} >> ${ONEDEST}
  49. fi
  50. done
  51. #120207 translate some strings... 120216...
  52. if [ "$LANG1" != "en" ];then
  53. if [ -f /usr/share/sss/menu_strings/menu_strings.${LANG1} ];then
  54. sPTN="/^\[${ONETPL}\]/,/^$/p" #this is a multi-line block find expression.
  55. 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.
  56. if [ "$CODEBLOCK" ];then
  57. echo "$CODEBLOCK" > /tmp/fixmenus-translationblock
  58. #121124 ensure that all [ ] are escaped... 121125 revert... 121126 restore, plus escape '.' chars...
  59. sed -i -e 's%\[%\\[%g' -e 's$\]$\\]$g' -e 's%\\\\\[%\\[%g' -e 's%\\\\\]%\\]%g' /tmp/fixmenus-translationblock
  60. 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.
  61. sed -i -f /tmp/fixmenus-translationblock ${ONEDEST}
  62. fi
  63. fi
  64. fi
  65. done
  66. #w001 support for fbpanel, lxpanel, openbox, fluxbox, pekwm...
  67. [ `which variconlinks` ] && variconlinks #100404 for my fbpanel pkg.
  68. [ `which tempicons` ] && tempicons
  69. [ `which fbpanel_menu_refresh` ] && fbpanel_menu_refresh
  70. [ `which lxpanel_menu_refresh` ] && lxpanel_menu_refresh
  71. [ `which jwm2fluxbox` ] && jwm2fluxbox ##current fluxbox_menu_refresh doesn't support menu icons while this does
  72. [ `which obmenu-refresh` ] && obmenu-refresh
  73. [ `which jwm2pekwm` ] && jwm2pekwm
  74. ###END###