#!/bin/sh ########################################################################## # SETUP for Mondo/Mindi installation CD, by Hugo Rabson # # # 10/19/2003 # - added code to distinguish zisofs from zisofs-tools when looking # for missing RPMs # # 10/16/2003 # - friendlier messages re: umount /mnt/cdrom # # 10/06/2003 # - better handling of dirs w/ final & snapshot in them at same time # # 09/22/2003 # - added SuSE and Trustix to the mix # - uninstall cdrecord if version is < 1.10 # # 09/08/2003 # - added partimagehack to the mix # # 07/31/2003 # - fixed input param bug # # 05/20/2003 # - added code to deal with mindi-kernel rpm # # 05/03/2003 # - copy self to /tmp/$RANDOM.$RANDOM.txt and run from there # - unmount (if not supermount) and eject CD at end of install # # 04/25/2003 # - pause before exiting, even Die()'ing # # 01/10/2003 # - misc bugs fixed # # 12/10/2002 # - misc bugs fixed # # 12/07/2002 # - changed ALX to ARK (ArkLinux) # # 11/31/2002 # - report success/failure at end # # 11/29/2002 # - tweaked it to automount; also to look for mondo/mindi RPM's in # the distro's directory before trying the vanilla RPM's # # 08/12/2002 # - minor tweaks # # 03/29/2002 # - started keeping a changelog in here ########################################################################## InBkgd() { cd / sleep 1 umount $1 eject $2 } # ------------------------- main ------------------------- LOGFILE=/tmp/mondo-setup.log STABLE_BRANCH=1.6 DEVEL_BRANCH=1.7 Die() { LogIt "$1" LogIt "" echo -en "Press ENTER to abort." read line exit 1 } GetDistroBanner() { local fname res res=`cat /etc/issue.net 2>/dev/null | fgrep -i turbolinux | head -n1` if [ "$res" != "" ] ; then echo "$res" return fi for fname in `find /etc -maxdepth 1 | fgrep release` /etc/issue.net ; do res=`cat $fname 2>/dev/null | fgrep -i "linux" | head -n1 | tr -s '\t' ' '` [ "$res" = "" ] && res=`cat $fname |head -n1 | tr -s '\t' ' '` if [ "$res" != "" ] ; then echo "$res" return fi done echo "UNKNOWN" } GetDistroName() { local banner name banner="`GetDistroBanner`" name="X" ;# unknown StrStr "$banner" "Red Hat" && name="RHT" ;# Red Hat StrStr "$banner" "Mandrake" && name="MDK" ;# Mandrake StrStr "$banner" "e-Smith" && name="SME" ;# e-Smith / SME StrStr "$banner" "SME Server" && name="SME" ;# e-Smith / SME StrStr "$banner" "SuSE" && name="SUS" ;# SuSE StrStr "$banner" "Trustix" && name="TSL" ;# Trustix if StrStr "$banner" "Turbolinux" ; then StrStr "$banner" "Server" && name="TLS" ;# TurboLinux Server StrStr "$banner" "Server" || name="TLW" ;# TurboLinux WorkSt'n fi if StrStr "$banner" "Caldera" ; then StrStr "$banner" "Server" && name="CALe";# Caldera e-Server StrStr "$banner" "Server" || name="CALo";# Caldera OpenLinux fi for i in "ArkLinux ARK" "Gentoo GEN" "RedHat RHT" "Mandrake MDK" ; do d=`echo "$i" | cut -d' ' -f1` e=`echo "$i" | cut -d' ' -f2` if strings /etc/ld.so.cache | grep -i "$d" &> /dev/null ; then echo $e return fi done echo "$name" } FindMissingRPMs() { local i pkg missing_packages j todo k blah missing_packages="" todo=`find $1 | grep -v mondo | grep -v mindi | grep -v XMondo` for i in mindi-kernel partimagehack "mindi-$MINDI_BRANCH" "mondo-$MY_BRANCH" ; do j=`find $1 -type f -maxdepth 1 | grep "$i" | head -n1` [ ! "$j" ] && j=`find RPMS -type f -maxdepth 1 | grep "$i" | head -n1` [ ! "$j" ] && Die "Unable to find $i in $1 or RPMS/" todo="$todo $j" done for i in $todo ; do [ -d "$i" ] && continue StrStr "$i" ".rpm" || continue i=`basename $i` j=`echo "$i" | tr '.' '#' | sed s/#rpm// | sed s/#i[3-8]86// | tr -s '#' '.'` k=`echo "$j" | cut -d'-' -f1` for blah in devel doc http kernel libs newt theme tools ; do if echo "$j" | grep "\-$blah" &> /dev/null ; then k=`echo "$j" | cut -d'-' -f1,2` fi done rpm -q $k &> /dev/null && continue missing_packages="$missing_packages $i" done echo "$missing_packages" } GetDistroVersion() { local banner i res j banner="`GetDistroBanner`" res="" for i in $banner ; do j=`echo $i | grep -x "[v|V][0-9]+*.*"` [ ! "$j" ] && j=`echo $i | grep -x "[0-9]+*.*"` [ "$j" ] && res=`echo $j | sed s/v// | sed s/V//` done [ "$res" ] && echo "$res" } InstallFromRpms() { local distro_TLA distro_ver distro_title replacement ch res q distro_TLA=$1 distro_ver=$2 # Look in directory 'RPMS/$distro_TLA' for a file called 'name' which contains # the user-friendly name of this distribution. distro_title=`cat RPMS/$distro_TLA/name` echo "InstallFromRPMS($distro_TLA,$distro_ver) --- title = $distro_title" >> $LOGFILE # Find a (compatible) version closest or identical to this user's version. if [ ! -d "RPMS/$distro_TLA/$distro_ver" ] ; then replacement=`find RPMS/$distro_TLA -type d | tail -n1` replacement=`basename $replacement` echo -en "Version $distro_ver is not supported. Would $replacement do? " read ch StrStr "YyYESyesYes" "$ch" && distro_ver=$replacement || Die "Please install Mondo manually.\nType 'cd $CDPATH/RPMS/$distro_TLA and \ninstall the RPM's of your choice." fi # Install RPM's from this directory. LogIt "Locating and installing packages suitable for $distro_title v $distro_ver" for q in XMondo mondo mindi mindi-kernel partimagehack ; do rpm -q $q &> /dev/null && rpm --erase $q --nodeps 2>> $LOGFILE >> $LOGFILE done # make list of and install missing packages if rpm -q cdrecord 2> /dev/null | grep "cdrecord-1\.[5-8]" ; then echo -en "Uninstalling outdated cdrecord package..." rpm --erase --nodeps cdrecord echo "Done." fi if ls RPMS/$distro_TLA/$distro_ver/mondo* &> /dev/null ; then InstallMissingPackages RPMS/$distro_TLA/$distro_ver RPMS/$distro_TLA/$distro_ver else InstallMissingPackages RPMS/$distro_TLA/$distro_ver RPMS fi res=$? # PostInstallSanityChecks # res=$(($res+$?)) return $res } InstallFromTgzs() { LogIt "I haven't written InstallFromTgzs() yet." return 1 } InstallMissingPackages() { local res pkg missing_packages command packages_path mindimondo_path possible_packages packages_path=$1 mindimondo_path=$2 missing_packages=`FindMissingRPMs $1` echo "missing_packages =$missing_packages" >> $LOGFILE command="rpm -Uvh" for pkg in $missing_packages ; do if [ -e "$packages_path/$pkg" ] ; then command="$command $packages_path/$pkg" elif [ -e "RPMS/$pkg" ] ; then command="$command RPMS/$pkg" else Die "Cannot find local path of $pkg - it's neither at RPMS nor at $packages_path" fi done # command="$command `find $mindimondo_path/mindi-$MINDI_BRANCH*rpm | tail -n1` `find $mindimondo_path/mondo-$MY_BRANCH*rpm | tail -n1`" LogIt "Installing$missing_packages" echo "Calling '$command'" >> $LOGFILE $command res=$? [ "$res" -ne "0" ] && Die "Some packages failed to be installed." return $res } LogIt() { echo -e "$1" >> /dev/stderr echo -e "$1" >> $LOGFILE } PostInstallSanityChecks() { local res res=0 if which /usr/local/mondo/mondo-archive &> /dev/null ; then echo "mondo-archive available to be executed" >> $LOGFILE else LogIt "mondo-archive --help failed" res=$(($res+1)) fi if [ "`/usr/local/mondo/mondo-tarme --wu-tang`" = "dollar dollar bill, y'all" ]; then echo "mondo-tarme executable intact" >> $LOGFILE else LogIt "mondo-tarme executable not available" res=$(($res+1)) fi if [ "`/usr/local/mondo/mondo-restore --cream`" = "dollar dollar bill, y'all" ] ; then echo "mondo-restore executable intact" >> $LOGFILE else LogIt "mondo-restore executable not available" res=$(($res+1)) fi return $res } StrStr() { [ "`echo "$1" | fgrep -i "$2"`" ] && return 0 || return 1 } WelcomeMessage() { LogIt "" LogIt "Welcome to the Mondo Rescue installer! This script" LogIt "will install Mondo and any missing dependencies." LogIt "--------------------------------------------------" echo "banner=`GetDistroBanner`" >> $LOGFILE echo "name =`GetDistroName`" >> $LOGFILE echo "ver =`GetDistroVersion`" >> $LOGFILE } InstallXmondoFromRpms() { rpm -i RPMS/XMondo-1*rpm return $? } InstallXmondoFromTgz() { echo "InstallXmondoFromTgz() --- not written yet" return 1 } # ------------------------------- main ------------------------------- cd `dirname $0` CDPATH=`pwd` if [ "$#" -ge "1" ] ; then if [ "`pwd`" != "/tmp" ] ; then rm -f /tmp/mondo-cd-setup.* new_fname="/tmp/mondo-cd-setup.$RANDOM.$RANDOM.$$.sh" cat $0 > $new_fname chmod +x $new_fname cd / exec sh $new_fname $0 fi cd `dirname $1` fi > $LOGFILE echo "pwd=`pwd`" >> $LOGFILE [ -e "/usr/local/mondo.devel" ] && [ -e "/usr/local/mindi" ] && Die "Noooo! Hugo, type 'mv /usr/local/mindi /usr/local/mindi.orig' first, please." MY_BRANCH=$STABLE_BRANCH MINDI_BRANCH=0.8 WelcomeMessage echo -en "Do you want to install the (S)table or the (D)evelopment branch of Mondo? " read ch if [ "`echo "development" | fgrep -i "$ch"`" ] ; then MY_BRANCH=$DEVEL_BRANCH MINDI_BRANCH=0.9 # XMONDO=yes fi [ "$MY_BRANCH" = "$STABLE_BRANCH" ] && LogIt "Installing stable branch." || LogIt "Installing development branch." LogIt "I see you are running `GetDistroBanner`" distro=`GetDistroName` version=`GetDistroVersion` [ "$distro" = "ARK" ] && version=1.0 [ ! "$version" ] && Die "Cannot ascertain version of distro" if [ ! -d "RPMS/$distro" ] && rpm --version &> /dev/null ; then LogIt "You are using an unknown version but you have RPM available, which means" LogIt "I could try installing the Red Hat 7.2-compatible stuff. It will probably work." echo -en "Shall I do that (y/n)? " read ch if [ "`echo "YESyesYes" | fgrep "$ch"`" ] ; then distro=RHT version=7.2 fi fi res=0 if [ -d "RPMS/$distro" ] ; then InstallFromRpms "$distro" "$version" res=$(($res+$?)) if [ "$XMONDO" ] ; then InstallXmondoFromRpms res=$(($res+$?)) fi elif [ -d "TGZS/$distro" ] ; then InstallFromTgzs "$distro" "$version" res=$(($res+$?)) if [ "$XMONDO" ] ; then InstallXmondoFromTgzs res=$(($res+$?)) fi else LogIt "`GetDistroBanner` is not supported by this script." LogIt "RPM's are stored in /RPMS and the tarballs are in /TGZS, both on the CD." Die "Please install Mondo manually." fi if [ "$res" -eq "0" ] ; then LogIt "End of install. Mondo was installed OK." else LogIt "End of install. Errors occurred." fi cd / if [ "$#" -ge "1" ] ; then mountpt=`dirname $1` dev=`mount | tr -s '\t' ' ' | grep "$mountpt " | awk '{print $1;}'` if [ ! "$dev" ] || [ "$dev" = "none" ] ; then dev=`mount | tr -s '\t' ' ' | grep "$mountpt " | tr -s ',' '\n' | sed s/dev=// | grep /dev` mountpt=""; # supermount - don't unmount it :) fi [ "$mountpt" ] && umount $mountpt [ "$dev" ] && eject $dev echo "mountpt=$mountpt; dev=$dev" >> $LOGFILE else LogIt "Please type:-" LogIt " cd /" LogIt " umount $CDPATH" LogIt "Then remove the Mondo installation CD." fi LogIt "Refer to Mondo's manual for instructions" LogIt "on the care and feeding of Mondo Rescue." LogIt "" #if fdisk -l | grep -w 7 &> /dev/null || fdisk -l | grep -wi ntfs &> /dev/null ; then # LogIt "To backup your NTFS partition, you must first install" # LogIt "partimagehack. This is in the CD's /TGZS directory as" # LogIt "partimagehack-0.6.2.tar.bz2, FYI." # which partimagehack &> /dev/null & LogIt "...Oh my, I think you already have. Good show!" #fi #LogIt "" LogIt "Log in as root and type 'mondoarchive' to backup your PC." LogIt "" echo -en "Press ENTER to finish." read line exit $res