]> andersk Git - openssh.git/blame - contrib/aix/buildbff.sh
- (dtucker) [contrib/aix/buildbff.sh] Always create privsep user.
[openssh.git] / contrib / aix / buildbff.sh
CommitLineData
ef817d21 1#!/bin/sh
2#
3# buildbff.sh: Create AIX SMIT-installable OpenSSH packages
ed00d4b7 4# $Id$
ef817d21 5#
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.
aff51935 9#
ef817d21 10# Based originally on Ben Lindstrom's buildpkg.sh for Solaris
11#
12
924681ee 13#
14# Tunable configuration settings
21e3ecaf 15# create a "config.local" in your build directory or set
16# environment variables to override these.
924681ee 17#
ed00d4b7 18[ -z "$PERMIT_ROOT_LOGIN" ] && PERMIT_ROOT_LOGIN=no
19[ -z "$X11_FORWARDING" ] && X11_FORWARDING=no
20[ -z "$AIX_SRC" ] && AIX_SRC=no
924681ee 21
ef817d21 22umask 022
924681ee 23
dd3943d0 24startdir=`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
924681ee 34#
ed00d4b7 35# We still support running from contrib/aix, but this is deprecated
924681ee 36#
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?)"
aff51935 48 exit 1
924681ee 49fi
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`
ef817d21 58PKGNAME=openssh
43e41c2c 59PKGDIR=package
ef817d21 60
924681ee 61#
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
ef817d21 88
924681ee 89# Set privsep defaults if not defined
90if [ -z "$SSH_PRIVSEP_USER" ]
ef817d21 91then
924681ee 92 SSH_PRIVSEP_USER=sshd
93fi
94if [ -z "$PRIVSEP_PATH" ]
95then
96 PRIVSEP_PATH=/var/empty
ef817d21 97fi
98
aff51935 99# Clean package build directory
924681ee 100rm -rf $objdir/$PKGDIR
101FAKE_ROOT=$objdir/$PKGDIR/root
102mkdir -p $FAKE_ROOT
103
aff51935 104# Start by faking root install
ef817d21 105echo "Faking root install..."
924681ee 106cd $objdir
ef817d21 107make install-nokeys DESTDIR=$FAKE_ROOT
108
43e41c2c 109if [ $? -gt 0 ]
110then
111 echo "Fake root install failed, stopping."
112 exit 1
113fi
114
924681ee 115#
116# Copy informational files to include in package
117#
118cp $srcdir/LICENCE $objdir/$PKGDIR/
119cp $srcdir/README* $objdir/$PKGDIR/
120
43e41c2c 121#
122# Extract common info requires for the 'info' part of the package.
123# AIX requires 4-part version numbers
124#
ed00d4b7 125VERSION=`./ssh -V 2>&1 | cut -f 1 -d , | cut -f 2 -d _`
43e41c2c 126MAJOR=`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 .`
924681ee 129PORTABLE=`echo $VERSION | awk 'BEGIN{FS="p"}{print $2}'`
130[ "$PATCH" = "" ] && PATCH=0
131[ "$PORTABLE" = "" ] && PORTABLE=0
43e41c2c 132BFFVERSION=`printf "%d.%d.%d.%d" $MAJOR $MINOR $PATCH $PORTABLE`
133
134echo "Building BFF for $PKGNAME $VERSION (package version $BFFVERSION)"
135
ef817d21 136#
924681ee 137# Set ssh and sshd parameters as per config.local
ef817d21 138#
aff51935 139if [ "${PERMIT_ROOT_LOGIN}" = no ]
924681ee 140then
aff51935 141 perl -p -i -e "s/#PermitRootLogin yes/PermitRootLogin no/" \
142 $FAKE_ROOT/${sysconfdir}/sshd_config
924681ee 143fi
144if [ "${X11_FORWARDING}" = yes ]
145then
aff51935 146 perl -p -i -e "s/#X11Forwarding no/X11Forwarding yes/" \
147 $FAKE_ROOT/${sysconfdir}/sshd_config
924681ee 148fi
149
ef817d21 150
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.
924681ee 159# working dir is $FAKE_ROOT but files are generated in dir above
ef817d21 160# and moved into place just before creation of .bff
161#
162cd $FAKE_ROOT
163echo Generating LPP control files
164find . ! -name . -print >../openssh.al
924681ee 165$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
ef817d21 171
21e3ecaf 172#
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
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
ef817d21 184#
185# Create postinstall script
186#
187cat <<EOF >>../openssh.post_i
188#!/bin/sh
189
924681ee 190echo Creating configs from defaults if necessary.
ef817d21 191for cfgfile in ssh_config sshd_config ssh_prng_cmds
192do
aff51935 193 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
ef817d21 200done
924681ee 201echo
202
d2f401fe 203# Create PrivilegeSeparation user and group if not present
204echo Checking for PrivilegeSeparation user and group.
205if cut -f1 -d: /etc/group | egrep '^'$SSH_PRIVSEP_USER'\$' >/dev/null
924681ee 206then
d2f401fe 207 echo "PrivSep group $SSH_PRIVSEP_USER already exists."
924681ee 208else
d2f401fe 209 echo "Creating PrivSep group $SSH_PRIVSEP_USER."
210 mkgroup -A $SSH_PRIVSEP_USER
211fi
924681ee 212
d2f401fe 213# Create user if required
214if lsuser "$SSH_PRIVSEP_USER" >/dev/null
215then
216 echo "PrivSep user $SSH_PRIVSEP_USER already exists."
217else
218 echo "Creating PrivSep user $SSH_PRIVSEP_USER."
219 mkuser gecos='SSHD PrivSep User' login=false rlogin=false account_locked=true pgrp=$SSH_PRIVSEP_USER $SSH_PRIVSEP_USER
220fi
924681ee 221
d2f401fe 222if egrep '^[ \t]*UsePrivilegeSeparation[ \t]+no' $sysconfdir/sshd_config >/dev/null
223then
224 echo UsePrivilegeSeparation not enabled, privsep directory not required.
225else
924681ee 226 # create chroot directory if required
227 if [ -d $PRIVSEP_PATH ]
228 then
229 echo "PrivSep chroot directory $PRIVSEP_PATH already exists."
230 else
231 echo "Creating PrivSep chroot directory $PRIVSEP_PATH."
232 mkdir $PRIVSEP_PATH
233 chown 0 $PRIVSEP_PATH
234 chgrp 0 $PRIVSEP_PATH
235 chmod 755 $PRIVSEP_PATH
236 fi
237fi
238echo
ef817d21 239
240# Generate keys unless they already exist
924681ee 241echo Creating host keys if required.
ef817d21 242if [ -f "$sysconfdir/ssh_host_key" ] ; then
aff51935 243 echo "$sysconfdir/ssh_host_key already exists, skipping."
ef817d21 244else
aff51935 245 $bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N ""
ef817d21 246fi
247if [ -f $sysconfdir/ssh_host_dsa_key ] ; then
aff51935 248 echo "$sysconfdir/ssh_host_dsa_key already exists, skipping."
ef817d21 249else
aff51935 250 $bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N ""
ef817d21 251fi
252if [ -f $sysconfdir/ssh_host_rsa_key ] ; then
aff51935 253 echo "$sysconfdir/ssh_host_rsa_key already exists, skipping."
254else
255 $bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N ""
ef817d21 256fi
924681ee 257echo
ef817d21 258
21e3ecaf 259# Set startup command depending on SRC support
260if [ "$AIX_SRC" = "yes" ]
261then
262 echo Creating SRC sshd subsystem.
263 rmssys -s sshd 2>&1 >/dev/null
264 mkssys -s sshd -p "$sbindir/sshd" -a '-D' -u 0 -S -n 15 -f 9 -R -G tcpip
265 startupcmd="start $sbindir/sshd \\\"\\\$src_running\\\""
266 oldstartcmd="$sbindir/sshd"
267else
268 startupcmd="$sbindir/sshd"
269 oldstartcmd="start $sbindir/sshd \\\"$src_running\\\""
270fi
271
272# If migrating to or from SRC, change previous startup command
273# otherwise add to rc.tcpip
274if egrep "^\$oldstartcmd" /etc/rc.tcpip >/dev/null
ef817d21 275then
21e3ecaf 276 if sed "s|^\$oldstartcmd|\$startupcmd|g" /etc/rc.tcpip >/etc/rc.tcpip.new
277 then
278 chmod 0755 /etc/rc.tcpip.new
279 mv /etc/rc.tcpip /etc/rc.tcpip.old && \
280 mv /etc/rc.tcpip.new /etc/rc.tcpip
281 else
282 echo "Updating /etc/rc.tcpip failed, please check."
283 fi
ef817d21 284else
21e3ecaf 285 # Add to system startup if required
286 if grep "^\$startupcmd" /etc/rc.tcpip >/dev/null
287 then
288 echo "sshd found in rc.tcpip, not adding."
289 else
290 echo "Adding sshd to rc.tcpip"
291 echo >>/etc/rc.tcpip
292 echo "# Start sshd" >>/etc/rc.tcpip
293 echo "\$startupcmd" >>/etc/rc.tcpip
294 fi
ef817d21 295fi
296EOF
297
298#
299# Create liblpp.a and move control files into it
300#
301echo Creating liblpp.a
302(
303 cd ..
21e3ecaf 304 for i in openssh.al openssh.copyright openssh.inventory openssh.post_i openssh.size LICENCE README*
ef817d21 305 do
924681ee 306 ar -r liblpp.a $i
307 rm $i
ef817d21 308 done
309)
310
311#
312# Create lpp_name
313#
314# This will end up looking something like:
315# 4 R I OpenSSH {
316# OpenSSH 3.0.2.1 1 N U en_US OpenSSH 3.0.2p1 Portable for AIX
317# [
318# %
319# /usr/local/bin 8073
320# /usr/local/etc 189
321# /usr/local/libexec 185
322# /usr/local/man/man1 145
323# /usr/local/man/man8 83
324# /usr/local/sbin 2105
325# /usr/local/share 3
326# %
327# ]
924681ee 328# }
329
ef817d21 330echo Creating lpp_name
331cat <<EOF >../lpp_name
3324 R I $PKGNAME {
333$PKGNAME $BFFVERSION 1 N U en_US OpenSSH $VERSION Portable for AIX
334[
335%
336EOF
337
924681ee 338for i in $bindir $sysconfdir $libexecdir $mandir/${mansubdir}1 $mandir/${mansubdir}8 $sbindir $datadir /usr/lpp/openssh
ef817d21 339do
340 # get size in 512 byte blocks
924681ee 341 if [ -d $FAKE_ROOT/$i ]
342 then
343 size=`du $FAKE_ROOT/$i | awk '{print $1}'`
344 echo "$i $size" >>../lpp_name
345 fi
ef817d21 346done
347
348echo '%' >>../lpp_name
349echo ']' >>../lpp_name
350echo '}' >>../lpp_name
351
352#
353# Move pieces into place
354#
355mkdir -p usr/lpp/openssh
356mv ../liblpp.a usr/lpp/openssh
357mv ../lpp_name .
358
359#
360# Now invoke backup to create .bff file
924681ee 361# note: lpp_name needs to be the first file so we generate the
ef817d21 362# file list on the fly and feed it to backup using -i
363#
364echo Creating $PKGNAME-$VERSION.bff with backup...
43e41c2c 365rm -f $PKGNAME-$VERSION.bff
ef817d21 366(
367 echo "./lpp_name"
aff51935 368 find . ! -name lpp_name -a ! -name . -print
ef817d21 369) | backup -i -q -f ../$PKGNAME-$VERSION.bff $filelist
370
924681ee 371#
dd3943d0 372# Move package into final location and clean up
924681ee 373#
dd3943d0 374mv ../$PKGNAME-$VERSION.bff $startdir
375cd $startdir
924681ee 376rm -rf $objdir/$PKGDIR
ef817d21 377
ef817d21 378echo $0: done.
379
This page took 0.222328 seconds and 5 git commands to generate.