#!/bin/sh # SCCSID(@(#)install-win4lin.sh 1.21) Modified 18:54:14 11/2/00 # This script installs the Win4Lin package from the CD. # Global variables: DOING_PKG_INST=not_yet MOUNT_PROG=/bin/mount WINSETUP=/usr/bin/winsetup DID_MOUNT=no AGREED=notagreed YES_ANS=0 NO_ANS=1 PKGMGRLIST="rpm dpkg none" # Ask a question, and return $YES_ANS or $NO_ANS Ask_y_n() { echo "in Ask_y_n" while true do echo -e "$1 (y/n) \c" read ANS case $ANS in y*|Y*) return $YES_ANS ;; n*|N*) return $NO_ANS ;; *) echo "Please answer y for yes, n for no" ;; esac done echo "at end of Ask_y_n" } Which_pkgmgr() { echo "in Which_pkgmgr" PKGMGR=rpm echo "at end of Which_pkgmgr" } Check_prereq() { echo "in Check_prereq" # Check to see if the package manager is available. $1 --version > /dev/null 2> /dev/null if [ $? -ne 0 ] then echo echo "Unable to invoke the $1 command." echo return 1 fi # See if kernel is Win4Lin ready. grep mki_install_hook /proc/ksyms > /dev/null 2> /dev/null if [ $? -ne 0 ] then echo echo "The currently running system is not 'Win4Lin Ready'." echo "Please read the release note for information on how" echo "to install a Win4Lin enhanced kernel." echo "You have to be using such a kernel to install Win4Lin." exit 1 fi echo "at end of Check_prereq" } Check_installed_rpm() { echo "in Check_installed_rpm" # If already installed, ask user if they want to proceed and replace # the current version. rpm -q -i Win4Lin > /dev/null 2> /dev/null if [ $? -eq 0 ] then echo echo "Win4Lin seems to be already installed." echo "This is the version information:" echo rpm -q -i Win4Lin | grep ": " echo Ask_y_n \ "Do you want to replace the installed version of Win4Lin?" if [ $? -eq $NO_ANS ] then echo echo "Canceling installation." exit 1 fi rpm -e Win4Lin fi echo "at end of Check_installed_rpm" } Check_Display() { echo "in Check_Display" # This function checks to make sure DISPLAY is set properly. # If it is not set properly it returns with it unset. # Thus later functions can safely test to see if DISPLAY is # set or not, and when it is set, can assume it is safe to use. if [ "x$DISPLAY" = "x" ] then # It is not set, so just return. return fi # It is set, so now make sure it is ok. We do this # by running a test script in an xterm and seeing # if the xterm failed to start or not. # (This is sufficient because xterm will be needed later # by the rpm post install script to display the license.) # Note: Put the temp file in root because that is safe # to do. If we put it in /tmp then there are security issues. TMPFILE=/win4lin-inst-$$ echo ":" > $TMPFILE echo "echo Testing" >> $TMPFILE echo "echo DISPLAY" >> $TMPFILE # NOTE: # This "sleep" is needed because xterm seems to have an occasional # a problem when the program run with the "-e" option finishes # very quickly. The symptom is that the xterm does not automatically # exit when the program finishes. # (For instance "xterm -e /bin/true" exhibits this problem.) echo "sleep 2" >> $TMPFILE echo "exit 0" >> $TMPFILE xterm -geometry 10x10 -e /bin/sh $TMPFILE 2>/dev/null RETVAL=$? if [ $RETVAL -ne 0 ] then # Could not use xterm, so silently unset DISPLAY unset DISPLAY fi rm -f $TMPFILE echo "at end of Check_Display" } License_Thang() { echo "in License_Thang" # If there is a Win4Lin license on the CD, then copy it # to /etc/default so the win4lin postinstall script # can install it as needed. if [ -f license.txt ] then rm -f /etc/default/Win4LinLic.txt if [ ! -d /etc/default ] then mkdir /etc/default chmod 755 /etc/default chown root /etc/default chgrp root /etc/default fi cp license.txt /etc/default/Win4LinLic.txt fi echo "at end of License_Thang" } Check_ed() { echo "in Check_ed" if [ ! -x /bin/ed -a ! -x /usr/bin/ed ] then if [ -f /usr/bin/ed ] then mv /usr/bin/ed /usr/bin/ed.noexec fi cp ../LINUX/tools/ed /usr/bin/ed chmod 555 /usr/bin/ed fi echo "at end of Check_ed" } Install_modutils() { echo "in Install_modutils" if [ ! -x /sbin/insmod_ver ] then if [ -f /sbin/insmod_ver ] then mv /sbin/insmod_ver /sbin/insmod_ver.noexec fi cp ../LINUX/tools/insmod /sbin/insmod_ver chmod 555 /sbin/insmod_ver fi if [ ! -x /sbin/rmmod_ver ] then if [ -f /sbin/rmmod_ver ] then mv /sbin/rmmod_ver /sbin/rmmod_ver.noexec fi cp ../LINUX/tools/rmmod /sbin/rmmod_ver chmod 555 /sbin/rmmod_ver fi echo "at end of Install_modutils" } Failed_Install() { echo "in Failed_Install" # Let the user know the install failed, and make sure # the rpm package is uninstalled. # Does not return. Unmount_CD if [ "$DOING_PKG_INST" = "doing_pkg_inst" ] then echo "The Win4Lin package install failed." rpm -e Win4Lin 2>/dev/null dpkg -r win4lin 2>/dev/null fi exit 6 echo "at end of Failed_Install" } Do_pkginstall() { echo "in Do_pkginstall" # This function does the rpm install of the Win4Lin package. # When that returns, we unmount the CD if the earlier step # did the mount of the CD. # Then we check to make sure that the license check was # done (i.e. that the user agreed to the license.) # When did not agree, or if the rpm install failed, # then remove the rpm package. # This function only returns when the rpm installed ok AND the # user agreed to the license. # Assume we are in the Win4Lin subdir of the CD. case $PKGMGR in rpm) if [ ! -f RPMS/i386/Win4Lin*.rpm ] then echo "Error, cannot find the Win4Lin RPM package file." Failed_Install fi DOING_PKG_INST=doing_pkg_inst rpm -i RPMS/i386/Win4Lin*.rpm ;; *) echo "Script error" echo "No package manager specified" exit -6 ;; esac Unmount_CD # At this point the cwd is "/" (Unmount_CD changed it) [ ! -f /etc/default/merge ] && Failed_Install [ ! -f /etc/mrgssv.sh ] && Failed_Install # The script /etc/mrgssvr sets $VARMERGE. # This script is installed as a part of the RPM. . /etc/mrgssv.sh [ ! -d $VARMERGE ] && Failed_Install if [ "$AGREED" = "agreed" ] then echo "The user agreed to the End User License Agreement" \ > "$VARMERGE/agree.txt" date >> "$VARMERGE/agree.txt" fi [ ! -f "$VARMERGE/agree.txt" ] && Failed_Install grep "^The user agreed to the End User License Agreement\$" \ "$VARMERGE/agree.txt" > /dev/null 2>&1 [ $? -ne 0 ] && Failed_Install # The install succeeded and the user has agreed to the license. echo "at end of Do_pkginstall" } FindmountCD() { echo "in FindmountCD" # Return success (0) when the cwd is in the "Win4Lin" subdirectory on # the CD (or copy thereof). # On failure to mount return 1. # On users request exit 6. # If the CD directory was not already specified, then # check the to see if it looks like the Win4Lin subdir on the CD. # The "Complete Instructions" tell the user to cd into this # directory before running this script. if [ "x$WIN4LIN_CD_DIR" = "x" ] then if [ -d RPMS ] then return 0 fi fi if [ "x$WIN4LIN_CD_DIR" != "x" ] then cd "$WIN4LIN_CD_DIR/Win4Lin" 2>/dev/null RETVAL=$? if [ $RETVAL -eq 0 ] then return 0 else [ ! -d "$WIN4LIN_CD_DIR" ] && WIN4LIN_CD_DIR="" [ ! -b "$WIN4LIN_CD_DEV" ] && WIN4LIN_CD_DEV="" if [ "x$WIN4LIN_CD_DIR" != "x" -a "x$WIN4LIN_CD_DEV" != "x" ] then $MOUNT_PROG -r -t iso9660 "$WIN4LIN_CD_DEV" "$WIN4LIN_CD_DIR" RETVAL=$? if [ $RETVAL -ne 0 ] then echo echo "Failed to mount $WIN4LIN_CD_DEV onto $WIN4LIN_CD_DIR" WIN4LIN_CD_DEV="" WIN4LIN_CD_DIR="" else DID_MOUNT=did_mount cd $WIN4LIN_CD_DIR/Win4Lin 2>/dev/null return 0 fi fi fi fi if [ x$WIN4LIN_CD_DEV = "x" ] then echo echo "Please enter the CD-ROM device name with" echo "the Win4Lin 1.0 CD. (or type 'q' to quit)" echo -e "[default is /dev/cdrom] : \c" read WIN4LIN_CD_DEV if [ x$WIN4LIN_CD_DEV = "x" ] then WIN4LIN_CD_DEV=/dev/cdrom fi if [ $WIN4LIN_CD_DEV = "q" ] then exit 6 fi if [ ! -b $WIN4LIN_CD_DEV ] then echo "" echo "$WIN4LIN_CD_DEV is not a block device" WIN4LIN_CD_DEV="" fi fi if [ x$WIN4LIN_CD_DEV != "x" -a x$WIN4LIN_CD_DIR = "x" ] then echo echo "Please enter the desired CD-ROM mount point" echo "(or type 'q' to quit)" echo -e "[default is /mnt/cdrom] : \c" read WIN4LIN_CD_DIR if [ x$WIN4LIN_CD_DIR = "x" ] then WIN4LIN_CD_DIR=/mnt/cdrom fi if [ $WIN4LIN_CD_DIR = "q" ] then exit 6 fi if [ ! -d $WIN4LIN_CD_DIR ] then echo "" echo "$WIN4LIN_CD_DIR is not a directory" fi fi return 1 echo "at end of FindmountCD" } Unmount_CD() { echo "in Unmount_CD" cd / if [ "$DID_MOUNT" = "did_mount" ] then umount "$WIN4LIN_CD_DEV" fi echo "at end of Unmount_CD" } License_Check() { echo "in License_Check" if [ ! -f "$EULA" ] then echo "Error, $EULA does not exist!" echo "Cannot complete installation of Win4Lin." echo echo "Press return to continue" read ANS return 1 fi cat $EULA echo echo "(A copy of the above license can be found in the file $EULA)" echo echo "You must agree to the terms of this license" echo " before using the Win4Lin software." echo Ask_y_n "Do you agree to the terms of this license?" if [ $? -eq $YES_ANS ] then return 0 fi echo echo "You must agree to the license before using this software." echo echo "Press return to continue" read ANS return 1 echo "at end of License_Check" } AskLoadWin() { echo "in AskLoadWin" if [ -f "$VARMERGE"/dosc_setup.found -a -x /usr/bin/loadwindowsCD ] then echo "You can load the Windows installation files from the" echo "native DOS drive C now." Ask_y_n "Would you like to load the installation files now?" if [ $? -eq $YES_ANS ] then echo "Loading the Windows installation files" echo "from the native DOS C drive." /usr/bin/loadwindowsCD dosc else echo "You can load the Windows installation files" echo "later by running 'loadwindowsCD dosc'" fi return fi # Winsetup is an X client, so DISPLAY must be set to run it. if [ "x$DISPLAY" = "x" -o ! -x "$WINSETUP" ] then echo "You can load the Windows installation files" echo "later by running 'winsetup'" return fi echo "You can load the Windows installation files from the" echo "a Windows 95 or 98 installation CD now." Ask_y_n "Would you like to load the installation files now?" if [ $? -eq $YES_ANS ] then echo echo "Insert your Windows CD and then click 'Install' on the" echo "Load Windows CD window." echo echo "Please wait while loading the Windows CD..." $WINSETUP -d return fi echo "You can load the Windows installation files" echo "later by running 'winsetup'" echo "at end of AskLoadWin" } Interrupt_Proc() { echo "in Interrupt_Proc" trap 1 2 3 15 echo "Installation canceled." Failed_Install echo "at end of Interrupt_Proc" } # main # START HERE! if [ `id -u` -ne 0 ] ; then echo "" echo "This script must be run as root - please su - and try again." echo "" exit 1 fi # When WIN4LIN_CD_DIR is set, then use copy of self in /usr/bin. # Else use from the current directory. if [ "x$WIN4LIN_CD_DIR" != "x" ] then MYSELF=/usr/bin/install-win4lin.sh else MYSELF=`pwd`/install-win4lin.sh fi Which_pkgmgr Check_prereq $PKGMGR trap Interrupt_Proc 1 2 3 15 Check_installed_rpm while true do FindmountCD && break done # At this point the cwd is the Win4Lin subdirectory on the CD. Check_Display if [ "x$DISPLAY" = "x" ] then EULA="win4lin_eula.txt" License_Check if [ $? -ne 0 ] then Failed_Install fi AGREED=agreed fi License_Thang Check_ed Install_modutils Do_pkginstall # At this point the cwd is "/". AskLoadWin exit 0 --------------020301010501070602080306--