Subversion Repositories svnkaklik

Rev

Rev 411 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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