pinstall.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/bin/sh
  2. #Barry Kauler, Feb. 2012. GPL3 (/usr/share/doc/legal)
  3. #this is the post-install script for a langpack PET created by /usr/sbin/momanager.
  4. #MoManager will replace the strings TARGETLANG and POSTINSTALLMSG.
  5. #120315 maybe have hunspell dictionaries in langpack.
  6. #120830 improved symlinks to hunspell dictionaries.
  7. #120924 DejaVu font no good for non-Latin languages. 120925 add korean.
  8. #120926 translate Comment field in .desktop file. note: applications.in now handled in /usr/local/petget/installpkg.sh.
  9. #120927 L18L requested if there is already a translation in .desktop, remove it, replace with one from langpack.
  10. #121011 L18L requested call to extra hacks script.
  11. #130503 L18L: merge AppInfo.xml.in with AppInfo.xml
  12. #130503 L18L: langpack may be different from current LANG setting. fixed.
  13. echo "Post install script for TARGETLANG language pack"
  14. LANG="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  15. export LANG
  16. LANG1="`cat pet.specs | cut -d'-' -f1 | cut -d'_' -f2-`" #130503 L18L: langpack may be different from current LANG setting.
  17. if [ -d usr/share/applications.in ];then #refer: /usr/sbin/momanager
  18. for ADESKTOPFILE in `find usr/share/applications.in -mindepth 1 -maxdepth 1 -type f -name '*.desktop' | tr '\n' ' '`
  19. do
  20. ABASEDESKTOP="`basename $ADESKTOPFILE`"
  21. ADIRDESKTOP=''
  22. [ -f usr/share/applications/${ABASEDESKTOP} ] && ADIRDESKTOP='usr/share/applications'
  23. [ ! "$ADIRDESKTOP" ] && [ -f usr/local/share/applications/${ABASEDESKTOP} ] && ADIRDESKTOP='usr/local/share/applications'
  24. if [ "$ADIRDESKTOP" ];then
  25. if [ "`grep '^Name\[TARGETLANG\]' usr/share/applications.in/${ABASEDESKTOP}`" != "" ];then
  26. if [ "`grep '^Name\[TARGETLANG\]' ${ADIRDESKTOP}/${ABASEDESKTOP}`" != "" ];then
  27. #120927 L18L requested if there is already a translation, remove it, replace with one from langpack.
  28. grep -v '^Name\[TARGETLANG\]' ${ADIRDESKTOP}/${ABASEDESKTOP} > /tmp/momanager-pinstall-sh-desktop
  29. mv -f /tmp/momanager-pinstall-sh-desktop ${ADIRDESKTOP}/${ABASEDESKTOP}
  30. fi
  31. #aaargh, these accursed back-slashes! ....
  32. INSERTALINE="`grep '^Name\[TARGETLANG\]' usr/share/applications.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
  33. sed -i -e "s%^Name=%${INSERTALINE}\\nName=%" ${ADIRDESKTOP}/${ABASEDESKTOP}
  34. fi
  35. #120926 do same for Comment field...
  36. if [ "`grep '^Comment\[TARGETLANG\]' usr/share/applications.in/${ABASEDESKTOP}`" != "" ];then
  37. if [ "`grep '^Comment\[TARGETLANG\]' ${ADIRDESKTOP}/${ABASEDESKTOP}`" != "" ];then
  38. #120927 L18L requested if there is already a translation, remove it, replace with one from langpack.
  39. grep -v '^Comment\[TARGETLANG\]' ${ADIRDESKTOP}/${ABASEDESKTOP} > /tmp/momanager-pinstall-sh-desktop
  40. mv -f /tmp/momanager-pinstall-sh-desktop ${ADIRDESKTOP}/${ABASEDESKTOP}
  41. fi
  42. #aaargh, these accursed back-slashes! ....
  43. INSERTALINE="`grep '^Comment\[TARGETLANG\]' usr/share/applications.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
  44. sed -i -e "s%^Comment=%${INSERTALINE}\\nComment=%" ${ADIRDESKTOP}/${ABASEDESKTOP}
  45. fi
  46. fi
  47. done
  48. fi
  49. if [ -d usr/share/desktop-directories.in ];then
  50. for ADESKTOPFILE in `find usr/share/desktop-directories.in -mindepth 1 -maxdepth 1 -type f -name '*.directory' | tr '\n' ' '`
  51. do
  52. ABASEDESKTOP="`basename $ADESKTOPFILE`"
  53. if [ -f usr/share/desktop-directories/${ABASEDESKTOP} ];then
  54. if [ "`grep '^Name\[TARGETLANG\]' usr/share/desktop-directories/${ABASEDESKTOP}`" = "" ];then
  55. if [ "`grep '^Name\[TARGETLANG\]' usr/share/desktop-directories.in/${ABASEDESKTOP}`" != "" ];then
  56. #aaargh, these accursed back-slashes! ....
  57. INSERTALINE="`grep '^Name\[TARGETLANG\]' usr/share/desktop-directories.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
  58. sed -i -e "s%^Name=%${INSERTALINE}\\nName=%" usr/share/desktop-directories/${ABASEDESKTOP}
  59. fi
  60. fi
  61. fi
  62. done
  63. rm -r -f usr/share/desktop-directories.in
  64. fi
  65. #130503 L18L: merge AppInfo.xml.in with AppInfo.xml
  66. for AFILE in `ls -1 usr/local/apps/*/AppInfo.xml.in | tr '\n' ' '`
  67. do
  68. XMLFILE="`echo $AFILE|rev|cut -d'.' -f2- | rev`"
  69. SUMMARY="`grep \<Summary\> $AFILE`" # ex: '<Summary>Trash<Summary>'
  70. oldSUMMARY=`grep "\<Summary\ xml\:lang\=\"$LANG1" $XMLFILE` # ex: '<Summary xml:lang="de">Muell<Summary>'
  71. mySUMMARY=`grep "\<Summary\ xml\:lang\=\"${LANG1}" $AFILE` # ex: '<Summary xml:lang="de">Müll<Summary>'
  72. [ "$mySUMMARY" ] || continue
  73. sed -ie "/Summary\ xml\:lang\=\"${LANG1}/d" $XMLFILE # delete translation
  74. sed -ie "s#${SUMMARY}#${SUMMARY}\n${mySUMMARY}#" $XMLFILE # insert it
  75. # the Labels now
  76. sed -ie "/Label\ xml\:lang\=\"${LANG1}/d" $XMLFILE # delete all translations of Label
  77. #find <Label>s and <Label xml:lang=$LANG1>
  78. grep '<Label>' $AFILE > /tmp/appinfoLABLE
  79. grep '<Label xml:lang=\"'${LANG1} $AFILE > /tmp/appinfoXMLLABLE
  80. N=0;
  81. while read LINE
  82. do
  83. N=$(($N + 1));echo $N
  84. LABEL="`head -n $N /tmp/appinfoLABLE | tail -n 1`" # is N th line
  85. sed -ie "s#${LABEL}#${LABEL}\n${LINE}#" $XMLFILE # insert translation
  86. done < /tmp/appinfoXMLLABLE
  87. done
  88. rm /tmp/appinfoLABLE /tmp/appinfoXMLLABLE
  89. echo "...merge AppInfo.xml.in with AppInfo.xml finished"
  90. #120830 improved...
  91. if [ -d ./usr/share/hunspell ];then
  92. for ONEHUN in `find ./usr/share/hunspell -mindepth 1 -maxdepth 1 -type f -name '*.dic' -o -name '*.aff' | tr '\n' ' '`
  93. do
  94. HUNBASE="`basename $ONEHUN`"
  95. DICTDIRS="`find ./usr/lib -mindepth 2 -maxdepth 2 -type d -name dictionaries | tr '\n' ' '`"
  96. for ONEDICTDIR in $DICTDIRS
  97. do
  98. [ ! -e ${ONEDICTDIR}/${HUNBASE} ] && ln -s ../../../share/hunspell/${HUNBASE} ${ONEDICTDIR}/${HUNBASE}
  99. done
  100. done
  101. fi
  102. #120924 DejaVu font no good for non-Latin languages...
  103. #see also similar code in /usr/local/petget/hacks-postinstall.sh.
  104. LANGPACKLANG=TARGETLANG
  105. case $LANGPACKLANG in
  106. zh*|ja*|ko*) #chinese, japanese, korean
  107. sed -i -e 's%DejaVu Sans%Sans%' ./etc/xdg/templates/_root_*
  108. if [ -d ./root/.jwm ];then
  109. sed -i -e 's%DejaVu Sans%Sans%' ./root/.jwm/themes/*-jwmrc
  110. sed -i -e 's%DejaVu Sans%Sans%' ./root/.jwm/jwmrc-theme
  111. fi
  112. [ -d ./etc/xdg/openbox ] && sed -i -e 's%DejaVu Sans%Sans%' ./etc/xdg/openbox/*.xml
  113. [ -d ./root/.config/openbox ] && sed -i -e 's%DejaVu Sans%Sans%' ./root/.config/openbox/*.xml
  114. GTKRCFILE="$(find ./usr/share/themes -type f -name gtkrc | tr '\n' ' ')"
  115. for ONEGTKRC in $GTKRCFILE
  116. do
  117. sed -i -e 's%DejaVu Sans%Sans%' $ONEGTKRC
  118. done
  119. if [ -d ./root/.mozilla ];then
  120. MOZFILE="$(find ./root/.mozilla -type f -name prefs.js -o -name '*.css' | tr '\n' ' ')"
  121. for ONEMOZ in $MOZFILE
  122. do
  123. sed -i -e 's%DejaVu Sans%Sans%' $ONEMOZ
  124. done
  125. fi
  126. ;;
  127. esac
  128. if [ "`pwd`" = "/" ];then #installing PET in a running puppy.
  129. if [ "$LANG1" != "en" ];then
  130. #need to update SSS translations...
  131. fixscripts
  132. fixdesk
  133. fixmenus
  134. [ -r /pinstall_hacks.sh ] && . /pinstall_hacks.sh #121011 L18L
  135. pupdialog --background green --backtitle "Language Pack" --msgbox "POSTINSTALLMSG" 0 0 &
  136. fi
  137. fi