Date: Sun, 30 Jun 2013 12:05:10 GMT From: jmuniz@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253728 - soc2013/jmuniz/PackageKit-Setter Message-ID: <201306301205.r5UC5AUr050836@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jmuniz Date: Sun Jun 30 12:05:10 2013 New Revision: 253728 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253728 Log: Corrected spelling errors, updated task list for pk-setter Modified: soc2013/jmuniz/PackageKit-Setter/pk-setter Modified: soc2013/jmuniz/PackageKit-Setter/pk-setter ============================================================================== --- soc2013/jmuniz/PackageKit-Setter/pk-setter Sun Jun 30 12:04:11 2013 (r253727) +++ soc2013/jmuniz/PackageKit-Setter/pk-setter Sun Jun 30 12:05:10 2013 (r253728) @@ -1,135 +1,265 @@ #!/bin/sh + # + # Copyright (C) 2013 Justin Edward Muniz <jmuniz@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 argugments that can be provided to this script: + + +# 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 arguements + +# 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 backednds + + +# 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 neccessary configuration file + + # 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 arguements + + # Determine if there are three arguments + if [ $# -eq 3 ]; then + # Set PK_PREFIX for later + ${PK_PREFIX}="$3" - # If there were two arguements given + + # 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 intallation prefix of PackageKit" + + 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 for listBackends: might need exception handling for if list cannot be generated + + # TODO: test validation and error handling in general -# TODO: check spelling + # TODO for generateBackendList: generate the list without hardcoding it -# TODO for setBackend: stop and start PackageKitd to load in the new backend \ No newline at end of file + +# TODO for setBackend: stop and start PackageKitd to load in the new backend
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306301205.r5UC5AUr050836>