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