| 1 | #!/bin/sh |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | trace=: |
|---|
| 20 | trace=echo |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | LANG=C; export LANG |
|---|
| 25 | LANGUAGE=C; export LANGUAGE |
|---|
| 26 | LC_ALL=C; export LC_ALL |
|---|
| 27 | LC_CTYPE=C; export LC_CTYPE |
|---|
| 28 | |
|---|
| 29 | OPTS_SUID= |
|---|
| 30 | OPTS_SGID= |
|---|
| 31 | OPTS_MODE= |
|---|
| 32 | OPTS_USR= |
|---|
| 33 | OPTS_GRP= |
|---|
| 34 | |
|---|
| 35 | while test $ |
|---|
| 36 | do |
|---|
| 37 | case $1 in |
|---|
| 38 | -*) |
|---|
| 39 | OPT="$1" |
|---|
| 40 | shift |
|---|
| 41 | if test $ |
|---|
| 42 | then |
|---|
| 43 | case $OPT in |
|---|
| 44 | -u) OPTS_USR="$1"; shift;; |
|---|
| 45 | -g) OPTS_GRP="$1"; shift;; |
|---|
| 46 | -m) OPTS_MODE="$1"; shift;; |
|---|
| 47 | esac |
|---|
| 48 | else |
|---|
| 49 | break |
|---|
| 50 | fi |
|---|
| 51 | ;; |
|---|
| 52 | u+s) shift; OPTS_SUID=4000;; |
|---|
| 53 | g+s) shift; OPTS_SGID=2000;; |
|---|
| 54 | *) break |
|---|
| 55 | ;; |
|---|
| 56 | esac |
|---|
| 57 | done |
|---|
| 58 | |
|---|
| 59 | SINSTALL="$1" |
|---|
| 60 | SRC_PROG="$2" |
|---|
| 61 | REF_PROG="$3" |
|---|
| 62 | DST_PROG="$4" |
|---|
| 63 | |
|---|
| 64 | test -z "$SINSTALL" && SINSTALL=install |
|---|
| 65 | test -z "$SRC_PROG" && SRC_PROG=xterm |
|---|
| 66 | test -z "$REF_PROG" && REF_PROG=/usr/bin/X11/xterm |
|---|
| 67 | test -z "$DST_PROG" && DST_PROG="$REF_PROG" |
|---|
| 68 | |
|---|
| 69 | test -n "$OPTS_SUID" && test -n "$OPTS_USR" && REF_PROG= |
|---|
| 70 | test -n "$OPTS_SGID" && test -n "$OPTS_GRP" && REF_PROG= |
|---|
| 71 | |
|---|
| 72 | echo checking for presumed installation-mode |
|---|
| 73 | |
|---|
| 74 | PROG_SUID= |
|---|
| 75 | PROG_SGID= |
|---|
| 76 | PROG_MODE= |
|---|
| 77 | PROG_USR= |
|---|
| 78 | PROG_GRP= |
|---|
| 79 | |
|---|
| 80 | if test -z "$REF_PROG" ; then |
|---|
| 81 | $trace "... reference program not used" |
|---|
| 82 | elif test -f "$REF_PROG" ; then |
|---|
| 83 | cf_option="-l -L" |
|---|
| 84 | MYTEMP=${TMPDIR-/tmp}/sinstall$$ |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | ls $cf_option $REF_PROG |
|---|
| 89 | ls $cf_option $REF_PROG >$MYTEMP |
|---|
| 90 | read cf_mode cf_links cf_usr cf_grp cf_size cf_date1 cf_date2 cf_date3 cf_rest <$MYTEMP |
|---|
| 91 | $trace "... if \"$cf_rest\" is null, try the ls -g option" |
|---|
| 92 | if test -z "$cf_rest" ; then |
|---|
| 93 | cf_option="$cf_option -g" |
|---|
| 94 | ls $cf_option $REF_PROG |
|---|
| 95 | ls $cf_option $REF_PROG >$MYTEMP |
|---|
| 96 | read cf_mode cf_links cf_usr cf_grp cf_size cf_date1 cf_date2 cf_date3 cf_rest <$MYTEMP |
|---|
| 97 | fi |
|---|
| 98 | rm -f $MYTEMP |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | $trace "... if \"$cf_rest\" is null, we do not look for group" |
|---|
| 103 | if test -n "$cf_rest" ; then |
|---|
| 104 | cf_test=`echo "${cf_date2}${cf_date3}" | sed -e 's/[0-9:]//g'` |
|---|
| 105 | $trace "... if we have date in proper columns ($cf_date1 $cf_date2 $cf_date3), \"$cf_test\" is null" |
|---|
| 106 | if test -z "$cf_test" ; then |
|---|
| 107 | PROG_USR=$cf_usr; |
|---|
| 108 | PROG_GRP=$cf_grp; |
|---|
| 109 | fi |
|---|
| 110 | fi |
|---|
| 111 | $trace "... derived user \"$PROG_USR\", group \"$PROG_GRP\" of previously-installed $SRC_PROG" |
|---|
| 112 | |
|---|
| 113 | $trace "... see if mode \"$cf_mode\" has s-bit set" |
|---|
| 114 | case ".$cf_mode" in |
|---|
| 115 | .???s??s*) |
|---|
| 116 | $trace "... both setuid/setgid" |
|---|
| 117 | PROG_SUID=4000 |
|---|
| 118 | PROG_SGID=2000 |
|---|
| 119 | ;; |
|---|
| 120 | .???s*) |
|---|
| 121 | $trace "... setuid" |
|---|
| 122 | PROG_SUID=4000 |
|---|
| 123 | PROG_GRP= |
|---|
| 124 | ;; |
|---|
| 125 | .??????s*) |
|---|
| 126 | $trace "... setgid" |
|---|
| 127 | PROG_SGID=2000 |
|---|
| 128 | PROG_USR= |
|---|
| 129 | ;; |
|---|
| 130 | esac |
|---|
| 131 | PROG_MODE=`echo ".$cf_mode" | sed -e 's/^..//' -e 's/rw./7/g' -e 's/r-./5/g' -e 's/---/0/g' -e 's/--[sxt]/1/g' -e 's/+//g'` |
|---|
| 132 | fi |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | test -n "$OPTS_SUID" && PROG_SUID="$OPTS_SUID" |
|---|
| 136 | test -n "$OPTS_SGID" && PROG_SGID="$OPTS_SGID" |
|---|
| 137 | test -n "$OPTS_MODE" && PROG_MODE="$OPTS_MODE" |
|---|
| 138 | test -n "$OPTS_USR" && PROG_USR="$OPTS_USR" |
|---|
| 139 | test -n "$OPTS_GRP" && PROG_GRP="$OPTS_GRP" |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | test -z "$PROG_MODE" && PROG_MODE=755 |
|---|
| 143 | |
|---|
| 144 | if test -n "${PROG_USR}${PROG_GRP}" ; then |
|---|
| 145 | cf_uid=`id | sed -e 's/^[^=]*=//' -e 's/(.*$//'` |
|---|
| 146 | cf_usr=`id | sed -e 's/^[^(]*(//' -e 's/).*$//'` |
|---|
| 147 | cf_grp=`id | sed -e 's/^.* gid=[^(]*(//' -e 's/).*$//'` |
|---|
| 148 | $trace "... installing $SRC_PROG as user \"$cf_usr\", group \"$cf_grp\"" |
|---|
| 149 | if test "$cf_uid" != 0 ; then |
|---|
| 150 | PROG_SUID= |
|---|
| 151 | PROG_SGID= |
|---|
| 152 | PROG_USR="" |
|---|
| 153 | PROG_GRP="" |
|---|
| 154 | fi |
|---|
| 155 | test "$PROG_USR" = "$cf_usr" && PROG_USR="" |
|---|
| 156 | test "$PROG_GRP" = "$cf_grp" && PROG_GRP="" |
|---|
| 157 | fi |
|---|
| 158 | |
|---|
| 159 | test -n "${PROG_SUID}${PROG_SGID}" && PROG_MODE=`expr $PROG_MODE % 1000` |
|---|
| 160 | test -n "$PROG_SUID" && PROG_MODE=`expr $PROG_SUID + $PROG_MODE` |
|---|
| 161 | test -n "$PROG_SGID" && PROG_MODE=`expr $PROG_SGID + $PROG_MODE` |
|---|
| 162 | |
|---|
| 163 | test -n "$PROG_USR" && PROG_USR="-o $PROG_USR" |
|---|
| 164 | test -n "$PROG_GRP" && PROG_GRP="-g $PROG_GRP" |
|---|
| 165 | |
|---|
| 166 | echo "$SINSTALL -m $PROG_MODE $PROG_USR $PROG_GRP $SRC_PROG $DST_PROG" |
|---|
| 167 | eval "$SINSTALL -m $PROG_MODE $PROG_USR $PROG_GRP $SRC_PROG $DST_PROG" |
|---|