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