Search
lxdream.org :: lxdream/mkinstalldirs
lxdream 0.9.1
released Jun 29
Download Now
filename mkinstalldirs
changeset 491:515c81624943
author nkeynes
date Wed Jul 30 03:00:40 2008 +0000 (11 years ago)
permissions -rwxr-xr-x
last change Add debian changelog file
file annotate diff log raw
nkeynes@491
     1
#! /bin/sh
nkeynes@491
     2
# mkinstalldirs --- make directory hierarchy
nkeynes@491
     3
# Author: Noah Friedman <friedman@prep.ai.mit.edu>
nkeynes@491
     4
# Created: 1993-05-16
nkeynes@491
     5
# Public domain
nkeynes@491
     6
nkeynes@491
     7
errstatus=0
nkeynes@491
     8
dirmode=""
nkeynes@491
     9
nkeynes@491
    10
usage="\
nkeynes@491
    11
Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
nkeynes@491
    12
nkeynes@491
    13
# process command line arguments
nkeynes@491
    14
while test $# -gt 0 ; do
nkeynes@491
    15
  case $1 in
nkeynes@491
    16
    -h | --help | --h*)         # -h for help
nkeynes@491
    17
      echo "$usage" 1>&2
nkeynes@491
    18
      exit 0
nkeynes@491
    19
      ;;
nkeynes@491
    20
    -m)                         # -m PERM arg
nkeynes@491
    21
      shift
nkeynes@491
    22
      test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
nkeynes@491
    23
      dirmode=$1
nkeynes@491
    24
      shift
nkeynes@491
    25
      ;;
nkeynes@491
    26
    --)                         # stop option processing
nkeynes@491
    27
      shift
nkeynes@491
    28
      break
nkeynes@491
    29
      ;;
nkeynes@491
    30
    -*)                         # unknown option
nkeynes@491
    31
      echo "$usage" 1>&2
nkeynes@491
    32
      exit 1
nkeynes@491
    33
      ;;
nkeynes@491
    34
    *)                          # first non-opt arg
nkeynes@491
    35
      break
nkeynes@491
    36
      ;;
nkeynes@491
    37
  esac
nkeynes@491
    38
done
nkeynes@491
    39
nkeynes@491
    40
for file
nkeynes@491
    41
do
nkeynes@491
    42
  if test -d "$file"; then
nkeynes@491
    43
    shift
nkeynes@491
    44
  else
nkeynes@491
    45
    break
nkeynes@491
    46
  fi
nkeynes@491
    47
done
nkeynes@491
    48
nkeynes@491
    49
case $# in
nkeynes@491
    50
  0) exit 0 ;;
nkeynes@491
    51
esac
nkeynes@491
    52
nkeynes@491
    53
case $dirmode in
nkeynes@491
    54
  '')
nkeynes@491
    55
    if mkdir -p -- . 2>/dev/null; then
nkeynes@491
    56
      echo "mkdir -p -- $*"
nkeynes@491
    57
      exec mkdir -p -- "$@"
nkeynes@491
    58
    fi
nkeynes@491
    59
    ;;
nkeynes@491
    60
  *)
nkeynes@491
    61
    if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
nkeynes@491
    62
      echo "mkdir -m $dirmode -p -- $*"
nkeynes@491
    63
      exec mkdir -m "$dirmode" -p -- "$@"
nkeynes@491
    64
    fi
nkeynes@491
    65
    ;;
nkeynes@491
    66
esac
nkeynes@491
    67
nkeynes@491
    68
for file
nkeynes@491
    69
do
nkeynes@491
    70
  set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
nkeynes@491
    71
  shift
nkeynes@491
    72
nkeynes@491
    73
  pathcomp=
nkeynes@491
    74
  for d
nkeynes@491
    75
  do
nkeynes@491
    76
    pathcomp="$pathcomp$d"
nkeynes@491
    77
    case $pathcomp in
nkeynes@491
    78
      -*) pathcomp=./$pathcomp ;;
nkeynes@491
    79
    esac
nkeynes@491
    80
nkeynes@491
    81
    if test ! -d "$pathcomp"; then
nkeynes@491
    82
      echo "mkdir $pathcomp"
nkeynes@491
    83
nkeynes@491
    84
      mkdir "$pathcomp" || lasterr=$?
nkeynes@491
    85
nkeynes@491
    86
      if test ! -d "$pathcomp"; then
nkeynes@491
    87
  	errstatus=$lasterr
nkeynes@491
    88
      else
nkeynes@491
    89
  	if test ! -z "$dirmode"; then
nkeynes@491
    90
	  echo "chmod $dirmode $pathcomp"
nkeynes@491
    91
    	  lasterr=""
nkeynes@491
    92
  	  chmod "$dirmode" "$pathcomp" || lasterr=$?
nkeynes@491
    93
nkeynes@491
    94
  	  if test ! -z "$lasterr"; then
nkeynes@491
    95
  	    errstatus=$lasterr
nkeynes@491
    96
  	  fi
nkeynes@491
    97
  	fi
nkeynes@491
    98
      fi
nkeynes@491
    99
    fi
nkeynes@491
   100
nkeynes@491
   101
    pathcomp="$pathcomp/"
nkeynes@491
   102
  done
nkeynes@491
   103
done
nkeynes@491
   104
nkeynes@491
   105
exit $errstatus
nkeynes@491
   106
nkeynes@491
   107
# Local Variables:
nkeynes@491
   108
# mode: shell-script
nkeynes@491
   109
# sh-indentation: 2
nkeynes@491
   110
# End:
nkeynes@491
   111
# mkinstalldirs ends here
.