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 ca) KEYLAYOUT_CONSOLE="fr_CA.acc.iso" ;;
172 ch) KEYLAYOUT_CONSOLE="swissgerman.iso" ;;
173 cz) KEYLAYOUT_CONSOLE="cz.iso2" ;;
174 de) KEYLAYOUT_CONSOLE="german.iso" ;;
175 dk) KEYLAYOUT_CONSOLE="danish.iso" ;;
176 ee) KEYLAYOUT_CONSOLE="estonian.iso" ;;
177 es) KEYLAYOUT_CONSOLE="spanish.iso" ;;
178 fi) KEYLAYOUT_CONSOLE="finnish.iso" ;;
179 is) KEYLAYOUT_CONSOLE="icelandic.iso" ;;
180 jp) KEYLAYOUT_CONSOLE="jp.106" ;;
181 nl) KEYLAYOUT_CONSOLE="dutch.iso.acc" ;;
182 no) KEYLAYOUT_CONSOLE="norwegian.iso" ;;
183 pl) KEYLAYOUT_CONSOLE="pl_PL.ISO8859-2" ;;
184 ru) KEYLAYOUT_CONSOLE="ru.koi8-r" ;;
185 sk) KEYLAYOUT_CONSOLE="sk.iso2" ;;
186 se) KEYLAYOUT_CONSOLE="swedish.iso" ;;
187 tr) KEYLAYOUT_CONSOLE="tr.iso9.q" ;;
188 gb) KEYLAYOUT_CONSOLE="uk.iso" ;;
189 *) if [ ! -z "${KEYLAYOUT}" ]
191 KEYLAYOUT_CONSOLE="${KEYLAYOUT}.iso"
196 if [ -n "${KEYLAYOUT_CONSOLE}" ]
198 echo "keymap=\"${KEYLAYOUT_CONSOLE}\"" >>${FSMNT}/etc/rc.conf
203 # Function which prunes other l10n files from the KDE install
204 localize_prune_langs()
206 get_value_from_cfg localizeLang
208 if [ -z "$KEEPLANG" ] ; then
213 echo_log "Pruning other l10n files, keeping ${KEEPLANG}"
215 # Create the script to do uninstalls
218 for i in `pkg_info -xEI kde-l10n`
220 echo "$i" | grep "${KEEPLANG}-kde"
221 if [ $? -ne 0 ] ; then
225 ' > ${FSMNT}/.pruneLangs.sh
227 chmod 755 ${FSMNT}/.pruneLangs.sh
228 chroot ${FSMNT} /.pruneLangs.sh >/dev/null 2>/dev/null
229 rm ${FSMNT}/.pruneLangs.sh
233 # Function which sets COUNTRY SETLANG and LOCALE based upon $1
237 # Setup the presets for the specific lang
421 SETLANG="${TARGETLANG}"
426 export COUNTRY SETLANG LOCALE
430 # Function which sets the timezone on the system
434 cp ${FSMNT}/usr/share/zoneinfo/${TZONE} ${FSMNT}/etc/localtime
437 # Function which enables / disables NTP
441 if [ "$ENABLED" = "yes" -o "${ENABLED}" = "YES" ]
443 cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q 'ntpd_enable="YES"' 2>/dev/null
446 echo 'ntpd_enable="YES"' >>${FSMNT}/etc/rc.conf
447 echo 'ntpd_sync_on_start="YES"' >>${FSMNT}/etc/rc.conf
450 cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q 'ntpd_enable="YES"' 2>/dev/null
453 sed -i.bak 's|ntpd_enable="YES"||g' ${FSMNT}/etc/rc.conf
458 # Starts checking for localization directives
467 # Check if we need to do any localization
468 echo $line | grep -q "^localizeLang=" 2>/dev/null
472 # Set our country / lang / locale variables
473 get_value_from_string "$line"
474 localize_get_codes ${VAL}
476 get_value_from_string "$line"
477 # If we are doing PC-BSD install, localize it as well as FreeBSD base
478 if [ "${INSTALLTYPE}" != "FreeBSD" ]
480 localize_pcbsd "$VAL"
484 localize_freebsd "$VAL"
486 # Localize any X pkgs
487 localize_x_desktops "$VAL"
490 # Check if we need to do any keylayouts
491 echo $line | grep -q "^localizeKeyLayout=" 2>/dev/null
492 if [ $? -eq 0 ] ; then
493 get_value_from_string "$line"
497 # Check if we need to do any key models
498 echo $line | grep -q "^localizeKeyModel=" 2>/dev/null
499 if [ $? -eq 0 ] ; then
500 get_value_from_string "$line"
504 # Check if we need to do any key variant
505 echo $line | grep -q "^localizeKeyVariant=" 2>/dev/null
506 if [ $? -eq 0 ] ; then
507 get_value_from_string "$line"
512 # Check if we need to set a timezone
513 echo $line | grep -q "^timeZone=" 2>/dev/null
514 if [ $? -eq 0 ] ; then
515 get_value_from_string "$line"
519 # Check if we need to set a timezone
520 echo $line | grep -q "^enableNTP=" 2>/dev/null
521 if [ $? -eq 0 ] ; then
522 get_value_from_string "$line"
527 if [ "${INSTALLTYPE}" != "FreeBSD" ] ; then
528 # Do our X keyboard localization
529 localize_x_keyboard "${KEYMOD}" "${KEYLAYOUT}" "${KEYVAR}" "${COUNTRY}"
532 # Check if we want to prunt any other KDE lang files to save some disk space
533 get_value_from_cfg localizePrune
534 if [ "${VAL}" = "yes" -o "${VAL}" = "YES" ] ; then
538 # Update the login.conf db, even if we didn't localize, its a good idea to make sure its up2date
539 run_chroot_cmd "/usr/bin/cap_mkdb /etc/login.conf" >/dev/null 2>/dev/null