#!/bin/bash

case "`tty`" in
  /dev/tty[1-8])
    MODE=text
    DIA=dialog
    ;;
  /dev/pts/*|/dev/ttyp*)
    MODE=x
    export XDIALOG_HIGH_DIALOG_COMPAT=1
    [ -x /usr/bin/gdialog ] && DIA=gdialog
    [ -x /usr/bin/Xdialog ] && DIA=Xdialog
    [ $DIA = dialog ] && MODE=text
    ;;
  *)
    MODE=text
    DIA=dialog
    ;;
esac
# text mode if DISPLAY is not set
if [ -z "$DISPLAY" ] ; then
  MODE=text
  DIA=dialog
fi
#
BT="日本語関連をapt-getでセットします"
T1="Knoppix To HD"
M1="apt-get update を行ないます。\
 Internetへは接続出来ますね, Yes or No?"
$DIA --backtitle "$BT" --title "$T1" --yesno "$M1" 15 60
x=$?
if [ $x != 0 ] ; then
   exit 0
fi
#
if [ -f /etc/apt/sources.list.kwb ]; then
   cp -af /etc/apt/sources.list.kwb /etc/apt/sources.list
else
   cp -af /etc/apt/sources.list /etc/apt/sources.list.kwb
fi
cat <<\EOF >>/etc/apt/sources.list
# Koffice Japanese Language-Set
deb http://ktown.kde.org/~nolden/kde woody main
EOF
#
#
apt-get update
#
T1="Knoppix To HD"
M1="apt-get update は正常に終了しましたか, Yes or No?"
$DIA --backtitle "$BT" --title "$T1" --yesno "$M1" 15 60
x=$?
if [ $x != 0 ] ; then
   cp -af /etc/apt/sources.list.kwb /etc/apt/sources.list
   rm -rf /etc/apt/sources.list.kwb
   exit 0
fi
#
#
  M1="入力等日本語セットをインストールします, Yes or No?"
  $DIA --backtitle "$BT" --title "$T1" --yesno "$M1" 15 60
  x=$?
  if [ $x = 0 ] ; then
    apt-get install freewnn-jserver kinput2-wnn kterm ttf-kochi-gothic ttf-kochi-mincho xfonts-shinonome
  fi
#
  M1="KOffice日本語セットをインストールします, Yes or No?"
  $DIA --backtitle "$BT" --title "$T1" --yesno "$M1" 15 60
  x=$?
  if [ $x = 0 ] ; then
    apt-get install koffice-i18n-ja
  fi
#
  M1="Mozilla日本語セットをインストールします, Yes or No?"
  $DIA --backtitle "$BT" --title "$T1" --yesno "$M1" 15 60
  x=$?
  if [ $x = 0 ] ; then
    apt-get install mozilla-locale-ja/unstable
  fi
#
 M1="OpenOffice日本語版をインストールしますか?, Yes or No? \n
 今までのOpenOffice関連はアンインストールされます"
 $DIA --backtitle "$BT" --title "$T1" --yesno "$M1" 15 60
 x=$?
 if [ $x = 0 ] ; then
   rm -rf /opt/openoffice
   cp -af /usr/share/applnk/Office/openoffice.desktop /usr/share/applnk/
   rm -rf /usr/share/applnk/Office/"OpenOffice.org 1.0"
   dpkg --purge openoffice-de-en
#
   apt-get install libgcc1/unstable libstdc++5/unstable libstlport4.5c102/unstable
#
   apt-get -f install openoffice.org-l10n-ja/unstable openoffice.org-l10n-en/unstable openoffice.org/unstable openoffice.org-bin/unstable
#
   mv /usr/share/applnk/openoffice.desktop /usr/share/applnk/Office/
   mkdir -p /opt
   ln -sf /usr/lib/openoffice /opt/openoffice
   ln -sf /usr/lib/openoffice/program/soffice /usr/bin/soffice
 fi
#
 M1="apt-get が完了したら再起動して下さい"
 $DIA --backtitle "$BT" --title "$T1" --msgbox "$M1" 16 45
# 
   cp -af /etc/apt/sources.list.kwb /etc/apt/sources.list
   rm -rf /etc/apt/sources.list.kwb
#
exit 0