DSL Ideas and Suggestions :: User friendly HDinstall



For my DSL remaster I felt the hdinstall script (/usr/sbin/dsl-hdinstall) wasn't particularly user friendly and so altered it to use dialog for user interaction. While it is still text based all questions are asked in the form of dialog boxes, menu choices etc and I feel this makes the hdinstall process clearer and easier to use.

I'd happily apply the same treatment to the DSL hdinstall script and post it here/send it to the developers if there is an interest in something like this for DSL.

freidgold,

DSL does not come with the dialog program.  Instead, it comes with an equivalent program called "whiptail".  Whiptail syntax is very similar to dialog, so it shouldn't be hard to convert it over from dialog.

Even if the developers are unsure to add it to the distro, you should post it here so that others may get some good ideas from the code.

Looks like I'm actually using whiptail already without realising it

ls -l /usr/bin/dialog
lrwxrwxrwx    1 root     root            8 May  9 09:09 /usr/bin/dialog -> whiptail

I'll try to post my script later today in the hope that its useful. I'll need to revert some changes I made specific to my remaster and give it a test.

As promised

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


The main changes are
-Use of whiptail to get user input
-Installation messages defined at start of script for easier editing.
-wget's output is no longer redirected to /dev/null. This means you can see the progress meter for the download of gnu-utils.dsl when using extended install.

Friedgold. I think your idea, to make the hdinstall process clearer and easier, is a great idea.

Booting the cd is no sweat for a novice, but I do think that the current hdinstall is perhaps dubious for a total novice.

It was no sweat for me, but I am not totally green.

I remember a few years ago it took me two days to figure out I had to insert a / (mount point) when I first ever installed a Linux. I know 2 days sounds pathetic, but 1st time round it is totally alien, and there is presumption that people can get on the net 24/7. Not everybody in this world can jump onto the net in a flash and do the research, and all you've got is a cd-r and no instructions.

I guess revising hdinstall is negligible in terms of bytes yeah.
Best Wishes, andyp.

Next Page...
original here.