3 # buildbff.sh: Create AIX SMIT-installable OpenSSH packages
5 # Author: Darren Tucker (dtucker at zip dot com dot au)
6 # This file is placed in the public domain and comes with absolutely
9 # Based originally on Ben Lindstrom's buildpkg.sh for Solaris
13 # Tunable configuration settings
14 # create a "config.local" in your build directory or set
15 # environment variables to override these.
17 [ -z "$PERMIT_ROOT_LOGIN" ] && PERMIT_ROOT_LOGIN=no
18 [ -z "$X11_FORWARDING" ] && X11_FORWARDING=no
19 [ -z "$AIX_SRC" ] && AIX_SRC=no
25 perl -v >/dev/null || (echo perl required; exit 1)
27 # Path to inventory.sh: same place as buildbff.sh
28 if echo $0 | egrep '^/'
30 inventory=`dirname $0`/inventory.sh # absolute path
32 inventory=`pwd`/`dirname $0`/inventory.sh # relative path
36 # We still support running from contrib/aix, but this is deprecated
38 if pwd | egrep 'contrib/aix$'
40 echo "Changing directory to `pwd`/../.."
41 echo "Please run buildbff.sh from your build directory in future."
48 echo "Makefile not found (did you run configure?)"
53 # Directories used during build:
54 # current dir = $objdir directory you ran ./configure in.
55 # $objdir/$PKGDIR/ directory package files are constructed in
56 # $objdir/$PKGDIR/root/ package root ($FAKE_ROOT)
63 # Collect local configuration settings to override defaults
65 if [ -s ./config.local ]
67 echo Reading local settings from config.local
72 # Fill in some details from Makefile, like prefix and sysconfdir
73 # the eval also expands variables like sysconfdir=${prefix}/etc
74 # provided they are eval'ed in the correct order
76 for confvar in prefix exec_prefix bindir sbindir libexecdir datadir mandir mansubdir sysconfdir piddir srcdir
78 eval $confvar=`grep "^$confvar=" $objdir/Makefile | cut -d = -f 2`
82 # Collect values of privsep user and privsep path
83 # currently only found in config.h
85 for confvar in SSH_PRIVSEP_USER PRIVSEP_PATH
87 eval $confvar=`awk '/#define[ \t]'$confvar'/{print $3}' $objdir/config.h`
90 # Set privsep defaults if not defined
91 if [ -z "$SSH_PRIVSEP_USER" ]
95 if [ -z "$PRIVSEP_PATH" ]
97 PRIVSEP_PATH=/var/empty
100 # Clean package build directory
101 rm -rf $objdir/$PKGDIR
102 FAKE_ROOT=$objdir/$PKGDIR/root
105 # Start by faking root install
106 echo "Faking root install..."
108 make install-nokeys DESTDIR=$FAKE_ROOT
112 echo "Fake root install failed, stopping."
117 # Copy informational files to include in package
119 cp $srcdir/LICENCE $objdir/$PKGDIR/
120 cp $srcdir/README* $objdir/$PKGDIR/
123 # Extract common info requires for the 'info' part of the package.
124 # AIX requires 4-part version numbers
126 VERSION=`./ssh -V 2>&1 | cut -f 1 -d , | cut -f 2 -d _`
127 MAJOR=`echo $VERSION | cut -f 1 -d p | cut -f 1 -d .`
128 MINOR=`echo $VERSION | cut -f 1 -d p | cut -f 2 -d .`
129 PATCH=`echo $VERSION | cut -f 1 -d p | cut -f 3 -d .`
130 PORTABLE=`echo $VERSION | awk 'BEGIN{FS="p"}{print $2}'`
131 [ "$PATCH" = "" ] && PATCH=0
132 [ "$PORTABLE" = "" ] && PORTABLE=0
133 BFFVERSION=`printf "%d.%d.%d.%d" $MAJOR $MINOR $PATCH $PORTABLE`
135 echo "Building BFF for $PKGNAME $VERSION (package version $BFFVERSION)"
138 # Set ssh and sshd parameters as per config.local
140 if [ "${PERMIT_ROOT_LOGIN}" = no ]
142 perl -p -i -e "s/#PermitRootLogin yes/PermitRootLogin no/" \
143 $FAKE_ROOT/${sysconfdir}/sshd_config
145 if [ "${X11_FORWARDING}" = yes ]
147 perl -p -i -e "s/#X11Forwarding no/X11Forwarding yes/" \
148 $FAKE_ROOT/${sysconfdir}/sshd_config
152 # Rename config files; postinstall script will copy them if necessary
153 for cfgfile in ssh_config sshd_config
155 mv $FAKE_ROOT/$sysconfdir/$cfgfile $FAKE_ROOT/$sysconfdir/$cfgfile.default
159 # Generate lpp control files.
160 # working dir is $FAKE_ROOT but files are generated in dir above
161 # and moved into place just before creation of .bff
164 echo Generating LPP control files
165 find . ! -name . -print >../openssh.al
166 $inventory >../openssh.inventory
168 cat <<EOD >../openssh.copyright
169 This software is distributed under a BSD-style license.
170 For the full text of the license, see /usr/lpp/openssh/LICENCE
174 # openssh.size file allows filesystem expansion as required
175 # generate list of directories containing files
176 # then calculate disk usage for each directory and store in openssh.size
178 files=`find . -type f -print`
179 dirs=`for file in $files; do dirname $file; done | sort -u`
183 done > ../openssh.size
186 # Create postinstall script
188 cat <<EOF >>../openssh.post_i
191 echo Creating configs from defaults if necessary.
192 for cfgfile in ssh_config sshd_config
194 if [ ! -f $sysconfdir/\$cfgfile ]
196 echo "Creating \$cfgfile from default"
197 cp $sysconfdir/\$cfgfile.default $sysconfdir/\$cfgfile
199 echo "\$cfgfile already exists."
204 # Create PrivilegeSeparation user and group if not present
205 echo Checking for PrivilegeSeparation user and group.
206 if cut -f1 -d: /etc/group | egrep '^'$SSH_PRIVSEP_USER'\$' >/dev/null
208 echo "PrivSep group $SSH_PRIVSEP_USER already exists."
210 echo "Creating PrivSep group $SSH_PRIVSEP_USER."
211 mkgroup -A $SSH_PRIVSEP_USER
214 # Create user if required
215 if lsuser "$SSH_PRIVSEP_USER" >/dev/null
217 echo "PrivSep user $SSH_PRIVSEP_USER already exists."
219 echo "Creating PrivSep user $SSH_PRIVSEP_USER."
220 mkuser gecos='SSHD PrivSep User' login=false rlogin=false account_locked=true pgrp=$SSH_PRIVSEP_USER $SSH_PRIVSEP_USER
223 if egrep '^[ \t]*UsePrivilegeSeparation[ \t]+no' $sysconfdir/sshd_config >/dev/null
225 echo UsePrivilegeSeparation not enabled, privsep directory not required.
227 # create chroot directory if required
228 if [ -d $PRIVSEP_PATH ]
230 echo "PrivSep chroot directory $PRIVSEP_PATH already exists."
232 echo "Creating PrivSep chroot directory $PRIVSEP_PATH."
234 chown 0 $PRIVSEP_PATH
235 chgrp 0 $PRIVSEP_PATH
236 chmod 755 $PRIVSEP_PATH
241 # Generate keys unless they already exist
242 echo Creating host keys if required.
243 $bindir/ssh-keygen -A
246 # Set startup command depending on SRC support
247 if [ "$AIX_SRC" = "yes" ]
249 echo Creating SRC sshd subsystem.
250 rmssys -s sshd 2>&1 >/dev/null
251 mkssys -s sshd -p "$sbindir/sshd" -a '-D' -u 0 -S -n 15 -f 9 -R -G tcpip
252 startupcmd="start $sbindir/sshd \\\"\\\$src_running\\\""
253 oldstartcmd="$sbindir/sshd"
255 startupcmd="$sbindir/sshd"
256 oldstartcmd="start $sbindir/sshd \\\"$src_running\\\""
259 # If migrating to or from SRC, change previous startup command
260 # otherwise add to rc.tcpip
261 if egrep "^\$oldstartcmd" /etc/rc.tcpip >/dev/null
263 if sed "s|^\$oldstartcmd|\$startupcmd|g" /etc/rc.tcpip >/etc/rc.tcpip.new
265 chmod 0755 /etc/rc.tcpip.new
266 mv /etc/rc.tcpip /etc/rc.tcpip.old && \
267 mv /etc/rc.tcpip.new /etc/rc.tcpip
269 echo "Updating /etc/rc.tcpip failed, please check."
272 # Add to system startup if required
273 if grep "^\$startupcmd" /etc/rc.tcpip >/dev/null
275 echo "sshd found in rc.tcpip, not adding."
277 echo "Adding sshd to rc.tcpip"
279 echo "# Start sshd" >>/etc/rc.tcpip
280 echo "\$startupcmd" >>/etc/rc.tcpip
286 # Create liblpp.a and move control files into it
288 echo Creating liblpp.a
291 for i in openssh.al openssh.copyright openssh.inventory openssh.post_i openssh.size LICENCE README*
301 # This will end up looking something like:
303 # OpenSSH 3.0.2.1 1 N U en_US OpenSSH 3.0.2p1 Portable for AIX
306 # /usr/local/bin 8073
308 # /usr/local/libexec 185
309 # /usr/local/man/man1 145
310 # /usr/local/man/man8 83
311 # /usr/local/sbin 2105
317 echo Creating lpp_name
318 cat <<EOF >../lpp_name
320 $PKGNAME $BFFVERSION 1 N U en_US OpenSSH $VERSION Portable for AIX
325 for i in $bindir $sysconfdir $libexecdir $mandir/${mansubdir}1 $mandir/${mansubdir}8 $sbindir $datadir /usr/lpp/openssh
327 # get size in 512 byte blocks
328 if [ -d $FAKE_ROOT/$i ]
330 size=`du $FAKE_ROOT/$i | awk '{print $1}'`
331 echo "$i $size" >>../lpp_name
335 echo '%' >>../lpp_name
336 echo ']' >>../lpp_name
337 echo '}' >>../lpp_name
340 # Move pieces into place
342 mkdir -p usr/lpp/openssh
343 mv ../liblpp.a usr/lpp/openssh
347 # Now invoke backup to create .bff file
348 # note: lpp_name needs to be the first file so we generate the
349 # file list on the fly and feed it to backup using -i
351 echo Creating $PKGNAME-$VERSION.bff with backup...
352 rm -f $PKGNAME-$VERSION.bff
355 find . ! -name lpp_name -a ! -name . -print
356 ) | backup -i -q -f ../$PKGNAME-$VERSION.bff $filelist
359 # Move package into final location and clean up
361 mv ../$PKGNAME-$VERSION.bff $startdir
363 rm -rf $objdir/$PKGDIR