#!/bin/sh
#
# Copyright 1993,1994 Patrick Volkerding, Moorhead, Minnesota USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is 
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# As always, bug reports, suggestions, etc: volkerdi@mhd1.moorhead.msus.edu
# or bf703@cleveland.freenet.edu, or (if you absolutely must) (218) 233-4349.
#
# ܸǤˤĤƤϡJF projectΥݡȤβ
# simazaki@yu-gate.yamanashi.ac.jpˤޤ
#

rm -f /tmp/SeT*
echo "on" > /tmp/SeTcolor # turn on color menus
PATH="$PATH:/usr/lib/setup"
export PATH;
/sbin/probe -r 1> /dev/null 2> /dev/null
PARTLIST="`probe -l | grep "83  Linux" 2> /dev/null`"
if [ "$PARTLIST" = "" ]; then
 SeTnopartj
 exit
fi
echo "$PARTLIST" > /tmp/SeTplist
T_PX="/mnt"
echo "$T_PX" > /tmp/SeTT_PX
#DISTRIBUTION_SOURCE="/var/adm/mount"
#echo "$DISTRIBUTION_SOURCE" > /tmp/SeTDS
#SOURCE_DEVICE="/dev/fd0"
# We may want to force the issue...
# echo "$SOURCE_DEVICE" > /tmp/SeTsource
ROOT_DEVICE="`mount | grep "on / " | cut -b-10`"
echo "$ROOT_DEVICE" > /tmp/SeTrootdev
if mount | grep /var/adm/mount 1> /dev/null 2> /dev/null ; then # clear source
 umount /var/adm/mount                                           # location
fi
rm -f /var/adm/mount 2> /dev/null
rmdir /var/adm/mount 2> /dev/null
mkdir /var/adm/mount 2> /dev/null

while [ 0 ]; do

# Reset menu flag:
rm -f /tmp/SeTQUICK
 dialog --title "Plamo Linux󥹥ȡ˥塼(version 2.0)" \
--menu \
"Plamo Linux󥹥ȡ˥塼ؤ褦.\n\
岼륭ӥڡ뤤ENTERǰʲΥץ\n\
򤷤Ƥ'+', '-'TABѤǤޤKEYMAP\n\
ꤷƤפǤ" 19 76 10 \
"HELP" "Plamo Linux åȥåפHELPɽ" \
"KEYMAP" "ܡɤΥѹ" \
"ADDSWAP" "åץѡƥ" \
"TARGET" "󥹥ȡѡƥ" \
"SOURCE" "󥹥ȡ븵" \
"DISK SETS" "󥹥ȡ뤹ǥåȤ" \
"INSTALL" "򤷤ǥåȤΥ󥹥ȡ" \
"CONFIGURE" "󥹥ȡ뤷Linuxƥ" \
"EXIT" "Plamo Linuxåȥåפλ" 2> /tmp/hdset
 if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/hdset /tmp/SeT*
  exit
 fi
 MAINSELECT="`cat /tmp/hdset`"
 rm /tmp/hdset

 # Start checking what to do. Some modules may reset MAINSELECT to run the
 # next item in line.

 if [ "$MAINSELECT" = "HELP" ]; then
  SeTfdHELPj
 fi


 if [ "$MAINSELECT" = "KEYMAP" ]; then
  SeTkeymapj
  if [ -r /tmp/SeTkeymap ]; then
   dialog --yesno "ѹλޤ˥åΰ\
Ԥޤ" 9 76
   if [ $? = 0 ]; then
    MAINSELECT="ADDSWAP" 
   fi
  fi
 fi
 
 if [ "$MAINSELECT" = "MAKE TAGS" ]; then
  SeTmaketagj
 fi
 
 if [ "$MAINSELECT" = "ADDSWAP" ]; then
  SeTswapj
  if [ -r /tmp/SeTswap ]; then
   dialog --title "󥹥ȡ³Ԥޤ" --yesno "åΰ꤬ѤߤޤΤޤޥ󥹥ȡ³\n\
ȤǤޤᥤ˥塼뤳ȤǤޤ󥹥\n\
³Ԥ󥹥ȡɥ饤֤Ԥޤ" 9 70
   if [ $? = 0 ]; then
    MAINSELECT="TARGET"
   fi
  fi
 fi

 if [ "$MAINSELECT" = "TARGET" ]; then
  SeTpartitionsj
  SeTDOSj
  if [ -r /tmp/SeTnative ]; then
   dialog --title "³Ԥޤ" --yesno "󥹥ȡɥ饤֤꤬λޤ\n\
󥹥ȡ븵ؿʤߤޤ" 7 62
   if [ $? = 0 ]; then
    MAINSELECT="SOURCE"
   fi
  fi
 fi

 if [ "$MAINSELECT" = "SOURCE" ]; then
  SeTmediaj 
  if [ -r /tmp/SeTsource ]; then
   dialog --title "³Ԥޤ" --yesno "DISK SETSؿʤߡɤΥեȥ򥤥󥹥ȡ뤹뤫\n\
򤷤ޤ" 7 60
   if [ $? = 0 ]; then
    MAINSELECT="DISK SETS"
   fi
  fi
 fi

 if [ "$MAINSELECT" = "DISK SETS" ]; then
  SeTPKGj
  if [ -r /tmp/SeTSERIES ]; then
   dialog --title "³ޤ" --yesno \
"󥹥ȡ뤹ǥåȤλ꤬λޤ\n\
INSTALL򤹤뤳Ȥǥ󥹥ȡ򳫻Ϥޤ󥹥ȡ\n\
ɬפ꤬äƤʤȡåФƥᥤ˥塼\n\
ޤդƤINSTALLؿʤߤޤ" 11 70
   if [ $? = 0 ]; then
    MAINSELECT="INSTALL"
   fi
  fi
 fi

 if [ "$MAINSELECT" = "INSTALL" ]; then
  if [ ! -r /tmp/SeTSERIES -o ! -r /tmp/SeTsource -o ! /tmp/SeTnative ]; then
   dialog --title "ޤ󥹥ȡϤǤޤ" --msgbox "\
\n\
եȥ򥤥󥹥ȡ뤹ˡʲιܤ¹ԤƤ\n\
\n\
1. 󥹥ȡ븵\n\
2. 󥹥ȡLinuxѡƥ\n\
3. 󥹥ȡ뤹ǥåȤ\n\
\n\
ܡѹꡢåץѡƥ\n\
Ǥޤ\n\
\n\
ᥤ˥塼ޤENTER򲡤Ƥ" 16 70
   continue
  fi
  SERIES="`cat /tmp/SeTSERIES`"
  SOURCE_DEVICE="`cat /tmp/SeTsource`"
  IGNORE_TAGFILES=""

  while [ 0 ]; do
   dialog --title "ץץȥ⡼ɤ" --menu "\
\n\
󥹥ȡκݤΥեɤ뤫򤷤\n\
褯狼ʤϥإפɤǤ\n\n\
ɤΥץץȥ⡼ɤѤޤ\
" 19 70 7 \
"RECOM" "ƥ꡼ñ̤Ƥ򥤥󥹥ȡ()" \
"EXPERT" "ġΥѥå(ܤ͸)" \
"HELP" "ץץȥ⡼ɤΥإפɤ" 2> /tmp/SeTpmode
   if [ $? = 1 -o $? = 255 ]; then
    rm -f /tmp/SeTpmode
    exit
   fi
   MODE="`cat /tmp/SeTpmode`"
   rm -f /tmp/SeTtagext

   if [ "$MODE" = "HELP" ]; then
    dialog --title "ץץȥ⡼ɤΥإ" --textbox "/usr/lib/setup/PROMPThelpj" 19 65
   fi

   if [ "$MODE" = "RECOM" ]; then
    touch /tmp/recom
    dialog --infobox "⡼ɡƥ꡼ñ̤ƤΥѥå \n\
󥹥ȡ뤷ޤ" 4 70
    break;
   fi

   if [ "$MODE" = "EXPERT" ]; then
    touch /tmp/SeTQUICK
    MAKETAG="maketag"
    dialog --infobox "˥塼ץץȥ⡼ɡ˥塼Ѥ \n\
ġΥѥå򤷤ޤ" 4 70
    break;
   fi 
  done

  export MAKETAG;
  sleep 3
 
 if [ ! -r /tmp/SeTCDdev ]; then # only try to remount media if it's a CD/DVD
    slackinstall --device noremount --promptmode $MODE --srcpath `cat /tmp/SeTDS` --mountpoint /var/log/mount --target $T_PX --series "$SERIES"
  else
    echo " calling slackinstall with --device `cat /tmp/SeTCDdev` --promptmode $MODE --srcpath `cat /tmp/SeTDS` --mountpoint /var/log/mount --target $T_PX --series $SERIES"
    slackinstall --device `cat /tmp/SeTCDdev` --promptmode $MODE --srcpath `cat /tmp/SeTDS` --mountpoint /var/log/mount --target $T_PX --series "$SERIES"
  fi
 
  MAINSELECT="CONFIGURE"
 fi

 if [ "$MAINSELECT" = "CONFIGURE" ]; then
  if [ -r /tmp/SeTnative ]; then
   if [ -r /mnt/etc/fstab ]; then
    dialog --title "/etc/fstab򹹿ޤ" --yesno "
󥹥ȡѡƥˤǤ/etc/fstabޤñ\n\
˥եȥɲäʤ顢/etc/fstabϤΤޤޤˤ\n\
褤Ǥ礦ѡƥѹƤ顢\n\
/etc/fstabȿǤʤФʤޤ󡣸Ť/etc/fstab򹹿\n\
ޤ" 10 70
    if [ $? = 0 ]; then
     cat /dev/null > /mnt/etc/fstab
     if [ -r /tmp/SeTswap ]; then
      cat /tmp/SeTswap > /mnt/etc/fstab
     fi
     cat /tmp/SeTnative >> /mnt/etc/fstab
     # Mount up the CD-ROM if it exists...
     # if [ -r /tmp/SeTcdfstab ]; then
     # mkdir -p /mnt/cdrom
     # cat /tmp/SeTcdfstab >> /tmp/SeTDOS
     #fi
     if [ -r /tmp/SeTDOS ]; then
      cat /tmp/SeTDOS >> /mnt/etc/fstab
     fi
     echo "/dev/cdrom       /cdrom   iso9660   user,ro,noauto,exec,iocharset=euc-jp 0   0" >> /mnt/etc/fstab
     echo "/dev/scd0       /cdrom   iso9660   user,ro,noauto,exec,iocharset=euc-jp 0   0" >> /mnt/etc/fstab
     echo "none             /proc    proc        defaults   0   0" >> /mnt/etc/fstab
     echo "none             /sys     sysfs       defaults   0   0" >> /mnt/etc/fstab
     echo "none             /dev     tmpfs       defaults   0   0" >> /mnt/etc/fstab
     echo "none		    /tmp     tmpfs       defaults   0   0" >> /mnt/etc/fstab
     echo "none            /dev/pts        devpts  gid=5,mode=620    0 0" >> /mnt/etc/fstab
     echo "none            /proc/bus/usb             usbfs        noauto   0   0" >> /mnt/etc/fstab

    fi
   else # /mnt/etc/fstab not found
    cat /dev/null > /mnt/etc/fstab
    if [ -r /tmp/SeTswap ]; then
     cat /tmp/SeTswap > /mnt/etc/fstab
    fi
    cat /tmp/SeTnative >> /mnt/etc/fstab
    # Mount up the CD-ROM if it exists...
    #if [ -r /tmp/SeTcdfstab ]; then
    # mkdir -p /mnt/cdrom
    # cat /tmp/SeTcdfstab >> /tmp/SeTDOS
    #fi
    if [ -r /tmp/SeTDOS ]; then
     cat /tmp/SeTDOS >> /mnt/etc/fstab
    fi
    echo "/dev/cdrom       /cdrom   iso9660   user,ro,noauto,exec,iocharset=euc-jp 0   0" >> /mnt/etc/fstab
    echo "/dev/scd0       /cdrom   iso9660   user,ro,noauto,exec,iocharset=euc-jp 0   0" >> /mnt/etc/fstab
    echo "none             /proc    proc        defaults   0   0" >> /mnt/etc/fstab
     echo "none             /sys     sysfs       defaults   0   0" >> /mnt/etc/fstab
     echo "none             /dev     tmpfs       defaults   0   0" >> /mnt/etc/fstab
     echo "none		    /tmp     tmpfs       defaults   0   0" >> /mnt/etc/fstab
     echo "none            /dev/pts        devpts  gid=5,mode=620    0 0" >> /mnt/etc/fstab
     echo "none            /proc/bus/usb             usbfs        noauto   0   0" >> /mnt/etc/fstab
   fi
  fi
  SeTconfigj
   dialog --title "åȥå״λ" --msgbox "ƥ꤬λޤåȥåפλ\n\
CTRL-ALT-DEL򲡤ƥޥ֡ȤƤ \
" 6 60
 fi

 if [ "$MAINSELECT" = "EXIT" ]; then
  break
 fi

done # end of main loop
 
sync
if mount | grep /var/adm/mount 1> /dev/null 2> /dev/null ; then
 umount /var/adm/mount 
fi
if mount | grep /var/log/mount 1> /dev/null 2> /dev/null ; then
 umount /var/log/mount 
fi
rm -f /var/adm/mount 2> /dev/null
rmdir /var/adm/mount 2> /dev/null
mkdir /var/adm/mount 2> /dev/null
chmod 755 /var/adm/mount
chmod 755 $T_PX
if [ -d $T_PX/tmp ]; then
 chmod 1777 $T_PX/tmp
fi
if [ -f /tmp/SeTCDdev ]; then
  eject `cat /tmp/SeTCDdev`
fi
rm -f /tmp/tagfile /tmp/SeT*
# end slackware setup script


