Fix a bug that was exposed by the SXEmacs configure script.
[pkgusr] / usr / lib / pkgusr / mkdir
1 #!/bin/bash
2 # Original...
3 # Copyright (c) 2000 Matthias S. Benkmann <article AT winterdrache DOT de>
4 # You may do everything with this code except misrepresent its origin.
5 # PROVIDED `AS IS' WITH ABSOLUTELY NO WARRANTY OF ANY KIND!
6
7 # Copyright (C) 2014 Steve Youngs <steve@steveyoungs.com>
8 #  Optionally nuke locale directories.
9
10 watchdir=/usr/share/locale
11
12 DAISY_CHAIN=""
13
14 for p in $(type -ap mkdir) ; do
15     if [ ! $p -ef $0 ]; then
16         DAISY_CHAIN=$p
17         break
18     fi
19 done
20
21 if [ ! -n "$DAISY_CHAIN" ]; then
22     echo 1>&2 '***' Cannot find real ${0##*/} command 
23     exit 1
24 fi
25
26 if [ $(id -u) == 0 ]; then
27     echo 1>&2 '***' $(dirname $0) should not be in root\'s \$PATH
28     echo 1>&2 '***' Call '"'$DAISY_CHAIN $@'"' directly.
29     exit 1
30 fi
31
32 cmdline="$@"
33
34 dirs=""
35 for((i=$#; $i>0;))
36   do
37   a="$1"
38   shift 1; i=$(($i-1))
39   case "$a" in
40       ($watchdir/*)
41       dirs="$dirs ""$(expr $a : "$watchdir/\(.*\)")" 
42       set -- "$@" "$a" 
43       ;;
44       (*) set -- "$@" "$a" ;;
45   esac
46 done
47
48 exec $DAISY_CHAIN "$@" || exit $?
49
50 test z"$dirs" != z &&
51 echo 1>&2 '***' mkdir "$cmdline"
52 for dir in $dirs ; do
53     cumuldir=""
54     for d in $(echo $dirs | sed 's#/# #g' -) ; do
55         cumuldir=$cumuldir$d/
56         if [ $SUPPRESSLOCALEDIR -eq 0 ]; then
57             echo 1>&2 '***' Possible root intervention required 
58             echo 1>&2 '***' install -vdm1775 -oroot -ginstall $watchdir/$cumuldir
59         else
60             echo 1>&2 '***' Locale directory creation suppressed
61             echo 1>&2 '***' $watchdir/$cumuldir
62             rm -rf $watchdir/$cumuldir
63         fi
64     done  
65 done
66
67 exit 0
68
69 # Local variables:
70 # sh-basic-offset: 4
71 # End: