File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / sudo / mkinstalldirs
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Mon Jul 22 10:46:11 2013 UTC (10 years, 10 months ago) by misho
Branches: sudo, MAIN
CVS tags: v1_8_8p0, v1_8_8, v1_8_7p0, v1_8_7, v1_8_5p1, v1_8_3p2, v1_8_10p3_0, v1_8_10p3, HEAD
1.8.7

    1: #! /bin/sh
    2: # mkinstalldirs --- make directory hierarchy
    3: # Author: Noah Friedman <friedman@prep.ai.mit.edu>
    4: # Created: 1993-05-16
    5: # Public domain
    6: 
    7: umask 022
    8: errstatus=0
    9: dirmode=""
   10: 
   11: usage="\
   12: Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
   13: 
   14: # process command line arguments
   15: while test $# -gt 0 ; do
   16:   case $1 in
   17:     -h | --help | --h*)         # -h for help
   18:       echo "$usage" 1>&2
   19:       exit 0
   20:       ;;
   21:     -m)                         # -m PERM arg
   22:       shift
   23:       test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
   24:       dirmode=$1
   25:       shift
   26:       ;;
   27:     --)                         # stop option processing
   28:       shift
   29:       break
   30:       ;;
   31:     -*)                         # unknown option
   32:       echo "$usage" 1>&2
   33:       exit 1
   34:       ;;
   35:     *)                          # first non-opt arg
   36:       break
   37:       ;;
   38:   esac
   39: done
   40: 
   41: for file
   42: do
   43:   set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
   44:   shift
   45: 
   46:   pathcomp=
   47:   for d
   48:   do
   49:     pathcomp="$pathcomp$d"
   50:     case $pathcomp in
   51:       -*) pathcomp=./$pathcomp ;;
   52:     esac
   53: 
   54:     if test ! -d "$pathcomp"; then
   55:       echo "mkdir $pathcomp"
   56: 
   57:       mkdir "$pathcomp" || lasterr=$?
   58: 
   59:       if test ! -d "$pathcomp"; then
   60:   	errstatus=$lasterr
   61:       else
   62:   	if test ! -z "$dirmode"; then
   63: 	  echo "chmod $dirmode $pathcomp"
   64:     	  lasterr=""
   65:   	  chmod "$dirmode" "$pathcomp" || lasterr=$?
   66: 
   67:   	  if test ! -z "$lasterr"; then
   68:   	    errstatus=$lasterr
   69:   	  fi
   70:   	fi
   71:       fi
   72:     fi
   73: 
   74:     pathcomp="$pathcomp/"
   75:   done
   76: done
   77: 
   78: exit $errstatus
   79: 
   80: # Local Variables:
   81: # mode: shell-script
   82: # sh-indentation: 2
   83: # End:
   84: # mkinstalldirs ends here

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