blob: 73da476d3df976fb0d1dd316f2435f24ddfe6b47 (
plain)
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
# $NetBSD: shell,v 1.1 2006/05/21 23:50:15 jlam Exp $
#
# Generate a +SHELL script that handles shell registration for the package.
#
case "${STAGE},$1" in
UNPACK,|UNPACK,+SHELL)
${CAT} > ./+SHELL << 'EOF'
#!@SH@
#
# +SHELL - shell registration script
#
# Usage: ./+SHELL ADD|REMOVE [metadatadir]
# ./+SHELL CHECK-ADD|CHECK-REMOVE [metadatadir]
#
# This script supports two actions, ADD and REMOVE, that will add or
# remove shell paths from the shell database in /etc/shells. The
# CHECK-ADD action will check whether shell paths provided by the
# package are missing from the shell database, and print an informative
# message noting those shell paths. The CHECK-REMOVE action will check
# whether shell paths provided by the package are still present in the
# shell database, and print an informative message noting those shell
# paths. The CHECK-ADD and CHECK-REMOVE actions return non-zero if
# they detect either missing or existing paths, respectively.
#
# Lines starting with "# SHELL: " are data read by this script that
# name the shell paths that should be added or removed from the shell
# database. If the path is relative, then it is taken to be relative
# to ${PKG_PREFIX}.
#
# # SHELL: bin/pdksh
#
CAT="@CAT@"
CP="@CP@"
ECHO="@ECHO@"
GREP="@GREP@"
PWD_CMD="@PWD_CMD@"
RM="@RM@"
SED="@SED@"
SORT="@SORT@"
TEST="@TEST@"
TRUE="@TRUE@"
TOUCH="@TOUCH@"
SELF=$0
ACTION=$1
PKG_METADATA_DIR="${2-`${PWD_CMD}`}"
: ${PKG_PREFIX=@PREFIX@}
: ${PKGNAME=${PKG_METADATA_DIR##*/}}
case "${PKG_REGISTER_SHELLS:-@PKG_REGISTER_SHELLS@}" in
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
_PKG_REGISTER_SHELLS=yes
;;
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
_PKG_REGISTER_SHELLS=no
;;
esac
exitcode=0
case $ACTION in
ADD)
${SED} -n "/^\# SHELL: /{s/^\# SHELL: //;p;}" ${SELF} | ${SORT} -u |
{ while read shell; do
case ${_PKG_REGISTER_SHELLS} in
no) continue ;;
esac
case $shell in
/*) continue ;;
*) if [ ${PKG_PREFIX} = / ] ; then
shell="/$shell"
else
shell="${PKG_PREFIX}/$shell"
fi ;;
esac
${TEST} -f "$shell" || continue
shelldb="/etc/shells"
${TEST} -f "$shelldb" || continue
if ${TEST} -f "$shelldb" && \
${GREP} "^$shell" $shelldb >/dev/null; then
:
else
case "$printed_header" in
yes) ;;
*) printed_header=yes
${ECHO} "==========================================================================="
${ECHO} "Adding shells from ${PKGNAME} to $shelldb:"
${ECHO} ""
;;
esac
${ECHO} " $shell"
${TOUCH} $shelldb
${CP} $shelldb $shelldb.pkgsrc."$$"
{ ${CAT} $shelldb.pkgsrc."$$"; ${ECHO} "$shell"; } > $shelldb
${RM} $shelldb.pkgsrc."$$"
fi
done
case "$printed_header" in
yes) ${ECHO} ""
${ECHO} "==========================================================================="
;;
esac; }
;;
REMOVE)
${SED} -n "/^\# SHELL: /{s/^\# SHELL: //;p;}" ${SELF} | ${SORT} -u |
{ while read shell; do
case ${_PKG_REGISTER_SHELLS} in
no) continue ;;
esac
case $shell in
/*) continue ;;
*) if [ ${PKG_PREFIX} = / ] ; then
shell="/$shell"
else
shell="${PKG_PREFIX}/$shell"
fi ;;
esac
${TEST} -f "$shell" || continue
shelldb="/etc/shells"
if ${TEST} -f "$shelldb" && \
${GREP} "^$shell" $shelldb >/dev/null; then
case "$printed_header" in
yes) ;;
*) printed_header=yes
${ECHO} "==========================================================================="
${ECHO} "Removing shells from ${PKGNAME} to $shelldb:"
${ECHO} ""
;;
esac
${ECHO} " $shell"
${TOUCH} $shelldb
${CP} $shelldb $shelldb.pkgsrc."$$"
{ ${GREP} -v "^$shell" $shelldb.pkgsrc."$$" || ${TRUE}; } > $shelldb
${RM} $shelldb.pkgsrc."$$"
fi
done
case "$printed_header" in
yes) ${ECHO} ""
${ECHO} "==========================================================================="
;;
esac; }
;;
CHECK-ADD)
${SED} -n "/^\# SHELL: /{s/^\# SHELL: //;p;}" ${SELF} | ${SORT} -u |
{ while read shell; do
case $shell in
/*) continue ;;
*) if [ ${PKG_PREFIX} = / ] ; then
shell="/$shell"
else
shell="${PKG_PREFIX}/$shell"
fi ;;
esac
${TEST} -f "$shell" || continue
shelldb="/etc/shells"
if ${TEST} -f "$shelldb" && \
${GREP} "^$shell" $shelldb >/dev/null; then
:
else
case "$printed_header" in
yes) ;;
*) printed_header=yes
${ECHO} "==========================================================================="
${ECHO} "The following lines can be added to $shelldb:"
${ECHO} ""
;;
esac
${ECHO} " $shell"
fi
done
case "$printed_header" in
yes) ${ECHO} ""
${ECHO} "==========================================================================="
exit 1
;;
esac; }
${TEST} $? -eq 0 || exitcode=1
;;
CHECK-REMOVE)
${SED} -n "/^\# SHELL: /{s/^\# SHELL: //;p;}" ${SELF} | ${SORT} -u |
{ while read shell; do
case $shell in
/*) continue ;;
*) if [ ${PKG_PREFIX} = / ] ; then
shell="/$shell"
else
shell="${PKG_PREFIX}/$shell"
fi ;;
esac
${TEST} -f "$shell" || continue
shelldb="/etc/shells"
if ${TEST} -f "$shelldb" && \
${GREP} "^$shell" $shelldb >/dev/null; then
case "$printed_header" in
yes) ;;
*) printed_header=yes
${ECHO} "==========================================================================="
${ECHO} "The following lines can be removed from $shelldb:"
${ECHO} ""
;;
esac
${ECHO} " $shell"
fi
done
case "$printed_header" in
yes) ${ECHO} ""
${ECHO} "==========================================================================="
exit 1
;;
esac; }
${TEST} $? -eq 0 || exitcode=1
;;
*)
${ECHO} "Usage: ./+SHELL ADD|REMOVE [metadatadir]"
${ECHO} " ./+SHELL CHECK-ADD|CHECK-REMOVE [metadatadir]"
;;
esac
exit $exitcode
EOF
${SED} -n "/^\# SHELL: /p" ${SELF} >> ./+SHELL
${CHMOD} +x ./+SHELL
;;
esac
|