3 # Fake Root Solaris/SVR4/SVR5 Build System - Prototype
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)
11 # Options for building the package
12 # You can create a openssh-config.local with your customized options
14 REMOVE_FAKE_ROOT_WHEN_DONE
=yes
16 # uncommenting TEST_DIR and using
17 # configure --prefix=/var/tmp --with-privsep-path=/var/tmp/empty
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
24 # revisions within the same version (REV=a)
26 SYSVINIT_NAME
=opensshd
29 SSHDUID
=67 # Default privsep uid
30 SSHDGID
=67 # Default privsep gid
31 # uncomment these next three as needed
34 #USR_LOCAL_IS_SYMLINK=yes
35 # System V init run levels
38 # We will source these if they exist
39 POST_MAKE_INSTALL_FIXES
=.
/pkg-post-make-install-fixes.sh
40 POST_PROTOTYPE_EDITS
=.
/pkg-post-prototype-edit.sh
41 # We'll be one level deeper looking for these
42 PKG_PREINSTALL_LOCAL
=..
/pkg-preinstall.
local
43 PKG_POSTINSTALL_LOCAL
=..
/pkg-postinstall.
local
44 PKG_PREREMOVE_LOCAL
=..
/pkg-preremove.
local
45 PKG_POSTREMOVE_LOCAL
=..
/pkg-postremove.
local
46 PKG_REQUEST_LOCAL
=..
/pkg-request.
local
47 # end of sourced files
49 OPENSSHD
=opensshd.init
50 OPENSSH_MANIFEST
=openssh.xml
51 OPENSSH_FMRI
=svc
:/site
/${SYSVINIT_NAME}:default
52 SMF_METHOD_DIR
=/lib
/svc
/method
/site
53 SMF_MANIFEST_DIR
=/var
/svc
/manifest
/site
55 PATH_GROUPADD_PROG
=@PATH_GROUPADD_PROG@
56 PATH_USERADD_PROG
=@PATH_USERADD_PROG@
57 PATH_PASSWD_PROG
=@PATH_PASSWD_PROG@
59 # list of system directories we do NOT want to change owner/group/perms
60 # when installing our package
71 /lib/svc/method/site \
96 /var/svc/manifest/site \
100 # We may need to build as root so we make sure PATH is set up
101 # only set the path if it's not set already
103 echo $PATH |
grep ":/opt/bin" > /dev
/null
2>&1
104 [ $?
-ne 0 ] && PATH
=$PATH:/opt
/bin
106 [ -d /usr
/local
/bin
] && {
107 echo $PATH |
grep ":/usr/local/bin" > /dev
/null
2>&1
108 [ $?
-ne 0 ] && PATH
=$PATH:/usr
/local
/bin
110 [ -d /usr
/ccs
/bin
] && {
111 echo $PATH |
grep ":/usr/ccs/bin" > /dev
/null
2>&1
112 [ $?
-ne 0 ] && PATH
=$PATH:/usr
/ccs
/bin
118 echo "Please run this script from your build directory"
122 # we will look for openssh-config.local to override the above options
123 [ -s .
/openssh-config.
local ] && . .
/openssh-config.
local
128 ## Fill in some details, like prefix and sysconfdir
129 for confvar
in prefix exec_prefix bindir sbindir libexecdir datadir mandir sysconfdir piddir srcdir
131 eval $confvar=`grep "^$confvar=" Makefile | cut -d = -f 2`
134 ## Are we using Solaris' SMF?
136 if egrep "^#define USE_SOLARIS_PROCESS_CONTRACTS" config.h
> /dev
/null
2>&1
141 ## Collect value of privsep user
142 for confvar
in SSH_PRIVSEP_USER
144 eval $confvar=`awk '/#define[ \t]'$confvar'/{print $3}' config.h`
147 ## Set privsep defaults if not defined
148 if [ -z "$SSH_PRIVSEP_USER" ]
150 SSH_PRIVSEP_USER
=sshd
153 ## Extract common info requires for the 'info' part of the package.
154 VERSION
=`./ssh -V 2>&1 | sed -e 's/,.*//'`
159 SCRIPT_SHELL
=/sbin
/sh
163 SunOS
) UNAME_S
=Solaris
167 DEF_MSG
="(default: n)"
169 SCO_SV
) case ${UNAME_R} in
170 3.2) UNAME_S
=OpenServer5
171 OS_VER
=`uname -X | grep Release | sed -e 's/^Rel.*3.2v//'`
173 5) UNAME_S
=OpenServer6
178 DEF_MSG
="(default: n)"
182 case `basename $0` in
184 ## Start by faking root install
185 echo "Faking root install..."
186 [ -d $FAKE_ROOT ] && rm -fr $FAKE_ROOT
188 ${MAKE} install-nokeys DESTDIR
=$FAKE_ROOT
191 echo "Fake root install failed, stopping."
195 ## Setup our run level stuff while we are at it.
198 # For Solaris' SMF, /lib/svc/method/site is the preferred place
199 # for start/stop scripts that aren't supplied with the OS, and
200 # similarly /var/svc/manifest/site for manifests.
201 mkdir
-p $FAKE_ROOT${TEST_DIR}${SMF_METHOD_DIR}
202 mkdir
-p $FAKE_ROOT${TEST_DIR}${SMF_MANIFEST_DIR}
204 cp ${OPENSSHD} $FAKE_ROOT${TEST_DIR}${SMF_METHOD_DIR}/${SYSVINIT_NAME}
205 chmod 744 $FAKE_ROOT${TEST_DIR}${SMF_METHOD_DIR}/${SYSVINIT_NAME}
207 cat ${OPENSSH_MANIFEST} | \
208 sed -e "s|__SYSVINIT_NAME__|${SYSVINIT_NAME}|" \
209 -e "s|__SMF_METHOD_DIR__|${SMF_METHOD_DIR}|" \
210 > $FAKE_ROOT${TEST_DIR}${SMF_MANIFEST_DIR}/${SYSVINIT_NAME}.xml
211 chmod 644 $FAKE_ROOT${TEST_DIR}${SMF_MANIFEST_DIR}/${SYSVINIT_NAME}.xml
213 mkdir
-p $FAKE_ROOT${TEST_DIR}/etc
/init.d
215 cp ${OPENSSHD} $FAKE_ROOT${TEST_DIR}/etc/init.d/${SYSVINIT_NAME}
216 chmod 744 $FAKE_ROOT${TEST_DIR}/etc
/init.d
/${SYSVINIT_NAME}
219 [ "${PERMIT_ROOT_LOGIN}" = no
] && \
220 perl
-p -i -e "s/#PermitRootLogin yes/PermitRootLogin no/" \
221 $FAKE_ROOT${sysconfdir}/sshd_config
222 [ "${X11_FORWARDING}" = yes ] && \
223 perl
-p -i -e "s/#X11Forwarding no/X11Forwarding yes/" \
224 $FAKE_ROOT${sysconfdir}/sshd_config
226 perl
-p -i -e "s/#PrintMotd yes/PrintMotd no/" \
227 $FAKE_ROOT${sysconfdir}/sshd_config
229 # We don't want to overwrite config files on multiple installs
230 mv $FAKE_ROOT${sysconfdir}/ssh_config
$FAKE_ROOT${sysconfdir}/ssh_config.default
231 mv $FAKE_ROOT${sysconfdir}/sshd_config
$FAKE_ROOT${sysconfdir}/sshd_config.default
232 [ -f $FAKE_ROOT${sysconfdir}/ssh_prng_cmds
] && \
233 mv $FAKE_ROOT${sysconfdir}/ssh_prng_cmds
$FAKE_ROOT${sysconfdir}/ssh_prng_cmds.default
236 [ -s "${POST_MAKE_INSTALL_FIXES}" ] && .
${POST_MAKE_INSTALL_FIXES}
240 ## Ok, this is outright wrong, but it will work. I'm tired of pkgmk
243 PROTO_ARGS
="$PROTO_ARGS $i=/$i";
247 echo "Building pkginfo file..."
248 cat > pkginfo
<< _EOF
250 NAME="OpenSSH Portable for ${UNAME_S}"
251 DESC="Secure Shell remote access utility; replaces telnet and rlogin/rsh."
252 VENDOR="OpenSSH Portable Team - http://www.openssh.com/portable.html"
255 CATEGORY="Security,application"
258 PSTAMP="${UNAME_S} ${OS_VER} ${ARCH} `date '+%d%b%Y %H:%M'`"
261 ## Build empty depend file that may get updated by $POST_PROTOTYPE_EDITS
262 echo "Building depend file..."
266 echo "Building space file..."
269 # XXX Is this necessary? If not, remove space line from mk-proto.awk.
273 # extra space required by start/stop links added by installf
275 $TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1
276 $TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME} 0 1
278 [ "$RC1_D" = no
] || \
279 echo "$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1" >> space
280 [ "$RCS_D" = yes ] && \
281 echo "$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1" >> space
284 ## Build preinstall file
285 echo "Building preinstall file..."
286 cat > preinstall
<< _EOF
291 # local preinstall changes here
292 [ -s "${PKG_PREINSTALL_LOCAL}" ] && .
${PKG_PREINSTALL_LOCAL}
294 cat >> preinstall
<< _EOF
296 if [ "\${PRE_INS_STOP}" = "yes" ]
300 svcadm disable $OPENSSH_FMRI
302 ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop
309 ## Build postinstall file
310 echo "Building postinstall file..."
311 cat > postinstall
<< _EOF
314 [ -f \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_config ] || \\
315 cp -p \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_config.default \\
316 \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_config
317 [ -f \${PKG_INSTALL_ROOT}${sysconfdir}/sshd_config ] || \\
318 cp -p \${PKG_INSTALL_ROOT}${sysconfdir}/sshd_config.default \\
319 \${PKG_INSTALL_ROOT}${sysconfdir}/sshd_config
320 [ -f \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_prng_cmds.default ] && {
321 [ -f \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_prng_cmds ] || \\
322 cp -p \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_prng_cmds.default \\
323 \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_prng_cmds
326 # make rc?.d dirs only if we are doing a test install
327 [ -n "${TEST_DIR}" ] && [ $DO_SMF -ne 1 ] && {
328 [ "$RCS_D" = yes ] && mkdir -p ${TEST_DIR}/etc/rcS.d
329 mkdir -p ${TEST_DIR}/etc/rc0.d
330 [ "$RC1_D" = no ] || mkdir -p ${TEST_DIR}/etc/rc1.d
331 mkdir -p ${TEST_DIR}/etc/rc2.d
336 # Delete the existing service, if it exists, then import the
338 if svcs $OPENSSH_FMRI > /dev/null 2>&1
340 svccfg delete -f $OPENSSH_FMRI
342 # NOTE, The manifest disables sshd by default.
343 svccfg import ${TEST_DIR}${SMF_MANIFEST_DIR}/${SYSVINIT_NAME}.xml
345 if [ "\${USE_SYM_LINKS}" = yes ]
347 [ "$RCS_D" = yes ] && \
348 installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
349 installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
350 [ "$RC1_D" = no ] || \
351 installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
352 installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
354 [ "$RCS_D" = yes ] && \
355 installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=\${PKG_INSTALL_ROOT}$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
356 installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=\${PKG_INSTALL_ROOT}$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
357 [ "$RC1_D" = no ] || \
358 installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=\${PKG_INSTALL_ROOT}$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
359 installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME}=\${PKG_INSTALL_ROOT}$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
363 # If piddir doesn't exist we add it. (Ie. --with-pid-dir=/var/opt/ssh)
364 [ -d $piddir ] || installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR$piddir d 0755 root sys
368 # local postinstall changes here
369 [ -s "${PKG_POSTINSTALL_LOCAL}" ] && .
${PKG_POSTINSTALL_LOCAL}
371 cat >> postinstall
<< _EOF
372 installf -f ${PKGNAME}
374 # Use chroot to handle PKG_INSTALL_ROOT
375 if [ ! -z "\${PKG_INSTALL_ROOT}" ]
377 chroot="chroot \${PKG_INSTALL_ROOT}"
379 # If this is a test build, we will skip the groupadd/useradd/passwd commands
380 if [ ! -z "${TEST_DIR}" ]
385 echo "PrivilegeSeparation user always required."
386 if cut -f1 -d: \${PKG_INSTALL_ROOT}/etc/passwd | egrep '^'$SSH_PRIVSEP_USER'\$' >/dev/null
388 echo "PrivSep user $SSH_PRIVSEP_USER already exists."
389 SSH_PRIVSEP_GROUP=\`grep "^$SSH_PRIVSEP_USER:" \${PKG_INSTALL_ROOT}/etc/passwd | awk -F: '{print \$4}'\`
390 SSH_PRIVSEP_GROUP=\`grep ":\$SSH_PRIVSEP_GROUP:" \${PKG_INSTALL_ROOT}/etc/group | awk -F: '{print \$1}'\`
394 [ -z "\$SSH_PRIVSEP_GROUP" ] && SSH_PRIVSEP_GROUP=$SSH_PRIVSEP_USER
397 if cut -f1 -d: \${PKG_INSTALL_ROOT}/etc/group | egrep '^'\$SSH_PRIVSEP_GROUP'\$' >/dev/null
399 echo "PrivSep group \$SSH_PRIVSEP_GROUP already exists."
404 # create group if required
405 [ "\$DO_GROUP" = yes ] && {
406 # Use gid of 67 if possible
407 if cut -f3 -d: \${PKG_INSTALL_ROOT}/etc/group | egrep '^'$SSHDGID'\$' >/dev/null
411 sshdgid="-g $SSHDGID"
413 echo "Creating PrivSep group \$SSH_PRIVSEP_GROUP."
414 \$chroot ${PATH_GROUPADD_PROG} \$sshdgid \$SSH_PRIVSEP_GROUP
417 # Create user if required
418 [ "\$DO_PASSWD" = yes ] && {
419 # Use uid of 67 if possible
420 if cut -f3 -d: \${PKG_INSTALL_ROOT}/etc/passwd | egrep '^'$SSHDUID'\$' >/dev/null
424 sshduid="-u $SSHDUID"
426 echo "Creating PrivSep user $SSH_PRIVSEP_USER."
427 \$chroot ${PATH_USERADD_PROG} -c 'SSHD PrivSep User' -s /bin/false -g $SSH_PRIVSEP_USER \$sshduid $SSH_PRIVSEP_USER
428 \$chroot ${PATH_PASSWD_PROG} -l $SSH_PRIVSEP_USER
431 if [ "\${POST_INS_START}" = "yes" ]
435 svcadm enable $OPENSSH_FMRI
437 ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} start
443 ## Build preremove file
444 echo "Building preremove file..."
445 cat > preremove
<< _EOF
450 svcadm disable $OPENSSH_FMRI
452 ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop
456 # local preremove changes here
457 [ -s "${PKG_PREREMOVE_LOCAL}" ] && .
${PKG_PREREMOVE_LOCAL}
459 cat >> preremove
<< _EOF
463 ## Build postremove file
464 echo "Building postremove file..."
465 cat > postremove
<< _EOF
470 if svcs $OPENSSH_FMRI > /dev/null 2>&1
472 svccfg delete -f $OPENSSH_FMRI
477 # local postremove changes here
478 [ -s "${PKG_POSTREMOVE_LOCAL}" ] && .
${PKG_POSTREMOVE_LOCAL}
480 cat >> postremove
<< _EOF
484 ## Build request file
485 echo "Building request file..."
486 cat > request
<< _EOF
491 [ -x /usr
/bin
/ckyorn
] ||
cat >> request
<< _EOF
494 # for some strange reason OpenServer5 has no ckyorn
495 # We build a striped down version here
498 PROMPT="Yes or No [yes,no,?,quit]"
499 HELP_PROMPT=" Enter y or yes if your answer is yes; n or no if your answer is no."
500 USAGE="usage: ckyorn [options]
501 where options may include:
509 while getopts d:p:h: c
512 h) HELP_PROMPT="\$OPTARG" ;;
513 d) DEFAULT=\$OPTARG ;;
514 p) PROMPT=\$OPTARG ;;
515 \\?) echo "\$USAGE" 1>&2
519 shift \`expr \$OPTIND - 1\`
524 echo "\${PROMPT}\\c " 1>&2
526 [ -z "\$key" ] && key=\$DEFAULT
528 [n,N]|[n,N][o,O]|[y,Y]|[y,Y][e,E][s,S]) echo "\${key}\\c"
530 \\?) echo \$HELP_PROMPT 1>&2 ;;
531 q|quit) echo "q\\c" 1>&2
542 # This could get hairy, as the running sshd may not be under SMF.
543 # We'll assume an earlier version of OpenSSH started via SMF.
544 cat >> request
<< _EOF
547 # determine if should restart the daemon
548 if [ -s ${piddir}/sshd.pid ] && \
549 /usr/bin/svcs -H $OPENSSH_FMRI 2>&1 | egrep "^online" > /dev/null 2>&1
552 -p "Should the running sshd daemon be restarted? ${DEF_MSG}"\` || exit \$?
554 [y,Y]*) PRE_INS_STOP=yes
561 # determine if we should start sshd
563 -p "Start the sshd daemon after installing this package? ${DEF_MSG}"\` || exit \$?
565 [y,Y]*) POST_INS_START=yes ;;
569 # make parameters available to installation service,
570 # and so to any other packaging scripts
572 PRE_INS_STOP='\$PRE_INS_STOP'
573 POST_INS_START='\$POST_INS_START'
578 cat >> request
<< _EOF
582 # Use symbolic links?
584 -p "Do you want symbolic links for the start/stop scripts? ${DEF_MSG}"\` || exit \$?
586 [y,Y]*) USE_SYM_LINKS=yes ;;
589 # determine if should restart the daemon
590 if [ -s ${piddir}/sshd.pid -a -f ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} ]
593 -p "Should the running sshd daemon be restarted? ${DEF_MSG}"\` || exit \$?
595 [y,Y]*) PRE_INS_STOP=yes
602 # determine if we should start sshd
604 -p "Start the sshd daemon after installing this package? ${DEF_MSG}"\` || exit \$?
606 [y,Y]*) POST_INS_START=yes ;;
610 # make parameters available to installation service,
611 # and so to any other packaging scripts
613 USE_SYM_LINKS='\$USE_SYM_LINKS'
614 PRE_INS_STOP='\$PRE_INS_STOP'
615 POST_INS_START='\$POST_INS_START'
621 # local request changes here
622 [ -s "${PKG_REQUEST_LOCAL}" ] && .
${PKG_REQUEST_LOCAL}
624 cat >> request
<< _EOF
629 ## Next Build our prototype
630 echo "Building prototype file..."
631 cat >mk-proto.
awk << _EOF
632 BEGIN { print "i pkginfo"; print "i depend"; \\
633 print "i preinstall"; print "i postinstall"; \\
634 print "i preremove"; print "i postremove"; \\
635 print "i request"; print "i space"; \\
636 split("$SYSTEM_DIR",sys_files); }
638 for (dir in sys_files) { if ( \$3 != sys_files[dir] )
642 { \$5="root"; \$6="sys"; }
645 { \$4="?"; \$5="?"; \$6="?"; break;}
650 find . |
egrep -v "prototype|pkginfo|mk-proto.awk" |
sort | \
651 pkgproto
$PROTO_ARGS |
${AWK} -f mk-proto.
awk > prototype
653 # /usr/local is a symlink on some systems
654 [ "${USR_LOCAL_IS_SYMLINK}" = yes ] && {
655 grep -v "^d none /usr/local ? ? ?$" prototype
> prototype.new
656 mv prototype.new prototype
659 ## Step back a directory and now build the package.
661 # local prototype tweeks here
662 [ -s "${POST_PROTOTYPE_EDITS}" ] && .
${POST_PROTOTYPE_EDITS}
664 echo "Building package.."
665 pkgmk
-d ${FAKE_ROOT} -f $FAKE_ROOT/prototype
-o
666 echo | pkgtrans
-os ${FAKE_ROOT} ${START}/$PKGNAME-$VERSION$REV-$UNAME_S-$ARCH.pkg
670 rm -fr ${FAKE_ROOT}/${PKGNAME}
671 grep -v "^PSTAMP=" $FAKE_ROOT/pkginfo
> $
$tmp
672 mv $
$tmp $FAKE_ROOT/pkginfo
673 cat >> $FAKE_ROOT/pkginfo
<< _EOF
674 PSTAMP="${UNAME_S} ${OS_VER} ${ARCH} `date '+%d%b%Y %H:%M'`"
676 pkgmk
-d ${FAKE_ROOT} -f $FAKE_ROOT/prototype
-o
677 echo | pkgtrans
-os ${FAKE_ROOT} ${START}/$PKGNAME-$VERSION$REV-$UNAME_S-$ARCH.pkg
682 [ "${REMOVE_FAKE_ROOT_WHEN_DONE}" = yes ] && rm -rf $FAKE_ROOT