#!/bin/sh
# Steven Shiau <steven@nchc.org.tw>
# License: GPL
# Script to setup DRBL server for the impatient.

# Source function library.
. /etc/rc.d/init.d/functions

# Setting
DRBL_SCRIPT_PATH="/opt/drbl"
drbl_setup_path="$DRBL_SCRIPT_PATH/setup"

# Source function
check_if_root() {
# Check if root or not
   if [ ! "$UID" = "0" ]; then
     echo
     echo "[$LOGNAME] You need to run this script \"`basename $0`\" as root."
     echo
     exit 1
   fi
}

#
check_if_root

# Language
echo "Language | y| 語言 ?".
echo "[0]: English"
echo "[1]: Chinese Traditional (Big5) - Taiwan |  (jX) - xW".
echo "[2]: Chinese Traditional (UTF-8, Unicode) - Taiwan | 中文 (萬國標準碼) - 台灣"
echo -n "[0] "
read lang_answer
case "$lang_answer" in
   1)
      lang="tw.BIG5"
      ;;
   2)
      lang="tw.UTF-8"
      ;;
   *)
      lang="en"
esac

# get the l10n message
. $drbl_setup_path/lang/bash/$lang

#
echo "$msg_delimiter_star_line"
echo "$msg_are_you_sure_run_impatient"
echo -n "[Y/n] "
read run_4impatient
case "$run_4impatient" in
	n|N|[nN][oO])
           echo "$msg_delimiter_star_line"
	   echo "$msg_run_step_by_step: "
           echo "(a):\"$DRBL_SCRIPT_PATH/sbin/drblsrv -i\" "
           echo "(b):\"$DRBL_SCRIPT_PATH/sbin/drblpush -i\" "
	   ;;
	*)
           echo "$msg_delimiter_star_line"
	   echo "$msg_run_drbl4imp"
           echo "$msg_press_enter_to_continue"
           read 
           [ -x "$drbl_setup_path/drblsrv" ] && yes "" | $drbl_setup_path/drblsrv -i -l $lang_answer
           [ -x "$drbl_setup_path/drblpush" ] && yes "" | $drbl_setup_path/drblpush -i -l $lang_answer
	   ;;
esac
