3 # buildbff.sh: Create AIX SMIT-installable OpenSSH packages
4 # $Id: buildbff.sh,v 1.7 2003/11/21 12:48:56 djm Exp $
6 # Author: Darren Tucker (dtucker at zip dot com dot au)
7 # This file is placed in the public domain and comes with absolutely
10 # Based originally on Ben Lindstrom's buildpkg.sh for Solaris
14 # Tunable configuration settings
15 # create a "config.local" in your build directory or set
16 # environment variables to override these.
18 [ -z "$PERMIT_ROOT_LOGIN" ] && PERMIT_ROOT_LOGIN=no
19 [ -z "$X11_FORWARDING" ] && X11_FORWARDING=no
20 [ -z "$AIX_SRC" ] && AIX_SRC=no
26 # Path to inventory.sh: same place as buildbff.sh
27 if echo $0 | egrep '^/'
29 inventory=`dirname $0`/inventory.sh # absolute path
31 inventory=`pwd`/`dirname $0`/inventory.sh # relative path
35 # We still support running from contrib/aix, but this is deprecated
37 if pwd | egrep 'contrib/aix$'
39 echo "Changing directory to `pwd`/../.."
40 echo "Please run buildbff.sh from your build directory in future."
47 echo "Makefile not found (did you run configure?)"
52 # Directories used during build:
53 # current dir = $objdir directory you ran ./configure in.
54 # $objdir/$PKGDIR/ directory package files are constructed in
55 # $objdir/$PKGDIR/root/ package root ($FAKE_ROOT)
62 # Collect local configuration settings to override defaults
64 if [ -s ./config.local ]
66 echo Reading local settings from config.local
71 # Fill in some details from Makefile, like prefix and sysconfdir
72 # the eval also expands variables like sysconfdir=${prefix}/etc
73 # provided they are eval'ed in the correct order
75 for confvar in prefix exec_prefix bindir sbindir libexecdir datadir mandir mansubdir sysconfdir piddir srcdir
77 eval $confvar=`grep "^$confvar=" $objdir/Makefile | cut -d = -f 2`
81 # Collect values of privsep user and privsep path
82 # currently only found in config.h
84 for confvar in SSH_PRIVSEP_USER PRIVSEP_PATH
86 eval $confvar=`awk '/#define[ \t]'$confvar'/{print $3}' $objdir/config.h`
89 # Set privsep defaults if not defined
90 if [ -z "$SSH_PRIVSEP_USER" ]
94 if [ -z "$PRIVSEP_PATH" ]
96 PRIVSEP_PATH=/var/empty
99 # Clean package build directory
100 rm -rf $objdir/$PKGDIR
101 FAKE_ROOT=$objdir/$PKGDIR/root
104 # Start by faking root install
105 echo "Faking root install..."
107 make install-nokeys DESTDIR=$FAKE_ROOT
111 echo "Fake root install failed, stopping."
116 # Copy informational files to include in package
118 cp $srcdir/LICENCE $objdir/$PKGDIR/
119 cp $srcdir/README* $objdir/$PKGDIR/
122 # Extract common info requires for the 'info' part of the package.
123 # AIX requires 4-part version numbers
125 VERSION=`./ssh -V 2>&1 | cut -f 1 -d , | cut -f 2 -d _`
126 MAJOR=`echo $VERSION | cut -f 1 -d p | cut -f 1 -d .`
127 MINOR=`echo $VERSION | cut -f 1 -d p | cut -f 2 -d .`
128 PATCH=`echo $VERSION | cut -f 1 -d p | cut -f 3 -d .`
129 PORTABLE=`echo $VERSION | awk 'BEGIN{FS="p"}{print $2}'`
130 [ "$PATCH" = "" ] && PATCH=0
131 [ "$PORTABLE" = "" ] && PORTABLE=0
132 BFFVERSION=`printf "%d.%d.%d.%d" $MAJOR $MINOR $PATCH $PORTABLE`
134 echo "Building BFF for $PKGNAME $VERSION (package version $BFFVERSION)"
137 # Set ssh and sshd parameters as per config.local
139 if [ "${PERMIT_ROOT_LOGIN}" = no ]
141 perl -p -i -e "s/#PermitRootLogin yes/PermitRootLogin no/" \
142 $FAKE_ROOT/${sysconfdir}/sshd_config
144 if [ "${X11_FORWARDING}" = yes ]
146 perl -p -i -e "s/#X11Forwarding no/X11Forwarding yes/" \
147 $FAKE_ROOT/${sysconfdir}/sshd_config
151 # Rename config files; postinstall script will copy them if necessary
152 for cfgfile in ssh_config sshd_config ssh_prng_cmds
154 mv $FAKE_ROOT/$sysconfdir/$cfgfile $FAKE_ROOT/$sysconfdir/$cfgfile.default
158 # Generate lpp control files.
159 # working dir is $FAKE_ROOT but files are generated in dir above
160 # and moved into place just before creation of .bff
163 echo Generating LPP control files
164 find . ! -name . -print >../openssh.al
165 $inventory >../openssh.inventory
167 cat <<EOD >../openssh.copyright
168 This software is distributed under a BSD-style license.
169 For the full text of the license, see /usr/lpp/openssh/LICENCE
173 # openssh.size file allows filesystem expansion as required
174 # generate list of directories containing files
175 # then calculate disk usage for each directory and store in openssh.size
177 files=`find . -type f -print`
178 dirs=`for file in $files; do dirname $file; done | sort -u`
182 done > ../openssh.size
185 # Create postinstall script
187 cat <<EOF >>../openssh.post_i
190 echo Creating configs from defaults if necessary.
191 for cfgfile in ssh_config sshd_config ssh_prng_cmds
193 if [ ! -f $sysconfdir/\$cfgfile ]
195 echo "Creating \$cfgfile from default"
196 cp $sysconfdir/\$cfgfile.default $sysconfdir/\$cfgfile
198 echo "\$cfgfile already exists."
203 # Create PrivSep user if PrivSep not disabled in config
204 echo Creating PrivSep prereqs if required.
205 if egrep '^[ \t]*UsePrivilegeSeparation[ \t]+no' $sysconfdir/sshd_config >/dev/null
207 echo "UsePrivilegeSeparation disabled in config, not creating PrivSep user,"
208 echo "group or chroot directory."
210 echo "UsePrivilegeSeparation enabled in config (or defaulting to on)."
212 # create group if required
213 if cut -f1 -d: /etc/group | egrep '^'$SSH_PRIVSEP_USER'\$' >/dev/null
215 echo "PrivSep group $SSH_PRIVSEP_USER already exists."
217 echo "Creating PrivSep group $SSH_PRIVSEP_USER."
218 mkgroup -A $SSH_PRIVSEP_USER
221 # Create user if required
222 if lsuser ALL | cut -f1 -d: | egrep '^'$SSH_PRIVSEP_USER'\$' >/dev/null
224 echo "PrivSep user $SSH_PRIVSEP_USER already exists."
226 echo "Creating PrivSep user $SSH_PRIVSEP_USER."
227 mkuser gecos='SSHD PrivSep User' login=false rlogin=false account_locked=true pgrp=$SSH_PRIVSEP_USER $SSH_PRIVSEP_USER
230 # create chroot directory if required
231 if [ -d $PRIVSEP_PATH ]
233 echo "PrivSep chroot directory $PRIVSEP_PATH already exists."
235 echo "Creating PrivSep chroot directory $PRIVSEP_PATH."
237 chown 0 $PRIVSEP_PATH
238 chgrp 0 $PRIVSEP_PATH
239 chmod 755 $PRIVSEP_PATH
244 # Generate keys unless they already exist
245 echo Creating host keys if required.
246 if [ -f "$sysconfdir/ssh_host_key" ] ; then
247 echo "$sysconfdir/ssh_host_key already exists, skipping."
249 $bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N ""
251 if [ -f $sysconfdir/ssh_host_dsa_key ] ; then
252 echo "$sysconfdir/ssh_host_dsa_key already exists, skipping."
254 $bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N ""
256 if [ -f $sysconfdir/ssh_host_rsa_key ] ; then
257 echo "$sysconfdir/ssh_host_rsa_key already exists, skipping."
259 $bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N ""
263 # Set startup command depending on SRC support
264 if [ "$AIX_SRC" = "yes" ]
266 echo Creating SRC sshd subsystem.
267 rmssys -s sshd 2>&1 >/dev/null
268 mkssys -s sshd -p "$sbindir/sshd" -a '-D' -u 0 -S -n 15 -f 9 -R -G tcpip
269 startupcmd="start $sbindir/sshd \\\"\\\$src_running\\\""
270 oldstartcmd="$sbindir/sshd"
272 startupcmd="$sbindir/sshd"
273 oldstartcmd="start $sbindir/sshd \\\"$src_running\\\""
276 # If migrating to or from SRC, change previous startup command
277 # otherwise add to rc.tcpip
278 if egrep "^\$oldstartcmd" /etc/rc.tcpip >/dev/null
280 if sed "s|^\$oldstartcmd|\$startupcmd|g" /etc/rc.tcpip >/etc/rc.tcpip.new
282 chmod 0755 /etc/rc.tcpip.new
283 mv /etc/rc.tcpip /etc/rc.tcpip.old && \
284 mv /etc/rc.tcpip.new /etc/rc.tcpip
286 echo "Updating /etc/rc.tcpip failed, please check."
289 # Add to system startup if required
290 if grep "^\$startupcmd" /etc/rc.tcpip >/dev/null
292 echo "sshd found in rc.tcpip, not adding."
294 echo "Adding sshd to rc.tcpip"
296 echo "# Start sshd" >>/etc/rc.tcpip
297 echo "\$startupcmd" >>/etc/rc.tcpip
303 # Create liblpp.a and move control files into it
305 echo Creating liblpp.a
308 for i in openssh.al openssh.copyright openssh.inventory openssh.post_i openssh.size LICENCE README*
318 # This will end up looking something like:
320 # OpenSSH 3.0.2.1 1 N U en_US OpenSSH 3.0.2p1 Portable for AIX
323 # /usr/local/bin 8073
325 # /usr/local/libexec 185
326 # /usr/local/man/man1 145
327 # /usr/local/man/man8 83
328 # /usr/local/sbin 2105
334 echo Creating lpp_name
335 cat <<EOF >../lpp_name
337 $PKGNAME $BFFVERSION 1 N U en_US OpenSSH $VERSION Portable for AIX
342 for i in $bindir $sysconfdir $libexecdir $mandir/${mansubdir}1 $mandir/${mansubdir}8 $sbindir $datadir /usr/lpp/openssh
344 # get size in 512 byte blocks
345 if [ -d $FAKE_ROOT/$i ]
347 size=`du $FAKE_ROOT/$i | awk '{print $1}'`
348 echo "$i $size" >>../lpp_name
352 echo '%' >>../lpp_name
353 echo ']' >>../lpp_name
354 echo '}' >>../lpp_name
357 # Move pieces into place
359 mkdir -p usr/lpp/openssh
360 mv ../liblpp.a usr/lpp/openssh
364 # Now invoke backup to create .bff file
365 # note: lpp_name needs to be the first file so we generate the
366 # file list on the fly and feed it to backup using -i
368 echo Creating $PKGNAME-$VERSION.bff with backup...
369 rm -f $PKGNAME-$VERSION.bff
372 find . ! -name lpp_name -a ! -name . -print
373 ) | backup -i -q -f ../$PKGNAME-$VERSION.bff $filelist
376 # Move package into final location and clean up
378 mv ../$PKGNAME-$VERSION.bff $startdir
380 rm -rf $objdir/$PKGDIR