blob: 4a5c32b0ecb9bbbe51ac1c1ed5b9a397de48e5b8 [file] [log] [blame]
Ben Lindstrom01e7fa12002-03-05 03:38:35 +00001#!/bin/sh
2#
3# buildbff.sh: Create AIX SMIT-installable OpenSSH packages
Damien Millera8e06ce2003-11-21 23:48:55 +11004# $Id: buildbff.sh,v 1.7 2003/11/21 12:48:56 djm Exp $
Ben Lindstrom01e7fa12002-03-05 03:38:35 +00005#
6# Author: Darren Tucker (dtucker at zip dot com dot au)
7# This file is placed in the public domain and comes with absolutely
8# no warranty.
Damien Millera8e06ce2003-11-21 23:48:55 +11009#
Ben Lindstrom01e7fa12002-03-05 03:38:35 +000010# Based originally on Ben Lindstrom's buildpkg.sh for Solaris
11#
12
Ben Lindstrom52237272002-06-25 23:38:47 +000013#
14# Tunable configuration settings
Damien Millerc9c1d372003-03-10 12:10:45 +110015# create a "config.local" in your build directory or set
16# environment variables to override these.
Ben Lindstrom52237272002-06-25 23:38:47 +000017#
Darren Tucker36ca53a2003-08-25 15:01:04 +100018[ -z "$PERMIT_ROOT_LOGIN" ] && PERMIT_ROOT_LOGIN=no
19[ -z "$X11_FORWARDING" ] && X11_FORWARDING=no
20[ -z "$AIX_SRC" ] && AIX_SRC=no
Ben Lindstrom52237272002-06-25 23:38:47 +000021
Ben Lindstrom01e7fa12002-03-05 03:38:35 +000022umask 022
Ben Lindstrom52237272002-06-25 23:38:47 +000023
Ben Lindstrom2faabf32002-07-18 01:04:50 +000024startdir=`pwd`
25
26# Path to inventory.sh: same place as buildbff.sh
27if echo $0 | egrep '^/'
28then
29 inventory=`dirname $0`/inventory.sh # absolute path
30else
31 inventory=`pwd`/`dirname $0`/inventory.sh # relative path
32fi
33
Ben Lindstrom52237272002-06-25 23:38:47 +000034#
Darren Tucker36ca53a2003-08-25 15:01:04 +100035# We still support running from contrib/aix, but this is deprecated
Ben Lindstrom52237272002-06-25 23:38:47 +000036#
37if pwd | egrep 'contrib/aix$'
38then
39 echo "Changing directory to `pwd`/../.."
40 echo "Please run buildbff.sh from your build directory in future."
41 cd ../..
42 contribaix=1
43fi
44
45if [ ! -f Makefile ]
46then
47 echo "Makefile not found (did you run configure?)"
Damien Millera8e06ce2003-11-21 23:48:55 +110048 exit 1
Ben Lindstrom52237272002-06-25 23:38:47 +000049fi
50
51#
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)
56#
57objdir=`pwd`
Ben Lindstrom01e7fa12002-03-05 03:38:35 +000058PKGNAME=openssh
Ben Lindstrom01e7fa12002-03-05 03:38:35 +000059PKGDIR=package
60
Ben Lindstrom52237272002-06-25 23:38:47 +000061#
62# Collect local configuration settings to override defaults
63#
64if [ -s ./config.local ]
65then
66 echo Reading local settings from config.local
67 . ./config.local
68fi
69
70#
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
74#
75for confvar in prefix exec_prefix bindir sbindir libexecdir datadir mandir mansubdir sysconfdir piddir srcdir
76do
77 eval $confvar=`grep "^$confvar=" $objdir/Makefile | cut -d = -f 2`
78done
79
80#
81# Collect values of privsep user and privsep path
82# currently only found in config.h
83#
84for confvar in SSH_PRIVSEP_USER PRIVSEP_PATH
85do
86 eval $confvar=`awk '/#define[ \t]'$confvar'/{print $3}' $objdir/config.h`
87done
88
89# Set privsep defaults if not defined
90if [ -z "$SSH_PRIVSEP_USER" ]
91then
92 SSH_PRIVSEP_USER=sshd
93fi
94if [ -z "$PRIVSEP_PATH" ]
95then
96 PRIVSEP_PATH=/var/empty
97fi
98
Damien Millera8e06ce2003-11-21 23:48:55 +110099# Clean package build directory
Ben Lindstrom52237272002-06-25 23:38:47 +0000100rm -rf $objdir/$PKGDIR
101FAKE_ROOT=$objdir/$PKGDIR/root
102mkdir -p $FAKE_ROOT
103
Damien Millera8e06ce2003-11-21 23:48:55 +1100104# Start by faking root install
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000105echo "Faking root install..."
Ben Lindstrom52237272002-06-25 23:38:47 +0000106cd $objdir
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000107make install-nokeys DESTDIR=$FAKE_ROOT
108
Tim Rice3a423462002-03-17 14:05:24 -0800109if [ $? -gt 0 ]
110then
111 echo "Fake root install failed, stopping."
112 exit 1
113fi
114
115#
Ben Lindstrom52237272002-06-25 23:38:47 +0000116# Copy informational files to include in package
117#
118cp $srcdir/LICENCE $objdir/$PKGDIR/
119cp $srcdir/README* $objdir/$PKGDIR/
120
121#
Tim Rice3a423462002-03-17 14:05:24 -0800122# Extract common info requires for the 'info' part of the package.
123# AIX requires 4-part version numbers
124#
Darren Tucker36ca53a2003-08-25 15:01:04 +1000125VERSION=`./ssh -V 2>&1 | cut -f 1 -d , | cut -f 2 -d _`
Tim Rice3a423462002-03-17 14:05:24 -0800126MAJOR=`echo $VERSION | cut -f 1 -d p | cut -f 1 -d .`
127MINOR=`echo $VERSION | cut -f 1 -d p | cut -f 2 -d .`
128PATCH=`echo $VERSION | cut -f 1 -d p | cut -f 3 -d .`
Ben Lindstrom52237272002-06-25 23:38:47 +0000129PORTABLE=`echo $VERSION | awk 'BEGIN{FS="p"}{print $2}'`
130[ "$PATCH" = "" ] && PATCH=0
131[ "$PORTABLE" = "" ] && PORTABLE=0
Tim Rice3a423462002-03-17 14:05:24 -0800132BFFVERSION=`printf "%d.%d.%d.%d" $MAJOR $MINOR $PATCH $PORTABLE`
133
134echo "Building BFF for $PKGNAME $VERSION (package version $BFFVERSION)"
135
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000136#
Ben Lindstrom52237272002-06-25 23:38:47 +0000137# Set ssh and sshd parameters as per config.local
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000138#
Damien Millera8e06ce2003-11-21 23:48:55 +1100139if [ "${PERMIT_ROOT_LOGIN}" = no ]
Ben Lindstrom52237272002-06-25 23:38:47 +0000140then
Damien Millera8e06ce2003-11-21 23:48:55 +1100141 perl -p -i -e "s/#PermitRootLogin yes/PermitRootLogin no/" \
142 $FAKE_ROOT/${sysconfdir}/sshd_config
Ben Lindstrom52237272002-06-25 23:38:47 +0000143fi
144if [ "${X11_FORWARDING}" = yes ]
145then
Damien Millera8e06ce2003-11-21 23:48:55 +1100146 perl -p -i -e "s/#X11Forwarding no/X11Forwarding yes/" \
147 $FAKE_ROOT/${sysconfdir}/sshd_config
Ben Lindstrom52237272002-06-25 23:38:47 +0000148fi
149
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000150
151# Rename config files; postinstall script will copy them if necessary
152for cfgfile in ssh_config sshd_config ssh_prng_cmds
153do
154 mv $FAKE_ROOT/$sysconfdir/$cfgfile $FAKE_ROOT/$sysconfdir/$cfgfile.default
155done
156
157#
158# Generate lpp control files.
Ben Lindstrom52237272002-06-25 23:38:47 +0000159# working dir is $FAKE_ROOT but files are generated in dir above
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000160# and moved into place just before creation of .bff
161#
162cd $FAKE_ROOT
163echo Generating LPP control files
164find . ! -name . -print >../openssh.al
Ben Lindstrom52237272002-06-25 23:38:47 +0000165$inventory >../openssh.inventory
166
167cat <<EOD >../openssh.copyright
168This software is distributed under a BSD-style license.
169For the full text of the license, see /usr/lpp/openssh/LICENCE
170EOD
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000171
172#
Damien Millerc9c1d372003-03-10 12:10:45 +1100173# 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
176#
177files=`find . -type f -print`
178dirs=`for file in $files; do dirname $file; done | sort -u`
179for dir in $dirs
180do
181 du $dir
182done > ../openssh.size
183
184#
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000185# Create postinstall script
186#
187cat <<EOF >>../openssh.post_i
188#!/bin/sh
189
Ben Lindstrom52237272002-06-25 23:38:47 +0000190echo Creating configs from defaults if necessary.
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000191for cfgfile in ssh_config sshd_config ssh_prng_cmds
192do
Damien Millera8e06ce2003-11-21 23:48:55 +1100193 if [ ! -f $sysconfdir/\$cfgfile ]
194 then
195 echo "Creating \$cfgfile from default"
196 cp $sysconfdir/\$cfgfile.default $sysconfdir/\$cfgfile
197 else
198 echo "\$cfgfile already exists."
199 fi
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000200done
Ben Lindstrom52237272002-06-25 23:38:47 +0000201echo
202
203# Create PrivSep user if PrivSep not disabled in config
204echo Creating PrivSep prereqs if required.
205if egrep '^[ \t]*UsePrivilegeSeparation[ \t]+no' $sysconfdir/sshd_config >/dev/null
206then
207 echo "UsePrivilegeSeparation disabled in config, not creating PrivSep user,"
208 echo "group or chroot directory."
209else
210 echo "UsePrivilegeSeparation enabled in config (or defaulting to on)."
211
212 # create group if required
213 if cut -f1 -d: /etc/group | egrep '^'$SSH_PRIVSEP_USER'\$' >/dev/null
214 then
215 echo "PrivSep group $SSH_PRIVSEP_USER already exists."
216 else
217 echo "Creating PrivSep group $SSH_PRIVSEP_USER."
218 mkgroup -A $SSH_PRIVSEP_USER
219 fi
220
221 # Create user if required
Darren Tucker36ca53a2003-08-25 15:01:04 +1000222 if lsuser ALL | cut -f1 -d: | egrep '^'$SSH_PRIVSEP_USER'\$' >/dev/null
Ben Lindstrom52237272002-06-25 23:38:47 +0000223 then
224 echo "PrivSep user $SSH_PRIVSEP_USER already exists."
225 else
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
228 fi
229
230 # create chroot directory if required
231 if [ -d $PRIVSEP_PATH ]
232 then
233 echo "PrivSep chroot directory $PRIVSEP_PATH already exists."
234 else
235 echo "Creating PrivSep chroot directory $PRIVSEP_PATH."
236 mkdir $PRIVSEP_PATH
237 chown 0 $PRIVSEP_PATH
238 chgrp 0 $PRIVSEP_PATH
239 chmod 755 $PRIVSEP_PATH
240 fi
241fi
242echo
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000243
244# Generate keys unless they already exist
Ben Lindstrom52237272002-06-25 23:38:47 +0000245echo Creating host keys if required.
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000246if [ -f "$sysconfdir/ssh_host_key" ] ; then
Damien Millera8e06ce2003-11-21 23:48:55 +1100247 echo "$sysconfdir/ssh_host_key already exists, skipping."
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000248else
Damien Millera8e06ce2003-11-21 23:48:55 +1100249 $bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N ""
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000250fi
251if [ -f $sysconfdir/ssh_host_dsa_key ] ; then
Damien Millera8e06ce2003-11-21 23:48:55 +1100252 echo "$sysconfdir/ssh_host_dsa_key already exists, skipping."
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000253else
Damien Millera8e06ce2003-11-21 23:48:55 +1100254 $bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N ""
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000255fi
256if [ -f $sysconfdir/ssh_host_rsa_key ] ; then
Damien Millera8e06ce2003-11-21 23:48:55 +1100257 echo "$sysconfdir/ssh_host_rsa_key already exists, skipping."
258else
259 $bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N ""
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000260fi
Ben Lindstrom52237272002-06-25 23:38:47 +0000261echo
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000262
Damien Millerc9c1d372003-03-10 12:10:45 +1100263# Set startup command depending on SRC support
264if [ "$AIX_SRC" = "yes" ]
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000265then
Damien Millerc9c1d372003-03-10 12:10:45 +1100266 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"
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000271else
Damien Millerc9c1d372003-03-10 12:10:45 +1100272 startupcmd="$sbindir/sshd"
273 oldstartcmd="start $sbindir/sshd \\\"$src_running\\\""
274fi
275
276# If migrating to or from SRC, change previous startup command
277# otherwise add to rc.tcpip
278if egrep "^\$oldstartcmd" /etc/rc.tcpip >/dev/null
279then
280 if sed "s|^\$oldstartcmd|\$startupcmd|g" /etc/rc.tcpip >/etc/rc.tcpip.new
281 then
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
285 else
286 echo "Updating /etc/rc.tcpip failed, please check."
287 fi
288else
289 # Add to system startup if required
290 if grep "^\$startupcmd" /etc/rc.tcpip >/dev/null
291 then
292 echo "sshd found in rc.tcpip, not adding."
293 else
294 echo "Adding sshd to rc.tcpip"
295 echo >>/etc/rc.tcpip
296 echo "# Start sshd" >>/etc/rc.tcpip
297 echo "\$startupcmd" >>/etc/rc.tcpip
298 fi
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000299fi
300EOF
301
302#
303# Create liblpp.a and move control files into it
304#
305echo Creating liblpp.a
306(
307 cd ..
Damien Millerc9c1d372003-03-10 12:10:45 +1100308 for i in openssh.al openssh.copyright openssh.inventory openssh.post_i openssh.size LICENCE README*
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000309 do
Ben Lindstrom52237272002-06-25 23:38:47 +0000310 ar -r liblpp.a $i
311 rm $i
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000312 done
313)
314
315#
316# Create lpp_name
317#
318# This will end up looking something like:
319# 4 R I OpenSSH {
320# OpenSSH 3.0.2.1 1 N U en_US OpenSSH 3.0.2p1 Portable for AIX
321# [
322# %
323# /usr/local/bin 8073
324# /usr/local/etc 189
325# /usr/local/libexec 185
326# /usr/local/man/man1 145
327# /usr/local/man/man8 83
328# /usr/local/sbin 2105
329# /usr/local/share 3
330# %
331# ]
Ben Lindstrom52237272002-06-25 23:38:47 +0000332# }
333
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000334echo Creating lpp_name
335cat <<EOF >../lpp_name
3364 R I $PKGNAME {
337$PKGNAME $BFFVERSION 1 N U en_US OpenSSH $VERSION Portable for AIX
338[
339%
340EOF
341
Ben Lindstrom52237272002-06-25 23:38:47 +0000342for i in $bindir $sysconfdir $libexecdir $mandir/${mansubdir}1 $mandir/${mansubdir}8 $sbindir $datadir /usr/lpp/openssh
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000343do
344 # get size in 512 byte blocks
Ben Lindstrom52237272002-06-25 23:38:47 +0000345 if [ -d $FAKE_ROOT/$i ]
346 then
347 size=`du $FAKE_ROOT/$i | awk '{print $1}'`
348 echo "$i $size" >>../lpp_name
349 fi
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000350done
351
352echo '%' >>../lpp_name
353echo ']' >>../lpp_name
354echo '}' >>../lpp_name
355
356#
357# Move pieces into place
358#
359mkdir -p usr/lpp/openssh
360mv ../liblpp.a usr/lpp/openssh
361mv ../lpp_name .
362
363#
364# Now invoke backup to create .bff file
Ben Lindstrom52237272002-06-25 23:38:47 +0000365# note: lpp_name needs to be the first file so we generate the
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000366# file list on the fly and feed it to backup using -i
367#
368echo Creating $PKGNAME-$VERSION.bff with backup...
Tim Rice3a423462002-03-17 14:05:24 -0800369rm -f $PKGNAME-$VERSION.bff
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000370(
371 echo "./lpp_name"
Damien Millera8e06ce2003-11-21 23:48:55 +1100372 find . ! -name lpp_name -a ! -name . -print
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000373) | backup -i -q -f ../$PKGNAME-$VERSION.bff $filelist
374
Ben Lindstrom52237272002-06-25 23:38:47 +0000375#
Ben Lindstrom2faabf32002-07-18 01:04:50 +0000376# Move package into final location and clean up
Ben Lindstrom52237272002-06-25 23:38:47 +0000377#
Ben Lindstrom2faabf32002-07-18 01:04:50 +0000378mv ../$PKGNAME-$VERSION.bff $startdir
379cd $startdir
Ben Lindstrom52237272002-06-25 23:38:47 +0000380rm -rf $objdir/$PKGDIR
381
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000382echo $0: done.
383