]> andersk Git - openssh.git/blame - buildpkg.sh.in
- (tim) [configure.ac buildpkg.sh.in contrib/solaris/README] move opensshd
[openssh.git] / buildpkg.sh.in
CommitLineData
9cefe228 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#
ddd8c95b 46OPENSSHD=opensshd.init
9cefe228 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
ddd8c95b 171cp ${OPENSSHD} $FAKE_ROOT${TEST_DIR}/etc/init.d/${SYSVINIT_NAME}
9cefe228 172chmod 744 $FAKE_ROOT${TEST_DIR}/etc/init.d/${SYSVINIT_NAME}
173
174[ "${PERMIT_ROOT_LOGIN}" = no ] && \
175 perl -p -i -e "s/#PermitRootLogin yes/PermitRootLogin no/" \
176 $FAKE_ROOT/${sysconfdir}/sshd_config
177[ "${X11_FORWARDING}" = yes ] && \
178 perl -p -i -e "s/#X11Forwarding no/X11Forwarding yes/" \
179 $FAKE_ROOT/${sysconfdir}/sshd_config
180# fix PrintMotd
181perl -p -i -e "s/#PrintMotd yes/PrintMotd no/" \
182 $FAKE_ROOT/${sysconfdir}/sshd_config
183
184# We don't want to overwrite config files on multiple installs
185mv $FAKE_ROOT/${sysconfdir}/ssh_config $FAKE_ROOT/${sysconfdir}/ssh_config.default
186mv $FAKE_ROOT/${sysconfdir}/sshd_config $FAKE_ROOT/${sysconfdir}/sshd_config.default
187[ -f $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds ] && \
188mv $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds.default
189
190# local tweeks here
191[ -s "${POST_MAKE_INSTALL_FIXES}" ] && . ${POST_MAKE_INSTALL_FIXES}
192
193cd $FAKE_ROOT
194
195## Ok, this is outright wrong, but it will work. I'm tired of pkgmk
196## whining.
197for i in *; do
198 PROTO_ARGS="$PROTO_ARGS $i=/$i";
199done
200
201## Build info file
202echo "Building pkginfo file..."
203cat > pkginfo << _EOF
204PKG=$PKGNAME
205NAME="OpenSSH Portable for ${UNAME_S}"
206DESC="Secure Shell remote access utility; replaces telnet and rlogin/rsh."
207VENDOR="OpenSSH Portable Team - http://www.openssh.com/portable.html"
208ARCH=$ARCH
209VERSION=$VERSION
210CATEGORY="Security,application"
211BASEDIR=/
212CLASSES="none"
213PSTAMP="${UNAME_S} ${OS_VER} ${ARCH} `date '+%d%b%Y %H:%M'`"
214_EOF
215
216## Build empty depend file that may get updated by $POST_PROTOTYPE_EDITS
217echo "Building depend file..."
218touch depend
219
220## Build space file
221echo "Building space file..."
222cat > space << _EOF
223# extra space required by start/stop links added by installf in postinstall
224$TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1
225$TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME} 0 1
226_EOF
227[ "$RC1_D" = no ] || \
228echo "$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1" >> space
229[ "$RCS_D" = yes ] && \
230echo "$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1" >> space
231
232## Build preinstall file
233echo "Building preinstall file..."
234cat > preinstall << _EOF
235#! ${SCRIPT_SHELL}
236#
237_EOF
238
239# local preinstall changes here
240[ -s "${PKG_PREINSTALL_LOCAL}" ] && . ${PKG_PREINSTALL_LOCAL}
241
242cat >> preinstall << _EOF
243#
244[ "\${PRE_INS_STOP}" = "yes" ] && ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop
245exit 0
246_EOF
247
248## Build postinstall file
249echo "Building postinstall file..."
250cat > postinstall << _EOF
251#! ${SCRIPT_SHELL}
252#
253[ -f \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_config ] || \\
254 cp -p \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_config.default \\
255 \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_config
256[ -f \${PKG_INSTALL_ROOT}${sysconfdir}/sshd_config ] || \\
257 cp -p \${PKG_INSTALL_ROOT}${sysconfdir}/sshd_config.default \\
258 \${PKG_INSTALL_ROOT}${sysconfdir}/sshd_config
259[ -f \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_prng_cmds.default ] && {
260 [ -f \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_prng_cmds ] || \\
261 cp -p \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_prng_cmds.default \\
262 \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_prng_cmds
263}
264
265# make rc?.d dirs only if we are doing a test install
266[ -n "${TEST_DIR}" ] && {
267 [ "$RCS_D" = yes ] && mkdir -p ${TEST_DIR}/etc/rcS.d
268 mkdir -p ${TEST_DIR}/etc/rc0.d
269 [ "$RC1_D" = no ] || mkdir -p ${TEST_DIR}/etc/rc1.d
270 mkdir -p ${TEST_DIR}/etc/rc2.d
271}
272
273if [ "\${USE_SYM_LINKS}" = yes ]
274then
275 [ "$RCS_D" = yes ] && \
276installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
277 installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
278 [ "$RC1_D" = no ] || \
279 installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
280 installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
281else
282 [ "$RCS_D" = yes ] && \
283installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
284 installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
285 [ "$RC1_D" = no ] || \
286 installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
287 installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
288fi
289
290# If piddir doesn't exist we add it. (Ie. --with-pid-dir=/var/opt/ssh)
291[ -d $piddir ] || installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR$piddir d 0755 root sys
292
293_EOF
294
295# local postinstall changes here
296[ -s "${PKG_POSTINSTALL_LOCAL}" ] && . ${PKG_POSTINSTALL_LOCAL}
297
298cat >> postinstall << _EOF
299installf -f ${PKGNAME}
300
301# Use chroot to handle PKG_INSTALL_ROOT
302if [ ! -z "\${PKG_INSTALL_ROOT}" ]
303then
304 chroot="chroot \${PKG_INSTALL_ROOT}"
305fi
306# If this is a test build, we will skip the groupadd/useradd/passwd commands
307if [ ! -z "${TEST_DIR}" ]
308then
309 chroot=echo
310fi
311
312if egrep '^[ \t]*UsePrivilegeSeparation[ \t]+no' \${PKG_INSTALL_ROOT}/$sysconfdir/sshd_config >/dev/null
313then
314 echo "UsePrivilegeSeparation disabled in config, not creating PrivSep user"
315 echo "or group."
316else
317 echo "UsePrivilegeSeparation enabled in config (or defaulting to on)."
318
319 # create group if required
320 if cut -f1 -d: \${PKG_INSTALL_ROOT}/etc/group | egrep '^'$SSH_PRIVSEP_USER'\$' >/dev/null
321 then
322 echo "PrivSep group $SSH_PRIVSEP_USER already exists."
323 else
324 # Use gid of 67 if possible
325 if cut -f3 -d: \${PKG_INSTALL_ROOT}/etc/group | egrep '^'$SSHDGID'\$' >/dev/null
326 then
327 :
328 else
329 sshdgid="-g $SSHDGID"
330 fi
331 echo "Creating PrivSep group $SSH_PRIVSEP_USER."
332 \$chroot ${PATH_GROUPADD_PROG} \$sshdgid $SSH_PRIVSEP_USER
333 fi
334
335 # Create user if required
336 if cut -f1 -d: \${PKG_INSTALL_ROOT}/etc/passwd | egrep '^'$SSH_PRIVSEP_USER'\$' >/dev/null
337 then
338 echo "PrivSep user $SSH_PRIVSEP_USER already exists."
339 else
340 # Use uid of 67 if possible
341 if cut -f3 -d: \${PKG_INSTALL_ROOT}/etc/passwd | egrep '^'$SSHDGID'\$' >/dev/null
342 then
343 :
344 else
345 sshduid="-u $SSHDUID"
346 fi
347 echo "Creating PrivSep user $SSH_PRIVSEP_USER."
348 \$chroot ${PATH_USERADD_PROG} -c 'SSHD PrivSep User' -s /bin/false -g $SSH_PRIVSEP_USER \$sshduid $SSH_PRIVSEP_USER
349 \$chroot ${PATH_PASSWD_PROG} -l $SSH_PRIVSEP_USER
350 fi
351fi
352
353[ "\${POST_INS_START}" = "yes" ] && ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} start
354exit 0
355_EOF
356
357## Build preremove file
358echo "Building preremove file..."
359cat > preremove << _EOF
360#! ${SCRIPT_SHELL}
361#
362${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop
363_EOF
364
365# local preremove changes here
366[ -s "${PKG_PREREMOVE_LOCAL}" ] && . ${PKG_PREREMOVE_LOCAL}
367
368cat >> preremove << _EOF
369exit 0
370_EOF
371
372## Build postremove file
373echo "Building postremove file..."
374cat > postremove << _EOF
375#! ${SCRIPT_SHELL}
376#
377_EOF
378
379# local postremove changes here
380[ -s "${PKG_POSTREMOVE_LOCAL}" ] && . ${PKG_POSTREMOVE_LOCAL}
381
382cat >> postremove << _EOF
383exit 0
384_EOF
385
386## Build request file
387echo "Building request file..."
388cat > request << _EOF
389trap 'exit 3' 15
390
391_EOF
392
393[ -x /usr/bin/ckyorn ] || cat >> request << _EOF
394
395ckyorn() {
396# for some strange reason OpenServer has no ckyorn
397# We build a striped down version here
398
399DEFAULT=n
400PROMPT="Yes or No [yes,no,?,quit]"
401HELP_PROMPT=" Enter y or yes if your answer is yes; n or no if your answer is no."
402USAGE="usage: ckyorn [options]
403where options may include:
404 -d default
405 -h help
406 -p prompt
407"
408
409if [ \$# != 0 ]
410then
411 while getopts d:p:h: c
412 do
413 case \$c in
414 h) HELP_PROMPT="\$OPTARG" ;;
415 d) DEFAULT=\$OPTARG ;;
416 p) PROMPT=\$OPTARG ;;
417 \\?) echo "\$USAGE" 1>&2
418 exit 1 ;;
419 esac
420 done
421 shift \`expr \$OPTIND - 1\`
422fi
423
424while true
425do
426 echo "\${PROMPT}\\c " 1>&2
427 read key
428 [ -z "\$key" ] && key=\$DEFAULT
429 case \$key in
430 [n,N]|[n,N][o,O]|[y,Y]|[y,Y][e,E][s,S]) echo "\${key}\\c"
431 exit 0 ;;
432 \\?) echo \$HELP_PROMPT 1>&2 ;;
433 q|quit) echo "q\\c" 1>&2
434 exit 3 ;;
435 esac
436done
437
438}
439
440_EOF
441
442cat >> request << _EOF
443USE_SYM_LINKS=no
444PRE_INS_STOP=no
445POST_INS_START=no
446# Use symbolic links?
447ans=\`ckyorn -d n \
448-p "Do you want symbolic links for the start/stop scripts? ${DEF_MSG}"\` || exit \$?
449case \$ans in
450 [y,Y]*) USE_SYM_LINKS=yes ;;
451esac
452
453# determine if should restart the daemon
454if [ -s ${piddir}/sshd.pid -a -f ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} ]
455then
456 ans=\`ckyorn -d n \
457-p "Should the running sshd daemon be restarted? ${DEF_MSG}"\` || exit \$?
458 case \$ans in
459 [y,Y]*) PRE_INS_STOP=yes
460 POST_INS_START=yes
461 ;;
462 esac
463
464else
465
466# determine if we should start sshd
467 ans=\`ckyorn -d n \
468-p "Start the sshd daemon after installing this package? ${DEF_MSG}"\` || exit \$?
469 case \$ans in
470 [y,Y]*) POST_INS_START=yes ;;
471 esac
472fi
473
474# make parameters available to installation service,
475# and so to any other packaging scripts
476cat >\$1 <<!
477USE_SYM_LINKS='\$USE_SYM_LINKS'
478PRE_INS_STOP='\$PRE_INS_STOP'
479POST_INS_START='\$POST_INS_START'
480!
481
482_EOF
483
484# local request changes here
485[ -s "${PKG_REQUEST_LOCAL}" ] && . ${PKG_REQUEST_LOCAL}
486
487cat >> request << _EOF
488exit 0
489
490_EOF
491
492## Next Build our prototype
493echo "Building prototype file..."
494cat >mk-proto.awk << _EOF
495 BEGIN { print "i pkginfo"; print "i depend"; \\
496 print "i preinstall"; print "i postinstall"; \\
497 print "i preremove"; print "i postremove"; \\
498 print "i request"; print "i space"; \\
499 split("$SYSTEM_DIR",sys_files); }
500 {
501 for (dir in sys_files) { if ( \$3 != sys_files[dir] )
502 { if ( \$1 == "s" )
503 { \$5=""; \$6=""; }
504 else
505 { \$5="root"; \$6="sys"; }
506 }
507 else
508 { \$4="?"; \$5="?"; \$6="?"; break;}
509 } }
510 { print; }
511_EOF
512
513find . | egrep -v "prototype|pkginfo|mk-proto.awk" | sort | \
514 pkgproto $PROTO_ARGS | nawk -f mk-proto.awk > prototype
515
516# /usr/local is a symlink on some systems
517[ "${USR_LOCAL_IS_SYMLINK}" = yes ] && {
518 grep -v "^d none /usr/local ? ? ?$" prototype > prototype.new
519 mv prototype.new prototype
520}
521
522## Step back a directory and now build the package.
523cd ..
524# local prototype tweeks here
525[ -s "${POST_PROTOTYPE_EDITS}" ] && . ${POST_PROTOTYPE_EDITS}
526
527echo "Building package.."
528pkgmk -d ${FAKE_ROOT} -f $FAKE_ROOT/prototype -o
529echo | pkgtrans -os ${FAKE_ROOT} ${START}/$PKGNAME-$VERSION-$UNAME_S-$ARCH.pkg
530 ;;
531
532 justpkg.sh)
533rm -fr ${FAKE_ROOT}/${PKGNAME}
534grep -v "^PSTAMP=" $FAKE_ROOT/pkginfo > $$tmp
535mv $$tmp $FAKE_ROOT/pkginfo
536cat >> $FAKE_ROOT/pkginfo << _EOF
537PSTAMP="${UNAME_S} ${OS_VER} ${ARCH} `date '+%d%b%Y %H:%M'`"
538_EOF
539pkgmk -d ${FAKE_ROOT} -f $FAKE_ROOT/prototype -o
540echo | pkgtrans -os ${FAKE_ROOT} ${START}/$PKGNAME-$VERSION-$UNAME_S-$ARCH.pkg
541 ;;
542
543esac
544
545[ "${REMOVE_FAKE_ROOT_WHEN_DONE}" = yes ] && rm -rf $FAKE_ROOT
25616c13 546exit 0
9cefe228 547
This page took 0.239011 seconds and 5 git commands to generate.