#!/bin/sh # # Otto - Automaticallly install autorpm, package updates, # and My Unix Staff from the Lucky 13 CD. # # Eric Myers - 2 March 2003 # @(#) $Id: Otto,v 2.11 2008/01/18 19:40:58 myers Exp myers $ ######################################################################## echo "Otto: automatically installs autorpm and updates from the Lucky 13 CD" # Settings: DEBUG=1 NAME=`basename $0` ############### # Functions: debug() { if [ $1 -le $DEBUG ]; then echo -n "$NAME[$1]: " shift echo $* fi } filefind() { if [ $# -lt 2 ]; then echo "Error: filefind pattern directories..." >&2 exit 2 fi PAT=$1 shift LIST=$* for DIR in $LIST do RESULT=`find $DIR -name "$PAT" -print` if [ ! -z "$RESULT" -a -f "$RESULT" ]; then echo $RESULT exit fi done } ############### # Begin: # Is autorpm is already installed (i.e. the standard directory exists)? ISAUTORPM=`ls -d /etc/autorpm.d` ## # Find the autorpm package on the CD (or NFS/AFS?) debug 5 "Looking for autorpm package with filefind..." AUTORPM=`filefind "autorpm-*.noarch.rpm" /media /mnt /cdrom ` debug 4 "Location of autorpm package is supposedly $AUTORPM" # # If autorpm is not already installed and we can't find it on the CD # then we have to stop to ask. # if [ -z "$AUTORPM" -a -z "$ISAUTORPM" ]; then echo " ! Cannot find the autorpm package. Are you sure the CD is mounted?" echo -n " ! Please enter the CD mount point: " read AUTORPM if [ -d "$AUTORPM" ]; then AUTORPM=`find $AUTORPM -name "autorpm-*.noarch.rpm" -print` else AUTORPM=`ls -d $AUTORPM` fi fi ### # Now we either install autorpm or update, if we can if [ -f "$AUTORPM" ]; then debug 5 "Installing/Updating autorpm..." rpm -Uhv $AUTORPM else debug 5 "Cannot find the autorpm package, so it's not been installed/updated." fi ## # Now is autorpm installed? Then use it... ISAUTORPM=`ls -d /etc/autorpm.d` if [ -z "$ISAUTORPM" ]; then echo " * We have a problem: autorpm is (still) not installed." echo " * You will have to update rpm's by hand." else echo -n " Okay, the version of autorpm now installed is: " rpm -q autorpm ## # if there is an existing autorpm.conf we should save it. if [ -f /etc/autorpm.d/autorpm.conf ]; then debug 5 "Saving autorpm.conf..." cp /etc/autorpm.d/autorpm.conf /etc/autorpm.d/autorpm.conf,ORIG fi ## # Locate the CD mount point CDPATH=`filefind LUCKY13-VERSION /cdrom /media /mnt ` CDPATH=`dirname $CDPATH` debug 5 "CD path is $CDPATH" if [ ! -d $CDPATH ]; then echo "! Cannot find path to CD drive. " exit 3 fi ## # Import any RPM Keys from the CD LIST=`ls -1 $CDPATH/keys/RPM-GPG-KEY* $CDPATH/RPM-GPG-KEY* ` for KEY in $LIST do echo rpm --import $KEY rpm --import $KEY done ## # Replace main config file with our own. There is a 'bug' in autorpm # that prevents one from having more than one source block in an # included file, so we put each in it's own file. cat < /etc/autorpm.d/autorpm.conf # /etc/autorpm.d/autorpm.conf created by Otto on `date` # UPDATE FROM LUCKY 13 CD Set_Var("ReportDest", "root"); Set_Var("Arch", "i686|i586|i386|noarch"); Set_Var("Lang", "en"); Eval_Var("RHVersion", "sed 's/\(Red Hat Linux \)\?release \([^ ]*\) (.*)/\2/' /etc/redhat-release"); Eval_Var("FedoraVersion", "awk '{print $4}' /etc/fedora-release"); Report_Queues_To ("\${ReportDest}"); Config_File("/etc/autorpm.d/Otto-rpm-1.conf"); Config_File("/etc/autorpm.d/Otto-rpm-2.conf"); #EOF autorpm.conf EOF # # Now the individual files to do this... # Otto-rpm-1.conf: Fedora rpm's from the CD # cat < /etc/autorpm.d/Otto-rpm-1.conf # /etc/autorpm.d/Otto-rpm-1.conf : update Red Hat rpm's from Lucky13 CD # Directory( "$CDPATH/rpm/fedora/\${FedoraVersion}/" ) { Report_To ("\${ReportDest}"); # Don't automatically update these! Regex_Ignore("-debuginfo-"); action (updated) { # install any updates PGP_Require (Yes); PGP_Fail_Install (Yes); Auto_Follow_Deps(Yes); Install (Auto); Report(Yes); } action(new) { # and new packages Install (No); Report(No); } } #EOF Otto-rpm-1.conf EOF # # Otto-rpm-2.conf: Local rpm's from our CD cat < /etc/autorpm.d/Otto-rpm-2.conf # /etc/autorpm.d/Otto-rpm-2.conf : update local rpm's from Lucky13 CD # Directory( "$CDPATH/rpm/extra/" ) { Report_To ("\${ReportDest}"); action(new) { # and new packages PGP_Require (No); Install (Auto); Report(Yes); } action (updated) { # install any updates PGP_Require (No); Auto_Follow_Deps(Yes); Install (Auto); Report(Yes); } } #EOF Otto-rpm-2.conf EOF ## # Then run autorpm with the one-time config file: debug 5 "Ready to run autorpm. Here I go-oh!... " echo " " echo " A copy of this autorpm session will be recorded in /root/autorpm.log" autorpm "auto --print " | tee /root/autorpm.log ## # And then set up for following runs to use the net ADMDIR=`filefind Tara /media /mnt /cdrom ` if [ ! -z "$ADMDIR" ]; then ADMDIR=`dirname $ADMDIR` debug 5 ADMDIR is $ADMDIR else debug 4 "Cannot find local/adm directory on the CD." fi ## # Place to store packages once installed (if so desired) mkdir -p /home/rpm/fedora/6 cp -f ${ADMDIR}/Otto-rpm.conf /etc/autorpm.d/Otto-rpm.conf cp -f ${ADMDIR}/Otto-rpm-3.conf /etc/autorpm.d/Otto-rpm-3.conf cp -f ${ADMDIR}/Otto-rpm-4.conf /etc/autorpm.d/Otto-rpm-4.conf cp -f /etc/autorpm.d/Otto-rpm.conf /etc/autorpm.d/autorpm.conf ## # Reminder echo " " echo " The next time autorpm is run it will compare against the network" echo " rather than the CD. You might even want to run it now... " echo " " ## # If there was a pre-existing config file, make a note if it. if [ -f /etc/autorpm.d/autorpm.conf,ORIG ]; then echo " " echo " Your previously existing autorpm.conf file has been replaced." echo " You can find the old one as /etc/autorpm.d/autorpm.conf,ORIG" fi fi ################################################## # Now update My Unix Staff using rsync - only newer versions if [ ! -d /usr/local/adm ]; then mkdir -p /usr/local/adm fi debug 1 "Updating /usr/local/adm from $ADMDIR with rsync..." /usr/bin/rsync -avz $ADMDIR/ /usr/local/adm/ exit 0 ##EOF