#!/bin/bash "Do not execute. Shebang line exists for syntax highlighting." # A file containing simple functions used in determining version numbers of # installed programs, based on ctime. # # Author:: Dan # Date:: 10 June 2006 Import GoboLinux Import File Import String # Gets the currently-installed version of the given program by reading the # 'Current' link. If the Current link doesn't exist, or if the program isn't # installed, this function returns no text and a nonzero result. # Usage Example: # Current_Version Scripts function Current_Version() { Parameters "$@" programName local basedir="$goboPrograms/$programName" Is_Directory "$basedir" || return 1 Is_Link "$basedir/Current" || return 1 basename "$(readlink -f "$basedir/Current")" return 0 } # Determines the second-most-recently installed version of a program. By default # it does this based on mtime, but you can pass atime or ctime as a second # argument to use that timestamp instead of the creation one. You can also pass # GuessLatest as the second argument if you'd like to # Returns 1 if # the program doesn't exist at all, or 2 if the Current version is installed. # Usage Examples: # Previous_Version Scripts # Previous_Version Scripts ctime # Previous_Version Scripts GuessLatest function Previous_Version() { local programName sortType version versions Parameters "$@" programName sortType [ "$sortType" ] || sortType=mtime useGuessLatest='' if [ "$sortType" = "GuessLatest" ]; then useGuessLatest='yes' sortType=mtime fi if [ "$sortType" = mtime ]; then sortType="--sort=time" else sortType="--time=$sortType" fi curVersion="`Current_Version $programName`" || return 1 Quiet pushd "$goboPrograms/$programName" versions=( `Chop "$( ls -1p $sortType --color=never | grep /$ )" \ | grep -vF Settings \ | grep -vF "$curVersion"` ) Quiet popd [ "${versions}" ] || return 2 if [ "$useGuessLatest" ]; then GuessLatest -- "${versions[@]}" else echo "${versions[0]}" fi } # Gets all available versions of the given program by listing the # contents in the program directory. # Usage Example: # All_Versions Scripts function All_Versions() { Parameters "$@" program program=$(GuessProgramCase "$program") if Is_Directory "$program" && [ -n "$(echo $program | grep \/)" ] then local basedir="$program" else local basedir="$goboPrograms/$program" fi Is_Directory "$basedir" || return 1 versions=$(ls -I Settings -I Variable -I Current ${basedir}) [ -z "${versions}" ] && return 1 echo "${versions}" return 0 }