12c7c4e3dSmrg#! /bin/sh 22c7c4e3dSmrg# mkinstalldirs --- make directory hierarchy 32c7c4e3dSmrg# Author: Noah Friedman <friedman@prep.ai.mit.edu> 42c7c4e3dSmrg# Created: 1993-05-16 52c7c4e3dSmrg# Public domain 62c7c4e3dSmrg 72c7c4e3dSmrgerrstatus=0 82c7c4e3dSmrgdirmode="" 92c7c4e3dSmrg 102c7c4e3dSmrgusage="\ 112c7c4e3dSmrgUsage: mkinstalldirs [-h] [--help] [-m mode] dir ..." 122c7c4e3dSmrg 132c7c4e3dSmrg# process command line arguments 142c7c4e3dSmrgwhile test $# -gt 0 ; do 152c7c4e3dSmrg case $1 in 162c7c4e3dSmrg -h | --help | --h*) # -h for help 172c7c4e3dSmrg echo "$usage" 1>&2 182c7c4e3dSmrg exit 0 192c7c4e3dSmrg ;; 202c7c4e3dSmrg -m) # -m PERM arg 212c7c4e3dSmrg shift 222c7c4e3dSmrg test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } 232c7c4e3dSmrg dirmode=$1 242c7c4e3dSmrg shift 252c7c4e3dSmrg ;; 262c7c4e3dSmrg --) # stop option processing 272c7c4e3dSmrg shift 282c7c4e3dSmrg break 292c7c4e3dSmrg ;; 302c7c4e3dSmrg -*) # unknown option 312c7c4e3dSmrg echo "$usage" 1>&2 322c7c4e3dSmrg exit 1 332c7c4e3dSmrg ;; 342c7c4e3dSmrg *) # first non-opt arg 352c7c4e3dSmrg break 362c7c4e3dSmrg ;; 372c7c4e3dSmrg esac 382c7c4e3dSmrgdone 392c7c4e3dSmrg 402c7c4e3dSmrgfor file 412c7c4e3dSmrgdo 422c7c4e3dSmrg if test -d "$file"; then 432c7c4e3dSmrg shift 442c7c4e3dSmrg else 452c7c4e3dSmrg break 462c7c4e3dSmrg fi 472c7c4e3dSmrgdone 482c7c4e3dSmrg 492c7c4e3dSmrgcase $# in 502c7c4e3dSmrg 0) exit 0 ;; 512c7c4e3dSmrgesac 522c7c4e3dSmrg 532c7c4e3dSmrgcase $dirmode in 542c7c4e3dSmrg '') 552c7c4e3dSmrg if mkdir -p -- . 2>/dev/null; then 562c7c4e3dSmrg echo "mkdir -p -- $*" 572c7c4e3dSmrg exec mkdir -p -- "$@" 582c7c4e3dSmrg fi 592c7c4e3dSmrg ;; 602c7c4e3dSmrg *) 612c7c4e3dSmrg if mkdir -m "$dirmode" -p -- . 2>/dev/null; then 622c7c4e3dSmrg echo "mkdir -m $dirmode -p -- $*" 632c7c4e3dSmrg exec mkdir -m "$dirmode" -p -- "$@" 642c7c4e3dSmrg fi 652c7c4e3dSmrg ;; 662c7c4e3dSmrgesac 672c7c4e3dSmrg 682c7c4e3dSmrgfor file 692c7c4e3dSmrgdo 702c7c4e3dSmrg set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 712c7c4e3dSmrg shift 722c7c4e3dSmrg 732c7c4e3dSmrg pathcomp= 742c7c4e3dSmrg for d 752c7c4e3dSmrg do 762c7c4e3dSmrg pathcomp="$pathcomp$d" 772c7c4e3dSmrg case $pathcomp in 782c7c4e3dSmrg -*) pathcomp=./$pathcomp ;; 792c7c4e3dSmrg esac 802c7c4e3dSmrg 812c7c4e3dSmrg if test ! -d "$pathcomp"; then 822c7c4e3dSmrg echo "mkdir $pathcomp" 832c7c4e3dSmrg 842c7c4e3dSmrg mkdir "$pathcomp" || lasterr=$? 852c7c4e3dSmrg 862c7c4e3dSmrg if test ! -d "$pathcomp"; then 872c7c4e3dSmrg errstatus=$lasterr 882c7c4e3dSmrg else 892c7c4e3dSmrg if test ! -z "$dirmode"; then 902c7c4e3dSmrg echo "chmod $dirmode $pathcomp" 912c7c4e3dSmrg lasterr="" 922c7c4e3dSmrg chmod "$dirmode" "$pathcomp" || lasterr=$? 932c7c4e3dSmrg 942c7c4e3dSmrg if test ! -z "$lasterr"; then 952c7c4e3dSmrg errstatus=$lasterr 962c7c4e3dSmrg fi 972c7c4e3dSmrg fi 982c7c4e3dSmrg fi 992c7c4e3dSmrg fi 1002c7c4e3dSmrg 1012c7c4e3dSmrg pathcomp="$pathcomp/" 1022c7c4e3dSmrg done 1032c7c4e3dSmrgdone 1042c7c4e3dSmrg 1052c7c4e3dSmrgexit $errstatus 1062c7c4e3dSmrg 1072c7c4e3dSmrg# Local Variables: 1082c7c4e3dSmrg# mode: shell-script 1092c7c4e3dSmrg# sh-indentation: 2 1102c7c4e3dSmrg# End: 1112c7c4e3dSmrg# mkinstalldirs ends here 112