[csw-devel] SF.net SVN: gar:[9868] csw/mgar/pkg/alternatives

theferret at users.sourceforge.net theferret at users.sourceforge.net
Fri May 14 20:45:54 CEST 2010


Revision: 9868
          http://gar.svn.sourceforge.net/gar/?rev=9868&view=rev
Author:   theferret
Date:     2010-05-14 18:45:54 +0000 (Fri, 14 May 2010)

Log Message:
-----------
alternatives: commited my overhaul into svn

Modified Paths:
--------------
    csw/mgar/pkg/alternatives/trunk/Makefile

Added Paths:
-----------
    csw/mgar/pkg/alternatives/branches/Makefile
    csw/mgar/pkg/alternatives/branches/checksums
    csw/mgar/pkg/alternatives/branches/files/
    csw/mgar/pkg/alternatives/trunk/alternatives
    csw/mgar/pkg/alternatives/trunk/copyright
    csw/mgar/pkg/alternatives/trunk/i.cswalternatives
    csw/mgar/pkg/alternatives/trunk/pkginfo
    csw/mgar/pkg/alternatives/trunk/prototype
    csw/mgar/pkg/alternatives/trunk/r.cswalternatives

Removed Paths:
-------------
    csw/mgar/pkg/alternatives/trunk/checksums
    csw/mgar/pkg/alternatives/trunk/files/

Copied: csw/mgar/pkg/alternatives/branches/Makefile (from rev 9789, csw/mgar/pkg/alternatives/trunk/Makefile)
===================================================================
--- csw/mgar/pkg/alternatives/branches/Makefile	                        (rev 0)
+++ csw/mgar/pkg/alternatives/branches/Makefile	2010-05-14 18:45:54 UTC (rev 9868)
@@ -0,0 +1,41 @@
+# : Makefile 9089 2010-03-11 08:34:46Z wahwah $
+GARNAME = alternatives
+GARVERSION = 1.0
+CATEGORIES = utils
+
+DESCRIPTION = Alternatives implementation specific to OpenCSW
+define BLURB
+endef
+
+MASTER_SITES = 
+DISTFILES  = alternatives alternatives.8
+DISTFILES += CSWalternatives.i.cswalternatives
+DISTFILES += CSWalternatives.r.cswalternatives
+DISTFILES += LICENSE-2.0.txt
+
+# File name regex to get notifications about upstream software releases
+UFILES_REGEX = $(GARNAME)-(\d+(?:\.\d+)*).tar.gz
+
+LICENSE = LICENSE-2.0.txt
+
+VENDOR_URL = http://wiki.opencsw.org/project-alternatives
+
+CONFIGURE_SCRIPTS = 
+BUILD_SCRIPTS =
+INSTALL_SCRIPTS = custom
+TEST_SCRIPTS = 
+
+include gar/category.mk
+
+install-custom:
+	ginstall -d $(DESTDIR)$(bindir)
+	ginstall $(WORKDIR)/alternatives $(DESTDIR)$(bindir)
+	ginstall -d $(DESTDIR)$(mandir)/man8
+	ginstall $(WORKDIR)/alternatives.1 $(DESTDIR)$(mandir)/man8
+	ginstall -d $(DESTDIR)/etc/opt/csw/alternatives
+	ginstall -d $(DESTDIR)/etc/opt/csw/preserve/CSWalternatives/alternatives
+	ginstall -d $(DESTDIR)/var/opt/csw/alternatives
+	ginstall -d $(DESTDIR)/usr/sadm/install/scripts
+	ginstall $(WORKDIR)/CSWalternatives.i.cswalternatives $(DESTDIR)/usr/sadm/install/scripts/i.cswalternatives
+	ginstall $(WORKDIR)/CSWalternatives.r.cswalternatives $(DESTDIR)/usr/sadm/install/scripts/r.cswalternatives
+	@$(MAKECOOKIE)

Copied: csw/mgar/pkg/alternatives/branches/checksums (from rev 9789, csw/mgar/pkg/alternatives/trunk/checksums)
===================================================================
--- csw/mgar/pkg/alternatives/branches/checksums	                        (rev 0)
+++ csw/mgar/pkg/alternatives/branches/checksums	2010-05-14 18:45:54 UTC (rev 9868)
@@ -0,0 +1,5 @@
+5e7b546021e5606165c34f154b70bc7b  CSWalternatives.i.cswalternatives
+b610f50080c8ffe65037bb9891316935  CSWalternatives.r.cswalternatives
+3b83ef96387f14655fc854ddc3c6bd57  LICENSE-2.0.txt
+d41d8cd98f00b204e9800998ecf8427e  alternatives
+d41d8cd98f00b204e9800998ecf8427e  alternatives.8

Modified: csw/mgar/pkg/alternatives/trunk/Makefile
===================================================================
--- csw/mgar/pkg/alternatives/trunk/Makefile	2010-05-14 17:56:52 UTC (rev 9867)
+++ csw/mgar/pkg/alternatives/trunk/Makefile	2010-05-14 18:45:54 UTC (rev 9868)
@@ -1,41 +1,6 @@
-# : Makefile 9089 2010-03-11 08:34:46Z wahwah $
-GARNAME = alternatives
-GARVERSION = 1.0
-CATEGORIES = utils
+package:	alternatives
+	createpkg -b `pwd`
+	touch package
 
-DESCRIPTION = Alternatives implementation specific to OpenCSW
-define BLURB
-endef
-
-MASTER_SITES = 
-DISTFILES  = alternatives alternatives.8
-DISTFILES += CSWalternatives.i.cswalternatives
-DISTFILES += CSWalternatives.r.cswalternatives
-DISTFILES += LICENSE-2.0.txt
-
-# File name regex to get notifications about upstream software releases
-UFILES_REGEX = $(GARNAME)-(\d+(?:\.\d+)*).tar.gz
-
-LICENSE = LICENSE-2.0.txt
-
-VENDOR_URL = http://wiki.opencsw.org/project-alternatives
-
-CONFIGURE_SCRIPTS = 
-BUILD_SCRIPTS =
-INSTALL_SCRIPTS = custom
-TEST_SCRIPTS = 
-
-include gar/category.mk
-
-install-custom:
-	ginstall -d $(DESTDIR)$(bindir)
-	ginstall $(WORKDIR)/alternatives $(DESTDIR)$(bindir)
-	ginstall -d $(DESTDIR)$(mandir)/man8
-	ginstall $(WORKDIR)/alternatives.1 $(DESTDIR)$(mandir)/man8
-	ginstall -d $(DESTDIR)/etc/opt/csw/alternatives
-	ginstall -d $(DESTDIR)/etc/opt/csw/preserve/CSWalternatives/alternatives
-	ginstall -d $(DESTDIR)/var/opt/csw/alternatives
-	ginstall -d $(DESTDIR)/usr/sadm/install/scripts
-	ginstall $(WORKDIR)/CSWalternatives.i.cswalternatives $(DESTDIR)/usr/sadm/install/scripts/i.cswalternatives
-	ginstall $(WORKDIR)/CSWalternatives.r.cswalternatives $(DESTDIR)/usr/sadm/install/scripts/r.cswalternatives
-	@$(MAKECOOKIE)
+clean:
+	rm *.pkg.gz

Added: csw/mgar/pkg/alternatives/trunk/alternatives
===================================================================
--- csw/mgar/pkg/alternatives/trunk/alternatives	                        (rev 0)
+++ csw/mgar/pkg/alternatives/trunk/alternatives	2010-05-14 18:45:54 UTC (rev 9868)
@@ -0,0 +1,311 @@
+#!/bin/ksh -p
+
+# ksh high-level implentation of linux style "alternatives".
+# Author: Philip Brown, phil at bolthole.com, 2010
+# @(#) alternatives 1.6@(#)
+
+PRIORITIESDIR=/opt/csw/share/alternatives 
+MANUALDIR=/etc/opt/etc/alternatives  #manual override location
+AWK=nawk
+DEBUG=${DEBUG:-/bin/true}
+
+function usage {
+	prog=`basename $0`
+	print "Usage for $prog :"
+	print "  $prog --display {name}"
+	print "  $prog --auto {name}"
+	print "  $prog --set {name} {/full/path}"
+	# --config interactive chooser, not implemented at this time
+	print "  "
+	print " The following are provided for compatibility, but do not work"
+	print " in exactly the same way as linux variants"
+	print " See usage function code for more information."
+	print "  $prog --install {/full/path/name} {name} {#priority}"
+	print "  $prog --remove {name} {/full/path}"
+
+# I dont want to bloat up the usage message, so here's a little more doc
+#  
+# This program is a lightweight 'workalike' to the linux alternatives prog.
+# It is written with OpenCSW in mind, and is specificaly tailored for
+# our needs. You may find it useful in other fields, but be aware that
+# its primary purpose is to be simple, and flexible. NOT an exact clone.
+# Part of its flexibility comes from the fact that it is configuration-file
+# driven, NOT internal-database-driven
+#   The --install and --remove flags, while (hopefully) provided as
+# a convenience, do NOT install, or remove, anything.
+# Priorities are driven by configuration files delivered by our packages.
+# They get delivered to /opt/csw, which keeps things NFS friendly.
+# Things only get "installed" or "removed" on a per-SVR4 package basis
+# normally. (although technically, it would be possible to drop in your
+# own config file in either $PRIORITIESDIR or $MANUALDIR, and then
+# have things integrate with your own custom non-packaged software).
+#
+# There is NO ERROR CHECKING, or saving state of prior actions,
+# other than the --set comand. 
+# It is up to individual implementers to make sure that everyone providing
+#  an alternative for {name}, all have the same "slaves"
+#     (when I actualy support "slave" links, anyway)
+
+}
+
+
+# Usage: find_highest_prio {name}
+#   search through all conf files for {name}
+# print out the highest priority match. or, potentially nothing.
+function find_highest_prio {
+	if [[ "$1" == "" ]] ; then
+		print INTERNAL ERROR: find_highest_prio called with no args
+		return
+	fi
+	# I hate using cat, but its the only way to avoid nawk throwing a fit.
+	cat $PRIORITIESDIR/* $MANUALDIR/* 2>/dev/null |
+	$AWK '	BEGIN {save=""}
+		$2 == "'$1'" {if($4 > highest){
+				save=$0;
+				highest=$4
+				}
+		}
+		
+		END {print save}
+	'
+}
+
+if [[ $# -lt 1 ]] ; then
+	print error: need an argument
+	usage
+	exit 1
+fi
+
+
+############################################################
+# Start of subroutine area
+
+# Usage: print_alternatives shortname
+# This prints only the INSTALLED alternatives lines, not manual settings
+# Prints in priority-sorted order
+function print_alternatives {
+	if [[ $# != 1 ]] ; then print ERROR print_alternatives needs an arg; fi
+	cat $PRIORITIESDIR/* 2>/dev/null|
+		nawk '$2 == "'$1'" {print}' | sort -nr +3
+}
+# prints ONLY the manually set alternatives line, if present
+function print_manual_set {
+	if [[ $# != 1 ]] ; then print ERROR print_manual_set needs an arg; fi
+	
+	if [[ -f $MANUALDIR/$1 ]] ; then
+		nawk '$2 == "'$1'" {print}' $MANUALDIR/$1
+	else
+		return 1
+	fi
+}
+
+function fileerr_exit {
+	print Debug: potentially should check to see if /opt/csw is
+	print  specifically read-only, or we're in jumpstart, or something
+	print  before returning a bad status exit, perhaps
+	exit 1
+}
+
+# Called only by set_alternative.
+#  args:   {target} {shortname} {implementation-path}
+# Split out, because one "alternatives" line may have multiple "slave" links
+function set_link {
+	$DEBUG set_link called with: $1 $2 $3
+	if [[ $# -lt 3 ]] ; then
+		print ERROR: set_link needs 3 arguments
+		return 1
+	fi
+	
+	if [[ -h $1 ]] ; then
+		linktarget=`ls -l $1 | nawk '{print $NF}'`
+		if [[ "$linktarget" == "$3 ]] ; then
+			$DEBUG $1 already linked to $3
+			return 0
+		fi
+		
+		$DEBUG removing symlink $1
+		/bin/rm -f $1
+		if [[ $? -ne 0 ]] ; then
+			$DEBUG permission to remove $1 failed
+			filerr_exit
+		fi
+	fi
+	if [[ ! -f $1 ]] ; then
+		$DEBUG linking $1 to $3
+		ln -s $3 $1
+		if [[ $? -ne 0 ]] ; then
+			$DEBUG permission to create symlink for $1 failed
+			filerr_exit
+		fi
+		return 0
+	else
+		print ERROR: $1 exists, and is not symlink.
+		print Not installing $3 as $1
+		return 1
+	fi
+
+	## Note to self: check existing, and dont attempt to
+	## update if already set how we want it?
+	## Also, dont crash if /opt/csw is read-only.
+	## Just politely print warning, and exit cleanly.
+	## At least if running from jumpstart environment?
+	## ALSO, be paranoid and dont remove a "real" file, if
+	## one already exists in the target space.
+	## only a symlink
+}
+# set_alternative: mostly internal function. 
+# Usage: set_alternative {shortname} [ignore-path]
+# Goes and checks both standard configs, and manual config, for best fit.
+#
+#   2nd arg is used for being called through --remove/--ignore
+#
+function set_alternative {
+	typeset line
+	if [[ $# -lt 1 ]] ; then print ERROR set_alternative needs an arg; exit 1;fi
+
+
+	line=`print_manual_set $1`
+	## Design choice: deliberately leave in manual choice,
+	## even if --remove of that alternative is used.
+	## That way makes it easier to implement pkgrm for us.
+	if [[ "$2" != "" ]] ; then
+		echo $line | grep " $2 " >/dev/null
+		if [[ $? -eq 0 ]] ; then
+			$DEBUG Note: manual choice is currently $line
+		fi
+	fi
+
+
+	if [[ "$line" = "" ]] ; then
+		if [[ "$2" != "" ]] ; then
+			line=`print_alternatives $1|
+				nawk ' $3 != "'$2'" {print}' |head -1`
+		else
+			line=`print_alternatives $1|head -1`
+		fi
+	fi
+	if [[ "$line" = "" ]] ; then
+		print "No alternatives found for $1"
+		return 0;
+	fi
+	set $line
+	set_link $1 $2 $3
+	shift 4
+	while [[ "$1" != "" ]] ; do
+		set_link $1 $2 $3
+		shift 3
+	done
+	
+}
+
+function revert_to_auto {
+	case $1 in
+		*/*)
+			print Error: need short name for --auto
+			exit 1
+		;;
+	esac
+	if [[ -f "$MANUALDIR/$1" ]] ; then
+		$DEBUG removing manual setting for $1
+		rm "$MANUALDIR/$1"
+	else
+		$DEBUG no manual setting for $1 found
+	fi
+	set_alternative $1
+}
+
+# Usage: set_manual_prio shortname /full/path
+function set_manual_prio {
+	case $1 in
+		*/*)
+			print Error: need short name as first arg for --set
+			exit 1
+		;;
+	esac
+
+	check=`egrep -l "^[^ ]* $1 $2 " $PRIORITIESDIR/*`
+	if [[ "$check" == "" ]] ; then
+		print Error: no installed match found for $1 $2
+		exit 1
+	fi
+	# Note: target file may have more than one line in it!!
+
+	$DEBUG found match for $1: $check
+	rm -f $MANUALDIR/$1
+	ln -s $check $MANUALDIR/$1
+
+	set_alternative $1
+	
+}
+
+
+
+function display_choices {
+	case $1 in
+		*/*)
+			print Error: need short name as arg for --display
+			exit 1
+		;;
+	esac
+
+	if [[ -f $MANUALDIR/$1 ]] ; then
+		print Manual mode for $1 set. Paths are:
+		print_manual_set $1
+	fi
+	print Installed alternatives for $1 are:
+		print_alternatives $1
+}
+
+
+############################################################
+# Return to "main" area below
+
+## Comment on --remove arg:
+## It does not actually **remove* registration of alternative.
+## That is left for pkgrm.
+## What it does do, is reset link, while ignoring the specified alternative.
+## So for strict purposes, it would better be called "--ignore-and-set"
+## Left in original flag, but dual-implemented as --ignore
+##
+
+if [[ "$1" == "--remove" ]] ; then
+	$DEBUG Note: --remove is really only a temporary --ignore
+	$DEBUG You must rm or pkgrm the appropriate file in $PRIORITIESDIR to remove
+fi
+
+
+
+case $1 in
+	--install)
+		shift
+		print "(Note: ignoring arguments for --install except for '$2')"
+		$DEBUG "(Using files in $PRIORITIESDIR)"
+		set_alternative $2
+		;;
+	--remove|--ignore)    #args = shortname /local/path
+		shift
+		print "(Note: ignoring arguments for --remove except for '$1')"
+		$DEBUG "(Using files in $PRIORITIESDIR)"
+		set_alternative $1 $2
+		;;
+	--auto)
+		shift
+		revert_to_auto $1
+		;;
+	--display)
+		shift
+		display_choices $1
+		;;
+	--set)
+		shift
+		set_manual_prio $1 $2
+		;;
+	*)
+		print -- $1 is not a recognized command.
+		usage
+		
+		exit 1
+		;;
+esac
+
+


Property changes on: csw/mgar/pkg/alternatives/trunk/alternatives
___________________________________________________________________
Added: svn:executable
   + *

Deleted: csw/mgar/pkg/alternatives/trunk/checksums
===================================================================
--- csw/mgar/pkg/alternatives/trunk/checksums	2010-05-14 17:56:52 UTC (rev 9867)
+++ csw/mgar/pkg/alternatives/trunk/checksums	2010-05-14 18:45:54 UTC (rev 9868)
@@ -1,5 +0,0 @@
-5e7b546021e5606165c34f154b70bc7b  CSWalternatives.i.cswalternatives
-b610f50080c8ffe65037bb9891316935  CSWalternatives.r.cswalternatives
-3b83ef96387f14655fc854ddc3c6bd57  LICENSE-2.0.txt
-d41d8cd98f00b204e9800998ecf8427e  alternatives
-d41d8cd98f00b204e9800998ecf8427e  alternatives.8

Added: csw/mgar/pkg/alternatives/trunk/copyright
===================================================================
--- csw/mgar/pkg/alternatives/trunk/copyright	                        (rev 0)
+++ csw/mgar/pkg/alternatives/trunk/copyright	2010-05-14 18:45:54 UTC (rev 9868)
@@ -0,0 +1,2 @@
+Scripts in this package are copyright Dagobert Michelsen and Philip Brown
+They may be freely used and copied as part of this package.

Added: csw/mgar/pkg/alternatives/trunk/i.cswalternatives
===================================================================
--- csw/mgar/pkg/alternatives/trunk/i.cswalternatives	                        (rev 0)
+++ csw/mgar/pkg/alternatives/trunk/i.cswalternatives	2010-05-14 18:45:54 UTC (rev 9868)
@@ -0,0 +1,52 @@
+#!/bin/sh
+#
+# i.cswalternatives - Class action script for
+# registering applications in alternatives
+#
+# Written and maintained by Dagobert Michelsen
+#
+# 2010-02-11 Initial release
+
+: ${PKG_INSTALL_ROOT:=/}
+
+while read src dest; do
+  /usr/bin/cp $src $dest || exit 2
+
+  cat $dest | while read C; do
+    set -- $C
+
+    ALTLINK="$1"
+    ALTNAME="$2"
+    ALTPATH="$3"
+    ALTPRIO="$4"
+
+    echo "Registering '$ALTNAME' alternative $ALTPATH ..."
+
+    ARGS="--install $ALTLINK $ALTNAME $ALTPATH $ALTPRIO"
+    shift; shift; shift; shift
+
+    while [ $# -gt 0 ]; do
+      ARGS="$ARGS --slave $1 $2 $3"
+      shift; shift; shift
+    done
+    
+    if [ ! -x ${PKG_INSTALL_ROOT}/opt/csw/sbin/alternatives ]; then
+      echo "ERROR: /opt/csw/sbin/alternatives could not be found" >&2
+      exit 2
+    fi
+
+    chroot ${PKG_INSTALL_ROOT} /opt/csw/sbin/alternatives $ARGS
+
+    # Redo previous manual selection if this is an upgrade
+    if /usr/bin/test -L "${PKG_INSTALL_ROOT}/etc/opt/csw/preserve/${PKG}/alternatives/$ALTNAME"; then
+      CHOICE=`/usr/bin/perl -e 'print readlink $ARGV[0]' "${PKG_INSTALL_ROOT}/etc/opt/csw/preserve/${PKG}/alternatives/$ALTNAME"`
+      if [ "${CHOICE}" = "$ALTPATH" ]; then
+        echo "Applying previous manual selection ${CHOICE} ..."
+        chroot ${PKG_INSTALL_ROOT} /opt/csw/sbin/alternatives --set $ALTNAME ${CHOICE}
+        rm -f ${PKG_INSTALL_ROOT}/etc/opt/csw/preserve/${PKG}/alternatives/$ALTNAME
+      fi
+    fi
+  done
+done
+
+exit 0

Added: csw/mgar/pkg/alternatives/trunk/pkginfo
===================================================================
--- csw/mgar/pkg/alternatives/trunk/pkginfo	                        (rev 0)
+++ csw/mgar/pkg/alternatives/trunk/pkginfo	2010-05-14 18:45:54 UTC (rev 9868)
@@ -0,0 +1,8 @@
+PKG=CSWalternatives
+NAME=alternatives - an implementation of linux-style alternatives choice mgr
+VERSION=1.0,REV=2009.10.04
+CATEGORY=system
+VENDOR=http://www.opencsw.org written and packaged for CSW by Philip Brown
+EMAIL=phil at opencsw.org
+HOTLINE=http://www.opencsw.org/bugtrack/
+PSTAMP=cswalternatives v1.0

Added: csw/mgar/pkg/alternatives/trunk/prototype
===================================================================
--- csw/mgar/pkg/alternatives/trunk/prototype	                        (rev 0)
+++ csw/mgar/pkg/alternatives/trunk/prototype	2010-05-14 18:45:54 UTC (rev 9868)
@@ -0,0 +1,5 @@
+i pkginfo
+i copyright
+f none /usr/sadm/install/scripts/i.cswalternatives=i.cswalternatives 0755 root bin
+f none /usr/sadm/install/scripts/r.cswalternatives=r.cswalternatives 0755 root bin
+f none /opt/csw/sbin/alternatives=alternatives

Added: csw/mgar/pkg/alternatives/trunk/r.cswalternatives
===================================================================
--- csw/mgar/pkg/alternatives/trunk/r.cswalternatives	                        (rev 0)
+++ csw/mgar/pkg/alternatives/trunk/r.cswalternatives	2010-05-14 18:45:54 UTC (rev 9868)
@@ -0,0 +1,42 @@
+#!/bin/sh
+#
+# r.cswalternatives - Class action script for
+# registering applications in alternatives
+#
+# Written and maintained by Dagobert Michelsen
+#
+# 2010-02-11 Initial release
+
+: ${PKG_INSTALL_ROOT:=/}
+
+while read dest; do
+  cat $dest | while read C; do
+    set -- $C
+
+    # If we are in manual mode and the selected item is about to be removed
+    # make sure to remember the selection for next install to be reset.
+
+    if egrep '^manual$' ${PKG_INSTALL_ROOT}/var/opt/csw/alternatives/$2 >/dev/null 2>&1; then
+      CHOICE="`perl -e 'print readlink $ARGV[0]' ${PKG_INSTALL_ROOT}/etc/opt/csw/alternatives/$2`"
+      if [ "$3" = "${CHOICE}" ]; then
+        echo "Preserving '$2' manual choice ${CHOICE} ..."
+        mkdir -p ${PKG_INSTALL_ROOT}/etc/opt/csw/preserve/${PKG}/alternatives
+        rm -f ${PKG_INSTALL_ROOT}/etc/opt/csw/preserve/${PKG}/alternatives/$2
+        ln -s "${CHOICE}" ${PKG_INSTALL_ROOT}/etc/opt/csw/preserve/${PKG}/alternatives/$2
+      fi
+    fi
+
+    echo "Unregistering '$2' alternative $3 ..."
+
+    if [ -x ${PKG_INSTALL_ROOT}/opt/csw/sbin/alternatives ]; then
+      chroot ${PKG_INSTALL_ROOT} /opt/csw/sbin/alternatives --remove $2 $3
+    else
+      echo "ERROR: /opt/csw/sbin/alternatives could not be found" >&2
+      exit 2
+    fi
+  done
+
+  rm -f $dest
+done
+
+exit 0


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list