#!/bin/ksh # # $Id: mkdist,v 1.2 2008/05/09 17:38:55 vogelke Exp $ # # NAME: # mkdist # # SYNOPSIS: # mkdist [-huvw] SRCDIR MANIFEST # # DESCRIPTION: # Accept a source directory SRCDIR and a MANIFEST file. Change # to SRCDIR, copy manifest files to a temp directory, and make a # shar-file holding the contents. The manifest file is read *after* # we change to the source directory. # # OPTIONS: # -h print help information and exit # -u print UUID and exit # -v print the version and exit # -w print the source code location and exit # # SAMPLE MANIFEST: # The format is loosely based on a Solaris Prototype file: # # d none ./bin 775 root staff # f none ./bin/older 755 root staff # d none ./doc 775 root staff # f none ./doc/MANIFEST 644 root staff # f ./etc ./doc/conf-dest 644 root staff # f none ./doc/cron-entries 644 root staff # d none ./etc 775 root staff # # Field 1: f=regular file, d=directory # Field 2: move file here after copying it to temp directory # Field 3: file to install, or directory to create # Field 4: mode # Field 5: owner # Field 6: group # # Directories are made first, then files are copied, and finally files # are moved if the second field contains something other than "none". # # AUTHOR: # Based on Free Software Foundation configure scripts. # # Karl Vogel # Sumaria Systems, Inc. PATH=/usr/local/bin:/usr/sfw/bin:/opt/sfw/bin:/bin:/usr/bin TMPDIR=/tmp export PATH TMPDIR umask 022 tag=`basename $0` # # usage: prints an optional string plus part of the comment # header (if any) to stderr, and exits with code 1. # usage () { lines=`egrep -n '^# (NAME|AUTHOR)' $0 | sed -e 's/:.*//'` ( case "$#" in 0) ;; *) echo "usage error: $*"; echo ;; esac case "$lines" in "") ;; *) set `echo $lines | sed -e 's/ /,/'` sed -n ${1}p $0 | sed -e 's/^#//g' | egrep -v AUTHOR: ;; esac ) 1>&2 } # # Print an error and exit. # die () { echo "$*" >& 2 exit 1 } # # Print the current version and source location. # myuuid () { lsedscr='s/UUID: // s/\$//g' lid='$UUID: 8a41d1df-71f7-3406-ac63-b9416ce55148 $' echo "$lid" | sed -e "$lsedscr" } version () { lsedscr='s/RCSfile: // s/.Date: // s/,v . .Revision: / v/ s/\$//g' lrevno='$RCSfile: mkdist,v $ $Revision: 1.2 $' lrevdate='$Date: 2008/05/09 17:38:55 $' echo "$lrevno $lrevdate" | sed -e "$lsedscr" } where () { lsedscr='s/Source: // s/\$//g' echo "$lsrc" | sed -e "$lsedscr" } # # Handle command line arguments. # while getopts huvw c do case $c in h) usage; exit 0 ;; u) myuuid; exit 0 ;; v) version; exit 0 ;; w) where; exit 0 ;; \?) exit 0 ;; esac done shift `expr $OPTIND - 1` case "$#" in 2) src="$1"; manifest="$2" ;; *) die "usage: $tag srcdir manifest, or $tag -h for help" ;; esac # # Real work starts here. # test -d "$src" || die "$src: not a directory" cd $src test -f "$manifest" || die "$manifest: not found" dst="$TMPDIR/$tag.$$" outfile="$TMPDIR/$tag.$$.shar" mkdir $dst || die "mkdir failed" # # Make directory tree specified by manifest. # grep '^d' $manifest | nawk -v "dir=$dst" '{printf "mkdir -p %s/%s\n", dir, $3}' | sort | sh # # Copy files specified by manifest. # grep -v '^d' $manifest | awk '{print $2, $3}' | while read alt file do cp -p $file $dst/$file case "$alt" in none) ;; *) mv $dst/$file $dst/$alt ;; esac done # # Create a shar archive starting at the parent of # the destination directory, which should be TMPDIR. # cd $TMPDIR base=`basename $dst` find $base -type f -print | sort | shar -S > $outfile rm -rf $dst echo $outfile exit 0