]> andersk Git - gssapi-openssh.git/blame - openssh/contrib/aix/buildbff.sh
Import of OpenSSH 3.4p1
[gssapi-openssh.git] / openssh / contrib / aix / buildbff.sh
CommitLineData
e9a17296 1#!/bin/sh
2#
3# buildbff.sh: Create AIX SMIT-installable OpenSSH packages
4#
5# Author: Darren Tucker (dtucker at zip dot com dot au)
6# This file is placed in the public domain and comes with absolutely
7# no warranty.
8#
9# Based originally on Ben Lindstrom's buildpkg.sh for Solaris
10#
11
680cee3b 12#
13# Tunable configuration settings
14# create a "config.local" in your build directory to override these.
15#
16PERMIT_ROOT_LOGIN=no
17X11_FORWARDING=no
18
e9a17296 19umask 022
680cee3b 20
21#
22# We still support running from contrib/aix, but this is depreciated
23#
24if pwd | egrep 'contrib/aix$'
25then
26 echo "Changing directory to `pwd`/../.."
27 echo "Please run buildbff.sh from your build directory in future."
28 cd ../..
29 contribaix=1
30fi
31
32if [ ! -f Makefile ]
33then
34 echo "Makefile not found (did you run configure?)"
35 exit 1
36fi
37
38#
39# Directories used during build:
40# current dir = $objdir directory you ran ./configure in.
41# $objdir/$PKGDIR/ directory package files are constructed in
42# $objdir/$PKGDIR/root/ package root ($FAKE_ROOT)
43#
44objdir=`pwd`
e9a17296 45PKGNAME=openssh
700318f3 46PKGDIR=package
e9a17296 47
680cee3b 48# Path to inventory.sh: same place as buildbff.sh
49if echo $0 | egrep '^/'
50then
51 inventory=`dirname $0`/inventory.sh # absolute path
52else
53 inventory=`pwd`/`dirname $0`/inventory.sh # relative path
54fi
e9a17296 55
680cee3b 56#
57# Collect local configuration settings to override defaults
58#
59if [ -s ./config.local ]
60then
61 echo Reading local settings from config.local
62 . ./config.local
63fi
64
65#
66# Fill in some details from Makefile, like prefix and sysconfdir
67# the eval also expands variables like sysconfdir=${prefix}/etc
68# provided they are eval'ed in the correct order
69#
70for confvar in prefix exec_prefix bindir sbindir libexecdir datadir mandir mansubdir sysconfdir piddir srcdir
71do
72 eval $confvar=`grep "^$confvar=" $objdir/Makefile | cut -d = -f 2`
73done
74
75#
76# Collect values of privsep user and privsep path
77# currently only found in config.h
78#
79for confvar in SSH_PRIVSEP_USER PRIVSEP_PATH
80do
81 eval $confvar=`awk '/#define[ \t]'$confvar'/{print $3}' $objdir/config.h`
82done
e9a17296 83
680cee3b 84# Set privsep defaults if not defined
85if [ -z "$SSH_PRIVSEP_USER" ]
e9a17296 86then
680cee3b 87 SSH_PRIVSEP_USER=sshd
88fi
89if [ -z "$PRIVSEP_PATH" ]
90then
91 PRIVSEP_PATH=/var/empty
e9a17296 92fi
93
680cee3b 94# Clean package build directory
95rm -rf $objdir/$PKGDIR
96FAKE_ROOT=$objdir/$PKGDIR/root
97mkdir -p $FAKE_ROOT
98
99# Start by faking root install
e9a17296 100echo "Faking root install..."
680cee3b 101cd $objdir
e9a17296 102make install-nokeys DESTDIR=$FAKE_ROOT
103
700318f3 104if [ $? -gt 0 ]
105then
106 echo "Fake root install failed, stopping."
107 exit 1
108fi
109
680cee3b 110#
111# Copy informational files to include in package
112#
113cp $srcdir/LICENCE $objdir/$PKGDIR/
114cp $srcdir/README* $objdir/$PKGDIR/
115
700318f3 116#
117# Extract common info requires for the 'info' part of the package.
118# AIX requires 4-part version numbers
119#
120VERSION=`./ssh -V 2>&1 | sed -e 's/,.*//' | cut -f 2 -d _`
121MAJOR=`echo $VERSION | cut -f 1 -d p | cut -f 1 -d .`
122MINOR=`echo $VERSION | cut -f 1 -d p | cut -f 2 -d .`
123PATCH=`echo $VERSION | cut -f 1 -d p | cut -f 3 -d .`
680cee3b 124PORTABLE=`echo $VERSION | awk 'BEGIN{FS="p"}{print $2}'`
125[ "$PATCH" = "" ] && PATCH=0
126[ "$PORTABLE" = "" ] && PORTABLE=0
700318f3 127BFFVERSION=`printf "%d.%d.%d.%d" $MAJOR $MINOR $PATCH $PORTABLE`
128
129echo "Building BFF for $PKGNAME $VERSION (package version $BFFVERSION)"
130
e9a17296 131#
680cee3b 132# Set ssh and sshd parameters as per config.local
e9a17296 133#
680cee3b 134if [ "${PERMIT_ROOT_LOGIN}" = no ]
135then
136 perl -p -i -e "s/#PermitRootLogin yes/PermitRootLogin no/" \
137 $FAKE_ROOT/${sysconfdir}/sshd_config
138fi
139if [ "${X11_FORWARDING}" = yes ]
140then
141 perl -p -i -e "s/#X11Forwarding no/X11Forwarding yes/" \
142 $FAKE_ROOT/${sysconfdir}/sshd_config
143fi
144
e9a17296 145
146# Rename config files; postinstall script will copy them if necessary
147for cfgfile in ssh_config sshd_config ssh_prng_cmds
148do
149 mv $FAKE_ROOT/$sysconfdir/$cfgfile $FAKE_ROOT/$sysconfdir/$cfgfile.default
150done
151
152#
153# Generate lpp control files.
680cee3b 154# working dir is $FAKE_ROOT but files are generated in dir above
e9a17296 155# and moved into place just before creation of .bff
156#
157cd $FAKE_ROOT
158echo Generating LPP control files
159find . ! -name . -print >../openssh.al
680cee3b 160$inventory >../openssh.inventory
161
162cat <<EOD >../openssh.copyright
163This software is distributed under a BSD-style license.
164For the full text of the license, see /usr/lpp/openssh/LICENCE
165EOD
e9a17296 166
167#
168# Create postinstall script
169#
170cat <<EOF >>../openssh.post_i
171#!/bin/sh
172
680cee3b 173echo Creating configs from defaults if necessary.
e9a17296 174for cfgfile in ssh_config sshd_config ssh_prng_cmds
175do
176 if [ ! -f $sysconfdir/\$cfgfile ]
177 then
178 echo "Creating \$cfgfile from default"
179 cp $sysconfdir/\$cfgfile.default $sysconfdir/\$cfgfile
180 else
181 echo "\$cfgfile already exists."
182 fi
183done
680cee3b 184echo
185
186# Create PrivSep user if PrivSep not disabled in config
187echo Creating PrivSep prereqs if required.
188if egrep '^[ \t]*UsePrivilegeSeparation[ \t]+no' $sysconfdir/sshd_config >/dev/null
189then
190 echo "UsePrivilegeSeparation disabled in config, not creating PrivSep user,"
191 echo "group or chroot directory."
192else
193 echo "UsePrivilegeSeparation enabled in config (or defaulting to on)."
194
195 # create group if required
196 if cut -f1 -d: /etc/group | egrep '^'$SSH_PRIVSEP_USER'\$' >/dev/null
197 then
198 echo "PrivSep group $SSH_PRIVSEP_USER already exists."
199 else
200 echo "Creating PrivSep group $SSH_PRIVSEP_USER."
201 mkgroup -A $SSH_PRIVSEP_USER
202 fi
203
204 # Create user if required
205 if cut -f1 -d: /etc/passwd | egrep '^'$SSH_PRIVSEP_USER'\$' >/dev/null
206 then
207 echo "PrivSep user $SSH_PRIVSEP_USER already exists."
208 else
209 echo "Creating PrivSep user $SSH_PRIVSEP_USER."
210 mkuser gecos='SSHD PrivSep User' login=false rlogin=false account_locked=true pgrp=$SSH_PRIVSEP_USER $SSH_PRIVSEP_USER
211 fi
212
213 # create chroot directory if required
214 if [ -d $PRIVSEP_PATH ]
215 then
216 echo "PrivSep chroot directory $PRIVSEP_PATH already exists."
217 else
218 echo "Creating PrivSep chroot directory $PRIVSEP_PATH."
219 mkdir $PRIVSEP_PATH
220 chown 0 $PRIVSEP_PATH
221 chgrp 0 $PRIVSEP_PATH
222 chmod 755 $PRIVSEP_PATH
223 fi
224fi
225echo
e9a17296 226
227# Generate keys unless they already exist
680cee3b 228echo Creating host keys if required.
e9a17296 229if [ -f "$sysconfdir/ssh_host_key" ] ; then
230 echo "$sysconfdir/ssh_host_key already exists, skipping."
231else
232 $bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N ""
233fi
234if [ -f $sysconfdir/ssh_host_dsa_key ] ; then
235 echo "$sysconfdir/ssh_host_dsa_key already exists, skipping."
236else
237 $bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N ""
238fi
239if [ -f $sysconfdir/ssh_host_rsa_key ] ; then
240 echo "$sysconfdir/ssh_host_rsa_key already exists, skipping."
241else
242 $bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N ""
243fi
680cee3b 244echo
e9a17296 245
246# Add to system startup if required
247if grep $sbindir/sshd /etc/rc.tcpip >/dev/null
248then
249 echo "sshd found in rc.tcpip, not adding."
250else
251 echo >>/etc/rc.tcpip
252 echo "echo Starting sshd" >>/etc/rc.tcpip
253 echo "$sbindir/sshd" >>/etc/rc.tcpip
254fi
255EOF
256
257#
258# Create liblpp.a and move control files into it
259#
260echo Creating liblpp.a
261(
262 cd ..
680cee3b 263 for i in openssh.al openssh.copyright openssh.inventory openssh.post_i LICENCE README*
e9a17296 264 do
680cee3b 265 ar -r liblpp.a $i
266 rm $i
e9a17296 267 done
268)
269
270#
271# Create lpp_name
272#
273# This will end up looking something like:
274# 4 R I OpenSSH {
275# OpenSSH 3.0.2.1 1 N U en_US OpenSSH 3.0.2p1 Portable for AIX
276# [
277# %
278# /usr/local/bin 8073
279# /usr/local/etc 189
280# /usr/local/libexec 185
281# /usr/local/man/man1 145
282# /usr/local/man/man8 83
283# /usr/local/sbin 2105
284# /usr/local/share 3
285# %
286# ]
680cee3b 287# }
288
e9a17296 289echo Creating lpp_name
290cat <<EOF >../lpp_name
2914 R I $PKGNAME {
292$PKGNAME $BFFVERSION 1 N U en_US OpenSSH $VERSION Portable for AIX
293[
294%
295EOF
296
680cee3b 297for i in $bindir $sysconfdir $libexecdir $mandir/${mansubdir}1 $mandir/${mansubdir}8 $sbindir $datadir /usr/lpp/openssh
e9a17296 298do
299 # get size in 512 byte blocks
680cee3b 300 if [ -d $FAKE_ROOT/$i ]
301 then
302 size=`du $FAKE_ROOT/$i | awk '{print $1}'`
303 echo "$i $size" >>../lpp_name
304 fi
e9a17296 305done
306
307echo '%' >>../lpp_name
308echo ']' >>../lpp_name
309echo '}' >>../lpp_name
310
311#
312# Move pieces into place
313#
314mkdir -p usr/lpp/openssh
315mv ../liblpp.a usr/lpp/openssh
316mv ../lpp_name .
317
318#
319# Now invoke backup to create .bff file
680cee3b 320# note: lpp_name needs to be the first file so we generate the
e9a17296 321# file list on the fly and feed it to backup using -i
322#
323echo Creating $PKGNAME-$VERSION.bff with backup...
700318f3 324rm -f $PKGNAME-$VERSION.bff
e9a17296 325(
326 echo "./lpp_name"
327 find . ! -name lpp_name -a ! -name . -print
328) | backup -i -q -f ../$PKGNAME-$VERSION.bff $filelist
329
680cee3b 330#
331# Move package into final location
332#
333if [ "$contribaix" = "1" ]
334then
335 mv ../$PKGNAME-$VERSION.bff $objdir/contrib/aix
336else
337 mv ../$PKGNAME-$VERSION.bff $objdir
338fi
339
340rm -rf $objdir/$PKGDIR
e9a17296 341
e9a17296 342echo $0: done.
343
This page took 0.775507 seconds and 5 git commands to generate.