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