Code Sample |
#!/bin/bash # dsl-hdinstall # stripped down - only en language version - based on: # knx-hdinstall 0.37 - 01/2003 Christian Perle <perle@itm.tu-clausthal.de> # Added mirror selection and ext3 by J.P Nimmo, aka SaidinUnleashed 1/2005 # Added dialog menus by Richard Osborne Jun 2005 PATH="/bin:/sbin:/usr/bin:/usr/sbin" export PATH DIALOG="dialog" TMP="/tmp/dsl-hdinstall.tmp$$" . /etc/init.d/dsl-functions bailout(){ rm -f "$TMP" exit 1 } TR="/mnt/hd" DEFHNAME="box" FSCHOICE="" MESSAGE1="DSL hard drive installation. No responsibility for \ data loss or hardware damage! This script installs DSL onto your \ hard disk." MESSAGE2="Enter the target partition (Example: hda2):" MESSAGE3="There are two options for hard drive installation. 1. Standard install is to uncompress the existing system thereby \ retaining its small size. 2. Enhanced uses Standard plus expands the system by restoring \ orginal binaries and libraries. This option requires a working \ internet connecion." MESSAGE4="Choose your install method:" MESSAGE5="Choose your mirror" MESSAGE6="Do you currently have a working internet connection?" MESSAGE7="Do you wish to enable multi-user logins? If you say \ no here DSL will boot directly into X as the user dsl" MESSAGE8="Choose your filesystem. Ext2 is recommended on slower machines" MESSAGE9="Last change to exit before writing any changes to your hard drive. \ Do you wish to continue?" MESSAGE10="Could not fetch the required files for the extended install at this \ time. Do you wish to continue with the standard install?" MESSAGE11="Do you want to run mkliloboot in order to setup your bootloader?" SUCCESS="DSL successfully installed" if [ $UID != 0 ]; then echo "This script requires root privileges." bailout fi # Check if running from an already installed DSL [ -e /KNOPPIX/bin/ash ] || { echo "Error: Can't find /KNOPPIX directory" 1>&2; bailout; } umask 022 killall dhcpcd >/dev/null 2>&1 killall -9 pump >/dev/null 2>&1 killall automount >/dev/null 2>&1 swapoff -a >/dev/null 2>&1 while read x mnt x do case "$mnt" in /mnt*) umount $mnt >/dev/null 2>&1 ;; *);; esac done < /proc/mounts $DIALOG --msgbox "$MESSAGE1" 10 45 $DIALOG --inputbox "$MESSAGE2" 10 45 2>"$TMP" || bailout FSCHOICE=$(cat "$TMP") [ -z "$FSCHOICE" ] && { echo "No target chosen. The script will be terminated." 1>&2; bailout; } DISK="$(echo $FSCHOICE | tr -d [0-9])" FSCHOICE="/dev/$FSCHOICE" $DIALOG --msgbox "$MESSAGE3" 15 45 $DIALOG --menu "$MESSAGE4" 10 45 0 "s" "Standard" "e" "Enhanced" 2>"$TMP" || bailout INSTALLTYPE=$(cat $TMP) if [ "$INSTALLTYPE" == "e" ]; then echo "${YELLOW}Proceeding with Enhanced installation...${NORMAL}" MIRRORS="" while read no mirror; do MIRRORS="$MIRRORS $no $mirror" done<<EOF 1 Belnet_HTTP_(Belgium) 2 Belnet_FTP_(Belgium) 3 Ibiblio_FTP_(USA) 4 Ibiblio_HTTP_(USA) 5 The_Geekery_HTTP 6 Tuwein_HTTP_(Austria) 7 Gulus_(Quebec,Canada) EOF $DIALOG --menu "$MESSAGE5" 15 45 0 $MIRRORS 2>"$TMP" || bailout MIRRORCHOICE=$(cat "$TMP") case "$MIRRORCHOICE" in 1) SELMIR="http://ftp.belnet.be/packages/damnsmalllinux/mydsl/system/gnu-utils.dsl" MIRRORNAME="Belnet HTTP (Belgium)" ;; 2) SELMIR="ftp://ftp.belnet.be/packages/damnsmalllinux/mydsl/system/gnu-utils.dsl" MIRRORNAME="Belnet FTP (Belgium)" ;; 3) SELMIR="ftp://ibiblio.org/pub/Linux/distributions/damnsmall/mydsl/system/gnu-utils.dsl" MIRRORNAME="Ibiblio FTP (USA)" ;; 4) SELMIR="http://ibiblio.org/pub/Linux/distributions/damnsmall/mydsl/system/gnu-utils.dsl" MIRRORNAME="Ibiblio HTTP (USA)" ;; 5) SELMIR="http://dsl.thegeekery.com/mydsl/system/gnu-utils.dsl" MIRRORNAME="The Geekery HTTP" ;; 6) SELMIR="http://gd.tuwien.ac.at/opsys/linux/damnsmall/mydsl/gnu-utils.dsl" MIRRORNAME="Tuwein HTTP (Austria)" ;; 7) SELMIR="http://gulus.usherbrooke.ca/pub/distro/DamnSmallLinux/mydsl/system/gnu-utils.dsl" MIRRORNAME="Gulus (Quebec, Canada)" ;; *) SELMIR="http://ftp.belnet.be/packages/damnsmalllinux/mydsl/system/gnu-utils.dsl" ;; esac $DIALOG --yesno "$MESSAGE6" 10 45 if [ "$?" != 0 ]; then echo "${RED}A working internet connection is required. The script will be terminated.${NORMAL}" bailout fi else echo "${YELLOW}Proceeding with Standard installation...${NORMAL}" fi $DIALOG --yesno "$MESSAGE7" 10 45 if [ "$?" == 0 ]; then MULTI=y echo "${YELLOW}The system will boot directly into X as the user dsl.${NORMAL}" else MULTI=n fi $DIALOG --menu "$MESSAGE8" 10 45 0 "ext2" "" "ext3" "" 2>"$TMP" || bailout FSTYPE=$(cat $TMP) $DIALOG --yesno "$MESSAGE9" 10 45 if [ "$?" != 0 ]; then echo "Aborted.." bailout fi echo "${BLUE}Creating filesystem $FSTYPE on $FSCHOICE...${NORMAL}" sleep 2 dd if=/dev/zero of=$FSCHOICE bs=1k count=16 >/dev/null 2>&1 sync case "$FSTYPE" in ext2) mke2fs -F $FSCHOICE 2> "$TMP" ;; ext3) mke2fs -Fj $FSCHOICE 2> "$TMP" ;; *) mke2fs -Fj $FSCHOICE 2> "$TMP" ;; esac if [ "$?" != 0 ]; then echo "${RED}An error occurred while creating the filesystem.${NORMAL}" echo "Some messages from mkfs:" tail -8 "$TMP" bailout fi echo " ${BLUE}Copying files...${NORMAL}" echo "Now copying system files from the CD to hard disk." echo "This will take 2 to 10 minutes, depending on the hardware." mkdir -p $TR >/dev/null 2>&1 mount -t "$FSTYPE" "$FSCHOICE" "$TR" 2> "$TMP" if [ "$?" != 0 ]; then echo "${RED}An error occurred while mounting the root partition $FSCHOICE.${NORMAL}" echo "Some messages from mount:" tail -8 "$TMP" bailout fi echo "${BLUE}Now the root filesystem is filled with data...${NORMAL}" tar -C /KNOPPIX -cf - . | tar -C $TR -xf - if [ "$INSTALLTYPE" == "e" ]; then echo "${CYAN}Using mirror at ${GREEN}$MIRRORNAME${CYAN}.${NORMAL}" cd $TR wget $SELMIR if [ $? != 0 ]; then $DIALOG --yesno "$MESSAGE10" 10 45 if [ "$?" != 0 ]; then echo "Script aborted by user. Please try again later." bailout fi else tar -zxf gnu-utils.dsl rm -f gnu-utils.dsl fi fi echo -ne "\007" >/dev/tty1; usleep 500000 echo -ne "\007" >/dev/tty1; usleep 500000 echo "${GREEN}The copying of system files has been completed.${NORMAL}" if [ -f /etc/sysconfig/mouse ]; then x="`grep DEVICE= /etc/sysconfig/mouse`" x=${x#*/dev/} MOUSEDEV=${x%\"*} fi [ -z "$MOUSEDEV" ] && MOUSEDEV="psaux" (cd $TR/dev; ln -sf $MOUSEDEV mouse; ln -sf sr0 cdrom) cat <<\EOF >$TMP EOF cat /proc/modules | tac | grep -v '\[.*\]' | while read mod x do if [ $mod = apm ]; then echo "apm power_off=1" >>$TMP else echo $mod >>$TMP fi done cp -f $TMP $TR/etc/modules cat <<EOF >$TR/etc/fstab EOF MOUNTPOINT="" MOUNTPOINT="$FSCHOICE" case "$FSTYPE" in reiserfs|xfs) echo "$MOUNTPOINT / $FSTYPE defaults 0 1" >>$TR/etc/fstab ;; *) echo "$MOUNTPOINT / $FSTYPE defaults,errors=remount-ro 0 1" >>$TR/etc/fstab ;; esac cat <<EOF >>$TR/etc/fstab proc /proc proc defaults 0 0 /dev/fd0 /floppy vfat defaults,user,noauto,showexec,umask=022 0 0 /dev/cdrom /cdrom iso9660 defaults,ro,user,noexec,noauto 0 0 EOF rm -rf $TR/mnt mkdir -p $TR/mnt echo "# partitions found by dsl " >>$TR/etc/fstab grep "^/dev/[hs]d.*/mnt/" /etc/fstab | while read dev mnt x do echo "#"$dev $mnt $x >>$TR/etc/fstab mkdir $TR/$mnt done echo "# remove comment(s) to enable DMA" >>$TR/etc/init.d/bootmisc.sh if [ -f /proc/partitions ]; then while read x x x p x do case "$p" in hd?) if [ "`cat /proc/ide/$p/media`" = "disk" ]; then echo "#/sbin/hdparm -qd1 /dev/$p" >>$TR/etc/init.d/bootmisc.sh fi ;; *);; esac done < /proc/partitions fi cat <<EOF >$TR/etc/hosts 127.0.0.1 box localhost ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts EOF sleep 1 echo box > $TR/etc/hostname echo box > $TR/etc/mailname if [ "$MULTI" == "y" ]; then mv $TR/etc/inittab.multi $TR/etc/inittab fi mkdir -p $TR/etc/sysconfig cp -af /etc/sysconfig/i18n $TR/etc/sysconfig/ rm -rf $TR/tmp mkdir $TR/tmp chmod 1777 $TR/tmp rm -f $TR/etc/mtab touch $TR/etc/mtab echo "Setting up /root/" tar -C /etc/skel -cf - . | tar -C $TR/root -xf - echo "Setting up /home/dsl/" tar -C / -cf - /home/dsl | tar -C $TR -xf - >/dev/null 2>&1 mkdir $TR/mnt/floppy mkdir $TR/mnt/hd touch $TR/tmp/firstboot chgrp staff $TR/opt chmod g+w $TR/opt echo "/sbin/syslogd" >> $TR/opt/bootlocal.sh mkdir $TR/boot if [ -f /cdrom/boot/isolinux/linux24 ]; then cp -f /cdrom/boot/isolinux/linux24 $TR/boot/linux24 else mkdir /mnt/bootimg mount /dev/cdrom /mnt/bootimg -t iso9660 -o ro cp -f /mnt/bootimg/boot/isolinux/linux24 $TR/boot/linux24 umount /mnt/bootimg fi chmod +rx $TR/dev/cdrom for i in 7 6 5 4 3 2 1 0 do losetup -d /dev/loop$i >/dev/null 2>&1 done umount $TR >/dev/null 2>&1 echo "${GREEN}The installation process is finished.${NORMAL}" rm -f "$TMP" $DIALOG --msgbox "$SUCCESS" 8 40 rm -f $TMP $DIALOG --yesno "$MESSAGE11" 10 45 if [ "$?" == 0 ]; then /usr/bin/mkliloboot $FSCHOICE fi exit 0 |