3 # Copyright (c) 2010 iXsystems, Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 # Functions which runs commands on the system
30 . ${BACKEND}/functions.sh
31 . ${BACKEND}/functions-parse.sh
34 # Function which localizes a FreeBSD install
37 sed -i.bak "s/lang=en_US/lang=${LOCALE}/g" ${FSMNT}/etc/login.conf
38 rm ${FSMNT}/etc/login.conf.bak
41 localize_x_desktops() {
43 # Check for and customize KDE lang
44 ##########################################################################
46 # Check if we can localize KDE via skel
47 if [ -e "${FSMNT}/usr/share/skel/.kde4/share/config/kdeglobals" ] ; then
48 sed -i '' "s/Country=us/Country=${COUNTRY}/g" ${FSMNT}/usr/share/skel/.kde4/share/config/kdeglobals
49 sed -i '' "s/Country=us/Country=${COUNTRY}/g" ${FSMNT}/root/.kde4/share/config/kdeglobals
50 sed -i '' "s/Language=en_US/Language=${SETLANG}:${LOCALE}/g" ${FSMNT}/usr/share/skel/.kde4/share/config/kdeglobals
53 # Check if we have a KDE root config
54 if [ -e "${FSMNT}/root/.kde4/share/config/kdeglobals" ] ; then
55 sed -i '' "s/Language=en_US/Language=${SETLANG}:${LOCALE}/g" ${FSMNT}/root/.kde4/share/config/kdeglobals
59 if [ -e "${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc" ] ; then
60 sed -i '' "s/Language=en_US/Language=${LOCALE}.UTF-8/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc
63 # Check for and customize GNOME / GDM lang
64 ##########################################################################
66 # See if GDM is enabled and customize its lang
67 cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q "gdm_enable=\"YES\"" 2>/dev/null
68 if [ "$?" = "0" ] ; then
69 echo "gdm_lang=\"${LOCALE}.UTF-8\"" >> ${FSMNT}/etc/rc.conf
74 # Function which localizes a PC-BSD install
77 # Check if we have a localized splash screen and copy it
78 if [ -e "${FSMNT}/usr/local/share/pcbsd/splash-screens/loading-screen-${SETLANG}.pcx" ]
80 cp ${FSMNT}/usr/local/share/pcbsd/splash-screens/loading-screen-${SETLANG}.pcx ${FSMNT}/boot/loading-screen.pcx
91 OPTION="grp:alt_shift_toggle"
94 if [ "${COUNTRY}" = "NONE" -o "${COUNTRY}" = "us" -o "${COUNTRY}" = "C" ] ; then
95 #In this case we don't need any additional language
102 if [ "${KEYMOD}" != "NONE" ]
104 SETXKBMAP="-model ${KEYMOD}"
110 if [ "${KEYLAY}" != "NONE" ]
112 localize_key_layout "$KEYLAY"
113 SETXKBMAP="${SETXKBMAP} -layout ${KEYLAY}"
119 if [ "${KEYVAR}" != "NONE" ]
121 SETXKBMAP="${SETXKBMAP} -variant ${KEYVAR}"
127 # Setup .xprofile with our setxkbmap call now
128 if [ ! -z "${SETXKBMAP}" ]
130 if [ ! -e "${FSMNT}/usr/share/skel/.xprofile" ]
132 echo "#!/bin/sh" >${FSMNT}/usr/share/skel/.xprofile
135 # Save the keyboard layout for user / root X logins
136 echo "setxkbmap ${SETXKBMAP}" >>${FSMNT}/usr/share/skel/.xprofile
137 chmod 755 ${FSMNT}/usr/share/skel/.xprofile
138 cp ${FSMNT}/usr/share/skel/.xprofile ${FSMNT}/root/.xprofile
141 if [ -e "${FSMNT}/usr/local/kde4/share/config/kdm/Xsetup" ] ; then
142 echo "setxkbmap ${SETXKBMAP}" >>${FSMNT}/usr/local/kde4/share/config/kdm/Xsetup
146 # Create the kxkbrc configuration using these options
147 if [ -d "${FSMNT}/usr/share/skel/.kde4/share/config" ] ; then
149 DisplayNames=${KXLAYOUT}${COUNTRY}
151 LayoutList=${KXLAYOUT}${KXVAR}${COUNTRY}
158 Use=true " >${FSMNT}/usr/share/skel/.kde4/share/config/kxkbrc
163 localize_key_layout()
168 # Set the keylayout in rc.conf
170 am) KEYLAYOUT_CONSOLE="hy.armscii-8" ;;
171 ch) KEYLAYOUT_CONSOLE="swissgerman.iso" ;;
172 cz) KEYLAYOUT_CONSOLE="cz.iso2" ;;
173 de) KEYLAYOUT_CONSOLE="german.iso" ;;
174 dk) KEYLAYOUT_CONSOLE="danish.iso" ;;
175 ee) KEYLAYOUT_CONSOLE="estonian.iso" ;;
176 es) KEYLAYOUT_CONSOLE="spanish.iso" ;;
177 fi) KEYLAYOUT_CONSOLE="finnish.iso" ;;
178 is) KEYLAYOUT_CONSOLE="icelandic.iso" ;;
179 jp) KEYLAYOUT_CONSOLE="jp.106" ;;
180 nl) KEYLAYOUT_CONSOLE="dutch.iso.acc" ;;
181 no) KEYLAYOUT_CONSOLE="norwegian.iso" ;;
182 pl) KEYLAYOUT_CONSOLE="pl_PL.ISO8859-2" ;;
183 ru) KEYLAYOUT_CONSOLE="ru.koi8-r" ;;
184 sk) KEYLAYOUT_CONSOLE="sk.iso2" ;;
185 se) KEYLAYOUT_CONSOLE="swedish.iso" ;;
186 tr) KEYLAYOUT_CONSOLE="tr.iso9.q" ;;
187 gb) KEYLAYOUT_CONSOLE="uk.iso" ;;
188 *) if [ ! -z "${KEYLAYOUT}" ]
190 KEYLAYOUT_CONSOLE="${KEYLAYOUT}.iso"
195 if [ -n "${KEYLAYOUT_CONSOLE}" ]
197 echo "keymap=\"${KEYLAYOUT_CONSOLE}\"" >>${FSMNT}/etc/rc.conf
202 # Function which prunes other l10n files from the KDE install
203 localize_prune_langs()
205 get_value_from_cfg localizeLang
207 if [ -z "$KEEPLANG" ] ; then
212 echo_log "Pruning other l10n files, keeping ${KEEPLANG}"
214 # Create the script to do uninstalls
217 for i in `pkg_info -xEI kde-l10n`
219 echo "$i" | grep "${KEEPLANG}-kde"
220 if [ $? -ne 0 ] ; then
224 ' > ${FSMNT}/.pruneLangs.sh
226 chmod 755 ${FSMNT}/.pruneLangs.sh
227 chroot ${FSMNT} /.pruneLangs.sh >/dev/null 2>/dev/null
228 rm ${FSMNT}/.pruneLangs.sh
232 # Function which sets COUNTRY SETLANG and LOCALE based upon $1
236 # Setup the presets for the specific lang
420 SETLANG="${TARGETLANG}"
425 export COUNTRY SETLANG LOCALE
429 # Function which sets the timezone on the system
433 cp ${FSMNT}/usr/share/zoneinfo/${TZONE} ${FSMNT}/etc/localtime
436 # Function which enables / disables NTP
440 if [ "$ENABLED" = "yes" -o "${ENABLED}" = "YES" ]
442 cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q 'ntpd_enable="YES"' 2>/dev/null
445 echo 'ntpd_enable="YES"' >>${FSMNT}/etc/rc.conf
446 echo 'ntpd_sync_on_start="YES"' >>${FSMNT}/etc/rc.conf
449 cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q 'ntpd_enable="YES"' 2>/dev/null
452 sed -i.bak 's|ntpd_enable="YES"||g' ${FSMNT}/etc/rc.conf
457 # Starts checking for localization directives
466 # Check if we need to do any localization
467 echo $line | grep -q "^localizeLang=" 2>/dev/null
471 # Set our country / lang / locale variables
472 get_value_from_string "$line"
473 localize_get_codes ${VAL}
475 get_value_from_string "$line"
476 # If we are doing PC-BSD install, localize it as well as FreeBSD base
477 if [ "${INSTALLTYPE}" != "FreeBSD" ]
479 localize_pcbsd "$VAL"
483 localize_freebsd "$VAL"
485 # Localize any X pkgs
486 localize_x_desktops "$VAL"
489 # Check if we need to do any keylayouts
490 echo $line | grep -q "^localizeKeyLayout=" 2>/dev/null
491 if [ $? -eq 0 ] ; then
492 get_value_from_string "$line"
496 # Check if we need to do any key models
497 echo $line | grep -q "^localizeKeyModel=" 2>/dev/null
498 if [ $? -eq 0 ] ; then
499 get_value_from_string "$line"
503 # Check if we need to do any key variant
504 echo $line | grep -q "^localizeKeyVariant=" 2>/dev/null
505 if [ $? -eq 0 ] ; then
506 get_value_from_string "$line"
511 # Check if we need to set a timezone
512 echo $line | grep -q "^timeZone=" 2>/dev/null
513 if [ $? -eq 0 ] ; then
514 get_value_from_string "$line"
518 # Check if we need to set a timezone
519 echo $line | grep -q "^enableNTP=" 2>/dev/null
520 if [ $? -eq 0 ] ; then
521 get_value_from_string "$line"
526 if [ "${INSTALLTYPE}" != "FreeBSD" ] ; then
527 # Do our X keyboard localization
528 localize_x_keyboard "${KEYMOD}" "${KEYLAYOUT}" "${KEYVAR}" "${COUNTRY}"
531 # Check if we want to prunt any other KDE lang files to save some disk space
532 get_value_from_cfg localizePrune
533 if [ "${VAL}" = "yes" -o "${VAL}" = "YES" ] ; then
537 # Update the login.conf db, even if we didn't localize, its a good idea to make sure its up2date
538 run_chroot_cmd "/usr/bin/cap_mkdb /etc/login.conf" >/dev/null 2>/dev/null