File: dpkg-www-installer

package info (click to toggle)
dpkg-www 2.59
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 192 kB
  • sloc: sh: 1,596; makefile: 16
file content (174 lines) | stat: -rwxr-xr-x 4,412 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/sh
#
# Dpkg-www install helper used for dpkg-www cgi installation.
#
# Copyright © 1999-2003 Massimo Dal Zotto <dz@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

usage() {
    echo "${0##*/} [-x|--xterm] [-f|--file] <file>"
}

press_enter() {
    echo ""
    echo -n "Press Enter to close this window..."; read x
}

# Restart self in an xterm window. Must be the first option. Used by netscape.
if [ "$1" = "-x" -o "$1" = "--xterm" ]; then
    shift 1
    xterm -T "Package Installation" -e $0 "$@"
    exit 0
fi
# Restart self in an xterm window. Used by firefox which cannot pass -x switch.
if [ "$DPKG_WWW_INSTALLER_XTERM" != true ] && ! tty -s; then
    DPKG_WWW_INSTALLER_XTERM=true xterm -T "Package Installation" -e $0 "$@"
    exit 0
fi

# Source optional config file
test -e /etc/dpkg-www.conf && . /etc/dpkg-www.conf 2>/dev/null

FILE=""
ACTION=""
HOST=""
PACKAGES=""

while [ "${1#-}" != "$1" ]; do
    case "$1" in
	-\?|-help|--help)
	    usage
	    exit
	    ;;
	-f|--file)
	    FILE="$2"
	    shift 2
	    ;;
	-*)
	    echo "Invalid option: $1" >&2
	    press_enter
	    exit 1
	    ;;
    esac
done
FILE="${FILE:-$1}"

if [ "$FILE" != "" -a ! -e "$FILE" ]; then
    echo "File not found: $FILE" >&2
    press_enter
    exit 1
fi

request="$(cat "$FILE" | head -10)"; rm -f "$FILE"
if echo "$request" | grep -q "^Install-packages:"; then
    ACTION=install
    HOST=$(
	echo "$request" | grep ^Install-host: \
	| head -1 | sed 's/.*: *//; s/,/ /g'
    )
    PACKAGES=$(
	echo "$request" | grep ^Install-packages: \
	| head -1 | sed 's/.*: *//; s/,/ /g'
    )
else
    ACTION=remove
    HOST=$(
	echo "$request" | grep ^Remove-host: \
	| head -1 | sed 's/.*: *//; s/,/ /g'
    )
    PACKAGES=$(
	echo "$request" | grep ^Remove-packages: \
	| head -1 | sed 's/.*: *//; s/,/ /g'
    )
fi

if [ ! "$HOST" ]; then
    echo "Missing hostname" >&2
    press_enter
    exit 1
fi

if [ "$(echo "$HOST" | sed 's/[ a-zA-Z0-9_.+-]//g')" ]; then
    echo "Invalid characters in hostname: $HOST" >&2
    press_enter
    exit 1
fi

if [ ! "$PACKAGES" ]; then
    echo "Missing package names" >&2
    press_enter
    exit 1
fi

# From Debian Packaging Manual, 4.2.1:
#
# The name of the binary package. Package names consist of the alphanumerics
# and + - . (plus, minus and full stop). In current versions of dpkg they are
# sort of case-sensitive.
#
if [ "$(echo "$PACKAGES" | sed 's/[ a-zA-Z0-9.+-]//g')" ]; then
    echo "Invalid characters in package names: $PACKAGES" >&2
    press_enter
    exit 1
fi

if [ $(echo "$PACKAGES" | wc -w) -gt 1 ]; then
    if [ "$ACTION" = install ]; then
	echo "Installing the following packages on $HOST:"
    else
	echo "Removing the following packages on $HOST:"
    fi
    echo ""
    echo "$PACKAGES" \
       | if [ -x /usr/bin/fold ]; then fold -s -w 76; else cat; fi \
       | sed 's/^/  /'
    echo ""
else
    if [ "$ACTION" = install ]; then
	echo "Installing package $PACKAGES on $HOST."
    else
	echo "Removing package $PACKAGES from $HOST."
    fi
    echo ""
fi

case "$HOST" in
    localhost|$(hostname)|$(hostname -f))
	if [ "$(id -u)" = "0" ]; then
		echo "You should NOT run this script as root!"
		echo ""
		echo -n "Press Enter to continue..."; read x
		echo ""
		apt-get -s $REINSTALL $ACTION $PACKAGES; echo
		apt-get    $REINSTALL $ACTION $PACKAGES
	else
	    echo -n "Root "; su root -c "\
		apt-get -s $REINSTALL $ACTION $PACKAGES; echo
		apt-get    $REINSTALL $ACTION $PACKAGES"
	fi
	;;
    *)
	# Ignore any active ssh-agent to force ssh passwd prompt
	test "$FORCE_SSH_PASSWD" = true && unset SSH_AGENT_PID SSH_AUTH_SOCK
	/usr/bin/ssh -l root "$HOST" PATH=/usr/sbin:/sbin:/usr/bin:/bin \
		apt-get -s $REINSTALL $ACTION $PACKAGES \; echo \; \
		apt-get    $REINSTALL $ACTION $PACKAGES
        ;;
esac

press_enter
exit 0

# end of file