#!/bin/sh

# Script : sansinstaller
# Purpose: Install Slackware quick and dirty without the Slackware installer
#          For use for bootstrapping a new port when the installer isn't
#          yet available.
#          For best results, run this script on the same architecture as
#          the packages you've prepared (eg run this on an existing ARM box).
#          This is because many of the package's post install scripts run
#          ARM binaries, which obviously won't work if you run this script
#          on x86.
# Author:  Stuart Winter <mozes@slackware.com>
# Date::   15-Sept-2009

### Notes ####
# [1] This script needs to be put into the "slackware" directory
#     eg.  armedslack-12.2/slackware
#     As root user on which ever host you choose, run it from this directory.
#       cd armedslack-12.2/slackware
#       ./sansinstaller
# [2] READ this script and make the modifications you need.
# [3] This script is not supported.
##############

# Set your host name:
NEWHOST="zaden.armedslack.org"
#NEWHOST="stokely.armedslack.org"
#NEWHOST="dastardly.armedslack.org"
#NEWHOST="mutley.armedslack.org"

# Set your root password:
ROOTPASS="password"

# Installing onto USB stick mounted on muddy/x86 laptop:
# /boot will need moving by hand
#B=/mnt/muddy/mnt/as/root/

# Onto local disk -- another partition:
# So this is where your new ARM OS' root, "/" will be.
# This could be anything -- I used to put a USB stick or disc into an x86
# machine, and run this on an existing ARM box, having mounted the USB stick
# over NFS.
#B=/mnt/hd
B=/tmp/chrootable
rm -rf $B
mkdir -vpm755 $B

# Install base packages required in order for the rest of the packages
# to install correctly.
# Some packages will be re-installed later -- this is fine.
installpkg -root $B a/aaa_base-*.t?z
installpkg -root $B a/etc-*.t?z
installpkg -root $B a/coreutils-*.t?z
installpkg -root $B a/sed-*.t?z
installpkg -root $B a/bin-*.t?z
installpkg -root $B a/attr-*.t?z
installpkg -root $B a/acl-*.t?z
installpkg -root $B d/gcc-*.t?z
find . -name '*.t?z' | while read pkg ; do
  installpkg -root $B  $pkg
done

# You'll need to update the fstab to match your environment:
# The two /dev/sda3 and /dev/sda4 were for when I was running this script
# on an existing ARM box, where I had two "root" partitions.  I'd
# have one live one, and once I was ready to reinstall, I'd install
# the second partition; change the fstab entries below; reboot into U-Boot
# and change the root parameters, and boot into the new installation.
cd $B
cat << EOF > etc/fstab
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
/dev/sda1       /boot               ext2    errors=remount-ro 0       1

#/dev/sda3       /               ext4    errors=remount-ro 0       1
#/dev/sda4       /mnt/hd         ext4    errors=remount-ro 0       1

/dev/sda4       /               ext4   errors=remount-ro 0       1
/dev/sda3       /mnt/hd         ext4    errors=remount-ro 0       1


/dev/sda2       none            swap    sw              0       0
EOF

# Update your resolver details:
cat << EOF > etc/resolv.conf
search polplex.org.uk
nameserver 192.168.1.1
EOF
# I need SSHd and RPC for NFS running at boot:
chmod +x etc/rc.d/rc.{ssh*,rpc}

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

# Set the host name:
echo $NEWHOST > etc/HOSTNAME

# Update fonts so that X and xVNC will work:
( cd usr/share/fonts/
  find . -type d -mindepth 1 -maxdepth 1 | while read dir ; do
  ( cd $dir
     mkfontscale .
     mkfontdir . )
  done
/usr/bin/fc-cache -f )

# Set default window manager:
( cd etc/X11/xinit/
  ln -vfs xinitrc.wmaker xinitrc )

# Allow root login on the first serial port
# (useful for SheevaPlugs and Marvell OpenRD-Client systems, and numerous others)
sed -i 's?^#ttyS0?ttyS0?' etc/securetty
# Start a login on the first serial port:
sed -i '/^# Local serial lines:/ a\s0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100' etc/inittab

# Set root password:
cat << EOF > tmp/setrootpw
/usr/bin/echo "root:$ROOTPASS" | /usr/sbin/chpasswd
EOF
chmod 755 tmp/setrootpw
chroot $B /tmp/setrootpw
rm -f tmp/setrootpw

#EOF
