Hi folks ! Along with this mail i send you two little pieces of code which i found extremely useful. The first is a patch to the install program. Since install is used by many source-packages to install themselves, i thought it would be nice if install keeps track of the installed programs. The patch attached does this. It takes some information from install-time and spills them to a log file. The second program is a little bash-script which utilizies this log. Ahh, please note that these are quick & dirty hacks. If you like them I think it would be great if you implement their functionality in a one of the next fileutils-releases.
Best regards Joern Merkel -- Murphy is watching you !
--- src/install.orig.c Mon Dec 25 12:07:36 2000 +++ src/install.c Fri Sep 28 17:12:47 2001 @@ -23,6 +23,9 @@ #include <config.h> #include <stdio.h> +#include <fcntl.h> +#include <time.h> +#include <sys/time.h> #include <getopt.h> #include <sys/types.h> #include <pwd.h> @@ -141,6 +144,58 @@ {NULL, 0, NULL, 0} }; +int installlog (const char *file0,const char *file1) +{ +/* The enviroment variable ILOGFILE specifies where to put the logfile. + i.e. /var/log/ilog */ + char *ilogfile = (char *) getenv("ILOGFILE"); +/* if ILOGFILE is set -> continue, else forget everything... */ + if (ilogfile != NULL) { + int fd = open (ilogfile, O_CREAT|O_APPEND|O_WRONLY, 0644); + if (fd<0) { + fprintf (stderr,"%s :",ilogfile); + perror ("open"); + return (1); + } + struct timeval tv; + struct timezone tz; + gettimeofday (&tv, &tz); + + char datestring[255]; +/* this forges the first part of the logstring, the date */ + strftime (datestring, 255, "%Y-%m-%d-%H:%M:%S ", localtime (&tv.tv_sec)); +/* and this tries to extract the packagename from PWD. Assume you installed the + sources to /usr/src/fileutils-4.1 then the extracted packagename will be + PWD minus /usr/src/ = fileutils-4.1 .Any following tree will be cutted away + also. */ + char *pathstring= (char *) getenv("PWD"); + int matches = strspn(pathstring,"/usr/src/"); + if (matches != 9) { + fprintf (stderr,"if you want loging, you have to install from /usr/src/* !\n"); + return (1); + } + char *startptr = &pathstring[matches]; + char *endptr = strchr(startptr, '/'); + char packstring[255]; + if (endptr != NULL) + strncpy (packstring, startptr, endptr-startptr); + else + strcpy (packstring, startptr); +/* this one forges the complete logstring, */ + strcat (datestring, packstring); + strcat (datestring, ": "); + strcat (datestring, file0); + strcat (datestring, " -> "); + strcat (datestring, file1); + strcat (datestring, "\n"); +/* which is finally written... */ + write(fd, datestring, strlen(datestring)); + + close (fd); + } + return (0); +} + static void cp_option_init (struct cp_options *x) { @@ -326,6 +381,8 @@ errors = install_file_in_file (file[0], file[1], &x); else errors = install_file_in_dir (file[0], file[1], &x); + if (errors == 0) + installlog (file[0], file[1]); } else { @@ -342,6 +399,8 @@ for (i = 0; i < n_files - 1; i++) { errors |= install_file_in_dir (file[i], dest, &x); + if (errors == 0) + installlog (file[i], dest); } } }
#!/bin/bash # # this is a little tool to handle to information provided by the install-patch # written in 2001 by Joern Merkel. # # Yeah, this is all GPL, of course... # # some parameters : # # -l : list (all) installed packs # -d packname : delete # -g pattern : grep # -t packname : make a tar of the installed files function dolistfiles { # -d -> delete # -t -> tar LIST="$(grep ".* $OPTARG:" $LOGPLACE | cut -d " " -f 3-5)" [ ! "$LIST" ] && echo "Nothing to do with $OPTARG" && exit 0 oldIFS="$IFS" IFS=$'\n' for LINE in $LIST; do FILE="$(echo "$LINE" | cut -d " " -f 3)" [ -d $FILE ] && FILE="${FILE%/}/$(echo "$LINE" | cut -d " " -f 1)" if [ -f $FILE ]; then [ "$1" == "-d" ] && rm $FILE && echo "$FILE removed" [ "$1" == "-t" ] && tar -r $FILE -f $HOME/$OPTARG-$HOSTNAME.tar 2>/dev/null fi done IFS="$oldIFS" } OPTERR=0 LOGPLACE=$ILOGFILE if [ $# -eq 0 ]; then echo "sorting $LOGPLACE..." (sort -r -k 2 $LOGPLACE | uniq -f 1 | sort > $LOGPLACE.2) && mv $LOGPLACE.2 $LOGPLACE echo "for a list of options use -h" [ "$DIALOG" ] || exit 0 fi while : ; do getopts "hld:g:t:" OPTNAME || exit 0 case "$OPTNAME" in h) echo "-l : list (all) installed packs" echo "-d packname : delete" echo "-g pattern : grep" echo "-t packname : make a tar of the installed files" ;; l) grep ":" $LOGPLACE | sort -k 2 | cut -d " " -f 2 | uniq ;; d) grep "$OPTARG:" $LOGPLACE echo "Maybe you want to tar this files first ? (Do packtool -t $OPTARG)" echo "Warning ! Removing those files !" echo -n "Are you absolutely sure (y/n) ? "; read INPUT [ "$INPUT" != "y" ] && exit 0 dolistfiles -d (grep -v ".* $OPTARG:" $LOGPLACE > $LOGPLACE.2) && mv $LOGPLACE.2 $LOGPLACE ;; g) grep "$OPTARG" $LOGPLACE ;; t) dolistfiles -t gzip $HOME/$OPTARG-$HOSTNAME.tar && echo "$OPTARG tarred to $HOME/$OPTARG-$HOSTNAME.tar.gz" ;; esac done