mkinstalldirs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #! /bin/sh
  2. # mkinstalldirs --- make directory hierarchy
  3. scriptversion=2020-07-26.22; # UTC
  4. # Original author: Noah Friedman <friedman@prep.ai.mit.edu>
  5. # Created: 1993-05-16
  6. # Public domain.
  7. #
  8. # This file is maintained in Automake, please report
  9. # bugs to <bug-automake@gnu.org> or send patches to
  10. # <automake-patches@gnu.org>.
  11. nl='
  12. '
  13. IFS=" "" $nl"
  14. errstatus=0
  15. dirmode=
  16. usage="\
  17. Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
  18. Create each directory DIR (with mode MODE, if specified), including all
  19. leading file name components.
  20. Report bugs to <bug-automake@gnu.org>."
  21. # process command line arguments
  22. while test $# -gt 0 ; do
  23. case $1 in
  24. -h | --help | --h*) # -h for help
  25. echo "$usage"
  26. exit $?
  27. ;;
  28. -m) # -m PERM arg
  29. shift
  30. test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
  31. dirmode=$1
  32. shift
  33. ;;
  34. --version)
  35. echo "$0 $scriptversion"
  36. exit $?
  37. ;;
  38. --) # stop option processing
  39. shift
  40. break
  41. ;;
  42. -*) # unknown option
  43. echo "$usage" 1>&2
  44. exit 1
  45. ;;
  46. *) # first non-opt arg
  47. break
  48. ;;
  49. esac
  50. done
  51. for file
  52. do
  53. if test -d "$file"; then
  54. shift
  55. else
  56. break
  57. fi
  58. done
  59. case $# in
  60. 0) exit 0 ;;
  61. esac
  62. # Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and
  63. # mkdir -p a/c at the same time, both will detect that a is missing,
  64. # one will create a, then the other will try to create a and die with
  65. # a "File exists" error. This is a problem when calling mkinstalldirs
  66. # from a parallel make. We use --version in the probe to restrict
  67. # ourselves to GNU mkdir, which is thread-safe.
  68. case $dirmode in
  69. '')
  70. if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
  71. echo "mkdir -p -- $*"
  72. exec mkdir -p -- "$@"
  73. else
  74. # On NextStep and OpenStep, the 'mkdir' command does not
  75. # recognize any option. It will interpret all options as
  76. # directories to create, and then abort because '.' already
  77. # exists.
  78. test -d ./-p && rmdir ./-p
  79. test -d ./--version && rmdir ./--version
  80. fi
  81. ;;
  82. *)
  83. if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
  84. test ! -d ./--version; then
  85. echo "umask 22"
  86. umask 22
  87. echo "mkdir -m $dirmode -p -- $*"
  88. exec mkdir -m "$dirmode" -p -- "$@"
  89. else
  90. # Clean up after NextStep and OpenStep mkdir.
  91. for d in ./-m ./-p ./--version "./$dirmode";
  92. do
  93. test -d $d && rmdir $d
  94. done
  95. fi
  96. ;;
  97. esac
  98. echo "umask 22"
  99. umask 22
  100. for file
  101. do
  102. case $file in
  103. /*) pathcomp=/ ;;
  104. *) pathcomp= ;;
  105. esac
  106. oIFS=$IFS
  107. IFS=/
  108. set fnord $file
  109. shift
  110. IFS=$oIFS
  111. for d
  112. do
  113. test "x$d" = x && continue
  114. pathcomp=$pathcomp$d
  115. case $pathcomp in
  116. -*) pathcomp=./$pathcomp ;;
  117. esac
  118. if test ! -d "$pathcomp"; then
  119. echo "mkdir $pathcomp"
  120. mkdir "$pathcomp" || lasterr=$?
  121. if test ! -d "$pathcomp"; then
  122. errstatus=$lasterr
  123. fi
  124. fi
  125. pathcomp=$pathcomp/
  126. done
  127. if test ! -z "$dirmode"; then
  128. echo "chmod $dirmode $file"
  129. chmod "$dirmode" "$file" || errstatus=$?
  130. fi
  131. done
  132. exit $errstatus
  133. # Local Variables:
  134. # mode: shell-script
  135. # sh-indentation: 2
  136. # eval: (add-hook 'before-save-hook 'time-stamp)
  137. # time-stamp-start: "scriptversion="
  138. # time-stamp-format: "%:y-%02m-%02d.%02H"
  139. # time-stamp-time-zone: "UTC0"
  140. # time-stamp-end: "; # UTC"
  141. # End: