summaryrefslogtreecommitdiff
path: root/contrib/solaris/buildpkg.sh
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/solaris/buildpkg.sh')
-rwxr-xr-xcontrib/solaris/buildpkg.sh287
1 files changed, 251 insertions, 36 deletions
diff --git a/contrib/solaris/buildpkg.sh b/contrib/solaris/buildpkg.sh
index 05abb2236..20f8544aa 100755
--- a/contrib/solaris/buildpkg.sh
+++ b/contrib/solaris/buildpkg.sh
@@ -1,52 +1,139 @@
1#!/bin/sh 1#!/bin/sh
2# 2#
3# Fake Root Solaris Build System - Prototype 3# Fake Root Solaris/SVR4/SVR5 Build System - Prototype
4# 4#
5# The following code has been provide under Public Domain License. I really 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 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) 7# nor my employer if you break it. - Ben Lindstrom (mouring@eviladmin.org)
8# 8#
9umask 022 9umask 022
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
10PKGNAME=OpenSSH 18PKGNAME=OpenSSH
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/opt \
33/opt/bin \
34/usr \
35/usr/bin \
36/usr/lib \
37/usr/sbin \
38/usr/share \
39/usr/share/man \
40/usr/share/man/man1 \
41/usr/share/man/man8 \
42/usr/local \
43/usr/local/bin \
44/usr/local/etc \
45/usr/local/libexec \
46/usr/local/man \
47/usr/local/man/man1 \
48/usr/local/man/man8 \
49/usr/local/sbin \
50/usr/local/share \
51/var \
52/var/run \
53/var/tmp \
54/tmp"
11 55
12## Extract common info requires for the 'info' part of the package. 56# We may need to buiild as root so we make sure PATH is set up
13VERSION=`tail -1 ../../version.h | sed -e 's/.*_\([0-9]\)/\1/g' | sed 's/\"$//'` 57# only set the path if it's not set already
14ARCH=`uname -p` 58[ -d /usr/local/bin ] && {
59 echo $PATH | grep ":/usr/local/bin" > /dev/null 2>&1
60 [ $? -ne 0 ] && PATH=$PATH:/usr/local/bin
61}
62[ -d /usr/ccs/bin ] && {
63 echo $PATH | grep ":/usr/ccs/bin" > /dev/null 2>&1
64 [ $? -ne 0 ] && PATH=$PATH:/usr/ccs/bin
65}
66export PATH
67#
68
69[ -f Makefile ] || {
70 echo "Please run this script from your build directory"
71 exit 1
72}
73
74# we will look for config.local to override the above options
75[ -s ./config.local ] && . ./config.local
15 76
16## Start by faking root install 77## Start by faking root install
17echo "Faking root install..." 78echo "Faking root install..."
18START=`pwd` 79START=`pwd`
80OPENSSHD_IN=`dirname $0`/opensshd.in
19FAKE_ROOT=$START/package 81FAKE_ROOT=$START/package
82[ -d $FAKE_ROOT ] && rm -fr $FAKE_ROOT
20mkdir $FAKE_ROOT 83mkdir $FAKE_ROOT
21cd ../.. 84${MAKE} install-nokeys DESTDIR=$FAKE_ROOT
22make install-nokeys DESTDIR=$FAKE_ROOT 85if [ $? -gt 0 ]
86then
87 echo "Fake root install failed, stopping."
88 exit 1
89fi
23 90
24## Fill in some details, like prefix and sysconfdir 91## Fill in some details, like prefix and sysconfdir
25ETCDIR=`grep "^sysconfdir=" Makefile | sed 's/sysconfdir=//'` 92for confvar in prefix exec_prefix bindir sbindir libexecdir datadir mandir sysconfdir piddir
26PREFIX=`grep "^prefix=" Makefile | cut -d = -f 2` 93do
27PIDDIR=`grep "^piddir=" Makefile | cut -d = -f 2` 94 eval $confvar=`grep "^$confvar=" Makefile | cut -d = -f 2`
28cd $FAKE_ROOT 95done
29 96
30## Setup our run level stuff while we are at it. 97## Extract common info requires for the 'info' part of the package.
31mkdir -p $FAKE_ROOT/etc/init.d 98VERSION=`./ssh -V 2>&1 | sed -e 's/,.*//'`
32mkdir -p $FAKE_ROOT/etc/rcS.d
33mkdir -p $FAKE_ROOT/etc/rc0.d
34mkdir -p $FAKE_ROOT/etc/rc1.d
35mkdir -p $FAKE_ROOT/etc/rc2.d
36 99
100UNAME_S=`uname -s`
101case ${UNAME_S} in
102 SunOS) UNAME_S=Solaris
103 ARCH=`uname -p`
104 RCS_D=yes
105 DEF_MSG="(default: n)"
106 ;;
107 *) ARCH=`uname -m` ;;
108esac
109
110## Setup our run level stuff while we are at it.
111mkdir -p $FAKE_ROOT${TEST_DIR}/etc/init.d
37 112
38## setup our initscript correctly 113## setup our initscript correctly
39sed -e "s#%%configDir%%#$ETCDIR#g" \ 114sed -e "s#%%configDir%%#${sysconfdir}#g" \
40 -e "s#%%openSSHDir%%#$PREFIX#g" \ 115 -e "s#%%openSSHDir%%#$prefix#g" \
41 -e "s#%%pidDir%%#$PIDDIR#g" \ 116 -e "s#%%pidDir%%#${piddir}#g" \
42 ../opensshd.in > $FAKE_ROOT/etc/init.d/opensshd 117 ${OPENSSHD_IN} > $FAKE_ROOT${TEST_DIR}/etc/init.d/${SYSVINIT_NAME}
43chmod 711 $FAKE_ROOT/etc/init.d/opensshd 118chmod 744 $FAKE_ROOT${TEST_DIR}/etc/init.d/${SYSVINIT_NAME}
44 119
45ln -s ../init.d/opensshd $FAKE_ROOT/etc/rcS.d/K30opensshd 120[ "${PERMIT_ROOT_LOGIN}" = no ] && \
46ln -s ../init.d/opensshd $FAKE_ROOT/etc/rc0.d/K30opensshd 121 perl -p -i -e "s/#PermitRootLogin yes/PermitRootLogin no/" \
47ln -s ../init.d/opensshd $FAKE_ROOT/etc/rc1.d/K30opensshd 122 $FAKE_ROOT/${sysconfdir}/sshd_config
48ln -s ../init.d/opensshd $FAKE_ROOT/etc/rc2.d/S98opensshd 123[ "${X11_FORWARDING}" = yes ] && \
124 perl -p -i -e "s/#X11Forwarding no/X11Forwarding yes/" \
125 $FAKE_ROOT/${sysconfdir}/sshd_config
126# fix PrintMotd
127perl -p -i -e "s/#PrintMotd yes/PrintMotd no/" \
128 $FAKE_ROOT/${sysconfdir}/sshd_config
49 129
130# We don't want to overwrite config files on multiple installs
131mv $FAKE_ROOT/${sysconfdir}/ssh_config $FAKE_ROOT/${sysconfdir}/ssh_config.default
132mv $FAKE_ROOT/${sysconfdir}/sshd_config $FAKE_ROOT/${sysconfdir}/sshd_config.default
133[ -f $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds ] && \
134mv $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds.default
135
136cd $FAKE_ROOT
50 137
51## Ok, this is outright wrong, but it will work. I'm tired of pkgmk 138## Ok, this is outright wrong, but it will work. I'm tired of pkgmk
52## whining. 139## whining.
@@ -58,28 +145,156 @@ done
58echo "Building pkginfo file..." 145echo "Building pkginfo file..."
59cat > pkginfo << _EOF 146cat > pkginfo << _EOF
60PKG=$PKGNAME 147PKG=$PKGNAME
61NAME=OpenSSH Portable for Solaris 148NAME="OpenSSH Portable for ${UNAME_S}"
62DESC="Secure Shell remote access utility; replaces telnet and rlogin/rsh." 149DESC="Secure Shell remote access utility; replaces telnet and rlogin/rsh."
63VENDOR="OpenSSH Portable Team - http://www.openssh.com/portable.html" 150VENDOR="OpenSSH Portable Team - http://www.openssh.com/portable.html"
64BASEDIR=$FAKE_ROOT
65ARCH=$ARCH 151ARCH=$ARCH
66VERSION=$VERSION 152VERSION=$VERSION
67CATEGORY=Security 153CATEGORY="Security,application"
68BASEDIR=/ 154BASEDIR=/
155CLASSES="none"
156_EOF
157
158## Build preinstall file
159echo "Building preinstall file..."
160cat > preinstall << _EOF
161#! /sbin/sh
162#
163[ "\${PRE_INS_STOP}" = "yes" ] && ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop
164exit 0
165_EOF
166
167## Build postinstall file
168echo "Building postinstall file..."
169cat > postinstall << _EOF
170#! /sbin/sh
171#
172[ -f ${sysconfdir}/ssh_config ] || \\
173 cp -p ${sysconfdir}/ssh_config.default ${sysconfdir}/ssh_config
174[ -f ${sysconfdir}/sshd_config ] || \\
175 cp -p ${sysconfdir}/sshd_config.default ${sysconfdir}/sshd_config
176[ -f ${sysconfdir}/ssh_prng_cmds.default ] && {
177 [ -f ${sysconfdir}/ssh_prng_cmds ] || \\
178 cp -p ${sysconfdir}/ssh_prng_cmds.default ${sysconfdir}/ssh_prng_cmds
179}
180
181# make rc?.d dirs only if we are doing a test install
182[ -n "${TEST_DIR}" ] && {
183 [ "$RCS_D" = yes ] && mkdir -p ${TEST_DIR}/etc/rcS.d
184 mkdir -p ${TEST_DIR}/etc/rc0.d
185 mkdir -p ${TEST_DIR}/etc/rc1.d
186 mkdir -p ${TEST_DIR}/etc/rc2.d
187}
188
189if [ "\${USE_SYM_LINKS}" = yes ]
190then
191 [ "$RCS_D" = yes ] && \
192installf ${PKGNAME} $TEST_DIR/etc/rcS.d/K30${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
193 installf ${PKGNAME} $TEST_DIR/etc/rc0.d/K30${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
194 installf ${PKGNAME} $TEST_DIR/etc/rc1.d/K30${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
195 installf ${PKGNAME} $TEST_DIR/etc/rc2.d/S98${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
196else
197 [ "$RCS_D" = yes ] && \
198installf ${PKGNAME} $TEST_DIR/etc/rcS.d/K30${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
199 installf ${PKGNAME} $TEST_DIR/etc/rc0.d/K30${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
200 installf ${PKGNAME} $TEST_DIR/etc/rc1.d/K30${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
201 installf ${PKGNAME} $TEST_DIR/etc/rc2.d/S98${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
202fi
203
204installf -f ${PKGNAME}
205
206[ "\${POST_INS_START}" = "yes" ] && ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} start
207exit 0
69_EOF 208_EOF
70 209
210## Build preremove file
211echo "Building preremove file..."
212cat > preremove << _EOF
213#! /sbin/sh
214#
215${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop
216exit 0
217_EOF
218
219## Build request file
220echo "Building request file..."
221cat > request << _EOF
222trap 'exit 3' 15
223USE_SYM_LINKS=no
224PRE_INS_STOP=no
225POST_INS_START=no
226# Use symbolic links?
227ans=\`ckyorn -d n \
228-p "Do you want symbolic links for the start/stop scripts? ${DEF_MSG}"\` || exit \$?
229case \$ans in
230 [y,Y]*) USE_SYM_LINKS=yes ;;
231esac
232
233# determine if should restart the daemon
234if [ -s ${piddir}/sshd.pid -a -f ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} ]
235then
236 ans=\`ckyorn -d n \
237-p "Should the running sshd daemon be restarted? ${DEF_MSG}"\` || exit \$?
238 case \$ans in
239 [y,Y]*) PRE_INS_STOP=yes
240 POST_INS_START=yes
241 ;;
242 esac
243
244else
245
246# determine if we should start sshd
247 ans=\`ckyorn -d n \
248-p "Start the sshd daemon after installing this package? ${DEF_MSG}"\` || exit \$?
249 case \$ans in
250 [y,Y]*) POST_INS_START=yes ;;
251 esac
252fi
253
254# make parameters available to installation service,
255# and so to any other packaging scripts
256cat >\$1 <<!
257USE_SYM_LINKS='\$USE_SYM_LINKS'
258PRE_INS_STOP='\$PRE_INS_STOP'
259POST_INS_START='\$POST_INS_START'
260!
261exit 0
262
263_EOF
264
265## Build space file
266echo "Building space file..."
267cat > space << _EOF
268# extra space required by start/stop links added by installf in postinstall
269$TEST_DIR/etc/rc0.d/K30${SYSVINIT_NAME} 0 1
270$TEST_DIR/etc/rc1.d/K30${SYSVINIT_NAME} 0 1
271$TEST_DIR/etc/rc2.d/S98${SYSVINIT_NAME} 0 1
272_EOF
273[ "$RCS_D" = yes ] && \
274echo "$TEST_DIR/etc/rcS.d/K30${SYSVINIT_NAME} 0 1" >> space
275
71## Next Build our prototype 276## Next Build our prototype
72echo "Building prototype file..." 277echo "Building prototype file..."
73find . | egrep -v "prototype|pkginfo" | sort | pkgproto $PROTO_ARGS | \ 278cat >mk-proto.awk << _EOF
74 awk ' 279 BEGIN { print "i pkginfo"; print "i preinstall"; \\
75 BEGIN { print "i pkginfo" } 280 print "i postinstall"; print "i preremove"; \\
76 { $5="root"; $6="sys"; } 281 print "i request"; print "i space"; \\
77 { print; }' > prototype 282 split("$SYSTEM_DIR",sys_files); }
283 {
284 for (dir in sys_files) { if ( \$3 != sys_files[dir] )
285 { \$5="root"; \$6="sys"; }
286 else
287 { \$4="?"; \$5="?"; \$6="?"; break;}
288 } }
289 { print; }
290_EOF
291find . | egrep -v "prototype|pkginfo|mk-proto.awk" | sort | \
292 pkgproto $PROTO_ARGS | nawk -f mk-proto.awk > prototype
78 293
79## Step back a directory and now build the package. 294## Step back a directory and now build the package.
80echo "Building package.." 295echo "Building package.."
81cd .. 296cd ..
82pkgmk -d . -f $FAKE_ROOT/prototype -o 297pkgmk -d ${FAKE_ROOT} -f $FAKE_ROOT/prototype -o
298echo | pkgtrans -os ${FAKE_ROOT} ${START}/$PKGNAME-$UNAME_S-$ARCH-$VERSION.pkg
83rm -rf $FAKE_ROOT 299rm -rf $FAKE_ROOT
84echo | pkgtrans -os . $PKGNAME-$ARCH-$VERSION.pkg 300
85rm -rf $PKGNAME