[csw-devel] SF.net SVN: gar:[6899] csw/mgar/pkg/cswclassutils/trunk

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon Oct 19 00:56:27 CEST 2009


Revision: 6899
          http://gar.svn.sourceforge.net/gar/?rev=6899&view=rev
Author:   wahwah
Date:     2009-10-18 22:56:27 +0000 (Sun, 18 Oct 2009)

Log Message:
-----------
cswclassutils: adding cswmigrateconf

Modified Paths:
--------------
    csw/mgar/pkg/cswclassutils/trunk/Makefile
    csw/mgar/pkg/cswclassutils/trunk/checksums

Added Paths:
-----------
    csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswmigrateconf
    csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.r.cswmigrateconf

Property Changed:
----------------
    csw/mgar/pkg/cswclassutils/trunk/Makefile

Modified: csw/mgar/pkg/cswclassutils/trunk/Makefile
===================================================================
--- csw/mgar/pkg/cswclassutils/trunk/Makefile	2009-10-18 22:20:05 UTC (rev 6898)
+++ csw/mgar/pkg/cswclassutils/trunk/Makefile	2009-10-18 22:56:27 UTC (rev 6899)
@@ -1,10 +1,12 @@
+# $Id$
+
 GARNAME = cswclassutils
-GARVERSION = 1.23
+GARVERSION = 1.24
 CATEGORIES = utils
 
 DESCRIPTION = CSW class action utilities
 
-MASTER_SITES = 
+MASTER_SITES =
 DISTFILES = COPYING
 
 ARCHALL = 1
@@ -16,7 +18,9 @@
 
 SPKG_SOURCEURL = http://www.opencsw.org
 
-CASLIST = $(foreach F,$(wildcard $(FILEDIR)/CSW$(GARNAME).[ir].*), $(subst $(FILEDIR)/CSW$(GARNAME).,,$(F)))
+CASFILES = $(wildcard $(FILEDIR)/CSW$(GARNAME).[ir].*)
+CASLIST = $(foreach F,$(CASFILES), $(subst $(FILEDIR)/CSW$(GARNAME).,,$(F)))
+DISTFILES += $(subst $(FILEDIR)/,,$(CASFILES))
 
 PROTOTYPE_FILTER = sed -e '/^d.*\/usr/d; /scripts/{ s/bin/sys/; }'
 


Property changes on: csw/mgar/pkg/cswclassutils/trunk/Makefile
___________________________________________________________________
Added: svn:keywords
   + Id

Modified: csw/mgar/pkg/cswclassutils/trunk/checksums
===================================================================
--- csw/mgar/pkg/cswclassutils/trunk/checksums	2009-10-18 22:20:05 UTC (rev 6898)
+++ csw/mgar/pkg/cswclassutils/trunk/checksums	2009-10-18 22:56:27 UTC (rev 6899)
@@ -1 +1,17 @@
-48a97af56d55bc90ce90303228ed8cc3  download/COPYING
+48a97af56d55bc90ce90303228ed8cc3  COPYING
+9f7a2603bf91ea53e70f2fe5c4a56726  CSWcswclassutils.i.cswcpsampleconf
+56900bb1fc9f40f7c227877eca32b1f8  CSWcswclassutils.i.cswetcservices
+a958a6d8b1b81720a27306b3d2ecdabf  CSWcswclassutils.i.cswinetd
+fa318ca696e80a9a9f2efbf35cb69080  CSWcswclassutils.i.cswinitsmf
+e9c9cafdd37be6f96797740711aee85c  CSWcswclassutils.i.cswmigrateconf
+9f34d51156032e6e08e87fd686723e33  CSWcswclassutils.i.cswpreserveconf
+4c4e668b9a8c52f1c547a91ce9971dfb  CSWcswclassutils.i.cswpycompile
+7f04b24b421f3afbf3c61845941ef5dd  CSWcswclassutils.i.cswusergroup
+4f926d97a780f9c116083e5e729c705c  CSWcswclassutils.r.cswcpsampleconf
+d60261ddc46e2cc83ecbbfc586a7e686  CSWcswclassutils.r.cswetcservices
+9039ea60ad4c3f8994205fb242a49a72  CSWcswclassutils.r.cswinetd
+791db9c2f6685aca67043820d260fc60  CSWcswclassutils.r.cswinitsmf
+add04169c99570731d8766ac5c38b771  CSWcswclassutils.r.cswmigrateconf
+a473d9cf739a6a33ac3a7306eb4a522c  CSWcswclassutils.r.cswpreserveconf
+02326250b63d3c75c45a8ff81768e923  CSWcswclassutils.r.cswpycompile
+752c74048ee18ae3a3c2c7b1d15e40f2  CSWcswclassutils.r.cswusergroup

Copied: csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswmigrateconf (from rev 5733, csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswpreserveconf)
===================================================================
--- csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswmigrateconf	                        (rev 0)
+++ csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswmigrateconf	2009-10-18 22:56:27 UTC (rev 6899)
@@ -0,0 +1,250 @@
+#!/bin/sh
+# vim:set sw=2 ts=2 sts=2 expandtab:
+#
+# (c) 2009 Maciej Blizinski
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+#
+# http://wiki.opencsw.org/configuration-directory-migration
+
+# To prevent issues with a-z in regular expressions
+unset LC_ALL
+LANG=C
+
+# Print errors when trying to read from an unset variable.
+set -u
+
+PKG_INSTALL_ROOT=${PKG_INSTALL_ROOT:-/}
+
+return_code=0
+
+migration_info="
+This location (/opt/csw/etc) is deprecated.
+
+Configuration files are currently being placed in /etc/opt/csw.  Please make
+sure your new configuration is in /etc/opt/csw and remove the old one from
+/opt/csw/etc.
+
+For more information, please see
+http://wiki.opencsw.org/configuration-directory-migration
+"
+readonly migration_info
+deprecated_file_ext="README.migration"
+readonly deprecated_file_ext
+
+# Create /etc/opt/csw/cswclassutils.DEBUG to enable debugging of this script
+if [ -r ${PKG_INSTALL_ROOT}etc/opt/csw/cswclassutils.DEBUG ]; then
+  DEBUG=1
+else
+  DEBUG=
+fi
+
+give_a_chance_to_stop() {
+  echo
+  echo "*******************************************************************"
+  echo "* Configuration files are going to be migrated from the deprecated "
+  echo "* location (/opt/csw/etc) to the new location (/etc/opt/csw).      "
+  echo "*                                                                  "
+  echo "*         Migration will continue in 10 seconds.                   "
+  echo "*          Press CTRL+C if you want to stop now.                   "
+  echo "*******************************************************************"
+  echo
+  for i in 10 9 8 7 6 5 4 3 2 1; do
+    printf "$i "
+    sleep 1
+  done
+  echo "0."
+}
+
+files_are_identical() {
+  cmp "$1" "$2" > /dev/null
+}
+
+drop_warning() {
+  echo "${migration_info}" > "$1.${deprecated_file_ext}"
+}
+
+sanitize() {
+  echo "$1" | sed -e 's/[^a-zA-Z0-9]/_/g'
+}
+
+expand_modifiers() {
+  # Emulating local variables
+  __per_file_variable="$1"
+  __per_file_modifier_value="$2"
+  eval echo `echo \\${${__per_file_variable}_${__per_file_modifier_value}:-}`
+}
+
+place_signpost_for() {
+  __file_name="$1"
+  echo "${migration_info}" > "${__file_name}.${deprecated_file_ext}"
+}
+
+debug() {
+  [ "${DEBUG}" ] & echo "$@"
+}
+
+should_copy_archived_file() {
+  __archived_file_name="$1"
+  __dest_file_name="$2"
+  __do_copy=0
+  __do_not_copy=1
+  debug "should_copy_archived_file(${__archived_file_name}, ${__dest_file_name})"
+  if [ ! -r "${__archived_file_name}" ]; then
+    debug "No archived file or directory at ${__archived_file_name}"
+    return "${__do_not_copy}"
+  else
+    debug "Archived version found in ${__archived_file_name}"
+  fi
+
+  if [ ! -r "${__dest_file_name}" -a ! -h "${__dest_file_name}" ]; then
+    debug "Destination file ${__dest_file_name} not readable and not a symlink."
+    return "${__do_copy}"
+  else
+    debug "Destination file ${__dest_file_name} is readable or a symlink."
+  fi
+
+  if [ -h "${__dest_file_name}" ]; then # symlink
+    debug "${__dest_file_name} is a symlink"
+    debug `ls -l "${__dest_file_name}"`
+    # Okay, it's a symlink, but is it a dangling symlink?
+    if [ -r "${__dest_file_name}" ]; then
+      debug "Symlink is readable"
+      return "${__do_not_copy}"
+    else
+      debug "Symlink not readable. Can delete."
+      return "${__do_copy}"
+    fi
+  fi # end symlink
+
+  # If there's a sample configuration file, remove the copied one.
+  __sample_conf="${__dest_file_name}.CSW"
+  if [ -r "${__sample_conf}" ]; then
+    if files_are_identical "${__sample_conf}" "${__dest_file_name}"; then
+      return "${__do_copy}"
+    else
+      return "${__do_not_copy}"
+    fi
+  fi
+  # If there's no sample configuration and the destination file exists, it
+  # shouldn't be overwritten.
+  return "${__do_not_copy}"
+}
+
+is_dangling_symlink() {
+  [ -h "$1" -a ! -r "$1" ]
+}
+
+run_already=0
+
+while read confsrc confdst ; do
+  # We're not sure if the files to be migrated have already been copied or not.
+
+  cp "$confsrc" "$confdst"
+  # Sourcing the file, it should contain the configuration.
+  if [ -r "$confsrc" ]; then
+    debug "Sourcing ${confsrc}"
+    . "$confsrc"
+  else
+    echo "${confsrc} is missing"
+    exit 1
+  fi
+
+  if [ -z "${MIGRATE_FILES}" ]; then
+    echo "ERROR! \$MIGRATE_FILES variable is empty."
+    exit 1
+  fi
+
+  if [ "${run_already}" -ne 0 ]; then
+    echo "ERROR! You can only use one configuration file."
+    exit 1
+  else
+    run_already=1
+  fi
+
+  # The defaults, if not set already by the script.
+  SOURCE_DIR___default__="${SOURCE_DIR___default__:-opt/csw/etc}"
+  readonly SOURCE_DIR___default__
+  ARCH_DIR___default__="${ARCH_DIR___default__:-opt/csw/etc/migration-archive}"
+  readonly ARCH_DIR___default__
+  DEST_DIR___default__="${DEST_DIR___default__:-etc/opt/csw}"
+  readonly DEST_DIR___default__
+
+  for file_name in ${MIGRATE_FILES}; do
+    modifier_value=`sanitize "${file_name}"`
+    debug "Processing file: ${file_name}"
+    debug "modifier_value: ${modifier_value}"
+
+    # Perhaps the following three segments of code could be turned into
+    # a function, but it would require complicated eval calls.
+    per_file_srcdir=`expand_modifiers SOURCE_DIR ${modifier_value}`
+    default_srcdir=`expand_modifiers SOURCE_DIR __default__`
+    srcdir="${per_file_srcdir:-${default_srcdir}}"
+    per_file_dstdir=`expand_modifiers DEST_DIR ${modifier_value}`
+    default_dstdir=`expand_modifiers DEST_DIR __default__`
+    dstdir="${per_file_dstdir:-${default_dstdir}}"
+    per_file_archdir=`expand_modifiers ARCH_DIR ${modifier_value}`
+    default_archdir=`expand_modifiers ARCH_DIR __default__`
+    archdir="${per_file_archdir:-${default_archdir}}"
+    srcpath="${PKG_INSTALL_ROOT}${srcdir}/${file_name}"
+    dstpath="${PKG_INSTALL_ROOT}${dstdir}/${file_name}"
+    archpath="${PKG_INSTALL_ROOT}${archdir}/${file_name}"
+
+    # Make sure we have the environment we expect
+    if [ ! -d "${archdir}" ]
+    then
+      debug "Creating ${archdir}"
+      mkdir -m 755 -p "${archdir}"
+      if [ $? -ne 0 ]
+      then
+        echo "ERROR: Couldn't create '${archdir}', bailing out."
+        exit 1
+      fi
+    fi
+
+    # All variables are set, the main algorithm goes here.
+
+    # Moving the file will only work in the global zone. The assumption is that
+    # the postinstall script is going to be run in the global zone first; by the
+    # time it gets to the non-global zones, the ${srcpath} will have been
+    # moved already.
+    if [ -r "${srcpath}" ]
+    then
+      place_signpost_for "${srcpath}"
+      debug "Moving '${srcpath}' to '${archpath}'"
+      mv "${srcpath}" "${archpath}"
+      if [ -r "${srcpath}" ]; then
+        echo "WARNING: '${srcpath}' still exists"
+      fi
+    fi
+
+    # If the destination file is not there and the archived file is, copy it over.
+    if should_copy_archived_file "${archpath}" "${dstpath}"; then
+      echo "Copying '${archpath}' to '${dstpath}'"
+
+      # Is it a dangling symlink?
+      if is_dangling_symlink "${dstpath}"; then
+        debug "Removing dangling symlink: '${dstpath}'"
+        rm "${dstpath}"
+      fi
+
+      # Directories are copied in whole
+      if [ -d "${archpath}" ]; then
+        debug "(cd ${archpath}/..; tar cf - `basename ${archpath}` \
+| ( mkdir ${dstpath}; cd ${dstpath}; cd ..; tar xf -))"
+        (cd ${archpath}/..; tar cf - `basename ${archpath}` \
+            | ( mkdir ${dstpath}; cd ${dstpath}; cd ..; tar xf -) \
+        )
+      elif [ -f "${archpath}" ]; then
+        debug cp "${archpath}" "${dstpath}"
+        cp "${archpath}" "${dstpath}"
+      else
+        echo "WARNING: ${archpath} is neither a file or directory."
+      fi
+    else
+      debug "Not copying '${archpath}' to '${dstpath}'."
+    fi
+  done
+done
+
+exit "${return_code}"


Property changes on: csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswmigrateconf
___________________________________________________________________
Added: svn:keywords
   + Id

Added: csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.r.cswmigrateconf
===================================================================
--- csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.r.cswmigrateconf	                        (rev 0)
+++ csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.r.cswmigrateconf	2009-10-18 22:56:27 UTC (rev 6899)
@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+# $Id$
+
+while read dest ; do
+  echo "Removing $dest"
+  rm $dest
+done


Property changes on: csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.r.cswmigrateconf
___________________________________________________________________
Added: svn:keywords
   + Id


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