]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - crypto/openssh/contrib/aix/buildbff.sh
Merge sendmail 8.16.1 to HEAD: See contrib/sendmail/RELEASE_NOTES for details
[FreeBSD/FreeBSD.git] / crypto / openssh / contrib / aix / buildbff.sh
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
12 #
13 # Tunable configuration settings
14 #       create a "config.local" in your build directory or set
15 #       environment variables to override these.
16 #
17 [ -z "$PERMIT_ROOT_LOGIN" ] && PERMIT_ROOT_LOGIN=no
18 [ -z "$X11_FORWARDING" ] && X11_FORWARDING=no
19 [ -z "$AIX_SRC" ] && AIX_SRC=no
20
21 umask 022
22
23 startdir=`pwd`
24
25 perl -v >/dev/null || (echo perl required; exit 1)
26
27 # Path to inventory.sh: same place as buildbff.sh
28 if  echo $0 | egrep '^/'
29 then
30         inventory=`dirname $0`/inventory.sh             # absolute path
31 else
32         inventory=`pwd`/`dirname $0`/inventory.sh       # relative path
33 fi
34
35 #
36 # We still support running from contrib/aix, but this is deprecated
37 #
38 if pwd | egrep 'contrib/aix$'
39 then
40         echo "Changing directory to `pwd`/../.."
41         echo "Please run buildbff.sh from your build directory in future."
42         cd ../..
43         contribaix=1
44 fi
45
46 if [ ! -f Makefile ]
47 then
48         echo "Makefile not found (did you run configure?)"
49         exit 1
50 fi
51
52 #
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)
57 #
58 objdir=`pwd`
59 PKGNAME=openssh
60 PKGDIR=package
61
62 #
63 # Collect local configuration settings to override defaults
64 #
65 if [ -s ./config.local ]
66 then
67         echo Reading local settings from config.local
68         . ./config.local
69 fi
70
71 #
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
75 #
76 for confvar in prefix exec_prefix bindir sbindir libexecdir datadir mandir mansubdir sysconfdir piddir srcdir
77 do
78         eval $confvar=`grep "^$confvar=" $objdir/Makefile | cut -d = -f 2`
79 done
80
81 #
82 # Collect values of privsep user and privsep path
83 #       currently only found in config.h
84 #
85 for confvar in SSH_PRIVSEP_USER PRIVSEP_PATH
86 do
87         eval $confvar=`awk '/#define[ \t]'$confvar'/{print $3}' $objdir/config.h`
88 done
89
90 # Set privsep defaults if not defined
91 if [ -z "$SSH_PRIVSEP_USER" ]
92 then
93         SSH_PRIVSEP_USER=sshd
94 fi
95 if [ -z "$PRIVSEP_PATH" ]
96 then
97         PRIVSEP_PATH=/var/empty
98 fi
99
100 # Clean package build directory
101 rm -rf $objdir/$PKGDIR
102 FAKE_ROOT=$objdir/$PKGDIR/root
103 mkdir -p $FAKE_ROOT
104
105 # Start by faking root install
106 echo "Faking root install..."
107 cd $objdir
108 make install-nokeys DESTDIR=$FAKE_ROOT
109
110 if [ $? -gt 0 ]
111 then
112         echo "Fake root install failed, stopping."
113         exit 1
114 fi
115
116 #
117 # Copy informational files to include in package
118 #
119 cp $srcdir/LICENCE $objdir/$PKGDIR/
120 cp $srcdir/README* $objdir/$PKGDIR/
121
122 #
123 # Extract common info requires for the 'info' part of the package.
124 #       AIX requires 4-part version numbers
125 #
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`
134
135 echo "Building BFF for $PKGNAME $VERSION (package version $BFFVERSION)"
136
137 #
138 # Set ssh and sshd parameters as per config.local
139 #
140 if [ "${PERMIT_ROOT_LOGIN}" = no ]
141 then
142         perl -p -i -e "s/#PermitRootLogin yes/PermitRootLogin no/" \
143                 $FAKE_ROOT/${sysconfdir}/sshd_config
144 fi
145 if [ "${X11_FORWARDING}" = yes ]
146 then
147         perl -p -i -e "s/#X11Forwarding no/X11Forwarding yes/" \
148                 $FAKE_ROOT/${sysconfdir}/sshd_config
149 fi
150
151
152 # Rename config files; postinstall script will copy them if necessary
153 for cfgfile in ssh_config sshd_config
154 do
155         mv $FAKE_ROOT/$sysconfdir/$cfgfile $FAKE_ROOT/$sysconfdir/$cfgfile.default
156 done
157
158 #
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
162 #
163 cd $FAKE_ROOT
164 echo Generating LPP control files
165 find . ! -name . -print >../openssh.al
166 $inventory >../openssh.inventory
167
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
171 EOD
172
173 #
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
177 #
178 files=`find . -type f -print`
179 dirs=`for file in $files; do dirname $file; done | sort -u`
180 for dir in $dirs
181 do
182         du $dir
183 done > ../openssh.size
184
185 #
186 # Create postinstall script
187 #
188 cat <<EOF >>../openssh.post_i
189 #!/bin/sh
190
191 echo Creating configs from defaults if necessary.
192 for cfgfile in ssh_config sshd_config
193 do
194         if [ ! -f $sysconfdir/\$cfgfile ]
195         then
196                 echo "Creating \$cfgfile from default"
197                 cp $sysconfdir/\$cfgfile.default $sysconfdir/\$cfgfile
198         else
199                 echo "\$cfgfile already exists."
200         fi
201 done
202 echo
203
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
207 then
208         echo "PrivSep group $SSH_PRIVSEP_USER already exists."
209 else
210         echo "Creating PrivSep group $SSH_PRIVSEP_USER."
211         mkgroup -A $SSH_PRIVSEP_USER
212 fi
213
214 # Create user if required
215 if lsuser "$SSH_PRIVSEP_USER" >/dev/null
216 then
217         echo "PrivSep user $SSH_PRIVSEP_USER already exists."
218 else
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
221 fi
222
223 if egrep '^[ \t]*UsePrivilegeSeparation[ \t]+no' $sysconfdir/sshd_config >/dev/null
224 then
225         echo UsePrivilegeSeparation not enabled, privsep directory not required.
226 else
227         # create chroot directory if required
228         if [ -d $PRIVSEP_PATH ]
229         then
230                 echo "PrivSep chroot directory $PRIVSEP_PATH already exists."
231         else
232                 echo "Creating PrivSep chroot directory $PRIVSEP_PATH."
233                 mkdir $PRIVSEP_PATH
234                 chown 0 $PRIVSEP_PATH
235                 chgrp 0 $PRIVSEP_PATH
236                 chmod 755 $PRIVSEP_PATH
237         fi
238 fi
239 echo
240
241 # Generate keys unless they already exist
242 echo Creating host keys if required.
243 $bindir/ssh-keygen -A
244 echo
245
246 # Set startup command depending on SRC support
247 if [ "$AIX_SRC" = "yes" ]
248 then
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"
254 else
255         startupcmd="$sbindir/sshd"
256         oldstartcmd="start $sbindir/sshd \\\"$src_running\\\""
257 fi
258
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
262 then
263         if sed "s|^\$oldstartcmd|\$startupcmd|g" /etc/rc.tcpip >/etc/rc.tcpip.new
264         then
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
268         else
269                 echo "Updating /etc/rc.tcpip failed, please check."
270         fi
271 else
272         # Add to system startup if required
273         if grep "^\$startupcmd" /etc/rc.tcpip >/dev/null
274         then
275                 echo "sshd found in rc.tcpip, not adding."
276         else
277                 echo "Adding sshd to rc.tcpip"
278                 echo >>/etc/rc.tcpip
279                 echo "# Start sshd" >>/etc/rc.tcpip
280                 echo "\$startupcmd" >>/etc/rc.tcpip
281         fi
282 fi
283 EOF
284
285 #
286 # Create liblpp.a and move control files into it
287 #
288 echo Creating liblpp.a
289 (
290         cd ..
291         for i in openssh.al openssh.copyright openssh.inventory openssh.post_i openssh.size LICENCE README*
292         do
293                 ar -r liblpp.a $i
294                 rm $i
295         done
296 )
297
298 #
299 # Create lpp_name
300 #
301 # This will end up looking something like:
302 # 4 R I OpenSSH {
303 # OpenSSH 3.0.2.1 1 N U en_US OpenSSH 3.0.2p1 Portable for AIX
304 # [
305 # %
306 # /usr/local/bin 8073
307 # /usr/local/etc 189
308 # /usr/local/libexec 185
309 # /usr/local/man/man1 145
310 # /usr/local/man/man8 83
311 # /usr/local/sbin 2105
312 # /usr/local/share 3
313 # %
314 # ]
315 # }
316
317 echo Creating lpp_name
318 cat <<EOF >../lpp_name
319 4 R I $PKGNAME {
320 $PKGNAME $BFFVERSION 1 N U en_US OpenSSH $VERSION Portable for AIX
321 [
322 %
323 EOF
324
325 for i in $bindir $sysconfdir $libexecdir $mandir/${mansubdir}1 $mandir/${mansubdir}8 $sbindir $datadir /usr/lpp/openssh
326 do
327         # get size in 512 byte blocks
328         if [ -d $FAKE_ROOT/$i ]
329         then
330                 size=`du $FAKE_ROOT/$i | awk '{print $1}'`
331                 echo "$i $size" >>../lpp_name
332         fi
333 done
334
335 echo '%' >>../lpp_name
336 echo ']' >>../lpp_name
337 echo '}' >>../lpp_name
338
339 #
340 # Move pieces into place
341 #
342 mkdir -p usr/lpp/openssh
343 mv ../liblpp.a usr/lpp/openssh
344 mv ../lpp_name .
345
346 #
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
350 #
351 echo Creating $PKGNAME-$VERSION.bff with backup...
352 rm -f $PKGNAME-$VERSION.bff
353 (
354         echo "./lpp_name"
355         find . ! -name lpp_name -a ! -name . -print
356 ) | backup  -i -q -f ../$PKGNAME-$VERSION.bff $filelist
357
358 #
359 # Move package into final location and clean up
360 #
361 mv ../$PKGNAME-$VERSION.bff $startdir
362 cd $startdir
363 rm -rf $objdir/$PKGDIR
364
365 echo $0: done.
366