#!/bin/bash

############################################################################
# Program: armedslack-current/slackware/tinstall.sh
# Purpose: In lieu of an installer, install ARMedSlack packages onto a
#          locally mounted root file system.
# Author : Stuart Winter <stuart@armedslack.org>
# Version: 1.00
# Date...: 30-May-2004
############################################################################
# Usage: tinstall.sh [riscpc]
############################################################################
# Warnings:
# [1] If this goes mad and installs ARM binaries all over your x86 Slackware
#     system then I DO NOT ACCEPT ANY RESPONSIBILITY
#     (it shouldn't do though)
#
# Caveats:
# [1] Some packages may not be configured correctly because the post install
#     script (install/doinst.sh) cannot execute part of the newly installed
#     package.  An example is n/bind which tries to create a key for rndc.
#     I don't see this as being a major problem, but if anybody notices
#     that a specific package is seriously broken because of this then
#     please let me know and I'll try and work around it.
#
# Notes:
# [1] This will leave your new ARMedslack installation without a root
#     password.  Use passwd to set it when you first boot the system.

SLKROOT=/mnt/armedslackinstall
PKGSTORE=$PWD

# Ensure we can see /mnt/armedslack mounted; I don't do this now
# because I often install locally onto an x86 box so that I can chroot into it
# using qemu.  It makes for a great disposable devbox!
#( mount | grep ${SLKROOT} ) || { echo "I can't find ${SLKROOT} mounted" ; exit 1; }

# This helps a little with the etc package:
mkdir -p ${SLKROOT}/{etc,usr/etc}

# Wibble our way through the package series:
# Yes, I know! Some of these directories are empty! I haven't built the packages
# yet! :-)
cd ${PKGSTORE}
for series in a ap d e f k kde kdei l n t tcl x xap y ; do
    ( echo "Installing package series '${series}'"
      cd ${series} && find . -name '*.tgz' -exec installpkg -root ${SLKROOT} {} \; )
done

# Create a **Sample** fstab:
printf "
/dev/hdd1        swap             swap        defaults         0   0
/dev/hdd2        /                ext3        defaults         1   1
/dev/cdrom       /mnt/cdrom       iso9660     noauto,owner,ro  0   0
/dev/fd0         /mnt/floppy      auto        noauto,owner     0   0
devpts           /dev/pts         devpts      gid=5,mode=620   0   0
proc             /proc            proc        defaults         0   0
" > $SLKROOT/etc/fstab
chmod 644 $SLKROOT/etc/fstab
chown root:root $SLKROOT/etc/fstab

# Create the all important /etc/ld.so.cache
# Without this your system will not boot.
ldconfig -r ${SLKROOT}

# Set keymap for acorn.  No longer required for Linux 2.6 and since
# ARMedslack uses 2.6 as its standard Kernel, I don't care for these anymore.
#if [ "$1" = "riscpc" ]; then
#   ( cd ${SLKROOT}/usr/share/kbd
#     rm -vf keymaps
#     ln -vs keymaps-acorn-for-linux-2.4 keymaps )
#fi

# Set the timezone to Europe/London. You should use timeconfig to
# change this if you're not in the UK.
( cd ${SLKROOT}/etc
  rm -f localtime*
  ln -vfs /usr/share/zoneinfo/Europe/London localtime-copied-from
  cp -favv ${SLKROOT}/usr/share/zoneinfo/Europe/London localtime )

# zaden's always the lucky one. The other build machines live on older 
# builds of armedslack until I feel that the new stuff is stable.
if [ "$1" = "dev" ]; then

   # Stop the console from blanking
   sed -i -e 's/-blank\ 15.*/-blank\ 0/' \
       -e 's/blanks\ after\ 15\ minutes/never\ blanks\ with/' $SLKROOT/etc/rc.d/rc.M

   echo "loadkeys uk" >> $SLKROOT/etc/rc.d/rc.local
   rm -f ${SLKROOT}/etc/{securetty,issue*}
   mkdir -p ${SLKROOT}/mnt/turrican
   echo "zaden.armedslack.org" > ${SLKROOT}/etc/HOSTNAME
   cat << EOF > ${SLKROOT}/etc/resolv.conf
search armedslack.org polplex.org.uk
nameserver 192.168.1.1
EOF

   # The RTC on the RiscPC Kernel is screwed and I don't want the dates on my packages to
   # be incorrect:
   echo 'ntpdate gate.demon.co.uk >/dev/null 2>&1' > ${SLKROOT}/etc/cron.hourly/updateclock
   echo 'ntpdate gate.demon.co.uk' >> ${SLKROOT}/etc/rc.d/rc.local
   chmod 755 ${SLKROOT}/etc/cron.hourly/updateclock

   # I like telnetting into my local machines & since I do the packaging as root
   # and I don't have to worry about security on my network ;p
   # Obviously I don't *recommend* this practice:
   perl -pi -e 's/^#(?=telnet)//' $SLKROOT/etc/inetd.conf
   perl -pi -e 's/^#(?=PermitRootLogin)//' $SLKROOT/etc/ssh/sshd_config
fi

# This makes my machines hammer the hard discs for long enough to wake me up.
# This will be removed when I change house :)
chmod -x ${SLKROOT}/etc/cron.daily/slocate

# I like WindowMaker to be my default Window Manager:
( cd $SLKROOT/etc/X11/xinit && ln -fs xinitrc.wmaker xinitrc )

# We're finished
cat << EOF
The package installation is complete.

You may wish to check ${SLKROOT}/etc/fstab to ensure
that it is correct.

You may now unmount & clean up ${SLKROOT} by doing:
 # cd /
 # umount ${SLKROOT}
 # rm -rf ${SLKROOT}

Now continue reading the rest of the document.

EOF
