3 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 # Copyright (c) 2010 iXsystems, Inc. All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # Functions which runs commands on the system
32 . ${BACKEND}/functions.sh
33 . ${BACKEND}/functions-parse.sh
36 # Function which localizes a FreeBSD install
39 sed -i.bak "s/lang=en_US/lang=${LOCALE}/g" ${FSMNT}/etc/login.conf
40 rm ${FSMNT}/etc/login.conf.bak
43 localize_x_desktops() {
45 # Check for and customize KDE lang
46 ##########################################################################
48 # Check if we can localize KDE via skel
49 if [ -e "${FSMNT}/usr/share/skel/.kde4/share/config/kdeglobals" ] ; then
50 sed -i '' "s/Country=us/Country=${COUNTRY}/g" ${FSMNT}/usr/share/skel/.kde4/share/config/kdeglobals
51 sed -i '' "s/Country=us/Country=${COUNTRY}/g" ${FSMNT}/root/.kde4/share/config/kdeglobals
52 sed -i '' "s/Language=en_US/Language=${SETLANG}:${LOCALE}/g" ${FSMNT}/usr/share/skel/.kde4/share/config/kdeglobals
55 # Check if we have a KDE root config
56 if [ -e "${FSMNT}/root/.kde4/share/config/kdeglobals" ] ; then
57 sed -i '' "s/Language=en_US/Language=${SETLANG}:${LOCALE}/g" ${FSMNT}/root/.kde4/share/config/kdeglobals
61 if [ -e "${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc" ] ; then
62 sed -i '' "s/Language=en_US/Language=${LOCALE}.UTF-8/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc
65 # Check for and customize GNOME / GDM lang
66 ##########################################################################
68 # See if GDM is enabled and customize its lang
69 cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q "gdm_enable=\"YES\"" 2>/dev/null
70 if [ "$?" = "0" ] ; then
71 echo "gdm_lang=\"${LOCALE}.UTF-8\"" >> ${FSMNT}/etc/rc.conf
76 # Function which localizes a PC-BSD install
79 # Check if we have a localized splash screen and copy it
80 if [ -e "${FSMNT}/usr/local/share/pcbsd/splash-screens/loading-screen-${SETLANG}.pcx" ]
82 cp ${FSMNT}/usr/local/share/pcbsd/splash-screens/loading-screen-${SETLANG}.pcx ${FSMNT}/boot/loading-screen.pcx
93 OPTION="grp:alt_shift_toggle"
96 if [ "${COUNTRY}" = "NONE" -o "${COUNTRY}" = "us" -o "${COUNTRY}" = "C" ] ; then
97 #In this case we don't need any additional language
101 COUNTRY=",${COUNTRY}"
104 if [ "${KEYMOD}" != "NONE" ]
106 SETXKBMAP="-model ${KEYMOD}"
112 if [ "${KEYLAY}" != "NONE" ]
114 localize_key_layout "$KEYLAY"
115 SETXKBMAP="${SETXKBMAP} -layout ${KEYLAY}"
121 if [ "${KEYVAR}" != "NONE" ]
123 SETXKBMAP="${SETXKBMAP} -variant ${KEYVAR}"
129 # Setup .xprofile with our setxkbmap call now
130 if [ ! -z "${SETXKBMAP}" ]
132 if [ ! -e "${FSMNT}/usr/share/skel/.xprofile" ]
134 echo "#!/bin/sh" >${FSMNT}/usr/share/skel/.xprofile
137 # Save the keyboard layout for user / root X logins
138 echo "setxkbmap ${SETXKBMAP}" >>${FSMNT}/usr/share/skel/.xprofile
139 chmod 755 ${FSMNT}/usr/share/skel/.xprofile
140 cp ${FSMNT}/usr/share/skel/.xprofile ${FSMNT}/root/.xprofile
143 if [ -e "${FSMNT}/usr/local/kde4/share/config/kdm/Xsetup" ] ; then
144 echo "setxkbmap ${SETXKBMAP}" >>${FSMNT}/usr/local/kde4/share/config/kdm/Xsetup
148 # Create the kxkbrc configuration using these options
149 if [ -d "${FSMNT}/usr/share/skel/.kde4/share/config" ] ; then
151 DisplayNames=${KXLAYOUT}${COUNTRY}
153 LayoutList=${KXLAYOUT}${KXVAR}${COUNTRY}
160 Use=true " >${FSMNT}/usr/share/skel/.kde4/share/config/kxkbrc
165 localize_key_layout()
170 # Set the keylayout in rc.conf
172 am) KEYLAYOUT_CONSOLE="hy.armscii-8" ;;
173 ca) KEYLAYOUT_CONSOLE="fr_CA.acc.iso" ;;
174 ch) KEYLAYOUT_CONSOLE="swissgerman.iso" ;;
175 cz) KEYLAYOUT_CONSOLE="cz.iso2" ;;
176 de) KEYLAYOUT_CONSOLE="german.iso" ;;
177 dk) KEYLAYOUT_CONSOLE="danish.iso" ;;
178 ee) KEYLAYOUT_CONSOLE="estonian.iso" ;;
179 es) KEYLAYOUT_CONSOLE="spanish.iso" ;;
180 fi) KEYLAYOUT_CONSOLE="finnish.iso" ;;
181 is) KEYLAYOUT_CONSOLE="icelandic.iso" ;;
182 jp) KEYLAYOUT_CONSOLE="jp.106" ;;
183 nl) KEYLAYOUT_CONSOLE="dutch.iso.acc" ;;
184 no) KEYLAYOUT_CONSOLE="norwegian.iso" ;;
185 pl) KEYLAYOUT_CONSOLE="pl_PL.ISO8859-2" ;;
186 ru) KEYLAYOUT_CONSOLE="ru.koi8-r" ;;
187 sk) KEYLAYOUT_CONSOLE="sk.iso2" ;;
188 se) KEYLAYOUT_CONSOLE="swedish.iso" ;;
189 tr) KEYLAYOUT_CONSOLE="tr.iso9.q" ;;
190 gb) KEYLAYOUT_CONSOLE="uk.iso" ;;
191 *) if [ ! -z "${KEYLAYOUT}" ]
193 KEYLAYOUT_CONSOLE="${KEYLAYOUT}.iso"
198 if [ -n "${KEYLAYOUT_CONSOLE}" ]
200 echo "keymap=\"${KEYLAYOUT_CONSOLE}\"" >>${FSMNT}/etc/rc.conf
205 # Function which prunes other l10n files from the KDE install
206 localize_prune_langs()
208 get_value_from_cfg localizeLang
210 if [ -z "$KEEPLANG" ] ; then
215 echo_log "Pruning other l10n files, keeping ${KEEPLANG}"
217 # Create the script to do uninstalls
220 for i in `pkg_info -xEI kde-l10n`
222 echo "$i" | grep "${KEEPLANG}-kde"
223 if [ $? -ne 0 ] ; then
227 ' > ${FSMNT}/.pruneLangs.sh
229 chmod 755 ${FSMNT}/.pruneLangs.sh
230 chroot ${FSMNT} /.pruneLangs.sh >/dev/null 2>/dev/null
231 rm ${FSMNT}/.pruneLangs.sh
235 # Function which sets COUNTRY SETLANG and LOCALE based upon $1
239 # Setup the presets for the specific lang
423 SETLANG="${TARGETLANG}"
428 export COUNTRY SETLANG LOCALE
432 # Function which sets the timezone on the system
436 cp ${FSMNT}/usr/share/zoneinfo/${TZONE} ${FSMNT}/etc/localtime
439 # Function which enables / disables NTP
443 if [ "$ENABLED" = "yes" -o "${ENABLED}" = "YES" ]
445 cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q 'ntpd_enable="YES"' 2>/dev/null
448 echo 'ntpd_enable="YES"' >>${FSMNT}/etc/rc.conf
449 echo 'ntpd_sync_on_start="YES"' >>${FSMNT}/etc/rc.conf
452 cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q 'ntpd_enable="YES"' 2>/dev/null
455 sed -i.bak 's|ntpd_enable="YES"||g' ${FSMNT}/etc/rc.conf
460 # Starts checking for localization directives
469 # Check if we need to do any localization
470 echo $line | grep -q "^localizeLang=" 2>/dev/null
474 # Set our country / lang / locale variables
475 get_value_from_string "$line"
476 localize_get_codes ${VAL}
478 get_value_from_string "$line"
479 # If we are doing PC-BSD install, localize it as well as FreeBSD base
480 if [ "${INSTALLTYPE}" != "FreeBSD" ]
482 localize_pcbsd "$VAL"
486 localize_freebsd "$VAL"
488 # Localize any X pkgs
489 localize_x_desktops "$VAL"
492 # Check if we need to do any keylayouts
493 echo $line | grep -q "^localizeKeyLayout=" 2>/dev/null
494 if [ $? -eq 0 ] ; then
495 get_value_from_string "$line"
499 # Check if we need to do any key models
500 echo $line | grep -q "^localizeKeyModel=" 2>/dev/null
501 if [ $? -eq 0 ] ; then
502 get_value_from_string "$line"
506 # Check if we need to do any key variant
507 echo $line | grep -q "^localizeKeyVariant=" 2>/dev/null
508 if [ $? -eq 0 ] ; then
509 get_value_from_string "$line"
514 # Check if we need to set a timezone
515 echo $line | grep -q "^timeZone=" 2>/dev/null
516 if [ $? -eq 0 ] ; then
517 get_value_from_string "$line"
521 # Check if we need to set a timezone
522 echo $line | grep -q "^enableNTP=" 2>/dev/null
523 if [ $? -eq 0 ] ; then
524 get_value_from_string "$line"
529 if [ "${INSTALLTYPE}" != "FreeBSD" ] ; then
530 # Do our X keyboard localization
531 localize_x_keyboard "${KEYMOD}" "${KEYLAYOUT}" "${KEYVAR}" "${COUNTRY}"
534 # Check if we want to prunt any other KDE lang files to save some disk space
535 get_value_from_cfg localizePrune
536 if [ "${VAL}" = "yes" -o "${VAL}" = "YES" ] ; then
540 # Update the login.conf db, even if we didn't localize, its a good idea to make sure its up2date
541 run_chroot_cmd "/usr/bin/cap_mkdb /etc/login.conf" >/dev/null 2>/dev/null