socsvn commit: r253788 - in soc2013/jmuniz: . PackageKit-Setter

jmuniz at FreeBSD.org jmuniz at FreeBSD.org
Mon Jul 1 09:02:18 UTC 2013


Author: jmuniz
Date: Mon Jul  1 09:02:18 2013
New Revision: 253788
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253788

Log:
  Fixed several issues with pk-setter, getting it to a stable point. Updated and moved task list from pk-setter to TODO.

Modified:
  soc2013/jmuniz/PackageKit-Setter/pk-setter
  soc2013/jmuniz/TODO

Modified: soc2013/jmuniz/PackageKit-Setter/pk-setter
==============================================================================
--- soc2013/jmuniz/PackageKit-Setter/pk-setter	Mon Jul  1 08:38:31 2013	(r253787)
+++ soc2013/jmuniz/PackageKit-Setter/pk-setter	Mon Jul  1 09:02:18 2013	(r253788)
@@ -1,133 +1,141 @@
-#!/bin/sh
-#
-# Copyright (C) 2013 Justin Edward Muniz <jmuniz at freebsd.org>
-#
-# Licensed under the GNU General Public License Version 2
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version. 
-#
-# Script to list and select from possible PackageKit backends
-
-# There are three arguments that can be provided to this script:
-# Instruction: mandatory; can be either 'list' or 'set'
-# Backend Name: mandatory for 'set'; a string that identifies for the set instruction
-# Prefix: optional; if included, must be a valid prefix path to the PackageKit installation
-
-# ENTRY POINT OF SCRIPT
-# Make sure there is an appropriate number of arguments
-if [ $# -eq 1 -o $# -eq 2 -o $# -eq 3 ]; then
-  # Determine if there is a user provided prefix and save it for later
-  setPrefix
-  # Determine if the user wants a list of backends, if so print it
-  listBackends
-  # Determine if the user wants a backend change, and process it
-  setBackend
-fi  
-# Let the user know how to use this script
-printUsage
-# Return to the shell with failure
-exit 1
-# EXIT POINT OF SCRIPT
-
-# This function presents the user with a list of available backends
-listBackends(){
-  # Make sure that the user has requested a list of the available backends
-  if [ "$1" == "list" ]; then	
-    # Create a string with each line representing the name of one backend
-	generateBackendList
-    # Print a header to describe the data to follow
-    echo "Available PackageKit backends:"
-	# Print the list of backends
-    echo "${PK_BACKENDS}"
-    # Return to the shell with success
-    exit 0
-  fi
-# End listBackends
-}
-
-# This function uses the prefix and backend name to configure PackageKit to use the chosen backend
-setBackend(){
-  # Make sure that the user wants to select the backend
-  if [ "$1" == "set" ]; then
-    # Determine if the prefix contains the necessary configuration file
-    if [ ! -e "${PK_PREFIX}etc/PackageKit/PackageKit.conf" ]; then
-      # Let the user know that the path does not lead to the configuration file
-      echo "Error: could not find PackageKit.conf, check prefix"
-      # Return to the shell with failure
-      exit 1
-    fi
-	# Run the algorithm to create a new-line delimited list of available backends
-	generateBackendList
-    # Test the backend value provided against the list of valid backend names
-    if [ ${PK_BACKENDS} != *$2* ]; then
-      # Let the user know that they made a mistake
-      echo "The backend provided was not found, please check your entry"
-      # Give advice to the user since they made a mistake, then return to the shell with failure
-      printUsage
-	fi
-	# Find the first instance of "DefaultBackend" and replace the line to reflect the new backend
-	sed -i 's/DefaultBackend=.*/DefaultBackend='$2
-    # Let the user know that the changes were successful
-    echo "PackageKit is now using the $2 backend"
-    # Return to the shell with success
-    exit 0
-  fi
-# End setBackend
-}
-
-# This function determines which argument is the prefix, if any, and sets the value of PK_PREFIX for later
-setPrefix(){
-  # Set PK_PREFIX to default (root) prefix 
-  ${PK_PREFIX}="/"
-  # Determine if there are three arguments
-  if [ $# -eq 3 ]; then 
-	# Set PK_PREFIX for later
-    ${PK_PREFIX}="$3"
-  # If there were two arguments given
-  elif [ $# -eq 2 ]; then 
-	# There must be a prefix if the "list" instruction is given
-	if [ "$1" == "list" ]; then 
-	  # Set PK_PREFIX to the third argument for later
-      ${PK_PREFIX}="$2"	  
-    fi
-  fi
-  # Find out if the path given does not end with a slash
-  if [ ${PK_PREFIX} != */ ]; then
-    # Then add a slash to the end to make a proper prefix
-    ${PK_PREFIX} .= "${PK_PREFIX}/"
-  fi
-  # Determine if the provided prefix even exists and if it refers to a directory
-  if [ ! -e "${PK_PREFIX}" -o ! -d "${PK_PREFIX}" ]; then 
-	# Inform the user that the prefix provided does not refer to an existing directory
-    echo "Error: $2 is not a valid directory."
-    # Return to shell with failure
-    exit 1
-  fi
-# End setPrefix
-}
-
-# This function explains to the user how to use this script, then exits
-printUsage(){
-  # Print the instructions to the user in a easily readable way
-  echo "pk-setter is used to select the PackageKit backend"
-  echo "usage: pk-setter list [prefix]"
-  echo "       pk-setter set [backend] [prefix]"
-  echo "note:  prefix is optional and defaults to the root directory"
-  echo "       and refers to the installation prefix of PackageKit"
-  # Returns to the shell with failure
-  exit 1
-# End printUsage
-}  
-
-# Create a list consisting of backend options, each on their own line  
-generateBackendList(){
-  # Until a better way is figured out, a hardcoded set of options for backend selection are stored in PK_BACKENDS
-  ${PK_BACKENDS}="ports"$'\n'"pkgng"$'\n'"dummy (for debugging)"
-# End generateBackendList  
-}
-
-# TODO: test validation and error handling in general
-# TODO for generateBackendList: generate the list without hardcoding it
-# TODO for setBackend: stop and start PackageKitd to load in the new backend
+#!/bin/sh
+#
+# Copyright (C) 2013 Justin Edward Muniz <jmuniz at freebsd.org>
+#
+# Licensed under the GNU General Public License Version 2
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Function: List and select from possible PackageKit backends
+#
+# There are three arguments that can be provided to this script:
+#   Instruction: mandatory; can be either 'list' or 'set'
+#   Backend Name: mandatory for 'set' instruction; a string that identifies the backend to use
+#   Prefix: optional; if included, must be a valid prefix to the PackageKit installation path
+
+# Determine if the prefix being used is an accurate PackageKit installation prefix
+verifyPrefix() {
+  # Make sure that the necessary configuration file exists given the prefix
+  if [ ! -e "${PK_PREFIX}etc/PackageKit/PackageKit.conf" ]; then
+    # Let the user know that the file was not found
+    echo "Could not find PackageKit.conf, please check your prefix"
+    # Advise user on usage
+    printUsage
+  fi
+# End verifyPrefix
+}
+
+# Store either a provided or default installation prefix for later operations
+setPrefix() {
+  # Establish the default prefix
+  PK_PREFIX="/usr/local/"
+  # If there are three arguments, the last argument must be the prefix
+  if [ $# -eq 3 ]; then
+    # Assign the third argument to be the prefix
+    PK_PREFIX="$3"
+  # If there are two arguments and the instruction is "list" the last argument must be the prefix
+  elif [ $# -eq 2 -a "$1" == "list" ]; then
+    # Assign the second argument to be the prefix
+    PK_PREFIX="$2"
+  fi
+  # The prefix must end in a slash (/) in order to be well-formed, test to see if the slash is missing
+  # Evaluate the prefix to determine if it is well-formed
+  case "${PK_PREFIX}" in
+    # If the prefix ends with a slash
+    *"/")
+      # Do nothing, because the prefix appears to be well-formed
+      ;;
+    # For all other cases
+    *)
+      # Concatenate the slash onto the end of the prefix
+      PK_PREFIX="${PK_PREFIX}/"
+      ;; 
+  esac
+  # Make sure that the prefix provided is correct
+  verifyPrefix
+# End setPrefix
+}
+
+# Create a list consisting of backend options, each occupying one line and surrounded by spaces
+generateBackendList() {
+  # Until this is developed further, hardcode the option set
+  PK_BACKENDS=" ports "$'\n'" pkgng "$'\n'" dummy "
+# End generateBackendList
+}
+
+# Present the user with a list of available backends
+listBackends() {
+  # Make sure that the user has requested the backend list
+  if [ "$1" == "list" ]; then
+    # Generate a list of backends, demarcated by newlines
+    generateBackendList
+    # Print a header to describe the following data
+    echo "Available PackageKit backends:"
+    # Print the list of backends
+    echo "${PK_BACKENDS}"
+  fi
+# End listBackends
+}
+
+# Configure PackageKit to use the chosen backend
+setBackend() {
+  # Make sure that the user wants to select the backend
+  if [ "$1" == "set" ]; then
+    # Generate the new-line demarcated list of backends
+    generateBackendList
+    # Determine if the backend provided is valid, each option is surrounded by spaces
+    case "${PK_BACKENDS}" in
+      # If the proved backend is valid
+      *" $2 "*) 
+        # Find the first instance of "DefaultBackend" in the configuration file and edit it
+        sed "s/DefaultBackend=.*/DefaultBackend=$2/" ${PK_PREFIX}etc/PackageKit/PackageKit.conf > ${PK_PREFIX}etc/PackageKit/PackageKit.conf
+        # Inform the user of success
+        echo "PackageKit is now using the $2 backend"
+        ;;
+      # The default case is true if the provided backend name is not on the list of available backends
+      *)
+        # Notify the user of their mistake
+        echo "The backend provided was not found, please check your entry"
+        # Share usage advice with the user
+        printUsage
+        ;;
+    esac
+  fi
+# End setBackend
+}
+
+# Explain to the user how to use this script, then exit
+printUsage() {
+  # Print the instructions to the user in an easily readable way
+  echo "pk-setter is used to select the PackageKit backend"
+  echo "usage: pk-setter list [prefix]"
+  echo "       pk-setter set [backend] [prefix]"
+  echo "note:  prefix is optional and defaults to \"/usr/local/\","
+  echo "       and refers to the installation prefix of PackageKit"
+  # Returns to the shell with error code
+  exit 1
+# End printUsage
+}
+
+# Beginning of execution
+
+# Make sure there is an appropriate number of arguments
+if [ $# -eq 1 -o $# -eq 2 -o $# -eq 3 ]; then
+  if [ "$1" == "list" -o "$1" == "set" ]; then
+    # Determine if there is a user defined prefix, save the prefix for later
+    setPrefix $*
+    # If the user wants a list of backends then print it
+    listBackends $*
+    # Change the current backend if the user wants to 
+    setBackend $*
+    # Return to the shell with success
+    exit 0
+  fi
+fi
+# Let the user know how to use this script
+printUsage
+
+# End of execution
+

Modified: soc2013/jmuniz/TODO
==============================================================================
--- soc2013/jmuniz/TODO	Mon Jul  1 08:38:31 2013	(r253787)
+++ soc2013/jmuniz/TODO	Mon Jul  1 09:02:18 2013	(r253788)
@@ -0,0 +1,12 @@
+Task list for this repository
+-----------------------------
+
+pk-setter:
+- when setting the backend, close packagekitd before, sync(8) and start packagekitd after
+- generate backend list without hardcoding it
+- make sure file permissions are correct
+- move a copy of the license agreement to this directory
+- determine if the BSD license can be used this intimately with GPLv2
+- verify that packagekitd starts with new configuration, or roll back to last known good configuration
+- create a new port to share this script 
+


More information about the svn-soc-all mailing list