#!/bin/sh # tdu-install creates td-user userID on a Thumb Drive # Markku (Rasatmakananda) # Date: 6 January 2004 ANSWER="/tmp/.tdsetup" TITLE="Thumb Dirive UserID installer" # partitions PART_ROOT= KVER="$(uname -r)" # Check usb system case "$KVER" in 2.6.*) VER="2.6" ;; esac case "$KVER" in 2.4.*) VER="2.4" ;; esac [ `id -u` -ne 0 ] && { echo "This program must be run in root mode (username: root)." exit 1 } # Run HWD if [ -f /tmp/.hwd ]; then dummy="" else echo -e "\033[1;33mRun 'hwd' (hardware detect) before installing Thumb Drive UserID.\033[0m" echo "" exit 1 fi # Check Thumb Drive if [ -a /dev/sda ]; then dummy="" else echo "" echo -e "\033[1;33mPlugin your Thumb Drive before running this installer!!!\033[0m " echo "" exit 1 fi abort() { dodialog yesno "Do you want to exit?" 5 45 && exit 0 return 0 } msg() { dodialog msgbox "$1" return 1 } dodialog() { # use this for msgbox, inputbox, yesnobox, infobox # # dodialog [height] [width] [other] height=0 width=0 if [ "$3" != "" ]; then height=$3 fi if [ "$4" != "" ]; then width=$4 fi dialog --backtitle "$TITLE" --aspect 15 --$1 "$2" $height $width $5 } domenu() { menutype=$1 ; shift text=$1 ; shift height=$1 ; shift width=$1 ; shift mheight=$1 ; shift dialog --backtitle "$TITLE" --$menutype "$text" $height $width $mheight $* } partition() { # # Select disk to partition # dodialog yesno "If you have partitioned your Thumb Drive (including a swap), press NO and go to step 2 'Set Mountpoint and Filesystem'. To continue press Yes." 8 65 || return 0 msg "Next screen select the partitioning software and create one partition (and 40MB swap if 128MB TD)" dialog --backtitle "$TITLE" --menu "Partition Hard Drives" 12 65 4 \ "1" "QTParted - Partition Magic clone (GUI)." \ "2" "Parted - add, resize and move (console)." \ "3" "Return to Main Menu" 2>$ANSWER case `cat $ANSWER` in "1") dodialog yesno "QTparted runs in KDE and other X windows only!! Press YES for X window." 8 60 || return 0 qtparted ;; "2") msg "When asked press 'i' to ignore. At parted prompt type 'h' to print general help, or help on COMMAND." parted ;; *) DONE=1 ;; esac } format() { # # Select mountpoints # if [ -f /tmp/udev.tmp ]; then dodialog yesno "Next screen is a list of your TD partitions (udev format e.g /dev/sda1). To continue press Yes." 6 60 || return 0 PARTS=`find /dev -follow -name "sd*[1-9]" | sed 's|$| _|g'` else dodialog yesno "Next screen is a list of your TD partitions (devfs format e.g /dev/discs/disc1/part1 = sda1). To continue press Yes." 6 60 || return 0 PARTS=`find /dev/discs/disc1 -follow -name "part*" | sed 's|$| _|g'` fi domenu menu "Select partition to mount as Thumb Drive root." 14 55 7 $PARTS 2>$ANSWER || return 1 PART=`cat $ANSWER` MNT=$PART msg "Next screen will create a filesystem in $PART (Selected filesystem will overwrite existing data!)" # Select filesystem type domenu menu "Select filesystem for $PART (if unsure select 'ext3')." 10 50 3 ext2 Ext2 ext3 Ext3 reiserfs Reiser 2>$ANSWER || return 1 FSTYPE=`cat $ANSWER` if [ $FSTYPE = "ext2" ]; then FSCOM="mke2fs" fi if [ $FSTYPE = "ext3" ]; then FSCOM="mke2fs -j" fi if [ $FSTYPE = "reiserfs" ]; then FSCOM="mkreiserfs" fi # Format Thumb Drive echo "Please wait, formating ($FSTYPE) $PART ...." echo "" $FSCOM $PART echo "" >> /tmp/.readyToCopy echo "" echo -e "\033[1;33mPress any key to continue.\033[0m " read KEY # Create swap dodialog yesno "If you don't have (or don't want) a swap partition, press 'No' and go to Main Menu step 2 'Install Thumb Drive UserID'. Press 'Yes' to configure swap." 7 60 || return 0 msg "Next screen is a list of your TD partitions." if [ -f /tmp/udev.tmp ]; then PARTS=`find /dev -follow -name "sd*[1-9]" | sed 's|$| _|g'` else PARTS=`find /dev/discs/disc1 -follow -name "part*" | sed 's|$| _|g'` fi domenu menu "Select partition to use as Thumb Drive swap." 14 55 7 $PARTS 2>$ANSWER || return 1 PART=`cat $ANSWER` PART_SWAP=$PART if [ "$MNT" = "$PART_SWAP" ]; then msg "Partition $MNT is already selected as Thumb Drive root!! Swap will not be included." msg "Go to Main Menu step 2 'Install Thumb Drive UserID'." return 0 else msg "Next screen will create a swap filesystem in $PART (This will overwrite existing data!)" mkswap $PART FSWAP="yes" echo "" echo -e "\033[1;33mPress any key to continue.\033[0m " read KEY msg "Go to Main Menu step 2 'Install Thumb Drive UserID'." fi } copyAMLUG () { # # Select disk to partition # if [ -f /tmp/.readyToCopy ]; then dodialog yesno "This will create 'td-user' userID and /home/td-user/ folder in Thumb Drive. To continue press Yes." 8 60 || return 0 dodialog yesno "Ready to install in partition $MNT ? To continue press Yes." 6 60 || return 0 msg "This will create userID: 'td-user'. Press Enter (use default) for each question and type a password when asked." echo "" echo -e "\033[1;33mCreating Thumb Drive UserID (username: 'td-user')...\033[0m " echo "" adduser td-user usermod -G root,wheel td-user echo "Please wait.... " # /etc/rc.d/cups stop echo "Installing......" mount $MNT /mnt/my-td if [ -f /tmp/.checkTD ]; then dummy="" else cd / rm -R /home/td-user cp -Raf /cdrom/system/etc /mnt/my-td/ rm -R /etc/default rm -R /etc/hwd rm -R /etc/localtime rm -R /etc/security rm /etc/cups/ppds.dat if [ -f /usr/X11R6/bin/xorgcfg ]; then SERVERx="Xorg" conf_hwd="xorg.conf.hwd" conf_file="xorg.conf" conf_tool="xorgcfg" else SERVERx="XFree86" conf_hwd="XF86Config-4.hwd" conf_file="XF86Config-4" conf_tool="xf86cfg" fi if [ -f /etc/X11/$conf_hwd ]; then cp -f /etc/X11/$conf_hwd /mnt/my-td/etc/X11/ cp -f /etc/X11/$conf_hwd /mnt/my-td/etc/X11/$conf_file else if [ -f /etc/X11/$conf_file ]; then if [ -f /etc/X11/$conf_hwd ]; then cp -f /etc/X11/$conf_hwd /mnt/my-td/etc/X11/ fi cp -f /etc/X11/$conf_file /mnt/my-td/etc/X11/ else dummy="" fi fi rm -R /etc/X11 cp -Raf /etc /mnt/my-td/ rm /mnt/my-td/etc/modules.conf mv /etc/modules.conf /mnt/my-td/etc/ rename etc etc-save etc ln -sf /mnt/my-td/etc etc rm -R /etc-save/sysconfig rm -R /etc-save/ssh rm -R /etc-save/ssl rm -R /etc-save/ppp rm -R /etc-save/pcmcia rm -R /etc-save/dhcpc rm -R /etc-save/hotplug rm -R /etc-save/cups rm -R /etc-save/httpd cp -Raf /var /mnt/my-td/ cp -Raf /cdrom/system/var/lib/mysql.tar.gz /mnt/my-td/var/lib/ rename var var-save var ln -sf /mnt/my-td/var var rm -R /var-save echo "MySQL..." cd /mnt/my-td/var/lib tar zxf mysql.tar.gz rm mysql.tar.gz cd / /etc/rc.d/mysqld start # /etc/rc.d/cups start fi echo "System configure...." rm -R /mnt/my-td/lost+found mkdir /mnt/my-td/setup echo "$MNT" >> /mnt/my-td/setup/config mkdir /mnt/my-td/home if [ -f /tmp/.checkTD ]; then dummy="" else cp -Raf /cdrom/system/home/httpd/ /mnt/my-td/home/ rm /home/httpd cd /home ln -sf /mnt/my-td/home/httpd httpd fi cp -Ra /home/amlug/ /mnt/my-td/home/ cd /mnt/my-td/home/ rename amlug td-user amlug cd /mnt/my-td/home/td-user cp -f /cdrom/system/qtrc .qt/ cp -f /cdrom/system/scribus.rc .scribus/ cp -f /cdrom/system/ksmserverrc .kde/share/config/ rm -R .mozilla/ cd / chown -R td-user:users /mnt/my-td/home/td-user cd /home ln -s /mnt/my-td/home/td-user td-user echo "Thumb Drive UserID configure...." cd / mkdir /mnt/tmp mount /dev/sda1 /mnt/tmp echo "$MNT" >> /mnt/tmp/Thumb-UserIDconfig # If swap created if [ "$FSWAP" = "yes" ]; then echo "$PART_SWAP" >> /mnt/tmp/Thumb-UserIDswap echo "$PART_SWAP none swap sw 0 0" >> /mnt/tmp/etc/fstab echo "Activating Swap..." swapon $TD_SWAP fi umount /mnt/tmp echo -e "\033[1;33mPress any key to continue...\033[0m " read KEY rm -f /tmp/.readyToCopy msg "Thumb Drive UserID is successfully installed. Login to Username: 'td-user' with your password." else msg "Prepare Thumb Drive before installing. Go to step 1 'Prepare Thumb Drive'." fi } mainmenu() { dialog --backtitle "$TITLE" --title "MAIN MENU" \ --menu "Use the UP and DOWN arrows to navigate menus. Use TAB to switch between buttons and ENTER to select." 12 55 4 \ "1" "Prepare Thumb Drive" \ "2" "Install Thumb UserID" \ "3" "Exit" 2>$ANSWER EDITOR= case `cat $ANSWER` in "1") if [ -f /mnt/my-td/setup/config ]; then dodialog yesno "Thumb Drive UserID is already installed!!! If you want re-install press Yes." 6 60 || return 0 msg "You have selected to re-install your Thumb Drive UserID system." cd / umount /mnt/my-td fi if [ -f /mnt/my-td/setup/config ]; then msg "Thumb Drive is busy... you must manually unmount before re-install. This will exit the installer." exit fi DONE=0 while [ "$DONE" = "0" ]; do dialog --backtitle "$TITLE" --menu "Prepare Thumb Drive" 12 60 4 \ "1" "Partition Thumb Drive" \ "2" "Set Mountpoint and Filesystem" \ "3" "Return to Main Menu" 2>$ANSWER case `cat $ANSWER` in "1") partition ;; "2") format ;; *) DONE=1 ;; esac done ;; "2") copyAMLUG ;; "3") abort ;; esac } dodialog msgbox "To use this Thumb Drive UserID installer requires 64MB or higher capacity Thumb Drive. To include a swap partition use 128MB. Run through the options in the order they are presented." 8 65 if [ -f /tmp/.readyToCopy ]; then rm /tmp/.readyToCopy fi loop() { while `/bin/true`; do mainmenu done } loop exit 0