blob: 1be6ed8d1dcb8fadbd5a71ee67d9932dbbf7d979 [file] [log] [blame]
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +00001#!/bin/sh
2#
Tim Rice29bdd2c2002-03-11 20:55:53 -08003# Fake Root Solaris/SVR4/SVR5 Build System - Prototype
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +00004#
5# The following code has been provide under Public Domain License. I really
6# don't care what you use it for. Just as long as you don't complain to me
7# nor my employer if you break it. - Ben Lindstrom (mouring@eviladmin.org)
8#
9umask 022
Tim Rice29bdd2c2002-03-11 20:55:53 -080010#
11# Options for building the package
12# You can create a config.local with your customized options
13#
14# uncommenting TEST_DIR and using configure--prefix=/var/tmp and
15# PKGNAME=tOpenSSH should allow testing a package without interfering
16# with a real OpenSSH package on a system.
17#TEST_DIR=/var/tmp # leave commented out for production build
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000018PKGNAME=OpenSSH
Tim Rice29bdd2c2002-03-11 20:55:53 -080019SYSVINIT_NAME=opensshd
20MAKE=${MAKE:="make"}
21# uncomment these next two as needed
22#PERMIT_ROOT_LOGIN=no
23#X11_FORWARDING=yes
24# list of system directories we do NOT want to change owner/group/perms
25# when installing our package
26SYSTEM_DIR="/etc \
27/etc/init.d \
28/etc/rcS.d \
29/etc/rc0.d \
30/etc/rc1.d \
31/etc/rc2.d \
Tim Rice3a423462002-03-17 14:05:24 -080032/etc/opt \
Tim Rice29bdd2c2002-03-11 20:55:53 -080033/opt \
34/opt/bin \
35/usr \
36/usr/bin \
37/usr/lib \
38/usr/sbin \
39/usr/share \
40/usr/share/man \
41/usr/share/man/man1 \
42/usr/share/man/man8 \
43/usr/local \
44/usr/local/bin \
45/usr/local/etc \
46/usr/local/libexec \
47/usr/local/man \
48/usr/local/man/man1 \
49/usr/local/man/man8 \
50/usr/local/sbin \
51/usr/local/share \
52/var \
Tim Rice3a423462002-03-17 14:05:24 -080053/var/opt \
Tim Rice29bdd2c2002-03-11 20:55:53 -080054/var/run \
55/var/tmp \
56/tmp"
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000057
Tim Rice29bdd2c2002-03-11 20:55:53 -080058# We may need to buiild as root so we make sure PATH is set up
59# only set the path if it's not set already
60[ -d /usr/local/bin ] && {
61 echo $PATH | grep ":/usr/local/bin" > /dev/null 2>&1
62 [ $? -ne 0 ] && PATH=$PATH:/usr/local/bin
63}
64[ -d /usr/ccs/bin ] && {
65 echo $PATH | grep ":/usr/ccs/bin" > /dev/null 2>&1
66 [ $? -ne 0 ] && PATH=$PATH:/usr/ccs/bin
67}
68export PATH
69#
70
71[ -f Makefile ] || {
72 echo "Please run this script from your build directory"
73 exit 1
74}
75
76# we will look for config.local to override the above options
77[ -s ./config.local ] && . ./config.local
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000078
79## Start by faking root install
80echo "Faking root install..."
81START=`pwd`
Tim Rice29bdd2c2002-03-11 20:55:53 -080082OPENSSHD_IN=`dirname $0`/opensshd.in
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000083FAKE_ROOT=$START/package
Tim Rice29bdd2c2002-03-11 20:55:53 -080084[ -d $FAKE_ROOT ] && rm -fr $FAKE_ROOT
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000085mkdir $FAKE_ROOT
Tim Rice29bdd2c2002-03-11 20:55:53 -080086${MAKE} install-nokeys DESTDIR=$FAKE_ROOT
87if [ $? -gt 0 ]
88then
89 echo "Fake root install failed, stopping."
90 exit 1
91fi
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000092
93## Fill in some details, like prefix and sysconfdir
Tim Rice29bdd2c2002-03-11 20:55:53 -080094for confvar in prefix exec_prefix bindir sbindir libexecdir datadir mandir sysconfdir piddir
95do
96 eval $confvar=`grep "^$confvar=" Makefile | cut -d = -f 2`
97done
98
99## Extract common info requires for the 'info' part of the package.
100VERSION=`./ssh -V 2>&1 | sed -e 's/,.*//'`
101
102UNAME_S=`uname -s`
103case ${UNAME_S} in
104 SunOS) UNAME_S=Solaris
105 ARCH=`uname -p`
106 RCS_D=yes
107 DEF_MSG="(default: n)"
108 ;;
109 *) ARCH=`uname -m` ;;
110esac
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +0000111
112## Setup our run level stuff while we are at it.
Tim Rice29bdd2c2002-03-11 20:55:53 -0800113mkdir -p $FAKE_ROOT${TEST_DIR}/etc/init.d
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +0000114
115## setup our initscript correctly
Tim Rice29bdd2c2002-03-11 20:55:53 -0800116sed -e "s#%%configDir%%#${sysconfdir}#g" \
117 -e "s#%%openSSHDir%%#$prefix#g" \
118 -e "s#%%pidDir%%#${piddir}#g" \
119 ${OPENSSHD_IN} > $FAKE_ROOT${TEST_DIR}/etc/init.d/${SYSVINIT_NAME}
120chmod 744 $FAKE_ROOT${TEST_DIR}/etc/init.d/${SYSVINIT_NAME}
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +0000121
Tim Rice29bdd2c2002-03-11 20:55:53 -0800122[ "${PERMIT_ROOT_LOGIN}" = no ] && \
123 perl -p -i -e "s/#PermitRootLogin yes/PermitRootLogin no/" \
124 $FAKE_ROOT/${sysconfdir}/sshd_config
125[ "${X11_FORWARDING}" = yes ] && \
126 perl -p -i -e "s/#X11Forwarding no/X11Forwarding yes/" \
127 $FAKE_ROOT/${sysconfdir}/sshd_config
128# fix PrintMotd
129perl -p -i -e "s/#PrintMotd yes/PrintMotd no/" \
130 $FAKE_ROOT/${sysconfdir}/sshd_config
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +0000131
Tim Rice29bdd2c2002-03-11 20:55:53 -0800132# We don't want to overwrite config files on multiple installs
133mv $FAKE_ROOT/${sysconfdir}/ssh_config $FAKE_ROOT/${sysconfdir}/ssh_config.default
134mv $FAKE_ROOT/${sysconfdir}/sshd_config $FAKE_ROOT/${sysconfdir}/sshd_config.default
135[ -f $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds ] && \
136mv $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds.default
137
138cd $FAKE_ROOT
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +0000139
140## Ok, this is outright wrong, but it will work. I'm tired of pkgmk
141## whining.
142for i in *; do
143 PROTO_ARGS="$PROTO_ARGS $i=/$i";
144done
145
146## Build info file
147echo "Building pkginfo file..."
148cat > pkginfo << _EOF
149PKG=$PKGNAME
Tim Rice29bdd2c2002-03-11 20:55:53 -0800150NAME="OpenSSH Portable for ${UNAME_S}"
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +0000151DESC="Secure Shell remote access utility; replaces telnet and rlogin/rsh."
152VENDOR="OpenSSH Portable Team - http://www.openssh.com/portable.html"
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +0000153ARCH=$ARCH
154VERSION=$VERSION
Tim Rice29bdd2c2002-03-11 20:55:53 -0800155CATEGORY="Security,application"
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +0000156BASEDIR=/
Tim Rice29bdd2c2002-03-11 20:55:53 -0800157CLASSES="none"
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +0000158_EOF
159
Tim Rice29bdd2c2002-03-11 20:55:53 -0800160## Build preinstall file
161echo "Building preinstall file..."
162cat > preinstall << _EOF
163#! /sbin/sh
164#
165[ "\${PRE_INS_STOP}" = "yes" ] && ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop
166exit 0
167_EOF
168
169## Build postinstall file
170echo "Building postinstall file..."
171cat > postinstall << _EOF
172#! /sbin/sh
173#
174[ -f ${sysconfdir}/ssh_config ] || \\
175 cp -p ${sysconfdir}/ssh_config.default ${sysconfdir}/ssh_config
176[ -f ${sysconfdir}/sshd_config ] || \\
177 cp -p ${sysconfdir}/sshd_config.default ${sysconfdir}/sshd_config
178[ -f ${sysconfdir}/ssh_prng_cmds.default ] && {
179 [ -f ${sysconfdir}/ssh_prng_cmds ] || \\
180 cp -p ${sysconfdir}/ssh_prng_cmds.default ${sysconfdir}/ssh_prng_cmds
181}
182
183# make rc?.d dirs only if we are doing a test install
184[ -n "${TEST_DIR}" ] && {
185 [ "$RCS_D" = yes ] && mkdir -p ${TEST_DIR}/etc/rcS.d
186 mkdir -p ${TEST_DIR}/etc/rc0.d
187 mkdir -p ${TEST_DIR}/etc/rc1.d
188 mkdir -p ${TEST_DIR}/etc/rc2.d
189}
190
191if [ "\${USE_SYM_LINKS}" = yes ]
192then
193 [ "$RCS_D" = yes ] && \
194installf ${PKGNAME} $TEST_DIR/etc/rcS.d/K30${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
195 installf ${PKGNAME} $TEST_DIR/etc/rc0.d/K30${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
196 installf ${PKGNAME} $TEST_DIR/etc/rc1.d/K30${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
197 installf ${PKGNAME} $TEST_DIR/etc/rc2.d/S98${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
198else
199 [ "$RCS_D" = yes ] && \
200installf ${PKGNAME} $TEST_DIR/etc/rcS.d/K30${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
201 installf ${PKGNAME} $TEST_DIR/etc/rc0.d/K30${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
202 installf ${PKGNAME} $TEST_DIR/etc/rc1.d/K30${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
203 installf ${PKGNAME} $TEST_DIR/etc/rc2.d/S98${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
204fi
205
Tim Rice3a423462002-03-17 14:05:24 -0800206# If piddir doesn't exist we add it. (Ie. --with-pid-dir=/var/opt/ssh)
207[ -d $piddir ] || installf ${PKGNAME} $TEST_DIR$piddir d 755 root sys
208
Tim Rice29bdd2c2002-03-11 20:55:53 -0800209installf -f ${PKGNAME}
210
211[ "\${POST_INS_START}" = "yes" ] && ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} start
212exit 0
213_EOF
214
215## Build preremove file
216echo "Building preremove file..."
217cat > preremove << _EOF
218#! /sbin/sh
219#
220${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop
221exit 0
222_EOF
223
224## Build request file
225echo "Building request file..."
226cat > request << _EOF
227trap 'exit 3' 15
228USE_SYM_LINKS=no
229PRE_INS_STOP=no
230POST_INS_START=no
231# Use symbolic links?
232ans=\`ckyorn -d n \
233-p "Do you want symbolic links for the start/stop scripts? ${DEF_MSG}"\` || exit \$?
234case \$ans in
235 [y,Y]*) USE_SYM_LINKS=yes ;;
236esac
237
238# determine if should restart the daemon
239if [ -s ${piddir}/sshd.pid -a -f ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} ]
240then
241 ans=\`ckyorn -d n \
242-p "Should the running sshd daemon be restarted? ${DEF_MSG}"\` || exit \$?
243 case \$ans in
244 [y,Y]*) PRE_INS_STOP=yes
245 POST_INS_START=yes
246 ;;
247 esac
248
249else
250
251# determine if we should start sshd
252 ans=\`ckyorn -d n \
253-p "Start the sshd daemon after installing this package? ${DEF_MSG}"\` || exit \$?
254 case \$ans in
255 [y,Y]*) POST_INS_START=yes ;;
256 esac
257fi
258
259# make parameters available to installation service,
260# and so to any other packaging scripts
261cat >\$1 <<!
262USE_SYM_LINKS='\$USE_SYM_LINKS'
263PRE_INS_STOP='\$PRE_INS_STOP'
264POST_INS_START='\$POST_INS_START'
265!
266exit 0
267
268_EOF
269
270## Build space file
271echo "Building space file..."
272cat > space << _EOF
273# extra space required by start/stop links added by installf in postinstall
274$TEST_DIR/etc/rc0.d/K30${SYSVINIT_NAME} 0 1
275$TEST_DIR/etc/rc1.d/K30${SYSVINIT_NAME} 0 1
276$TEST_DIR/etc/rc2.d/S98${SYSVINIT_NAME} 0 1
277_EOF
278[ "$RCS_D" = yes ] && \
279echo "$TEST_DIR/etc/rcS.d/K30${SYSVINIT_NAME} 0 1" >> space
280
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +0000281## Next Build our prototype
282echo "Building prototype file..."
Tim Rice29bdd2c2002-03-11 20:55:53 -0800283cat >mk-proto.awk << _EOF
284 BEGIN { print "i pkginfo"; print "i preinstall"; \\
285 print "i postinstall"; print "i preremove"; \\
286 print "i request"; print "i space"; \\
287 split("$SYSTEM_DIR",sys_files); }
288 {
289 for (dir in sys_files) { if ( \$3 != sys_files[dir] )
290 { \$5="root"; \$6="sys"; }
291 else
292 { \$4="?"; \$5="?"; \$6="?"; break;}
293 } }
294 { print; }
295_EOF
296find . | egrep -v "prototype|pkginfo|mk-proto.awk" | sort | \
297 pkgproto $PROTO_ARGS | nawk -f mk-proto.awk > prototype
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +0000298
299## Step back a directory and now build the package.
300echo "Building package.."
301cd ..
Tim Rice29bdd2c2002-03-11 20:55:53 -0800302pkgmk -d ${FAKE_ROOT} -f $FAKE_ROOT/prototype -o
303echo | pkgtrans -os ${FAKE_ROOT} ${START}/$PKGNAME-$UNAME_S-$ARCH-$VERSION.pkg
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +0000304rm -rf $FAKE_ROOT
Tim Rice29bdd2c2002-03-11 20:55:53 -0800305