]> andersk Git - gssapi-openssh.git/blame - openssh/contrib/solaris/buildpkg.sh
Import of OpenSSH 3.2.2p1
[gssapi-openssh.git] / openssh / contrib / solaris / buildpkg.sh
CommitLineData
3c0ef626 1#!/bin/sh
2#
700318f3 3# Fake Root Solaris/SVR4/SVR5 Build System - Prototype
3c0ef626 4#
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
700318f3 10#
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
3c0ef626 18PKGNAME=OpenSSH
700318f3 19SYSVINIT_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 \
32/etc/opt \
33/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 \
53/var/opt \
54/var/run \
55/var/tmp \
56/tmp"
3c0ef626 57
700318f3 58# 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
3c0ef626 78
79## Start by faking root install
80echo "Faking root install..."
81START=`pwd`
700318f3 82OPENSSHD_IN=`dirname $0`/opensshd.in
3c0ef626 83FAKE_ROOT=$START/package
700318f3 84[ -d $FAKE_ROOT ] && rm -fr $FAKE_ROOT
3c0ef626 85mkdir $FAKE_ROOT
700318f3 86${MAKE} install-nokeys DESTDIR=$FAKE_ROOT
87if [ $? -gt 0 ]
88then
89 echo "Fake root install failed, stopping."
90 exit 1
91fi
3c0ef626 92
93## Fill in some details, like prefix and sysconfdir
700318f3 94for confvar in prefix exec_prefix bindir sbindir libexecdir datadir mandir sysconfdir piddir
95do
96 eval $confvar=`grep "^$confvar=" Makefile | cut -d = -f 2`
97done
3c0ef626 98
700318f3 99## Extract common info requires for the 'info' part of the package.
100VERSION=`./ssh -V 2>&1 | sed -e 's/,.*//'`
3c0ef626 101
700318f3 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
111
112## Setup our run level stuff while we are at it.
113mkdir -p $FAKE_ROOT${TEST_DIR}/etc/init.d
3c0ef626 114
115## setup our initscript correctly
700318f3 116sed -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}
3c0ef626 121
700318f3 122[ "${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
3c0ef626 131
700318f3 132# 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
3c0ef626 139
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
700318f3 150NAME="OpenSSH Portable for ${UNAME_S}"
3c0ef626 151DESC="Secure Shell remote access utility; replaces telnet and rlogin/rsh."
152VENDOR="OpenSSH Portable Team - http://www.openssh.com/portable.html"
3c0ef626 153ARCH=$ARCH
154VERSION=$VERSION
700318f3 155CATEGORY="Security,application"
3c0ef626 156BASEDIR=/
700318f3 157CLASSES="none"
158_EOF
159
160## 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
3c0ef626 167_EOF
168
700318f3 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
206# 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
209installf -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
3c0ef626 281## Next Build our prototype
282echo "Building prototype file..."
700318f3 283cat >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
3c0ef626 298
299## Step back a directory and now build the package.
300echo "Building package.."
301cd ..
700318f3 302pkgmk -d ${FAKE_ROOT} -f $FAKE_ROOT/prototype -o
303echo | pkgtrans -os ${FAKE_ROOT} ${START}/$PKGNAME-$UNAME_S-$ARCH-$VERSION.pkg
3c0ef626 304rm -rf $FAKE_ROOT
700318f3 305
This page took 0.106524 seconds and 5 git commands to generate.