Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Apr 1998 00:23:51 -0700
From:      "Jordan K. Hubbard" <jkh@time.cdrom.com>
To:        ports@FreeBSD.ORG
Subject:   Useful hack or just weird?
Message-ID:  <14759.893575431@time.cdrom.com>

next in thread | raw e-mail | index | archive | help
You be the judge..  This little hack lets the ports collection install
"stubs" rather than full binaries, the mission in life of each stub
being to essentially commit suicide by installing the relevant package
on top of itself and then reinvoking the real binary with the original
arguments.

This is also sort of a shell-script equivalent of thinking out loud,
so please don't judge my little quick hack too harshly - it was all of
a 10 minute job.  I can identify right off the bat, in fact, a number
of its shortcomings: Its "media search" is extremely simplistic in its
assumption of where packages are, its derivation of "EXECNAME" is
similarly simplistic and surely won't work for all the packages
(especially ones with version clash) and it doesn't adequately
determine when it's running non-interactively and should just shut up
with the various status reports.  That said, for such a small hack, it
also works a lot better than I thought it would. :-)

Unpack the following sharchive and do the following:

#      patch -d /usr/share/mk < port-stub.diffs
#      install -c -m 755 port-stub.sh /usr/share/misc
       (it is very important that port-stub.sh be executable!)

Then go to some port directory (for a port you _haven't_ yet
installed) and say "make install-stubs" to install a stub executable
for it.  Then you just invoke this executable as you normally would
(perhaps after rehashing your shell) and it should come up after the
associated package is found and loaded from the current directory,
your mounted FreeBSD cdrom or the ftp.freebsd.org site (in that order).

Like I said, useful or weird?  You decide. :-)

P.S. If anyone can tell me how to make "yap()" in the port-stub script
be quiet when run non-interactively, I'd appreciate it.  I only know
how to check non-interactivity with csh. :-) Thanks.

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	port-stub.diffs
#	port-stub.sh
#
echo x - port-stub.diffs
sed 's/^X//' >port-stub.diffs << 'END-of-port-stub.diffs'
XIndex: bsd.port.mk
X===================================================================
XRCS file: /home/ncvs/src/share/mk/bsd.port.mk,v
Xretrieving revision 1.227.2.35
Xdiff -u -u -r1.227.2.35 bsd.port.mk
X--- bsd.port.mk	1998/03/24 03:35:54	1.227.2.35
X+++ bsd.port.mk	1998/04/26 06:43:58
X@@ -87,6 +87,8 @@
X # PKGNAME		- Name of the package file to create if the DISTNAME 
X #				  isn't really relevant for the port/package
X #				  (default: ${DISTNAME}).
X+# EXECNAME		- String to derive "stub executable" name from if creating
X+#				  stubs.  (default: ${PKGNAME})
X # EXTRACT_ONLY	- If defined, a subset of ${DISTFILES} you want to
X #			  	  actually extract.
X # PATCHDIR 		- A directory containing any additional patches you made
X@@ -632,6 +634,8 @@
X # Derived names so that they're easily overridable.
X DISTFILES?=		${DISTNAME}${EXTRACT_SUFX}
X PKGNAME?=		${DISTNAME}
X+EXECNAME?=		${PKGNAME}
X+PORTSTUB?=		/usr/share/misc/port-stub.sh
X 
X ALLFILES?=	${DISTFILES} ${PATCHFILES}
X 
X@@ -1796,6 +1800,13 @@
X 				fi; \
X 			fi; \
X 		done; \
X+	fi
X+.endif
X+
X+.if !target(install-stubs)
X+install-stubs:
X+	@if [ ! -z "${EXECNAME}" -a -x ${PORTSTUB} ]; then \
X+		${SETENV} PKGNAME=${PKGNAME} ${PORTSTUB} ${PREFIX}/bin/`echo ${EXECNAME} | sed -e 's/[_.-].*//'`; \
X 	fi
X .endif
X 
XIndex: bsd.port.subdir.mk
X===================================================================
XRCS file: /home/ncvs/src/share/mk/bsd.port.subdir.mk,v
Xretrieving revision 1.15.2.3
Xdiff -u -u -r1.15.2.3 bsd.port.subdir.mk
X--- bsd.port.subdir.mk	1997/11/20 05:36:46	1.15.2.3
X+++ bsd.port.subdir.mk	1998/04/26 06:43:06
X@@ -129,6 +129,10 @@
X readmes: readme _SUBDIRUSE
X .endif
X 
X+.if !target(install-subs)
X+install-stubs: _SUBDIRUSE
X+.endif
X+
X .if !target(readme)
X readme:
X 	@rm -f README.html
END-of-port-stub.diffs
echo x - port-stub.sh
sed 's/^X//' >port-stub.sh << 'END-of-port-stub.sh'
X#!/bin/sh
X#
X# Don't move this!
X_PKGNAME=__PKGNAME
X
X# Be selectively verbose (someday)
Xyap() {
X	echo $*
X}
X
X# Main body.  First check to see if we're just an installer invocation.
Xif [ "${_PKGNAME}" = "__PKGNAME" ]; then
X	if [ $# -ne 1 ]; then
X		yap "This script should only be run by the install-stubs target in ports."
X	elif [ -f $1 ]; then
X		yap "$1 already exists, not installing stub."
X	elif [ ! -w `dirname $1` ]; then
X		yap "No write permission for `dirname $1`, can't install stub."
X	else
X		yap "===> Installing stub file for $1"
X		sed -e "1,5s/__PKGNAME/${PKGNAME}/" < $0 > $1 && chmod 755 $1
X	fi
X	return 0
Xfi
X
XRELNAME=`uname -r | sed -e 's/-.*//'`
Xif [ -r ${_PKGNAME}.tgz ]; then
X	_PKGFILE=${_PKGNAME}.tgz
Xelif [ -r /cdrom/packages/All/${_PKGNAME}.tgz ]; then
X	_PKGFILE=/cdrom/packages/All/${_PKGNAME}.tgz
Xelse
X	_PKGFILE=ftp://ftp.freebsd.org/pub/FreeBSD/packages-${RELNAME}/All/${_PKGNAME}.tgz
Xfi
Xyap "$0 is not currently installed on your system."
Xyap "Attempting to install the associated package from:"
Xyap "${_PKGFILE}."
Xif ! pkg_add ${_PKGFILE}; then
X	yap "Unable to add package ${_PKGFILE}, sorry!";
X	return 1
Xfi
Xexec $0 $*
END-of-port-stub.sh
exit





To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?14759.893575431>