#! /usr/local/bin/perl eval "exec /usr/local/bin/perl -S $0 $*" if $running_under_some_shell; ################################################################################ # # File: manageBInstallDirs # RCS: $XConsortium: manageBInstallDirs /main/3 1995/10/30 13:43:53 rswiston $ # Author: Marc Ayotte Hewlett-Packard, OSSD-CV # Created: Thu Dec 30 14:02:31 PST 1993 # Language: perl # Package: N/A # Status: CDE distributed # # (c) Copyright 1993, Hewlett-Packard Company, all rights reserved. # # Usage: manageBInstallDirs [#dirsleft] # # Description: This script removes excessive binstall directories of # the type parentdir/mm_dd (month day). # It also symbolically links the most recent subdirectory # to parentdir/latest. # ################################################################################ if ($ARGV[1]) { $tree = $ARGV[0]; $latestSubdir = $ARGV[1]; } else { die "USAGE manageBInstallDirs [# dirsleft]\n"; } if (! chdir("$tree")) { die " ERROR -> Couldn't change directory to $tree.\n"; } if ($ARGV[2]) { $numDirsLeft = $ARGV[2]; } else { $numDirsLeft = 7; } ####################################################### # define local subroutines ####################################################### sub dokill { die "\n left on INTR \n"; exit 1; } ######################################################## # Catch signals ######################################################## $SIG{'INT'} = 'dokill'; ################################################## # get the mm_dd directories in oldest first order. # remove the oldest if there are more than minimum. ################################################## @allDirs = (`ls -t`); $counter = 0; foreach $dir (@allDirs){ chop $dir; $_ = $dir; if (m%^[0-9][0-9]_[0-9][0-9]$% && -d $dir) { if ($counter++ >= $numDirsLeft) { print "removing $tree/$dir\n"; system "rm -rf $dir"; } } } ############################ # link latestSubdir to latest ############################ if (-l "latest") { print "linking $latestSubdir to \"latest\"\n"; system "rm -f latest"; system "ln -s -f $latestSubdir latest"; } elsif(-d "latest") { print "Error - directory \"latest\" is a real directory"; } else { # create link system "ln -s -f $latestSubdir latest"; }