#!/bin/ksh # # $Id: mkproto,v 1.7 2009/08/14 17:29:20 vogelke Exp $ # # NAME: # mkproto # # SYNOPSIS: # mkproto [-hv] [dir] # mkproto -l < list # # DESCRIPTION: # Makes a bare-bones prototype file to describe files under # a given directory, or the current directory if no arguments # are entered. Output goes to stdout. # # A record looks like this: # f none pathname mode owner group # # OPTIONS: # -h, --help print this message # -l, --list read files from stdin # -v, --version print the version and exit # # NOTE: # Depends on GNU version of find. # # AUTHOR: # Based on Free Software Foundation configure scripts. # # Karl Vogel # Sumaria Systems, Inc. PATH=/bin:/usr/bin:/usr/local/bin:/opt/sfw/bin export PATH umask 022 FIND=gfind # ======================== FUNCTIONS ============================= # # 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 exit 1 } # version: prints the current version to stdout. version () { lsedscr='s/RCSfile: // s/.Date: // s/,v . .Revision: / v/ s/\$//g' lrevno='$RCSfile: mkproto,v $ $Revision: 1.7 $' lrevdate='$Date: 2009/08/14 17:29:20 $' echo "$lrevno $lrevdate" | sed -e "$lsedscr" } # ======================== MAIN PROGRAM ========================== # Defaults: ac_help= ac_prev= ac_invalid="invalid option; use -h or --help to show usage" argv= list=no for ac_option do # If the previous option needs an argument, assign it. case "$ac_prev" in "") ;; *) eval "$ac_prev=\$ac_option"; ac_prev=; continue ;; esac case "$ac_option" in -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; *) ac_optarg= ;; esac # main switch case "$ac_option" in -h | -help | --help | --hel | --he) usage ;; -l | -list | --list | --lis | --li) list=yes ;; -v | -version | --version | --versio |\ --versi | --vers) version; exit 0 ;; -*) die "$ac_option: $ac_invalid" ;; *) case "$argv" in "") argv="$ac_option" ;; *) argv="$argv $ac_option" ;; esac ;; esac done case "$ac_prev" in "") ;; *) die "missing arg to --`echo $ac_prev | sed 's/_/-/g'`" ;; esac # # Real work starts here. Check the starting directory # and write the prototype. # fmt="%y %l %p %m %u %g\n" sedscr=" s/^\([fd]\) /\1 none / s/$USER $USER\$/bin bin/ " case "$list" in "yes") ( while read file; do $FIND $file -maxdepth 1 -printf "$fmt" done ) | sort | sed -e "$sedscr" ;; "no") case "$argv" in "") dir=. ;; *) dir="$1" ;; esac test -d "$dir" || die "$dir: not a directory" $FIND $dir -printf "$fmt" | sort | sed -e "$sedscr" ;; esac exit 0