1 | #!/bin/sh |
---|
2 | # |
---|
3 | # Fake Root Solaris/SVR4/SVR5 Build System - Prototype |
---|
4 | # |
---|
5 | # The following code has been provide under Public Domain License. I really |
---|
6 | # don't care what you use it for. Just as long as you don't complain to me |
---|
7 | # nor my employer if you break it. - Ben Lindstrom (mouring@eviladmin.org) |
---|
8 | # |
---|
9 | umask 022 |
---|
10 | # |
---|
11 | # Options for building the package |
---|
12 | # You can create a openssh-config.local with your customized options |
---|
13 | # |
---|
14 | REMOVE_FAKE_ROOT_WHEN_DONE=yes |
---|
15 | # |
---|
16 | # uncommenting TEST_DIR and using |
---|
17 | # configure --prefix=/var/tmp --with-privsep-path=/var/tmp/empty |
---|
18 | # and |
---|
19 | # PKGNAME=tOpenSSH should allow testing a package without interfering |
---|
20 | # with a real OpenSSH package on a system. This is not needed on systems |
---|
21 | # that support the -R option to pkgadd. |
---|
22 | #TEST_DIR=/var/tmp # leave commented out for production build |
---|
23 | PKGNAME=OpenSSH |
---|
24 | # revisions within the same version (REV=a) |
---|
25 | #REV= |
---|
26 | SYSVINIT_NAME=opensshd |
---|
27 | MAKE=${MAKE:="make"} |
---|
28 | SSHDUID=67 # Default privsep uid |
---|
29 | SSHDGID=67 # Default privsep gid |
---|
30 | # uncomment these next three as needed |
---|
31 | #PERMIT_ROOT_LOGIN=no |
---|
32 | #X11_FORWARDING=yes |
---|
33 | #USR_LOCAL_IS_SYMLINK=yes |
---|
34 | # System V init run levels |
---|
35 | SYSVINITSTART=S98 |
---|
36 | SYSVINITSTOPT=K30 |
---|
37 | # We will source these if they exist |
---|
38 | POST_MAKE_INSTALL_FIXES=./pkg_post_make_install_fixes.sh |
---|
39 | POST_PROTOTYPE_EDITS=./pkg-post-prototype-edit.sh |
---|
40 | # We'll be one level deeper looking for these |
---|
41 | PKG_PREINSTALL_LOCAL=../pkg-preinstall.local |
---|
42 | PKG_POSTINSTALL_LOCAL=../pkg-postinstall.local |
---|
43 | PKG_PREREMOVE_LOCAL=../pkg-preremove.local |
---|
44 | PKG_POSTREMOVE_LOCAL=../pkg-postremove.local |
---|
45 | PKG_REQUEST_LOCAL=../pkg-request.local |
---|
46 | # end of sourced files |
---|
47 | # |
---|
48 | OPENSSHD=opensshd.init |
---|
49 | |
---|
50 | PATH_GROUPADD_PROG=@PATH_GROUPADD_PROG@ |
---|
51 | PATH_USERADD_PROG=@PATH_USERADD_PROG@ |
---|
52 | PATH_PASSWD_PROG=@PATH_PASSWD_PROG@ |
---|
53 | # |
---|
54 | # list of system directories we do NOT want to change owner/group/perms |
---|
55 | # when installing our package |
---|
56 | SYSTEM_DIR="/etc \ |
---|
57 | /etc/init.d \ |
---|
58 | /etc/rcS.d \ |
---|
59 | /etc/rc0.d \ |
---|
60 | /etc/rc1.d \ |
---|
61 | /etc/rc2.d \ |
---|
62 | /etc/opt \ |
---|
63 | /opt \ |
---|
64 | /opt/bin \ |
---|
65 | /usr \ |
---|
66 | /usr/bin \ |
---|
67 | /usr/lib \ |
---|
68 | /usr/sbin \ |
---|
69 | /usr/share \ |
---|
70 | /usr/share/man \ |
---|
71 | /usr/share/man/man1 \ |
---|
72 | /usr/share/man/man8 \ |
---|
73 | /usr/local \ |
---|
74 | /usr/local/bin \ |
---|
75 | /usr/local/etc \ |
---|
76 | /usr/local/libexec \ |
---|
77 | /usr/local/man \ |
---|
78 | /usr/local/man/man1 \ |
---|
79 | /usr/local/man/man8 \ |
---|
80 | /usr/local/sbin \ |
---|
81 | /usr/local/share \ |
---|
82 | /var \ |
---|
83 | /var/opt \ |
---|
84 | /var/run \ |
---|
85 | /var/tmp \ |
---|
86 | /tmp" |
---|
87 | |
---|
88 | # We may need to build as root so we make sure PATH is set up |
---|
89 | # only set the path if it's not set already |
---|
90 | [ -d /opt/bin ] && { |
---|
91 | echo $PATH | grep ":/opt/bin" > /dev/null 2>&1 |
---|
92 | [ $? -ne 0 ] && PATH=$PATH:/opt/bin |
---|
93 | } |
---|
94 | [ -d /usr/local/bin ] && { |
---|
95 | echo $PATH | grep ":/usr/local/bin" > /dev/null 2>&1 |
---|
96 | [ $? -ne 0 ] && PATH=$PATH:/usr/local/bin |
---|
97 | } |
---|
98 | [ -d /usr/ccs/bin ] && { |
---|
99 | echo $PATH | grep ":/usr/ccs/bin" > /dev/null 2>&1 |
---|
100 | [ $? -ne 0 ] && PATH=$PATH:/usr/ccs/bin |
---|
101 | } |
---|
102 | export PATH |
---|
103 | # |
---|
104 | |
---|
105 | [ -f Makefile ] || { |
---|
106 | echo "Please run this script from your build directory" |
---|
107 | exit 1 |
---|
108 | } |
---|
109 | |
---|
110 | # we will look for openssh-config.local to override the above options |
---|
111 | [ -s ./openssh-config.local ] && . ./openssh-config.local |
---|
112 | |
---|
113 | START=`pwd` |
---|
114 | FAKE_ROOT=$START/pkg |
---|
115 | |
---|
116 | ## Fill in some details, like prefix and sysconfdir |
---|
117 | for confvar in prefix exec_prefix bindir sbindir libexecdir datadir mandir sysconfdir piddir srcdir |
---|
118 | do |
---|
119 | eval $confvar=`grep "^$confvar=" Makefile | cut -d = -f 2` |
---|
120 | done |
---|
121 | |
---|
122 | |
---|
123 | ## Collect value of privsep user |
---|
124 | for confvar in SSH_PRIVSEP_USER |
---|
125 | do |
---|
126 | eval $confvar=`awk '/#define[ \t]'$confvar'/{print $3}' config.h` |
---|
127 | done |
---|
128 | |
---|
129 | ## Set privsep defaults if not defined |
---|
130 | if [ -z "$SSH_PRIVSEP_USER" ] |
---|
131 | then |
---|
132 | SSH_PRIVSEP_USER=sshd |
---|
133 | fi |
---|
134 | |
---|
135 | ## Extract common info requires for the 'info' part of the package. |
---|
136 | VERSION=`./ssh -V 2>&1 | sed -e 's/,.*//'` |
---|
137 | |
---|
138 | ARCH=`uname -m` |
---|
139 | DEF_MSG="\n" |
---|
140 | OS_VER=`uname -v` |
---|
141 | SCRIPT_SHELL=/sbin/sh |
---|
142 | UNAME_S=`uname -s` |
---|
143 | case ${UNAME_S} in |
---|
144 | SunOS) UNAME_S=Solaris |
---|
145 | ARCH=`uname -p` |
---|
146 | RCS_D=yes |
---|
147 | DEF_MSG="(default: n)" |
---|
148 | ;; |
---|
149 | SCO_SV) UNAME_S=OpenServer |
---|
150 | OS_VER=`uname -X | grep Release | sed -e 's/^Rel.*3.2v//'` |
---|
151 | SCRIPT_SHELL=/bin/sh |
---|
152 | RC1_D=no |
---|
153 | DEF_MSG="(default: n)" |
---|
154 | ;; |
---|
155 | esac |
---|
156 | |
---|
157 | case `basename $0` in |
---|
158 | buildpkg.sh) |
---|
159 | ## Start by faking root install |
---|
160 | echo "Faking root install..." |
---|
161 | [ -d $FAKE_ROOT ] && rm -fr $FAKE_ROOT |
---|
162 | mkdir $FAKE_ROOT |
---|
163 | ${MAKE} install-nokeys DESTDIR=$FAKE_ROOT |
---|
164 | if [ $? -gt 0 ] |
---|
165 | then |
---|
166 | echo "Fake root install failed, stopping." |
---|
167 | exit 1 |
---|
168 | fi |
---|
169 | |
---|
170 | ## Setup our run level stuff while we are at it. |
---|
171 | mkdir -p $FAKE_ROOT${TEST_DIR}/etc/init.d |
---|
172 | |
---|
173 | cp ${OPENSSHD} $FAKE_ROOT${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} |
---|
174 | chmod 744 $FAKE_ROOT${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} |
---|
175 | |
---|
176 | [ "${PERMIT_ROOT_LOGIN}" = no ] && \ |
---|
177 | perl -p -i -e "s/#PermitRootLogin yes/PermitRootLogin no/" \ |
---|
178 | $FAKE_ROOT/${sysconfdir}/sshd_config |
---|
179 | [ "${X11_FORWARDING}" = yes ] && \ |
---|
180 | perl -p -i -e "s/#X11Forwarding no/X11Forwarding yes/" \ |
---|
181 | $FAKE_ROOT/${sysconfdir}/sshd_config |
---|
182 | # fix PrintMotd |
---|
183 | perl -p -i -e "s/#PrintMotd yes/PrintMotd no/" \ |
---|
184 | $FAKE_ROOT/${sysconfdir}/sshd_config |
---|
185 | |
---|
186 | # We don't want to overwrite config files on multiple installs |
---|
187 | mv $FAKE_ROOT/${sysconfdir}/ssh_config $FAKE_ROOT/${sysconfdir}/ssh_config.default |
---|
188 | mv $FAKE_ROOT/${sysconfdir}/sshd_config $FAKE_ROOT/${sysconfdir}/sshd_config.default |
---|
189 | [ -f $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds ] && \ |
---|
190 | mv $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds.default |
---|
191 | |
---|
192 | # local tweeks here |
---|
193 | [ -s "${POST_MAKE_INSTALL_FIXES}" ] && . ${POST_MAKE_INSTALL_FIXES} |
---|
194 | |
---|
195 | cd $FAKE_ROOT |
---|
196 | |
---|
197 | ## Ok, this is outright wrong, but it will work. I'm tired of pkgmk |
---|
198 | ## whining. |
---|
199 | for i in *; do |
---|
200 | PROTO_ARGS="$PROTO_ARGS $i=/$i"; |
---|
201 | done |
---|
202 | |
---|
203 | ## Build info file |
---|
204 | echo "Building pkginfo file..." |
---|
205 | cat > pkginfo << _EOF |
---|
206 | PKG=$PKGNAME |
---|
207 | NAME="OpenSSH Portable for ${UNAME_S}" |
---|
208 | DESC="Secure Shell remote access utility; replaces telnet and rlogin/rsh." |
---|
209 | VENDOR="OpenSSH Portable Team - http://www.openssh.com/portable.html" |
---|
210 | ARCH=$ARCH |
---|
211 | VERSION=$VERSION$REV |
---|
212 | CATEGORY="Security,application" |
---|
213 | BASEDIR=/ |
---|
214 | CLASSES="none" |
---|
215 | PSTAMP="${UNAME_S} ${OS_VER} ${ARCH} `date '+%d%b%Y %H:%M'`" |
---|
216 | _EOF |
---|
217 | |
---|
218 | ## Build empty depend file that may get updated by $POST_PROTOTYPE_EDITS |
---|
219 | echo "Building depend file..." |
---|
220 | touch depend |
---|
221 | |
---|
222 | ## Build space file |
---|
223 | echo "Building space file..." |
---|
224 | cat > space << _EOF |
---|
225 | # extra space required by start/stop links added by installf in postinstall |
---|
226 | $TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1 |
---|
227 | $TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME} 0 1 |
---|
228 | _EOF |
---|
229 | [ "$RC1_D" = no ] || \ |
---|
230 | echo "$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1" >> space |
---|
231 | [ "$RCS_D" = yes ] && \ |
---|
232 | echo "$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1" >> space |
---|
233 | |
---|
234 | ## Build preinstall file |
---|
235 | echo "Building preinstall file..." |
---|
236 | cat > preinstall << _EOF |
---|
237 | #! ${SCRIPT_SHELL} |
---|
238 | # |
---|
239 | _EOF |
---|
240 | |
---|
241 | # local preinstall changes here |
---|
242 | [ -s "${PKG_PREINSTALL_LOCAL}" ] && . ${PKG_PREINSTALL_LOCAL} |
---|
243 | |
---|
244 | cat >> preinstall << _EOF |
---|
245 | # |
---|
246 | [ "\${PRE_INS_STOP}" = "yes" ] && ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop |
---|
247 | exit 0 |
---|
248 | _EOF |
---|
249 | |
---|
250 | ## Build postinstall file |
---|
251 | echo "Building postinstall file..." |
---|
252 | cat > postinstall << _EOF |
---|
253 | #! ${SCRIPT_SHELL} |
---|
254 | # |
---|
255 | [ -f \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_config ] || \\ |
---|
256 | cp -p \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_config.default \\ |
---|
257 | \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_config |
---|
258 | [ -f \${PKG_INSTALL_ROOT}${sysconfdir}/sshd_config ] || \\ |
---|
259 | cp -p \${PKG_INSTALL_ROOT}${sysconfdir}/sshd_config.default \\ |
---|
260 | \${PKG_INSTALL_ROOT}${sysconfdir}/sshd_config |
---|
261 | [ -f \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_prng_cmds.default ] && { |
---|
262 | [ -f \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_prng_cmds ] || \\ |
---|
263 | cp -p \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_prng_cmds.default \\ |
---|
264 | \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_prng_cmds |
---|
265 | } |
---|
266 | |
---|
267 | # make rc?.d dirs only if we are doing a test install |
---|
268 | [ -n "${TEST_DIR}" ] && { |
---|
269 | [ "$RCS_D" = yes ] && mkdir -p ${TEST_DIR}/etc/rcS.d |
---|
270 | mkdir -p ${TEST_DIR}/etc/rc0.d |
---|
271 | [ "$RC1_D" = no ] || mkdir -p ${TEST_DIR}/etc/rc1.d |
---|
272 | mkdir -p ${TEST_DIR}/etc/rc2.d |
---|
273 | } |
---|
274 | |
---|
275 | if [ "\${USE_SYM_LINKS}" = yes ] |
---|
276 | then |
---|
277 | [ "$RCS_D" = yes ] && \ |
---|
278 | installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s |
---|
279 | installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s |
---|
280 | [ "$RC1_D" = no ] || \ |
---|
281 | installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s |
---|
282 | installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s |
---|
283 | else |
---|
284 | [ "$RCS_D" = yes ] && \ |
---|
285 | installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=\${PKG_INSTALL_ROOT}$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l |
---|
286 | installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=\${PKG_INSTALL_ROOT}$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l |
---|
287 | [ "$RC1_D" = no ] || \ |
---|
288 | installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=\${PKG_INSTALL_ROOT}$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l |
---|
289 | installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME}=\${PKG_INSTALL_ROOT}$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l |
---|
290 | fi |
---|
291 | |
---|
292 | # If piddir doesn't exist we add it. (Ie. --with-pid-dir=/var/opt/ssh) |
---|
293 | [ -d $piddir ] || installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR$piddir d 0755 root sys |
---|
294 | |
---|
295 | _EOF |
---|
296 | |
---|
297 | # local postinstall changes here |
---|
298 | [ -s "${PKG_POSTINSTALL_LOCAL}" ] && . ${PKG_POSTINSTALL_LOCAL} |
---|
299 | |
---|
300 | cat >> postinstall << _EOF |
---|
301 | installf -f ${PKGNAME} |
---|
302 | |
---|
303 | # Use chroot to handle PKG_INSTALL_ROOT |
---|
304 | if [ ! -z "\${PKG_INSTALL_ROOT}" ] |
---|
305 | then |
---|
306 | chroot="chroot \${PKG_INSTALL_ROOT}" |
---|
307 | fi |
---|
308 | # If this is a test build, we will skip the groupadd/useradd/passwd commands |
---|
309 | if [ ! -z "${TEST_DIR}" ] |
---|
310 | then |
---|
311 | chroot=echo |
---|
312 | fi |
---|
313 | |
---|
314 | if egrep '^[ \t]*UsePrivilegeSeparation[ \t]+no' \${PKG_INSTALL_ROOT}/$sysconfdir/sshd_config >/dev/null |
---|
315 | then |
---|
316 | echo "UsePrivilegeSeparation disabled in config, not creating PrivSep user" |
---|
317 | echo "or group." |
---|
318 | else |
---|
319 | echo "UsePrivilegeSeparation enabled in config (or defaulting to on)." |
---|
320 | |
---|
321 | # user required? |
---|
322 | if cut -f1 -d: \${PKG_INSTALL_ROOT}/etc/passwd | egrep '^'$SSH_PRIVSEP_USER'\$' >/dev/null |
---|
323 | then |
---|
324 | echo "PrivSep user $SSH_PRIVSEP_USER already exists." |
---|
325 | SSH_PRIVSEP_GROUP=\`grep "^$SSH_PRIVSEP_USER:" \${PKG_INSTALL_ROOT}/etc/passwd | awk -F: '{print \$4}'\` |
---|
326 | SSH_PRIVSEP_GROUP=\`grep ":\$SSH_PRIVSEP_GROUP:" \${PKG_INSTALL_ROOT}/etc/group | awk -F: '{print \$1}'\` |
---|
327 | else |
---|
328 | DO_PASSWD=yes |
---|
329 | fi |
---|
330 | [ -z "\$SSH_PRIVSEP_GROUP" ] && SSH_PRIVSEP_GROUP=$SSH_PRIVSEP_USER |
---|
331 | |
---|
332 | # group required? |
---|
333 | if cut -f1 -d: \${PKG_INSTALL_ROOT}/etc/group | egrep '^'\$SSH_PRIVSEP_GROUP'\$' >/dev/null |
---|
334 | then |
---|
335 | echo "PrivSep group \$SSH_PRIVSEP_GROUP already exists." |
---|
336 | else |
---|
337 | DO_GROUP=yes |
---|
338 | fi |
---|
339 | |
---|
340 | # create group if required |
---|
341 | [ "\$DO_GROUP" = yes ] && { |
---|
342 | # Use gid of 67 if possible |
---|
343 | if cut -f3 -d: \${PKG_INSTALL_ROOT}/etc/group | egrep '^'$SSHDGID'\$' >/dev/null |
---|
344 | then |
---|
345 | : |
---|
346 | else |
---|
347 | sshdgid="-g $SSHDGID" |
---|
348 | fi |
---|
349 | echo "Creating PrivSep group \$SSH_PRIVSEP_GROUP." |
---|
350 | \$chroot ${PATH_GROUPADD_PROG} \$sshdgid \$SSH_PRIVSEP_GROUP |
---|
351 | } |
---|
352 | |
---|
353 | # Create user if required |
---|
354 | [ "\$DO_PASSWD" = yes ] && { |
---|
355 | # Use uid of 67 if possible |
---|
356 | if cut -f3 -d: \${PKG_INSTALL_ROOT}/etc/passwd | egrep '^'$SSHDGID'\$' >/dev/null |
---|
357 | then |
---|
358 | : |
---|
359 | else |
---|
360 | sshduid="-u $SSHDUID" |
---|
361 | fi |
---|
362 | echo "Creating PrivSep user $SSH_PRIVSEP_USER." |
---|
363 | \$chroot ${PATH_USERADD_PROG} -c 'SSHD PrivSep User' -s /bin/false -g $SSH_PRIVSEP_USER \$sshduid $SSH_PRIVSEP_USER |
---|
364 | \$chroot ${PATH_PASSWD_PROG} -l $SSH_PRIVSEP_USER |
---|
365 | } |
---|
366 | fi |
---|
367 | |
---|
368 | [ "\${POST_INS_START}" = "yes" ] && ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} start |
---|
369 | exit 0 |
---|
370 | _EOF |
---|
371 | |
---|
372 | ## Build preremove file |
---|
373 | echo "Building preremove file..." |
---|
374 | cat > preremove << _EOF |
---|
375 | #! ${SCRIPT_SHELL} |
---|
376 | # |
---|
377 | ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop |
---|
378 | _EOF |
---|
379 | |
---|
380 | # local preremove changes here |
---|
381 | [ -s "${PKG_PREREMOVE_LOCAL}" ] && . ${PKG_PREREMOVE_LOCAL} |
---|
382 | |
---|
383 | cat >> preremove << _EOF |
---|
384 | exit 0 |
---|
385 | _EOF |
---|
386 | |
---|
387 | ## Build postremove file |
---|
388 | echo "Building postremove file..." |
---|
389 | cat > postremove << _EOF |
---|
390 | #! ${SCRIPT_SHELL} |
---|
391 | # |
---|
392 | _EOF |
---|
393 | |
---|
394 | # local postremove changes here |
---|
395 | [ -s "${PKG_POSTREMOVE_LOCAL}" ] && . ${PKG_POSTREMOVE_LOCAL} |
---|
396 | |
---|
397 | cat >> postremove << _EOF |
---|
398 | exit 0 |
---|
399 | _EOF |
---|
400 | |
---|
401 | ## Build request file |
---|
402 | echo "Building request file..." |
---|
403 | cat > request << _EOF |
---|
404 | trap 'exit 3' 15 |
---|
405 | |
---|
406 | _EOF |
---|
407 | |
---|
408 | [ -x /usr/bin/ckyorn ] || cat >> request << _EOF |
---|
409 | |
---|
410 | ckyorn() { |
---|
411 | # for some strange reason OpenServer has no ckyorn |
---|
412 | # We build a striped down version here |
---|
413 | |
---|
414 | DEFAULT=n |
---|
415 | PROMPT="Yes or No [yes,no,?,quit]" |
---|
416 | HELP_PROMPT=" Enter y or yes if your answer is yes; n or no if your answer is no." |
---|
417 | USAGE="usage: ckyorn [options] |
---|
418 | where options may include: |
---|
419 | -d default |
---|
420 | -h help |
---|
421 | -p prompt |
---|
422 | " |
---|
423 | |
---|
424 | if [ \$# != 0 ] |
---|
425 | then |
---|
426 | while getopts d:p:h: c |
---|
427 | do |
---|
428 | case \$c in |
---|
429 | h) HELP_PROMPT="\$OPTARG" ;; |
---|
430 | d) DEFAULT=\$OPTARG ;; |
---|
431 | p) PROMPT=\$OPTARG ;; |
---|
432 | \\?) echo "\$USAGE" 1>&2 |
---|
433 | exit 1 ;; |
---|
434 | esac |
---|
435 | done |
---|
436 | shift \`expr \$OPTIND - 1\` |
---|
437 | fi |
---|
438 | |
---|
439 | while true |
---|
440 | do |
---|
441 | echo "\${PROMPT}\\c " 1>&2 |
---|
442 | read key |
---|
443 | [ -z "\$key" ] && key=\$DEFAULT |
---|
444 | case \$key in |
---|
445 | [n,N]|[n,N][o,O]|[y,Y]|[y,Y][e,E][s,S]) echo "\${key}\\c" |
---|
446 | exit 0 ;; |
---|
447 | \\?) echo \$HELP_PROMPT 1>&2 ;; |
---|
448 | q|quit) echo "q\\c" 1>&2 |
---|
449 | exit 3 ;; |
---|
450 | esac |
---|
451 | done |
---|
452 | |
---|
453 | } |
---|
454 | |
---|
455 | _EOF |
---|
456 | |
---|
457 | cat >> request << _EOF |
---|
458 | USE_SYM_LINKS=no |
---|
459 | PRE_INS_STOP=no |
---|
460 | POST_INS_START=no |
---|
461 | # Use symbolic links? |
---|
462 | ans=\`ckyorn -d n \ |
---|
463 | -p "Do you want symbolic links for the start/stop scripts? ${DEF_MSG}"\` || exit \$? |
---|
464 | case \$ans in |
---|
465 | [y,Y]*) USE_SYM_LINKS=yes ;; |
---|
466 | esac |
---|
467 | |
---|
468 | # determine if should restart the daemon |
---|
469 | if [ -s ${piddir}/sshd.pid -a -f ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} ] |
---|
470 | then |
---|
471 | ans=\`ckyorn -d n \ |
---|
472 | -p "Should the running sshd daemon be restarted? ${DEF_MSG}"\` || exit \$? |
---|
473 | case \$ans in |
---|
474 | [y,Y]*) PRE_INS_STOP=yes |
---|
475 | POST_INS_START=yes |
---|
476 | ;; |
---|
477 | esac |
---|
478 | |
---|
479 | else |
---|
480 | |
---|
481 | # determine if we should start sshd |
---|
482 | ans=\`ckyorn -d n \ |
---|
483 | -p "Start the sshd daemon after installing this package? ${DEF_MSG}"\` || exit \$? |
---|
484 | case \$ans in |
---|
485 | [y,Y]*) POST_INS_START=yes ;; |
---|
486 | esac |
---|
487 | fi |
---|
488 | |
---|
489 | # make parameters available to installation service, |
---|
490 | # and so to any other packaging scripts |
---|
491 | cat >\$1 <<! |
---|
492 | USE_SYM_LINKS='\$USE_SYM_LINKS' |
---|
493 | PRE_INS_STOP='\$PRE_INS_STOP' |
---|
494 | POST_INS_START='\$POST_INS_START' |
---|
495 | ! |
---|
496 | |
---|
497 | _EOF |
---|
498 | |
---|
499 | # local request changes here |
---|
500 | [ -s "${PKG_REQUEST_LOCAL}" ] && . ${PKG_REQUEST_LOCAL} |
---|
501 | |
---|
502 | cat >> request << _EOF |
---|
503 | exit 0 |
---|
504 | |
---|
505 | _EOF |
---|
506 | |
---|
507 | ## Next Build our prototype |
---|
508 | echo "Building prototype file..." |
---|
509 | cat >mk-proto.awk << _EOF |
---|
510 | BEGIN { print "i pkginfo"; print "i depend"; \\ |
---|
511 | print "i preinstall"; print "i postinstall"; \\ |
---|
512 | print "i preremove"; print "i postremove"; \\ |
---|
513 | print "i request"; print "i space"; \\ |
---|
514 | split("$SYSTEM_DIR",sys_files); } |
---|
515 | { |
---|
516 | for (dir in sys_files) { if ( \$3 != sys_files[dir] ) |
---|
517 | { if ( \$1 == "s" ) |
---|
518 | { \$5=""; \$6=""; } |
---|
519 | else |
---|
520 | { \$5="root"; \$6="sys"; } |
---|
521 | } |
---|
522 | else |
---|
523 | { \$4="?"; \$5="?"; \$6="?"; break;} |
---|
524 | } } |
---|
525 | { print; } |
---|
526 | _EOF |
---|
527 | |
---|
528 | find . | egrep -v "prototype|pkginfo|mk-proto.awk" | sort | \ |
---|
529 | pkgproto $PROTO_ARGS | nawk -f mk-proto.awk > prototype |
---|
530 | |
---|
531 | # /usr/local is a symlink on some systems |
---|
532 | [ "${USR_LOCAL_IS_SYMLINK}" = yes ] && { |
---|
533 | grep -v "^d none /usr/local ? ? ?$" prototype > prototype.new |
---|
534 | mv prototype.new prototype |
---|
535 | } |
---|
536 | |
---|
537 | ## Step back a directory and now build the package. |
---|
538 | cd .. |
---|
539 | # local prototype tweeks here |
---|
540 | [ -s "${POST_PROTOTYPE_EDITS}" ] && . ${POST_PROTOTYPE_EDITS} |
---|
541 | |
---|
542 | echo "Building package.." |
---|
543 | pkgmk -d ${FAKE_ROOT} -f $FAKE_ROOT/prototype -o |
---|
544 | echo | pkgtrans -os ${FAKE_ROOT} ${START}/$PKGNAME-$VERSION$REV-$UNAME_S-$ARCH.pkg |
---|
545 | ;; |
---|
546 | |
---|
547 | justpkg.sh) |
---|
548 | rm -fr ${FAKE_ROOT}/${PKGNAME} |
---|
549 | grep -v "^PSTAMP=" $FAKE_ROOT/pkginfo > $$tmp |
---|
550 | mv $$tmp $FAKE_ROOT/pkginfo |
---|
551 | cat >> $FAKE_ROOT/pkginfo << _EOF |
---|
552 | PSTAMP="${UNAME_S} ${OS_VER} ${ARCH} `date '+%d%b%Y %H:%M'`" |
---|
553 | _EOF |
---|
554 | pkgmk -d ${FAKE_ROOT} -f $FAKE_ROOT/prototype -o |
---|
555 | echo | pkgtrans -os ${FAKE_ROOT} ${START}/$PKGNAME-$VERSION$REV-$UNAME_S-$ARCH.pkg |
---|
556 | ;; |
---|
557 | |
---|
558 | esac |
---|
559 | |
---|
560 | [ "${REMOVE_FAKE_ROOT_WHEN_DONE}" = yes ] && rm -rf $FAKE_ROOT |
---|
561 | exit 0 |
---|
562 | |
---|