lang2initrd 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler 2012. License: GPL3 (/usr/share/doc/legal)
  3. #this script called from /usr/sbin/quicksetup, /usr/bin/wmreboot, wmpoweroff.
  4. #passed in params: $NEWLANG
  5. #120401 change logic to modify init (see also quicksetup).
  6. #121124 ensure that all [ ] are escaped in initrd translation-file. see also /usr/sbin/fixdesk, fixmenus.
  7. #121125 revert 121124.
  8. #121126 restore 121124, plus escape '.' chars in regex.
  9. export TEXTDOMAIN=lang2initrd
  10. export OUTPUT_CHARSET=UTF-8
  11. . gettext.sh
  12. . /etc/rc.d/PUPSTATE
  13. NEWLANG=$1
  14. LANG1="`echo -n $NEWLANG | cut -f 1 -d '_'`" #ex: de
  15. LANG12="`echo -n $NEWLANG | cut -f 1 -d '.'`" #ex: de_DE
  16. #various reasons for not doing it...
  17. case $PDEV1 in
  18. sr*) exit 1 ;;
  19. esac
  20. [ "$DEV1FS" = "iso9660" ] && exit 1
  21. if [ "$PLANG" ];then #120401
  22. PLANG1="${PLANG%_*}" #defined in PUPSTATE by initrd. ex: de
  23. PLANG12="${PLANG%.*}" #ex: de_DE
  24. [ "$PLANG" = "$NEWLANG" ] && exit 1 #initrd already in this language.
  25. else
  26. [ "$LANG1" = "en" ] && exit 1
  27. fi
  28. [ ! -d /initrd ] && exit 1 #dir exists, then puppy booted up with an initrd.
  29. INITRANS=''
  30. [ -f /usr/share/sss/initrd_strings/initrd_strings.${LANG12} ] && INITRANS="/usr/share/sss/initrd_strings/initrd_strings.${LANG12}"
  31. [ ! "$INITRANS" ] && [ -f /usr/share/sss/initrd_strings/initrd_strings.${LANG1} ] && INITRANS="/usr/share/sss/initrd_strings/initrd_strings.${LANG1}"
  32. [ "$INITRANS" ] && TRANSLANG="`echo -n "$INITRANS" | rev | cut -f 1 -d '.' | rev`" #120401
  33. [ "$LANG1" != "en" ] && [ ! "$INITRANS" ] && exit 1 #120401
  34. [ "$LANG1" = "en" ] && TRANSLANG='en' #120401
  35. if [ "$DISPLAY" ];then
  36. pupdialog --background '#FF80FF' --colors --backtitle "$(gettext 'Early boot messages')" --yesno "$(gettext 'Do you want to translate the early boot messages? These are in what is known as the initrd or initramfs, when the Linux operating system (kernel) is first loading. It is usually good to answer yes here.')
  37. $(gettext 'They will be translated to:') ${NEWLANG}" 0 0
  38. else
  39. dialog --yesno "$(gettext 'Do you want to translate the early boot messages? These are in what is known as the initrd or initramfs, when the Linux operating system (kernel) is first loading. It is usually good to answer yes here.')
  40. $(gettext 'They will be translated to:') ${NEWLANG}" 0 0 >/dev/console
  41. fi
  42. if [ $? -ne 0 ];then
  43. echo "DECLINED ${DISTRO_IDSTRING}" >> /var/local/lang2initrd.log #variable in /etc/DISTRO_SPECS
  44. exit 2
  45. fi
  46. #locate the initrd.gz and open it up...
  47. #try and figure out where the initrd.gz is... (init script doesn't know)
  48. #this is an assumption, GRUB can specify elsewhere... these variables are in PUPSTATE...
  49. INITRDPART="$PDEV1"
  50. INITRDFS="$DEV1FS"
  51. INITRDSPEC="${PSUBDIR}/initrd.gz"
  52. iniPTN="^/dev/${INITRDPART} "
  53. INITRDMNT="`mount | grep "$iniPTN" | cut -f 3 -d ' '`"
  54. if [ ! "$INITRDMNT" ];then
  55. mkdir -p /mnt/$INITRDPART
  56. mount -t $INITRDFS /dev/$INITRDPART /mnt/$INITRDPART
  57. if [ $? -eq 0 ];then
  58. INITRDMNT="/mnt/$INITRDPART"
  59. FLAGINIUNMOUNT='yes'
  60. fi
  61. fi
  62. if [ "$INITRDMNT" ];then
  63. if [ -f ${INITRDMNT}${INITRDSPEC} ];then
  64. cp -a -f ${INITRDMNT}${INITRDSPEC} /root
  65. CURRDIR="`pwd`"
  66. [ -d /root/initrd-tree ] && rm -rf /root/initrd-tree
  67. [ -f /root/initrd ] && rm -f /root/initrd
  68. mkdir /root/initrd-tree
  69. cd /root
  70. gunzip initrd.gz
  71. if [ $? -eq 0 ];then
  72. cd initrd-tree
  73. cat ../initrd | cpio -i -d -m
  74. if [ "$TRANSLANG" = "en" ];then #120401
  75. rm -f PUPPYLANG
  76. rm -f PUPPYKEYMAP
  77. else
  78. echo -n "$NEWLANG" > PUPPYLANG #file /PUPPYLANG in initrd sets default LANG.
  79. [ -f /etc/keymap ] && cat /etc/keymap > PUPPYKEYMAP #120216 also useful in initrd.
  80. #might need to update the translation files in initrd also (was done by 3builddistro)...
  81. INITRDTRANSFILES="`find /usr/share/sss/initrd_strings -mindepth 1 -maxdepth 1 -type f -name 'initrd_strings.*'`"
  82. if [ "$INITRDTRANSFILES" ];then
  83. for ATRANS in $INITRDTRANSFILES
  84. do
  85. ENDBIT="`echo -n "$ATRANS" | rev | cut -f 1 -d '.' | rev`" #ex: de (from initrd_strings.de)
  86. mkdir -p locale/${ENDBIT}
  87. #only supporting translating the init script for now...
  88. sPTN="/^\[init\]/,/^$/p" #this is a multi-line block find expression.
  89. CODEBLOCK="`sed -n "$sPTN" ${ATRANS} | sed -e '/^#/d' -e '/%%/d' -e '/^$/d' -e '/^\[/d'`" #extracts just the relevant block of lines.
  90. echo "$CODEBLOCK" > locale/${ENDBIT}/init #translation file, read by /init script in initrd.
  91. #121124 ensure that all [ ] are escaped... 121125 revert... 121126 restore, plus escape '.' chars...
  92. sed -i -e 's%\[%\\[%g' -e 's$\]$\\]$g' -e 's%\\\\\[%\\[%g' -e 's%\\\\\]%\\]%g' locale/${ENDBIT}/init
  93. sed -i -e 's%\.%\\.%g' -e 's%\\\\\.%\\.%g' locale/${ENDBIT}/init #note: 2nd ptn gets rid of prior escape char, so there remains just one.
  94. done
  95. fi
  96. fi
  97. sync
  98. #now put the initrd.gz back together again...
  99. rm -f ../initrd
  100. find . | cpio -o -H newc | gzip -9 > ../initrd.gz
  101. sync
  102. cd ..
  103. rm -rf initrd-tree
  104. cp -a -f initrd.gz ${INITRDMNT}${INITRDSPEC}
  105. sync
  106. rm -f initrd.gz
  107. [ "$FLAGINIUNMOUNT" = "yes" ] && umount ${INITRDMNT}
  108. FLAGINISUCCESS='yes'
  109. fi
  110. cd $CURRDIR
  111. fi
  112. fi
  113. if [ "$FLAGINISUCCESS" = "yes" ];then
  114. INIMSG="`eval_gettext \"The file \Zbinitrd.gz\ZB (at \\\${INITRDSPEC} on \\\${INITRDPART}) has been successfully translated to language \Zb\\\${NEWLANG}\ZB. You will see the effect at the next boot. Warning: Puppy thinks that this is the correct initrd.gz used at bootup, although it is possible that a boot manager such as GRUB can specify an alternate location, which means that the wrong initrd.gz file has been translated!\"`"
  115. BACKCOLOR='#80FF80'
  116. #keep a record that have done it...
  117. echo "SUCCESS ${DISTRO_IDSTRING}" >> /var/local/lang2initrd.log #variable in /etc/DISTRO_SPECS
  118. else
  119. INIMSG="`eval_gettext \"Sorry, something went wrong, was unable to translate file \Zbinitrd.gz\ZB (at \\\${INITRDSPEC} on \\\${INITRDPART}). A possible reason for this is that initrd.gz is located somewhere else, specified by a boot manager such as GRUB.\"`"
  120. BACKCOLOR='#FF8080'
  121. fi
  122. if [ $DISPLAY ];then
  123. pupdialog --background ${BACKCOLOR} --colors --backtitle "$(gettext 'Initrd translation')" --msgbox "${INIMSG}" 0 0
  124. else
  125. dialog --colors --msgbox "${INIMSG}" 0 0 >/dev/console
  126. fi
  127. ###END###