mkinstalldirs revision 130561
138889Sjdp#! /bin/sh 238889Sjdp# mkinstalldirs --- make directory hierarchy 338889Sjdp# Author: Noah Friedman <friedman@prep.ai.mit.edu> 438889Sjdp# Created: 1993-05-16 538889Sjdp# Public domain 638889Sjdp 738889Sjdperrstatus=0 8130561Sobriendirmode="" 938889Sjdp 10130561Sobrienusage="\ 11130561SobrienUsage: mkinstalldirs [-h] [--help] [-m mode] dir ..." 1238889Sjdp 13130561Sobrien# process command line arguments 14130561Sobrienwhile test $# -gt 0 ; do 15130561Sobrien case $1 in 16130561Sobrien -h | --help | --h*) # -h for help 17130561Sobrien echo "$usage" 1>&2 18130561Sobrien exit 0 19130561Sobrien ;; 20130561Sobrien -m) # -m PERM arg 21130561Sobrien shift 22130561Sobrien test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } 23130561Sobrien dirmode=$1 24130561Sobrien shift 25130561Sobrien ;; 26130561Sobrien --) # stop option processing 27130561Sobrien shift 28130561Sobrien break 29130561Sobrien ;; 30130561Sobrien -*) # unknown option 31130561Sobrien echo "$usage" 1>&2 32130561Sobrien exit 1 33130561Sobrien ;; 34130561Sobrien *) # first non-opt arg 35130561Sobrien break 36130561Sobrien ;; 37130561Sobrien esac 38130561Sobriendone 3938889Sjdp 40130561Sobrienfor file 41130561Sobriendo 42130561Sobrien if test -d "$file"; then 43130561Sobrien shift 44130561Sobrien else 45130561Sobrien break 46130561Sobrien fi 47130561Sobriendone 4838889Sjdp 49130561Sobriencase $# in 50130561Sobrien 0) exit 0 ;; 51130561Sobrienesac 5238889Sjdp 53130561Sobriencase $dirmode in 54130561Sobrien '') 55130561Sobrien if mkdir -p -- . 2>/dev/null; then 56130561Sobrien echo "mkdir -p -- $*" 57130561Sobrien exec mkdir -p -- "$@" 58130561Sobrien fi 59130561Sobrien ;; 60130561Sobrien *) 61130561Sobrien if mkdir -m "$dirmode" -p -- . 2>/dev/null; then 62130561Sobrien echo "mkdir -m $dirmode -p -- $*" 63130561Sobrien exec mkdir -m "$dirmode" -p -- "$@" 64130561Sobrien fi 65130561Sobrien ;; 66130561Sobrienesac 67130561Sobrien 68130561Sobrienfor file 69130561Sobriendo 70130561Sobrien set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 71130561Sobrien shift 72130561Sobrien 73130561Sobrien pathcomp= 74130561Sobrien for d 75130561Sobrien do 76130561Sobrien pathcomp="$pathcomp$d" 77130561Sobrien case $pathcomp in 78130561Sobrien -*) pathcomp=./$pathcomp ;; 79130561Sobrien esac 80130561Sobrien 81130561Sobrien if test ! -d "$pathcomp"; then 82130561Sobrien echo "mkdir $pathcomp" 83130561Sobrien 84130561Sobrien mkdir "$pathcomp" || lasterr=$? 85130561Sobrien 86130561Sobrien if test ! -d "$pathcomp"; then 87130561Sobrien errstatus=$lasterr 88130561Sobrien else 89130561Sobrien if test ! -z "$dirmode"; then 90130561Sobrien echo "chmod $dirmode $pathcomp" 91130561Sobrien lasterr="" 92130561Sobrien chmod "$dirmode" "$pathcomp" || lasterr=$? 93130561Sobrien 94130561Sobrien if test ! -z "$lasterr"; then 95130561Sobrien errstatus=$lasterr 96130561Sobrien fi 97130561Sobrien fi 98130561Sobrien fi 99130561Sobrien fi 100130561Sobrien 101130561Sobrien pathcomp="$pathcomp/" 102130561Sobrien done 10338889Sjdpdone 10438889Sjdp 10538889Sjdpexit $errstatus 10638889Sjdp 107130561Sobrien# Local Variables: 108130561Sobrien# mode: shell-script 109130561Sobrien# sh-indentation: 2 110130561Sobrien# End: 11138889Sjdp# mkinstalldirs ends here 112