]>
Commit | Line | Data |
---|---|---|
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 | # | |
9 | umask 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 | 18 | PKGNAME=OpenSSH |
700318f3 | 19 | SYSVINIT_NAME=opensshd |
20 | MAKE=${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 | |
26 | SYSTEM_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 | } | |
68 | export 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 | |
80 | echo "Faking root install..." | |
81 | START=`pwd` | |
700318f3 | 82 | OPENSSHD_IN=`dirname $0`/opensshd.in |
3c0ef626 | 83 | FAKE_ROOT=$START/package |
700318f3 | 84 | [ -d $FAKE_ROOT ] && rm -fr $FAKE_ROOT |
3c0ef626 | 85 | mkdir $FAKE_ROOT |
700318f3 | 86 | ${MAKE} install-nokeys DESTDIR=$FAKE_ROOT |
87 | if [ $? -gt 0 ] | |
88 | then | |
89 | echo "Fake root install failed, stopping." | |
90 | exit 1 | |
91 | fi | |
3c0ef626 | 92 | |
93 | ## Fill in some details, like prefix and sysconfdir | |
700318f3 | 94 | for confvar in prefix exec_prefix bindir sbindir libexecdir datadir mandir sysconfdir piddir |
95 | do | |
96 | eval $confvar=`grep "^$confvar=" Makefile | cut -d = -f 2` | |
97 | done | |
3c0ef626 | 98 | |
700318f3 | 99 | ## Extract common info requires for the 'info' part of the package. |
100 | VERSION=`./ssh -V 2>&1 | sed -e 's/,.*//'` | |
3c0ef626 | 101 | |
700318f3 | 102 | UNAME_S=`uname -s` |
103 | case ${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` ;; | |
110 | esac | |
111 | ||
112 | ## Setup our run level stuff while we are at it. | |
113 | mkdir -p $FAKE_ROOT${TEST_DIR}/etc/init.d | |
3c0ef626 | 114 | |
115 | ## setup our initscript correctly | |
700318f3 | 116 | sed -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} | |
120 | chmod 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 | |
129 | perl -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 |
133 | mv $FAKE_ROOT/${sysconfdir}/ssh_config $FAKE_ROOT/${sysconfdir}/ssh_config.default | |
134 | mv $FAKE_ROOT/${sysconfdir}/sshd_config $FAKE_ROOT/${sysconfdir}/sshd_config.default | |
135 | [ -f $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds ] && \ | |
136 | mv $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds.default | |
137 | ||
138 | cd $FAKE_ROOT | |
3c0ef626 | 139 | |
140 | ## Ok, this is outright wrong, but it will work. I'm tired of pkgmk | |
141 | ## whining. | |
142 | for i in *; do | |
143 | PROTO_ARGS="$PROTO_ARGS $i=/$i"; | |
144 | done | |
145 | ||
146 | ## Build info file | |
147 | echo "Building pkginfo file..." | |
148 | cat > pkginfo << _EOF | |
149 | PKG=$PKGNAME | |
700318f3 | 150 | NAME="OpenSSH Portable for ${UNAME_S}" |
3c0ef626 | 151 | DESC="Secure Shell remote access utility; replaces telnet and rlogin/rsh." |
152 | VENDOR="OpenSSH Portable Team - http://www.openssh.com/portable.html" | |
3c0ef626 | 153 | ARCH=$ARCH |
154 | VERSION=$VERSION | |
700318f3 | 155 | CATEGORY="Security,application" |
3c0ef626 | 156 | BASEDIR=/ |
700318f3 | 157 | CLASSES="none" |
158 | _EOF | |
159 | ||
160 | ## Build preinstall file | |
161 | echo "Building preinstall file..." | |
162 | cat > preinstall << _EOF | |
163 | #! /sbin/sh | |
164 | # | |
165 | [ "\${PRE_INS_STOP}" = "yes" ] && ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop | |
166 | exit 0 | |
3c0ef626 | 167 | _EOF |
168 | ||
700318f3 | 169 | ## Build postinstall file |
170 | echo "Building postinstall file..." | |
171 | cat > 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 | ||
191 | if [ "\${USE_SYM_LINKS}" = yes ] | |
192 | then | |
193 | [ "$RCS_D" = yes ] && \ | |
194 | installf ${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 | |
198 | else | |
199 | [ "$RCS_D" = yes ] && \ | |
200 | installf ${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 | |
204 | fi | |
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 | ||
209 | installf -f ${PKGNAME} | |
210 | ||
211 | [ "\${POST_INS_START}" = "yes" ] && ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} start | |
212 | exit 0 | |
213 | _EOF | |
214 | ||
215 | ## Build preremove file | |
216 | echo "Building preremove file..." | |
217 | cat > preremove << _EOF | |
218 | #! /sbin/sh | |
219 | # | |
220 | ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop | |
221 | exit 0 | |
222 | _EOF | |
223 | ||
224 | ## Build request file | |
225 | echo "Building request file..." | |
226 | cat > request << _EOF | |
227 | trap 'exit 3' 15 | |
228 | USE_SYM_LINKS=no | |
229 | PRE_INS_STOP=no | |
230 | POST_INS_START=no | |
231 | # Use symbolic links? | |
232 | ans=\`ckyorn -d n \ | |
233 | -p "Do you want symbolic links for the start/stop scripts? ${DEF_MSG}"\` || exit \$? | |
234 | case \$ans in | |
235 | [y,Y]*) USE_SYM_LINKS=yes ;; | |
236 | esac | |
237 | ||
238 | # determine if should restart the daemon | |
239 | if [ -s ${piddir}/sshd.pid -a -f ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} ] | |
240 | then | |
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 | ||
249 | else | |
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 | |
257 | fi | |
258 | ||
259 | # make parameters available to installation service, | |
260 | # and so to any other packaging scripts | |
261 | cat >\$1 <<! | |
262 | USE_SYM_LINKS='\$USE_SYM_LINKS' | |
263 | PRE_INS_STOP='\$PRE_INS_STOP' | |
264 | POST_INS_START='\$POST_INS_START' | |
265 | ! | |
266 | exit 0 | |
267 | ||
268 | _EOF | |
269 | ||
270 | ## Build space file | |
271 | echo "Building space file..." | |
272 | cat > 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 ] && \ | |
279 | echo "$TEST_DIR/etc/rcS.d/K30${SYSVINIT_NAME} 0 1" >> space | |
280 | ||
3c0ef626 | 281 | ## Next Build our prototype |
282 | echo "Building prototype file..." | |
700318f3 | 283 | cat >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 | |
296 | find . | 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. | |
300 | echo "Building package.." | |
301 | cd .. | |
700318f3 | 302 | pkgmk -d ${FAKE_ROOT} -f $FAKE_ROOT/prototype -o |
303 | echo | pkgtrans -os ${FAKE_ROOT} ${START}/$PKGNAME-$UNAME_S-$ARCH-$VERSION.pkg | |
3c0ef626 | 304 | rm -rf $FAKE_ROOT |
700318f3 | 305 |