#!/bin/sh
# rc.S:  Basic system initialization.

# Any /etc/mtab that exists here is old, so we start with a new one:
/bin/rm -f /etc/mtab{,~,.tmp} && /bin/touch /etc/mtab

# Add (fake) entry for / to /etc/mtab:
/sbin/mount -f -w /dev/initramfs / -t tmpfs 1> /dev/null

# Mount /proc:
/sbin/mount -v proc /proc -t proc 1> /dev/null

# Mount sysfs next:
/sbin/mount -v sysfs /sys -t sysfs 1> /dev/null

# Activate swap:
/sbin/swapon -a 1> /dev/null

if [ -x /sbin/ldconfig ]; then
  /sbin/ldconfig 1> /dev/null
fi

export TEXTDOMAIN=slint
. gettext.sh

## Detect serial console from kernel command line:
#if cat /proc/cmdline | grep console=ttyS 1> /dev/null 2> /dev/null ; then
#  SERIAL_CONSOLE="true"
#fi

# System logger (mostly to eat annoying messages):
/sbin/syslogd 2> /dev/null
sleep 1
/sbin/klogd -c 3 1> /dev/null

# Try to load the loop module:
modprobe loop 1> /dev/null 2> /dev/null

# Run udev:
if ! grep -wq noudev /proc/cmdline ; then
  /bin/bash /etc/rc.d/rc.udev start

  # Re-assemble RAID volumes:
  /sbin/mdadm -E -s > /etc/mdadm.conf
  /sbin/mdadm -S -s
  /sbin/mdadm -A -s
  # This seems to make the kernel see partitions more reliably:
  fdisk -l /dev/md* 1> /dev/null 2> /dev/null
else

  # Look for USB keyboard or storage:
  /etc/rc.d/rc.usb start
  sleep 3

  # Look for IEEE1394 devices:
  if grep 1394 /proc/pci 1> /dev/null 2> /dev/null ; then
    /etc/rc.d/rc.ieee1394 start
    #sleep 3
  fi

  ### PROBABLY USELESS WITHOUT SOME TIMED DELAY ABOVE
  ## Start USB again (in case we missed a USB keyboard)
  #/etc/rc.d/rc.usb start

  # Make detected partitions:
  /dev/makedevs.sh

  # Re-assemble RAID volumes:
  /sbin/mdadm -E -s > /etc/mdadm.conf
  /sbin/mdadm -S -s
  /sbin/mdadm -A -s
  # This seems to make the kernel see partitions more reliably:
  fdisk -l /dev/md* 1> /dev/null 2> /dev/null

  # Check /proc/partitions again:
  /dev/makedevs.sh

  # Create LVM nodes:
  /dev/devmap_mknod.sh

fi # End Run udev:

# Start brltty if requested in the command line - Didier Spaier
if grep -wq brltty /proc/cmdline; then
  echo "starting brltty"
  sleep 3
  /bin/brltty
  sleep 2
fi

touch /.today
/bin/sh /sbin/fakedate

if [ -x /etc/rc.d/rc.inet1 ]; then
  /bin/sh /etc/rc.d/rc.inet1
fi

# pcmciautils is installing rc.pcmcia as chmod 644, so we'll change that.
# It won't be run at boot time, but it'll make it easy for the pcmcia script
# or to run it from the command line.
chmod 755 /etc/rc.d/rc.pcmcia

# Scan for existing LVM partitions:
# We will run 'vgscan -ay' in the setup to prevent a 10 second sleep;
vgscan --mknodes 2> /tmp/foo
cat /tmp/foo | uniq
rm -f /tmp/foo

/bin/sh /etc/rc.d/rc.font

# Don't automatically blank the screen, or it will go black during the install
# process when stray keystrokes might be dangerous:
/bin/setterm -blank 0

TMP=/var/log/setup/tmp
if [ ! -d $TMP ]; then
 mkdir -p $TMP
fi

TMP=/var/log/setup/tmp
if grep -wq brltty /proc/cmdline; then
  if [ ! -r /dev/tty1 ]; then
    mknod /dev/tty1 c 4 1
    chown root:tty /dev/tty1
    chmod 620 /dev/tty1
  fi
  if [ ! -r /dev/tty2 ]; then
    mknod /dev/tty2 c 4 2
    chown root:tty /dev/tty2
    chmod 620 /dev/tty2
  fi
  if [ ! -r /dev/tty3 ]; then
    mknod /dev/tty3 c 4 3
    chown root:tty /dev/tty3
    chmod 620 /dev/tty3
  fi
  if [ ! -r /dev/tty4 ]; then
    mknod /dev/tty4 c 4 4
    chown root:tty /dev/tty4
    chmod 620 /dev/tty4
  fi
    /bin/stty -F /dev/tty1 cols 80 rows 25
    /bin/stty -F /dev/tty2 cols 80 rows 25
    /bin/stty -F /dev/tty3 cols 80 rows 25
    /bin/stty -F /dev/tty4 cols 80 rows 25
fi

kbd_stored="`cat /tmp/Pkeymap`"
kbd=${kbd_stored%.*}

echo
echo
sleep 5
eval_gettext "<OPTION TO LOAD SUPPORT FOR ANOTHER KEYBOARD>

If you are not using a \"\$kbd\" keyboard map, you may load another one now.
To select a different keyboard map, please enter 1 now.
To continue using the \"\$kbd\" keyboard map, just hit [Enter]."
echo
echo
gettext "Enter 1 to select a keyboard map: "
read ONE
if [ "$ONE" = "1" ]; then
  /usr/lib/setup/SeTkeymap
fi
clear

echo > /etc/motd
echo "`/bin/uname -a | /bin/cut -d\  -f1,3`." >> /etc/motd
echo >> /etc/motd
gettext "If you're upgrading an existing Slint system, you might want to
remove old packages before you run 'setup' to install the new ones. If
you don't, your system will still work but there might be some old files
left laying around on your drive.

Just mount your Linux partitions under /mnt and type 'pkgtool'. If you
don't know how to mount your partitions, type 'pkgtool' and it will tell
you how it's done.

To partition your hard drive(s), use 'cfdisk' or 'fdisk'.
For systems using GPT instead of MBR, partition using 'cgdisk' or 'gdisk'.
To activate PCMCIA/Cardbus devices needed for installation, type 'pcmcia'.
To start the main installation (after partitioning), type 'setup'.

" >> /etc/motd
echo > /etc/motd.net
gettext "First command to run is 'source /etc/profile'.
This will setup the PATH for you." >> /etc/motd.net
echo >> /etc/motd.net
echo >> /etc/motd.net

. /etc/profile

# Provision for unattended network configuration:
/usr/lib/setup/SeTnet boot
# Start dropbear ssh server (only if a configured interface is present):
/etc/rc.d/rc.dropbear start

# Fake login:  (fooled ya! ;^)
#
Version=14.2
eval_gettext "


Welcome to the Slint Linux installation disk! (version \${Version})

######  IMPORTANT!  READ THE INFORMATION BELOW CAREFULLY.  ######

- You will need one or more partitions of type 'Linux' prepared.  It is also
  recommended that you create a swap partition (type 'Linux swap') prior
  to installation.  For more information, run 'setup' and read the help file.

- If you're having problems that you think might be related to low memory, you
  can try activating a swap partition before you run setup.  After making a
  swap partition (type 82) with cfdisk or fdisk, activate it like this:
    mkswap /dev/<partition> ; swapon /dev/<partition>

- Once you have prepared the disk partitions for Linux, type 'setup' to begin
  the installation process.

- If you do not have a color monitor, type:  TERM=vt100
  before you start 'setup'.

You may now login as 'root'.


slint login: "
read BOGUS_LOGIN
cat /etc/motd
