File:  [LON-CAPA] / loncom / build / Attic / kirs.pl
Revision 1.1: download - view: text, annotated - select for diffs
Mon Oct 1 20:16:13 2001 UTC (22 years, 9 months ago) by harris41
Branches: MAIN
CVS tags: stable_2002_spring, stable_2001_fall, HEAD, Before_rewrite
ridiculously simple tool for updating rpms on a system

    1: #!/usr/bin/perl
    2: #
    3: # kirs.pl
    4: # 
    5: # RPM installation.  Keeping It Ridiculously Simple.
    6: 
    7: # YEAR=2001
    8: # 10/1 Scott Harrison
    9: 
   10: # Brief essay:
   11: #
   12: # This program automates what SHOULD be automated
   13: # in an RPM upgrade process.  That is to say, it
   14: # automatically tells the system administrator
   15: # what should be updated.  In addition to a streaming
   16: # terminal output, it creates two files:
   17: # updatenow.txt - a list of rpms that should upgrade
   18: #                  on the system with no problems
   19: # updateproblems.txt - a list of rpms with potential upgrade
   20: #                       problems such as dependencies and/or
   21: #                       file conflicts
   22: #
   23: # What this program does not do, is make the decisions based
   24: # on dependencies, file conflicts, or even the decision to
   25: # update an RPM.
   26: #
   27: # Why?  Because in my experience, the implementation of rpm
   28: # information is often buggy, the actual rpm information is often
   29: # buggy, and taking care of exceptional cases (such as kernel
   30: # rpm's) is buggy.  And, in principle, I view it as serious
   31: # business when it comes to keeping a server in a well-defined
   32: # state that is not screwed up by unknown bugs.
   33: #
   34: # Usage, can be non-root: perl kirs.pl
   35: #
   36: # As befits the name, a very simple invocation.
   37: #
   38: # After running the program, as root, the administrator
   39: # can:
   40: #
   41: # cat updatenow.txt | xargs rpm -Uvh 
   42: # and then
   43: # look at the contents of updateproblems.txt in an editor
   44: # and make appropriate decisions
   45: #
   46: # This program relies on the following executables
   47: # to be in the path: cat, grep, rpm
   48: #
   49: # And for the bad attributes of this program:
   50: # * It downloads the ENTIRE i386 update RPM directory
   51: #   (specific to the redhat release)
   52: # * It is hardcoded to use 
   53: #   ftp://mirror.pa.msu.edu/linux/redhat/linux/updates/RELEASENUM/en/os/i386/
   54: #   where RELEASENUM is 6.2, 7.1, etc
   55: # * It creates a lot of files in the current directory in which it
   56: #   resides (basically all the update *.rpm's)
   57: #
   58: # WARNING
   59: # THIS PROGRAM IS PROVIDED "AS IS" WITHOUT
   60: # WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLICIT.
   61: # IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   62: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   63: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   64: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   65: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   66: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   67: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   68: # SUCH DAMAGE.
   69: 
   70: my $issue=`cat /etc/issue`;
   71: $issue=~/Linux release (\S+)/;
   72: my $releasenum=$1;
   73: print "Detecting a RedHat version $releasenum system\n";
   74: 
   75: open NOW,">updatenow.txt";
   76: open PROBLEMS,">updateproblems.txt";
   77: 
   78: my $ftpbase="ftp://mirror.pa.msu.edu/linux/redhat/linux/updates/";
   79: 
   80: $|=1;
   81: print "Downloading update repository...$ftpbase...\n";
   82: system('wget','-q',
   83:        "$ftpbase$releasenum/en/os/i386/*.rpm");
   84: die "bad ftp connection" if $?;
   85: print "Finished downloading\n";
   86: 
   87: my @list=`rpm -qp *.rpm --queryformat "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm\t%{NAME}\t%{VERSION}-%{RELEASE}\n"`;
   88: 
   89: for (@list) {
   90:     chop;
   91:     next if /^kernel/;
   92:     my ($file,$name,$version)=split(/\t/);
   93:     my $currentversion=`rpm -q $name --queryformat="\%{VERSION}-%{RELEASE}"`;
   94:     if ($currentversion!~/is not installed/) {
   95: 	if ($version ne $currentversion) {
   96: 	    print "$name compare $currentversion to $version\n";
   97: 	    my $status=`rpm -Uvh --test $file 2>&1| grep -v ^Preparing`;
   98: 	    system("rpm -Uvh --test $file 1>/dev/null");
   99: 	    if ($?) {
  100: 		print PROBLEMS "$file\n$status";
  101: 	    }
  102: 	    else {
  103: 		print NOW "$file\n";
  104: 	    }
  105: 	    print $status;
  106: 	}
  107:     }
  108: }
  109: close PROBLEMS;
  110: close NOW;
  111: 
  112: print <<END;
  113: # The program has completed.  As root, the administrator
  114: # can now:
  115: #
  116: # cat updatenow.txt | xargs rpm -Uvh 
  117: # and then
  118: # look at the contents of updateproblems.txt in an editor
  119: # and make appropriate decisions
  120: END

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>