#!/bin/sh # locknload by Linus Sphinx 1/3/2004 # Copyright (c) 2004 Linus Sphinx # Part of the gn*nix conspiracy http://gnnix.org # when consultants attack... # TZ=UTC DIALOGRC=/etc/bw.rc MTPT=/mnt/cdrom ROOT=/mnt/root KVER=2.6.6 MODULESTGZ=${MTPT}/tool/modules.tgz export MTPT KVER MODULESTGZ CDROM DIALOGRC ROOT bail=0 retval=0 showinitialprogress() { if [ "$bail" = "1" ]; then echo "We will now exit so you can attempt to fix the problem" >> /tmp/log else echo "ready to begin." >> /tmp/log fi dialog --title "| gn*nix init |" --exit-label " close " --tailbox /tmp/log 0 0 if [ "$bail" = "1" ]; then exit 1 fi } findandmountgnnix() { echo "looking for ide cdrom..." >> /tmp/log find /proc/ide -name media -print | while read i do grep -q cdrom $i if [ "$?" -eq "0" ]; then olifs=$IFS IFS=/ set $i IFS=$olifs echo mount -t iso9660 -r /dev/${5} $MTPT >> /tmp/log mount -t iso9660 -r /dev/${5} $MTPT if [ -f $MODULESTGZ ]; then echo -n /dev/${5} > /tmp/cdrom echo successfully mounted /dev/${5} >>/tmp/log FOUND=yes return else FOUND=no umount $MTPT fi fi done if [ "$FOUND" = "no" ]; then echo "looking for scsi cdrom..." >> /tmp/log find /dev -name scd? -print | while read i do mount -t iso9660 -r ${i} $MTPT >> /tmp/log mount -t iso9660 -r ${i} $MTPT if [ -f $MODULESTGZ ]; then echo -n ${i} > /tmp/cdrom echo successfully mounted ${i} >>/tmp/log FOUND=yes return else FOUND=no umount $MTPT fi done fi } unpackmodulesdep() { if [ -f $MODULESTGZ ]; then echo "unpacking module dependencies..." >> /tmp/log cd /lib/modules/${KVER} zcat $MODULESTGZ | tar x ./modules.* if [ -f /lib/modules/${KVER}/modules.dep ]; then echo "successfully extracted modules.dep" >> /tmp/log else echo "ERROR extracting modules.dep" >> /tmp/log echo "zcat $MODULESTGZ | tar x ./modules.dep in /lib/modules FAILED." >> /tmp/log bail=1 fi else echo "CANNOT LOCATE GNNIX CDROM" >> /tmp/log bail=1 # do something helpful here fi } keydirsformenu() { cd $KEYDIRS let x=1 ls -1 | sort -r | grep -v README | grep -v include | grep -v mk_modmap | while read i do echo $i $x let x=$x+1 done } chooseeditor() { exec 3>&1 val=`dialog --clear --title "| choose an editor to use |" --ok-label "Use" \ --cancel-label "Back" --menu \ "Save the file created as /tmp/fstab" 0 0 0 \ "Vi" "The classic *NIX editor " \ "Nano" "A not like VI editor " \ 2>&1 1>&3` rval=$? exec 3>&- if [ "$rval" = "0" ]; then if [ "$val" = "Vi" ]; then vi $1 elif [ "$val" = "Nano" ]; then nano $1 fi fi } listdeviceforchecklist() { find /dev -type b -name ?d? -print | while read i do if [ $i != `cat /tmp/cdrom` ]; then echo "${i#/dev/} $i $i" fi done } listfsforchecklist() { for g in $@ do grep ${g} /tmp/fstab | while read i do set ${i} echo ${1#/dev/} ${3} ${1} done done } fkfs() { drv=`grep ${1} /tmp/fstab` if [ "$?" = "0" ]; then set $drv trg=${1} typ=${3} if [ "$typ" = "ext2" ]; then clear echo mkfs.ext2 -v ${trg} mkfs.ext2 -v ${trg} if [ "$?" != "0" ]; then dialog --msgbox "mkfs.ext2 ${trg} failed!" 0 0 fi elif [ "$typ" = "ext3" ]; then clear echo mkfs.ext3 -v ${trg} mkfs.ext3 -v ${trg} if [ "$?" != "0" ]; then dialog --msgbox "mkfs.ext3 ${trg} failed!" 0 0 fi elif [ "$typ" = "xfs" ]; then clear echo mkfs.xfs -f ${trg} mkfs.xfs -f ${trg} if [ "$?" != "0" ]; then dialog --msgbox "mkfs.xfs ${trg} failed!" 0 0 fi elif [ "$typ" = "reiserfs" ]; then clear echo mkfs.reiserfs ${trg} mkfs.reiserfs ${trg} if [ "$?" != "0" ]; then dialog --msgbox "mkfs.reiserfs ${trg} failed!" 0 0 fi elif [ "$typ" = "jfs" ]; then clear echo mkfs.jfs -q ${trg} mkfs.jfs -q ${trg} if [ "$?" != "0" ]; then dialog --msgbox "mkfs.jfs -q ${trg} failed!" 0 0 fi elif [ "$typ" = "swap" ]; then clear echo mkswap ${trg} mkswap ${trg} if [ "$?" != "0" ]; then dialog --msgbox "mkswap ${trg} failed!" 0 0 fi fi fi } makefs() { if [ ! -s /tmp/fstab ]; then dialog --msgbox "Create a /tmp/fstab first. It controls what filesystem type to use on which partitions." 0 0 return fi dialog --title "| available devices |" \ --cancel-label "Back" --ok-label "Continue" \ --checklist "select targets to include" 0 0 0 \ `listdeviceforchecklist` 2> /tmp/mfztab if [ -s /tmp/mfztab ]; then ds="" for i in `cat /tmp/mfztab` do dl=${i#\"} dr=${dl%\"} ds="$ds /dev/$dr" done dialog --title "| available devices |" \ --cancel-label "Back" --ok-label "Continue" \ --checklist "select targets to include" 0 0 0 \ `listfsforchecklist $ds` 2> /tmp/mfztab for j in `cat /tmp/mfztab` do dl=${j#\"} ds=${dl%\"} fkfs /dev/${ds} done dialog --title "| gn*nix |" --exit-label " close " --msgbox "FileSystems Made" 0 0 fi rm -f /tmp/mfztab } selectable() { dialog --title "| available devices |" \ --cancel-label "Back" --ok-label "Continue" \ --checklist "targets to include" 0 0 0 \ `listdeviceforchecklist` 2> /tmp/fztab if [ ! -s /tmp/fstab ]; then echo "# /etc/fstab" >> /tmp/fstab echo "# static file system information" >> /tmp/fstab echo "#" >> /tmp/fstab echo "# This file is not used by the kernel, but rather by mount(8) and umount(8)" >> /tmp/fstab echo "# (and some day fsck(8)). Comment lines have "#" in the first column." >> /tmp/fstab echo "# Entries that are to be ignored should have "none" in the directory field," >> /tmp/fstab echo "# and have type "ignore" or options "xx". Frequency and pass are numeric" >> /tmp/fstab echo "# fields for dump(8) and fsck(8) that are not used yet in Linux. You can" >> /tmp/fstab echo "# leave them empty if want." >> /tmp/fstab grep -q devpts /tmp/fstab if [ "$?" = "1" ]; then echo -e "devpts\t\t/dev/pts\tdevpts\tgid=5,mode=620\t0\t0" >> /tmp/fstab fi grep -q proc /tmp/fstab if [ "$?" = "1" ]; then echo -e "proc\t\t/proc\t\tproc\tdefaults\t0\t0" >> /tmp/fstab fi grep -q cdrom /tmp/fstab if [ "$?" = "1" ]; then echo -e "`cat /tmp/cdrom`\t/mnt/cdrom\tiso9660\tnoauto,owner,ro\t0\t0" >> /tmp/fstab fi grep -q fd0 /tmp/fstab if [ "$?" = "1" ]; then echo -e "/dev/fd0\t/mnt/floppy\tauto\tnoauto,owner\t0\t0" >> /tmp/fstab fi grep -q sysfs /tmp/fstab if [ "$?" = "1" ]; then echo -e "sysfs\t\t/sys\t\tsysfs\tdefaults\t0\t0" >> /tmp/fstab fi echo -e "lazyfs\t/uri/0install\tlazyfs0d1d23\t/usr/local/zero\t0\t0" >> /tmp/fstab fi if [ -s /tmp/fztab ]; then for i in `cat /tmp/fztab` do cl=${i#\"} cr=${cl%\"} fdisk -l /dev/${cr} | grep /dev/ | grep -v Extended | grep -v Disk | sed 's/*/ROOTY/g' > /tmp/mztab done let mnt=1 if [ -s /tmp/mztab ]; then grep Linux /tmp/mztab | while read i do set $i grep -q $1 /tmp/fstab if [ "$?" = "1" ]; then if [ "$6" = "83" ]; then echo -e "$1\t/\t\t`fstype $6`\tdefaults\t1\t1" >> /tmp/fstab elif [ "$6" = "85" ]; then echo -e "$1\t/\t\t`fstype $6`\tdefaults\t1\t1" >> /tmp/fstab elif [ "$5" = "82" ]; then echo -e "$1\tswap\t\tswap\tdefaults\t0\t0" >> /tmp/fstab elif [ "$5" = "83" ]; then echo -e "$1\t`mountpoint $mnt $1`\t\t`fstype $5`\tdefaults\t1\t2" >> /tmp/fstab let mnt=$mnt+1 elif [ "$5" = "85" ]; then echo -e "$1\t`mountpoint $mnt $1`\t\t`fstype $5`\tdefaults\t1\t2" >> /tmp/fstab let mnt=$mnt+1 else echo -e "$1\tnone\t\t`fstype $5`\tdefaults\t1\t2" >> /tmp/fstab fi fi done chooseeditor /tmp/fstab fi fi rm -f /tmp/fztab } mountpoint() { if [ "$1" = "1" ]; then echo /boot elif [ "$1" = "2" ]; then echo /usr elif [ "$1" = "3" ]; then echo /home elif [ "$1" = "4" ]; then echo /var elif [ "$1" = "5" ]; then echo /tmp elif [ "$1" = "6" ]; then echo /usr/local elif [ "$1" = "7" ]; then echo /db else (( di = $1 - 6 )) echo /db${di} fi } fstype() { if [ "$1" = "-1" ]; then echo unusable elif [ "$1" = "0" ]; then echo vfat elif [ "$1" = "7" ]; then echo ntfs elif [ "$1" = "f" ]; then echo hpfs elif [ "$1" = "85" ]; then echo reiserfs elif [ "$1" = "81" ]; then echo minix elif [ "$1" = "82" ]; then echo swap elif [ "$1" = "83" ]; then echo xfs else echo unknown fi } listdeviceformenu() { find /dev -type b -name ?d? -print | while read i do if [ $i != `cat /tmp/cdrom` ]; then echo "${i#/dev/} $i" fi done } selectdevice() { dialog --title "| available devices |" \ --cancel-label "Back" --ok-label "Continue" \ --menu "select a target" 0 0 0 \ `listdeviceformenu` 2> /tmp/devize retval=$? case $retval in 0) clear if [ -s /tmp/devize ]; then drv=`cat /tmp/devize` $1 /dev/${drv} fi ;; 1) ;; esac return } formatfdiskmenu() { while true do exec 3>&1 val=`dialog --clear --title "| media preparation |" --help-button --ok-label "Go" --cancel-label "Back" \ --menu "First time here? READ THE HELP" 0 0 0 \ "I" "Install Modules Only If Required " \ "C" "Use Cfdisk To Partition A Device " \ "F" "Use Fdisk To Partition A Device " \ 2>&1 1>&3` retval=$? exec 3>&- case $retval in 0) if [ "$val" = "I" ]; then modprober elif [ "$val" = "C" ]; then if [ `ls -1 /dev/?d? | wc -l` < 2 ]; then dialog --msgbox "No Devices Found, Module Not Loading?" 0 0 else selectdevice cfdisk fi elif [ "$val" = "F" ]; then if [ `ls -1 /dev/?d? | wc -l` < 2 ]; then dialog --msgbox "No Devices Found, Module Not Loading?" 0 0 else selectdevice fdisk fi fi ;; 1) return ;; 2) dialog --title "| fdisk help |" --exit-label "close" --textbox /etc/fshelp.txt 0 0 ;; esac done } availablesoftware() { ls -1 $1 | while read i do pkg=`echo ${i%.gnx}` olifs=$IFS IFS=- set $pkg IFS=$olifs if [ "$2" = "" ]; then echo $1 latest $1.gnx elif [ "$3" != "" ]; then echo "${1}-${2} $3 ${1}-${2}-${3}.gnx" else echo "$1 $2 ${1}-${2}.gnx" fi done } softwarelist() { dialog --clear --separate-output --title "| software available |" --cancel-label "Back" \ --help-label "Help" --checklist "Program Version" 0 0 0 \ `availablesoftware $1` 2>/tmp/warez } softwarebundlelistdir() { ret=0 gnxmount 2>>/tmp/log 1>>/tmp/log cd ${MTPT} star=`du -sk ${MTPT}/parts/bin | cut -f1`k if [ "$star" = "k" ]; then star=0k fi base=`du -sk ${MTPT}/parts/bin/base | cut -f1`k if [ "$base" = "k" ]; then base=0k fi grfx=`du -sk ${MTPT}/parts/bin/grfx | cut -f1`k if [ "$grfx" = "k" ]; then grfx=0k fi ears=`du -sk ${MTPT}/parts/bin/ears | cut -f1`k if [ "$ears" = "k" ]; then ears=0k fi mail=`du -sk ${MTPT}/parts/bin/mail | cut -f1`k if [ "$mail" = "k" ]; then mail=0k fi wapp=`du -sk ${MTPT}/parts/bin/wapp | cut -f1`k if [ "$wapp" = "k" ]; then wapp=0k fi exts=`du -sk ${MTPT}/parts/bin/exts | cut -f1`k if [ "$exts" = "k" ]; then exts=0k fi while [ "$ret" != "1" ] do dialog --clear --separate-output --title "| bundles available |" \ --cancel-label "Back" --help-label "Help" --checklist \ "Select All Or At Least Base For A New System" 0 0 0 \ "ALL" "The Complete System ${star}" "star" \ "base" "Base Operating System ${base}" "base" \ "grfx" "Graphic Workstation ${grfx}" "grfx" \ "ears" "Audio Applications ${ears}" "ears" \ "mail" "Mail and Directory Server ${mail}" "mail" \ "wapp" "Web Application XML Server ${wapp}" "apps" \ "exts" "Extra Shells, Tools not required ${exts}" "exts" 2>/tmp/bundlez ret=$? if [ "$ret" = "0" ]; then clear grep -q ALL /tmp/bundlez if [ "$?" = "0" ]; then for i in `ls -1 parts/bin` do for j in `ls -1 parts/bin/${i}` do if [ -f ${MTPT}/parts/pre/${j%.gnx} ]; then ${MTPT}/parts/pre/${j%.gnx} fi # unzip -X ${MTPT}/parts/bin/${i}/${j} -x ${j%.gnx}.xml var/gnx/${j%.gnx}.files -d /mnt/root unzip -X ${MTPT}/parts/bin/${i}/${j} -x ${j%.gnx}.xml -d /mnt/root if [ -f ${MTPT}/parts/post/${j%.gnx} ]; then ${MTPT}/parts/post/${j%.gnx} fi done done dialog --title "| gn*nix |" --exit-label " close " --msgbox "All Software installed" 0 0 return else cat /tmp/bundlez | while read i do for j in `ls -1 parts/bin/${i}` do if [ -f ${MTPT}/parts/pre/${j%.gnx} ]; then ${MTPT}/parts/pre/${j%.gnx} fi # unzip -X ${MTPT}/parts/bin/${i}/${j} -x ${j%.gnx}.xml var/gnx/${j%.gnx}.files -d /mnt/root unzip -X ${MTPT}/parts/bin/${i}/${j} -x ${j%.gnx}.xml -d /mnt/root if [ -f ${MTPT}/parts/post/${j%.gnx} ]; then ${MTPT}/parts/post/${j%.gnx} fi done done dialog --title "| gn*nix |" --exit-label " close " --msgbox "Software installed" 0 0 return fi elif [ "$ret" = "2" ]; then echo 2 fi done gnxumount >> /tmp/log } grubvert() { dev=${1#/dev/} de=${dev#??} let slc=${de#?}-1 drv=${de%?} case $drv in "a") d=0;; "b") d=1;; "c") d=2;; "d") d=3;; "e") d=4;; "f") d=5;; "g") d=6;; "h") d=7;; esac echo ${d} ${slc} } grubpname() { g=`grubvert ${1}` set $g echo "(hd${1},${2})" } grubdname() { g=`grubvert ${1}` set $g echo "(hd${1})" } grubhead() { echo "# # part of the gnnix conspiracy http://gnnix.org # timeout 9 default 0 fallback 0 splashimage = /grub/gnnix.xpm.gz " } grubboot() { echo "title gnnix root `grubpname ${2}` kernel /bzImage root=${1} initrd /initrd.img" } grubnoboot() { echo "title gnnix root `grubpname ${1}` kernel /boot/bzImage root=${1} initrd /boot/initrd.img" } # pass root, boot grubconf() { grubhead if [ "$2" = "" ]; then grubnoboot ${1} else grubboot ${2} ${1} fi } grubstall() { grub --batch </tmp/log 1>/tmp/log root `grubpname ${1}` setup `grubdname ${1}` quit EOF } mkpaths() { cd /mnt/root mkdir -p boot/grub dev sys proc home lib/modules mnt/floppy mnt/cdrom mnt/flash mnt/iso mkdir -p root sbin bin tmp usr mkdir -p etc/pam.d etc/rc.d etc/init.d etc/udev etc/hotplug etc/hotplug.d mkdir -p usr/bin usr/include usr/lib usr/sbin usr/share usr/src usr/man usr/info mkdir -p usr/man/man1 usr/man/man2 usr/man/man3 usr/man/man4 usr/man/man5 usr/man/man6 \ usr/man/man7 usr/man/man8 mkdir -p usr/local/bin usr/local/etc usr/local/include usr/local/lib usr/local/sbin \ usr/local/share usr/local/src mkdir -p usr/share/dict usr/share/doc usr/share/locale usr/share/man mkdir -p usr/share/nls usr/share/misc usr/share/terminfo usr/share/zoneinfo usr/share/man mkdir -p var/gnx var/lock/subsys var/log var/mail var/run var/spool/mqueue var/spool/lpd \ var/spool/cron var/spool/cron/crontabs /var/state/dhcp mkdir -p var/tmp var/cache var/lib/misc var/local var/lock/subsys mkdir -p uri/0install usr/local/zero cd usr/share ln -sf ../info info cd man for i in 1 2 3 4 5 6 7 8 do ln -sf ../../man/man${i} man${i} done } wheredabooty() { while read i do set $i if [ "$2" = "/" ]; then rootie=${1} elif [ "$2" = "/boot" ]; then bootie=${1} fi done < /tmp/fstab echo $bootie > /tmp/booty echo $rootie > /tmp/rooty } mkbare() { if [ ! -f /tmp/rooty -o ! -s /tmp/rooty ]; then wheredabooty fi gnxmount 2>>/tmp/log 1>>/tmp/log sleep 2 mkpaths >> /tmp/log grubconf `cat /tmp/booty` `cat /tmp/rooty` > /mnt/root/boot/grub/menu.lst cp /tmp/fstab /mnt/root/etc/fstab rm -f /mnt/root/etc/localtime cp -a /etc/localtime /mnt/root/etc/localtime rm -f /mnt/root/etc/hardwareclock cp -a /etc/hardwareclock /mnt/root/etc/hardwareclock rm -f /mnt/root/etc/keymap cp -a /etc/keymap /mnt/root/etc/keymap sed 's/udev_log="no"/udev_log="yes"/' /etc/udev/udev.conf > /mnt/root/etc/udev/udev.conf cp -a /etc/hosts /mnt/root/etc/hosts cp -a /etc/passwd /mnt/root/etc/passwd cp -a /etc/group /mnt/root/etc/group cp -a /bin/which /usr/bin/which # mkinitrd for gnnix here touch /mnt/root/boot/initrd.img cd /mnt/root/dev/ mknod initctl p mknod console c 5 1 mknod -m 660 null c 1 3 mknod -m 600 random c 1 8 mknod -m 600 urandom c 1 9 mknod tty c 5 0 SUFFIXES="0 1 2 3 4 5" let MAJOR=0 for i in $SUFFIXES; do mknod tty$i c 4 $MAJOR let MAJOR=${MAJOR}+1 done echo "/lib /usr/lib /usr/X11R6/lib /usr/local/lib" > /mnt/root/etc/ld.so.conf ln -sf /bin/test '/bin/[' cd / dialog --title "| gn*nix |" --exit-label " close " --msgbox "System Framework Created" 0 0 gnxumount 2>>/tmp/log 1>>/tmp/log } mkgrub() { cd / if [ ! -f /tmp/rooty -o ! -s /tmp/rooty ]; then wheredabooty fi clear echo Initializing disk... standby please gnxumount 2>>/tmp/log 1>>/tmp/log grubstall `cat /tmp/booty` `cat /tmp/rooty` >> /tmp/log echo GRUB INSTALLATION COMPLETE >> /tmp/log dialog --title "| grub installed |" --exit-label "close" --textbox /tmp/log 0 0 } bigfinish() { echo unmounting cdrom... >> /tmp/log umount /mnt/cdrom rm -f /tmp/modz rm -f /tmp/fz rm -f /tmp/kz rm -r /tmp/keyz rm -f /tmp/bundlez rm -f /tmp/log rm -f /tmp/mztab rm -f /tmp/mfztab rm -f /tmp/fztab clear exit } mainmenu() { exec 3>&1 value=`dialog --help-button --clear --backtitle "$1" --title "| gn*nix install by the numbers |" --ok-label "Go" --cancel-label "Exit" --menu \ "" 0 0 0 \ "1" " Partition Disk Media " \ "2" " FileSystem Mount Table " \ "3" " Make New FileSystems " \ "4" " Load A Keyboard Map " \ "5" " Configure Time Zone " \ "6" " Create Empty System " \ "7" " Fill It With Software " \ "8" " Install Boot Loader " \ "9" " Set Superuser Password " \ 2>&1 1>&3` retval=$? exec 3>&- } #-# MAIN #-# echo "Starting the probulator..." > /tmp/log findandmountgnnix unpackmodulesdep showinitialprogress rm -f /tmp/log bt="First step: Partition Disk Media" while true do mainmenu "$bt" case $retval in 0) if [ "$value" = "1" ]; then formatfdiskmenu bt="Next step: Create A FileSystem Mount Table" elif [ "$value" = "2" ]; then selectable bt="Next step: Make New FileSystems" elif [ "$value" = "3" ]; then makefs bt="Next step: Load A Keyboard Map" elif [ "$value" = "4" ]; then loadkeyz bt="Next step: Configure Time Zone" elif [ "$value" = "5" ]; then tzset bt="Next step: Create An Empty System" elif [ "$value" = "6" ]; then mkbare bt="Next step: Fill It With Software" elif [ "$value" = "7" ]; then softwarebundlelistdir bt="Next step: Install Boot Loader" elif [ "$value" = "8" ]; then mkgrub bt="Next step: Set Superuser Password" elif [ "$value" = "9" ]; then setpass bt="Final step: Exit, remove CD, activate console and type reboot " fi ;; 1) bigfinish ;; 2) echo "Help pressed ($value)" ;; 255) if test -n "$value" ; then echo -n "" else echo -n "" fi ;; esac done #eof