blob: 97a7cbbba9a2b779d2c7e27b97e51b2714f33928 [file] [log] [blame]
Ben Lindstrom01e7fa12002-03-05 03:38:35 +00001#!/bin/sh
2#
3# buildbff.sh: Create AIX SMIT-installable OpenSSH packages
Darren Tuckerf3766692006-09-10 13:24:18 +10004# $Id: buildbff.sh,v 1.10 2006/09/10 03:24:19 dtucker 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
Darren Tuckerf3766692006-09-10 13:24:18 +100026perl -v >/dev/null || (echo perl required; exit 1)
27
Ben Lindstrom2faabf32002-07-18 01:04:50 +000028# Path to inventory.sh: same place as buildbff.sh
29if echo $0 | egrep '^/'
30then
31 inventory=`dirname $0`/inventory.sh # absolute path
32else
33 inventory=`pwd`/`dirname $0`/inventory.sh # relative path
34fi
35
Ben Lindstrom52237272002-06-25 23:38:47 +000036#
Darren Tucker36ca53a2003-08-25 15:01:04 +100037# We still support running from contrib/aix, but this is deprecated
Ben Lindstrom52237272002-06-25 23:38:47 +000038#
39if pwd | egrep 'contrib/aix$'
40then
41 echo "Changing directory to `pwd`/../.."
42 echo "Please run buildbff.sh from your build directory in future."
43 cd ../..
44 contribaix=1
45fi
46
47if [ ! -f Makefile ]
48then
49 echo "Makefile not found (did you run configure?)"
Damien Millera8e06ce2003-11-21 23:48:55 +110050 exit 1
Ben Lindstrom52237272002-06-25 23:38:47 +000051fi
52
53#
54# Directories used during build:
55# current dir = $objdir directory you ran ./configure in.
56# $objdir/$PKGDIR/ directory package files are constructed in
57# $objdir/$PKGDIR/root/ package root ($FAKE_ROOT)
58#
59objdir=`pwd`
Ben Lindstrom01e7fa12002-03-05 03:38:35 +000060PKGNAME=openssh
Ben Lindstrom01e7fa12002-03-05 03:38:35 +000061PKGDIR=package
62
Ben Lindstrom52237272002-06-25 23:38:47 +000063#
64# Collect local configuration settings to override defaults
65#
66if [ -s ./config.local ]
67then
68 echo Reading local settings from config.local
69 . ./config.local
70fi
71
72#
73# Fill in some details from Makefile, like prefix and sysconfdir
74# the eval also expands variables like sysconfdir=${prefix}/etc
75# provided they are eval'ed in the correct order
76#
77for confvar in prefix exec_prefix bindir sbindir libexecdir datadir mandir mansubdir sysconfdir piddir srcdir
78do
79 eval $confvar=`grep "^$confvar=" $objdir/Makefile | cut -d = -f 2`
80done
81
82#
83# Collect values of privsep user and privsep path
84# currently only found in config.h
85#
86for confvar in SSH_PRIVSEP_USER PRIVSEP_PATH
87do
88 eval $confvar=`awk '/#define[ \t]'$confvar'/{print $3}' $objdir/config.h`
89done
90
91# Set privsep defaults if not defined
92if [ -z "$SSH_PRIVSEP_USER" ]
93then
94 SSH_PRIVSEP_USER=sshd
95fi
96if [ -z "$PRIVSEP_PATH" ]
97then
98 PRIVSEP_PATH=/var/empty
99fi
100
Damien Millera8e06ce2003-11-21 23:48:55 +1100101# Clean package build directory
Ben Lindstrom52237272002-06-25 23:38:47 +0000102rm -rf $objdir/$PKGDIR
103FAKE_ROOT=$objdir/$PKGDIR/root
104mkdir -p $FAKE_ROOT
105
Damien Millera8e06ce2003-11-21 23:48:55 +1100106# Start by faking root install
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000107echo "Faking root install..."
Ben Lindstrom52237272002-06-25 23:38:47 +0000108cd $objdir
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000109make install-nokeys DESTDIR=$FAKE_ROOT
110
Tim Rice3a423462002-03-17 14:05:24 -0800111if [ $? -gt 0 ]
112then
113 echo "Fake root install failed, stopping."
114 exit 1
115fi
116
117#
Ben Lindstrom52237272002-06-25 23:38:47 +0000118# Copy informational files to include in package
119#
120cp $srcdir/LICENCE $objdir/$PKGDIR/
121cp $srcdir/README* $objdir/$PKGDIR/
122
123#
Tim Rice3a423462002-03-17 14:05:24 -0800124# Extract common info requires for the 'info' part of the package.
125# AIX requires 4-part version numbers
126#
Darren Tucker36ca53a2003-08-25 15:01:04 +1000127VERSION=`./ssh -V 2>&1 | cut -f 1 -d , | cut -f 2 -d _`
Tim Rice3a423462002-03-17 14:05:24 -0800128MAJOR=`echo $VERSION | cut -f 1 -d p | cut -f 1 -d .`
129MINOR=`echo $VERSION | cut -f 1 -d p | cut -f 2 -d .`
130PATCH=`echo $VERSION | cut -f 1 -d p | cut -f 3 -d .`
Ben Lindstrom52237272002-06-25 23:38:47 +0000131PORTABLE=`echo $VERSION | awk 'BEGIN{FS="p"}{print $2}'`
132[ "$PATCH" = "" ] && PATCH=0
133[ "$PORTABLE" = "" ] && PORTABLE=0
Tim Rice3a423462002-03-17 14:05:24 -0800134BFFVERSION=`printf "%d.%d.%d.%d" $MAJOR $MINOR $PATCH $PORTABLE`
135
136echo "Building BFF for $PKGNAME $VERSION (package version $BFFVERSION)"
137
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000138#
Ben Lindstrom52237272002-06-25 23:38:47 +0000139# Set ssh and sshd parameters as per config.local
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000140#
Damien Millera8e06ce2003-11-21 23:48:55 +1100141if [ "${PERMIT_ROOT_LOGIN}" = no ]
Ben Lindstrom52237272002-06-25 23:38:47 +0000142then
Damien Millera8e06ce2003-11-21 23:48:55 +1100143 perl -p -i -e "s/#PermitRootLogin yes/PermitRootLogin no/" \
144 $FAKE_ROOT/${sysconfdir}/sshd_config
Ben Lindstrom52237272002-06-25 23:38:47 +0000145fi
146if [ "${X11_FORWARDING}" = yes ]
147then
Damien Millera8e06ce2003-11-21 23:48:55 +1100148 perl -p -i -e "s/#X11Forwarding no/X11Forwarding yes/" \
149 $FAKE_ROOT/${sysconfdir}/sshd_config
Ben Lindstrom52237272002-06-25 23:38:47 +0000150fi
151
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000152
153# Rename config files; postinstall script will copy them if necessary
154for cfgfile in ssh_config sshd_config ssh_prng_cmds
155do
156 mv $FAKE_ROOT/$sysconfdir/$cfgfile $FAKE_ROOT/$sysconfdir/$cfgfile.default
157done
158
159#
160# Generate lpp control files.
Ben Lindstrom52237272002-06-25 23:38:47 +0000161# working dir is $FAKE_ROOT but files are generated in dir above
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000162# and moved into place just before creation of .bff
163#
164cd $FAKE_ROOT
165echo Generating LPP control files
166find . ! -name . -print >../openssh.al
Ben Lindstrom52237272002-06-25 23:38:47 +0000167$inventory >../openssh.inventory
168
169cat <<EOD >../openssh.copyright
170This software is distributed under a BSD-style license.
171For the full text of the license, see /usr/lpp/openssh/LICENCE
172EOD
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000173
174#
Damien Millerc9c1d372003-03-10 12:10:45 +1100175# openssh.size file allows filesystem expansion as required
176# generate list of directories containing files
177# then calculate disk usage for each directory and store in openssh.size
178#
179files=`find . -type f -print`
180dirs=`for file in $files; do dirname $file; done | sort -u`
181for dir in $dirs
182do
183 du $dir
184done > ../openssh.size
185
186#
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000187# Create postinstall script
188#
189cat <<EOF >>../openssh.post_i
190#!/bin/sh
191
Ben Lindstrom52237272002-06-25 23:38:47 +0000192echo Creating configs from defaults if necessary.
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000193for cfgfile in ssh_config sshd_config ssh_prng_cmds
194do
Damien Millera8e06ce2003-11-21 23:48:55 +1100195 if [ ! -f $sysconfdir/\$cfgfile ]
196 then
197 echo "Creating \$cfgfile from default"
198 cp $sysconfdir/\$cfgfile.default $sysconfdir/\$cfgfile
199 else
200 echo "\$cfgfile already exists."
201 fi
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000202done
Ben Lindstrom52237272002-06-25 23:38:47 +0000203echo
204
Darren Tucker19a66db2006-09-09 20:34:15 +1000205# Create PrivilegeSeparation user and group if not present
206echo Checking for PrivilegeSeparation user and group.
207if cut -f1 -d: /etc/group | egrep '^'$SSH_PRIVSEP_USER'\$' >/dev/null
208then
209 echo "PrivSep group $SSH_PRIVSEP_USER already exists."
210else
211 echo "Creating PrivSep group $SSH_PRIVSEP_USER."
212 mkgroup -A $SSH_PRIVSEP_USER
213fi
214
215# Create user if required
216if lsuser "$SSH_PRIVSEP_USER" >/dev/null
217then
218 echo "PrivSep user $SSH_PRIVSEP_USER already exists."
219else
220 echo "Creating PrivSep user $SSH_PRIVSEP_USER."
221 mkuser gecos='SSHD PrivSep User' login=false rlogin=false account_locked=true pgrp=$SSH_PRIVSEP_USER $SSH_PRIVSEP_USER
222fi
223
Ben Lindstrom52237272002-06-25 23:38:47 +0000224if egrep '^[ \t]*UsePrivilegeSeparation[ \t]+no' $sysconfdir/sshd_config >/dev/null
225then
Darren Tucker19a66db2006-09-09 20:34:15 +1000226 echo UsePrivilegeSeparation not enabled, privsep directory not required.
Ben Lindstrom52237272002-06-25 23:38:47 +0000227else
Ben Lindstrom52237272002-06-25 23:38:47 +0000228 # create chroot directory if required
229 if [ -d $PRIVSEP_PATH ]
230 then
231 echo "PrivSep chroot directory $PRIVSEP_PATH already exists."
232 else
233 echo "Creating PrivSep chroot directory $PRIVSEP_PATH."
234 mkdir $PRIVSEP_PATH
235 chown 0 $PRIVSEP_PATH
236 chgrp 0 $PRIVSEP_PATH
237 chmod 755 $PRIVSEP_PATH
238 fi
239fi
240echo
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000241
242# Generate keys unless they already exist
Ben Lindstrom52237272002-06-25 23:38:47 +0000243echo Creating host keys if required.
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000244if [ -f "$sysconfdir/ssh_host_key" ] ; then
Damien Millera8e06ce2003-11-21 23:48:55 +1100245 echo "$sysconfdir/ssh_host_key already exists, skipping."
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000246else
Damien Millera8e06ce2003-11-21 23:48:55 +1100247 $bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N ""
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000248fi
249if [ -f $sysconfdir/ssh_host_dsa_key ] ; then
Damien Millera8e06ce2003-11-21 23:48:55 +1100250 echo "$sysconfdir/ssh_host_dsa_key already exists, skipping."
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000251else
Damien Millera8e06ce2003-11-21 23:48:55 +1100252 $bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N ""
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000253fi
254if [ -f $sysconfdir/ssh_host_rsa_key ] ; then
Damien Millera8e06ce2003-11-21 23:48:55 +1100255 echo "$sysconfdir/ssh_host_rsa_key already exists, skipping."
256else
257 $bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N ""
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000258fi
Ben Lindstrom52237272002-06-25 23:38:47 +0000259echo
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000260
Damien Millerc9c1d372003-03-10 12:10:45 +1100261# Set startup command depending on SRC support
262if [ "$AIX_SRC" = "yes" ]
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000263then
Damien Millerc9c1d372003-03-10 12:10:45 +1100264 echo Creating SRC sshd subsystem.
265 rmssys -s sshd 2>&1 >/dev/null
266 mkssys -s sshd -p "$sbindir/sshd" -a '-D' -u 0 -S -n 15 -f 9 -R -G tcpip
267 startupcmd="start $sbindir/sshd \\\"\\\$src_running\\\""
268 oldstartcmd="$sbindir/sshd"
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000269else
Damien Millerc9c1d372003-03-10 12:10:45 +1100270 startupcmd="$sbindir/sshd"
271 oldstartcmd="start $sbindir/sshd \\\"$src_running\\\""
272fi
273
274# If migrating to or from SRC, change previous startup command
275# otherwise add to rc.tcpip
276if egrep "^\$oldstartcmd" /etc/rc.tcpip >/dev/null
277then
278 if sed "s|^\$oldstartcmd|\$startupcmd|g" /etc/rc.tcpip >/etc/rc.tcpip.new
279 then
280 chmod 0755 /etc/rc.tcpip.new
281 mv /etc/rc.tcpip /etc/rc.tcpip.old && \
282 mv /etc/rc.tcpip.new /etc/rc.tcpip
283 else
284 echo "Updating /etc/rc.tcpip failed, please check."
285 fi
286else
287 # Add to system startup if required
288 if grep "^\$startupcmd" /etc/rc.tcpip >/dev/null
289 then
290 echo "sshd found in rc.tcpip, not adding."
291 else
292 echo "Adding sshd to rc.tcpip"
293 echo >>/etc/rc.tcpip
294 echo "# Start sshd" >>/etc/rc.tcpip
295 echo "\$startupcmd" >>/etc/rc.tcpip
296 fi
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000297fi
298EOF
299
300#
301# Create liblpp.a and move control files into it
302#
303echo Creating liblpp.a
304(
305 cd ..
Damien Millerc9c1d372003-03-10 12:10:45 +1100306 for i in openssh.al openssh.copyright openssh.inventory openssh.post_i openssh.size LICENCE README*
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000307 do
Ben Lindstrom52237272002-06-25 23:38:47 +0000308 ar -r liblpp.a $i
309 rm $i
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000310 done
311)
312
313#
314# Create lpp_name
315#
316# This will end up looking something like:
317# 4 R I OpenSSH {
318# OpenSSH 3.0.2.1 1 N U en_US OpenSSH 3.0.2p1 Portable for AIX
319# [
320# %
321# /usr/local/bin 8073
322# /usr/local/etc 189
323# /usr/local/libexec 185
324# /usr/local/man/man1 145
325# /usr/local/man/man8 83
326# /usr/local/sbin 2105
327# /usr/local/share 3
328# %
329# ]
Ben Lindstrom52237272002-06-25 23:38:47 +0000330# }
331
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000332echo Creating lpp_name
333cat <<EOF >../lpp_name
3344 R I $PKGNAME {
335$PKGNAME $BFFVERSION 1 N U en_US OpenSSH $VERSION Portable for AIX
336[
337%
338EOF
339
Ben Lindstrom52237272002-06-25 23:38:47 +0000340for i in $bindir $sysconfdir $libexecdir $mandir/${mansubdir}1 $mandir/${mansubdir}8 $sbindir $datadir /usr/lpp/openssh
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000341do
342 # get size in 512 byte blocks
Ben Lindstrom52237272002-06-25 23:38:47 +0000343 if [ -d $FAKE_ROOT/$i ]
344 then
345 size=`du $FAKE_ROOT/$i | awk '{print $1}'`
346 echo "$i $size" >>../lpp_name
347 fi
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000348done
349
350echo '%' >>../lpp_name
351echo ']' >>../lpp_name
352echo '}' >>../lpp_name
353
354#
355# Move pieces into place
356#
357mkdir -p usr/lpp/openssh
358mv ../liblpp.a usr/lpp/openssh
359mv ../lpp_name .
360
361#
362# Now invoke backup to create .bff file
Ben Lindstrom52237272002-06-25 23:38:47 +0000363# note: lpp_name needs to be the first file so we generate the
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000364# file list on the fly and feed it to backup using -i
365#
366echo Creating $PKGNAME-$VERSION.bff with backup...
Tim Rice3a423462002-03-17 14:05:24 -0800367rm -f $PKGNAME-$VERSION.bff
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000368(
369 echo "./lpp_name"
Damien Millera8e06ce2003-11-21 23:48:55 +1100370 find . ! -name lpp_name -a ! -name . -print
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000371) | backup -i -q -f ../$PKGNAME-$VERSION.bff $filelist
372
Ben Lindstrom52237272002-06-25 23:38:47 +0000373#
Ben Lindstrom2faabf32002-07-18 01:04:50 +0000374# Move package into final location and clean up
Ben Lindstrom52237272002-06-25 23:38:47 +0000375#
Ben Lindstrom2faabf32002-07-18 01:04:50 +0000376mv ../$PKGNAME-$VERSION.bff $startdir
377cd $startdir
Ben Lindstrom52237272002-06-25 23:38:47 +0000378rm -rf $objdir/$PKGDIR
379
Ben Lindstrom01e7fa12002-03-05 03:38:35 +0000380echo $0: done.
381