#!/bin/sh # ALT's /sbin/setsysfont. # Agrees with RH's initscripts-7.06-1. # Last change: by imz@altlinux.ru on 2003 Feb 7. # Source library functions . /etc/init.d/functions EXECPATH=(/bin /usr/bin) # inspired by FindFile() form /etc/init.d/functions (initscripts-5.49-ipl49mdk) FindExec() { local n f d for n in "$@"; do for d in "${EXECPATH[@]}"; do f="$d/$n" if [ -x "$f" ]; then echo "$f" return 0 fi done done return 1 } addLoadableData() { local option="$1" name="$2" type case "$option" in --font) type=psf ;; *) type="${option#--}" ;; esac if [ -n "$name" ]; then args[${#args[@]}]="$option" local found if found="$(FindFile "/etc/sysconfig/console/$name.$type")"; then args[${#args[@]}]="$found" else args[${#args[@]}]="$name" fi fi # An alternative to FindFile() and the corresponding readbility test could be # a test performed by consolechars themselves, like this: # # "$CONSOLECHARS" --no-act "$option" "$f" # # But I don't think such complexity is reasonable here. # imz@altlinux.ru, Feb 2003. } if [ "$LANG" = POSIX -o "$LANGUAGE" = POSIX ]; then SourceIfNotEmpty /etc/sysconfig/i18n fi # Our parameters: readonly SYSFONT UNIMAP SYSFONTACM readonly \ CONSOLECHARS="$(FindExec consolechars)" \ SETFONT="$(FindExec setfont)" if [ -z "$CONSOLECHARS" -a -z "$SETFONT" ]; then echo "${0##*/}: cannot set font because no tools found." >&2 exit 1 fi let 'RETVAL = 0' ############### Set font (+ the map for its encoding) ################# if [ -n "$CONSOLECHARS" ]; then args=() addLoadableData --font "$SYSFONT" addLoadableData --sfm "$UNIMAP" "$CONSOLECHARS" "$@" "${args[@]}" else # if [ -n "$SETFONT" ]; then if [ -n "$SYSFONT" ]; then "$SETFONT" "$SYSFONT" ${UNIMAP:+-u "$UNIMAP"} fi fi || let 'RETVAL |= 1' # Font set. If not, RETVAL & 1. ############## Set ACM ################ # for newer fonts and ACMs it's value is independent of the system font: # stage 1: application --> ACM (charmap -> Unicode) --> Unicode data --> # stage 2: --> Unicode data --> SFM (Unicode -> font encoding) --> data # encoded corresponding to the console font. # # Perhaps this should be done in a separate script. # Another enhancement would be to fall back on $(locale charmap) # (or its lower-case variant) -- but the utilities are in /usr/bin/; # something like this is done only for the Unicode case now. # We examine only LANG here. What about LC_CTYPE, LC_ALL, LANGUAGE # -- they can also indicate a Unicode console. case "$LANG" in *.utf8|*.UTF-8) # In this case, there is no ACM: applications output data # already in Unicode; the first stage is not needed. # The font and SFM has been set already; # unicode_start will use the current settings unicode_start || let 'RETVAL |= 2' exit $RETVAL ;; esac if [ -n "$SYSFONTACM" ]; then if [ -n "$CONSOLECHARS" ]; then args=() addLoadableData --acm "$SYSFONTACM" "$CONSOLECHARS" "$@" "${args[@]}" else # if [ -n "$SETFONT" ]; then "$SETFONT" -m "$SYSFONTACM" echo -ne '\e(K' > /dev/console fi fi || let 'RETVAL |= 2' # ACM set. If not, RETVAL & 2. exit $RETVAL