#!/bin/sh
load_font() {
 if [ -r $T_PX/usr/lib/kbd/consolefonts/$1 ]; then
  setfont $T_PX/usr/lib/kbd/consolefonts/$1 1> /dev/null 2> /dev/null
 elif [ -r /var/adm/mount/live/usr/lib/kbd/consolefonts/$1 ]; then
  setfont /var/adm/mount/live/usr/lib/kbd/consolefonts/$1 1> /dev/null 2> /dev/null
 fi
}
if [ -r /tmp/SeTT_PX ]; then
 T_PX="`cat /tmp/SeTT_PX`"
elif [ ! "$1" = "" ]; then
 T_PX=$1
else
 T_PX=/
fi
if [ "$COLOR" = "on" -o -r /tmp/SeTcolor ]; then # use color menus
 dialog --title "SCREEN FONT CONFIGURATION" --yesno "Would you like to try \
out some custom screen fonts?" 7 35
 if [ $? = 1 ]; then
  exit
 fi
 while [ 0 ]; do
  dialog --title "SELECT A SCREEN FONT" --menu "Select one of the following \
custom fonts. If you decide you like it, you can make it your new default \
screen font. You'll be able to try as many of these as you like." 21 40 10 \
"8x14alt" "" "8x14thin" "" "8x15" "" "8x16alt" "" "8x8thin" "" \
"Cyr_a8x14" "" "Cyr_a8x16" "" "Cyr_a8x8" "" "aply16.psf" "" "b.fnt" "" \
"c.fnt" "" "def2_8x16" "" "default8x16" "" "default8x9" "" "gr.f14" "" \
"gr.f16 " "" "iso01.f08" "" "iso01.f14" "" "iso01.f16" ""  "iso02.f08" "" \
"iso02.f14" "" "iso02.f16" "" "iso03.f08" "" "iso03.f14" "" "iso03.f16" "" \
"iso04.f08" "" "iso04.f14" "" "iso04.f16" "" "iso05.f08" "" "iso05.f14" "" \
"iso05.f16" "" "iso06.f08" "" "iso06.f14" "" "iso06.f16" "" "iso07.f08" "" \
"iso07.f14" "" "iso07.f16" "" "iso08.f08" "" "iso08.f14" "" "iso08.f16" "" \
"iso09.f08" "" "iso09.f14" "" "iso09.f16" "" "iso10.f08" "" "iso10.f14" "" \
"iso10.f16" "" "koi8-14.psf" "" "lat1-08.psf" "" "lat1-10.psf" "" \
"lat1-12.psf" "" "lat1-14.psf" "" "lat1-16.psf" "" "lat2-08.psf" "" \
"lat2-10.psf" "" "lat2-12.psf" "" "lat2-14.psf" "" \
"lat2-16.psf" "" "m.fnt" "" "ml.fnt" "" "mod_d.fnt" "" "mod_s.fnt" "" \
"mr.fnt" "" "mu.fnt" "" "r.fnt" "" "rl.fnt" "" "s.fnt" "" "sc.fnt" "" \
"scrawl_s.fnt" "" "scrawl_w.fnt" "" "sd.fnt" "" "t.fnt" "" 2> /tmp/font

  if [ $? = 1 -o $? = 255 ]; then
   rm -f /tmp/font
   load_font default8x16
   exit
  fi
  FONT="`cat /tmp/font`"
  rm -f /tmp/font
  load_font $FONT
  dialog --title "SET AS DEFAULT FONT" --yesno "Well, what do you think? \
If you'd like to make this your default font, select YES. You can change \
the default font any time by typing 'fontconfig' or by editing \
/etc/rc.d/rc.font. If you don't \
like this font, select NO, and you'll be returned to the font selection \
menu. If you decide you want to stick with the default font, hit ESC or \
CANCEL once you get to that menu." 13 60
  if [ $? = 0 ]; then
   cat << EOF > $T_PX/etc/rc.d/rc.font
#!/bin/sh
#
# This selects your default screen font from among the ones in
# /usr/lib/kbd/consolefonts.
#
setfont $FONT
EOF
   chmod 755 $T_PX/etc/rc.d/rc.font
   exit
  fi
 done
else # no color!
 echo
 echo -n "Would you like to try out some custom screen fonts ([y]es, [n]o)? "
 read YESNO;
 if [ "$YESNO" = "n" ]; then
  exit
 fi
 while [ 0 ]; do
  cat << EOF
SELECT A SCREEN FONT

Select one of the following custom fonts. If you decide you like it, you can
make it your new default screen font. You'll be able to try as many of these
as you like.

8x14alt     8x14thin    8x15        8x16alt      8x8thin      Cyr_a8x14
Cyr_a8x16   Cyr_a8x8    b.fnt       c.fnt        def2_8x16    default8x16
koi8-14.psf lat1-08.psf lat1-10.psf lat1-12.psf  lat1-14.psf  lat1-16.psf
lat2-08.psf lat2-10.psf lat2-12.psf lat2-14.psf  lat2-16.psf  m.fnt
ml.fnt      mod_d.fnt   mod_s.fnt   mr.fnt       mu.fnt       r.fnt
rl.fnt      s.fnt       sc.fnt      scrawl_s.fnt scrawl_w.fnt sd.fnt
t.fnt       aply16.psf  default8x9  gr.f14       gr.f16       iso01.f08
iso01.f14   iso01.f16   iso02.f08   iso02.f14    iso02.f16    iso03.f08
iso03.f14   iso03.f16   iso04.f08   iso04.f14    iso04.f16    iso05.f08
iso05.f14   iso05.f16   iso06.f08   iso06.f14    iso06.f16    iso07.f08
iso07.f14   iso07.f16   iso08.f08   iso08.f14    iso08.f16    iso09.f08
iso09.f14   iso09.f16   iso10.f08   iso10.f14    iso10.f16 

EOF
  echo -n "Which font would you like (or ENTER to quit)? "
  read FONT;
  if [ "$FONT" = "" ]; then
   load_font default8x16
   echo
   exit
  fi
  if [ ! -r $T_PX/usr/lib/kbd/consolefonts/$FONT -a ! -r \
         /var/adm/mount/usr/lib/kbd/consolefonts/$FONT ]; then
   cat << EOF

Sorry, I couldn't find that font. Try again.

EOF
  fi
  load_font $FONT
  cat << EOF

SET AS DEFAULT FONT

Well, what do you think? If you'd like to make this your default font, select
YES. You can change the default font any time by typing 'fontconfig' or by 
editing /etc/rc.d/rc.font. If you don't like this font, select NO, and you'll
be able to select a different one. If you decide you want to stick with the
default font, hit RETURN once you return to the font selection menu.

EOF
  echo -n "Would you like to have this font loaded by default ([y]es, [n]o)? "
  read DEF
  if [ "$DEF" = "YES" -o "$DEF" = "y" ]; then
   cat << EOF > $T_PX/etc/rc.d/rc.font
#!/bin/sh
#
# This selects your default screen font from among the ones in
# /usr/lib/kbd/consolefonts.
#
setfont $FONT
EOF
   chmod 755 $T_PX/etc/rc.d/rc.font
   echo
   exit
  fi
  echo
 done
fi
