Fix Zsh completion
[pkgusr] / usr / lib / pkgusr / install
1 #!/bin/bash
2 # Copyright (c) 2000,2004 Matthias S. Benkmann <article AT winterdrache DOT de>
3 # You may do everything with this code except misrepresent its origin.
4 # PROVIDED `AS IS' WITH ABSOLUTELY NO WARRANTY OF ANY KIND!
5
6 manpagesowner=man-pages
7 localedir=/usr/share/locale
8 cmdline="$@"
9
10 DAISY_CHAIN=""
11
12 for p in $(type -ap install) ; do
13     if [ ! $p -ef $0 ]; then
14         DAISY_CHAIN=$p
15         break
16     fi
17 done
18
19 if [ ! -n "$DAISY_CHAIN" ]; then
20     echo Cannot find real ${0##*/} command 
21     exit 1
22 fi
23
24 if [ $UID == 0 ]; then
25     exec $DAISY_CHAIN "$@"
26 fi
27
28 #kill unused -c parameter if we get it
29 if [ z"$1" = z"-c" ]; then shift 1 ; fi
30
31         #********** test if we create directories ********************
32 if [ \( z"$1" = z"-d" \) -o \( z"$1" = z"-m" -a z"$3" = z"-d" \) ]; then  
33     locdirs=""
34     notify=0
35     havedir=0
36     for((i=$#; $i>0; ))
37     do
38         a="$1"
39         shift 1; i=$(($i-1))
40         case "$a" in
41             -o|-g|--owner|--group)
42                  notify=1 
43                 shift 1; i=$(($i-1))
44                 set -- "$@" 
45                 ;;
46             $localedir/*)
47                 if [ ! -d "$a" ]; then
48                     locdirs="$locdirs ""$(expr $a : "$localedir/\(.*\)")" 
49                     set -- "$@" "$a"
50                     havedir=1
51                 else
52                     notify=1
53                     set -- "$@"
54                 fi  
55                 ;;
56             */*|/sbin)
57                 if [ ! -d "$a" ]; then 
58                     set -- "$@" "$a" 
59                     havedir=1
60                 else
61                     notify=1
62                     set -- "$@"
63                 fi             
64                 ;;
65             *) set -- "$@" "$a" ;;
66         esac
67     done
68   
69     test $notify -eq 1 -o z"$locdirs" != z && \
70         echo 1>&2 '***' install "$cmdline"
71
72     test $havedir -eq 0 && exit 0
73
74     $DAISY_CHAIN "$@" || exit $?
75   
76     test z"$locdirs" != z &&
77     for dir in $locdirs ; do
78         cumuldir=""
79         for d in $(echo $locdirs | sed 's#/# #g' -) ; do
80             cumuldir=$cumuldir$d/
81             if [ -d $localedir/$cumuldir ]; then
82                 chgrp install $localedir/$cumuldir
83                 chmod g+w,o+t $localedir/$cumuldir
84             fi  
85         done  
86     done
87
88 else  #if "$1" != "-d"  ,i.e. we do not create directories *****************
89     notify=0
90     for((i=$# ; $i>0; ))
91     do
92         a="$1"
93         shift 1; i=$(($i-1))
94         case "$a" in
95             -m)
96                 set -- "$@" "$a" 
97                 a="$1"
98                 shift 1; i=$(($i-1))
99                 case "$a" in
100                     4755) notify=1 ; set -- "$@" "755" ;;
101                     4775) notify=1 ; set -- "$@" "755" ;;
102                     4711) notify=1 ; set -- "$@" "711" ;;
103                     *) set -- "$@" "$a"  ;;
104                 esac
105                 ;;
106             -m4755) notify=1 ; set -- "$@" "-m755" ;;
107             -m4775) notify=1 ; set -- "$@" "-m755" ;;
108             -m4711) notify=1 ; set -- "$@" "-m711" ;;
109             -o|-g|--owner|--group)
110                 notify=1 
111                 shift 1; i=$(($i-1))
112                 set -- "$@" 
113                 ;;
114             */man/man?/*) 
115                 if [ -e "$a" -a ! -O "$a" ]; then
116                     if [ $(find "$a" -printf \%u) = $manpagesowner ]; then
117                         notify=1
118                         set -- "$@" not_installed
119                     else
120                         set -- "$@" "$a"
121                     fi  
122                 else
123                     set -- "$@" "$a"
124                 fi
125                 ;;    
126             *) set -- "$@" "$a" ;;
127         esac
128     done
129
130     test $notify -eq 1 && echo 1>&2 '***' install "$cmdline"
131
132     $DAISY_CHAIN "$@" || exit $?
133 fi
134
135 exit 0