All pastes #749571 Raw Edit

Something

public shellscript v1 · immutable
#749571 ·published 2007-10-25 19:49 UTC
rendered paste body
#Initialize VariablesVERSION="0.0.1"NETPKGCONF="/etc/netpkg.conf"INFO=0LIST=0OWNS=0#Test $ROOT to see if it is set, set ROOTDIR accordingly if [ -n "$ROOT" ]; then  ROOTDIR="$ROOT"else  ROOTDIR="/"fi#Use netpkg configuration values if file existsif [ -f "$NETPKGCONF" ]; then  LOGDIR="$(awk '/Package_logs/ {print $3}' <"$NETPKGCONF")"  DBDIR="$(awk '/Netpkg_dir/ {print $3}' <"$NETPKGCONF")/db"else #assume some defaults  LOGDIR="/var/log/packages"  DBDIR="/var/netpkg/db"fiDEPFILE="$DBDIR/depfile"PKGLIST="$DBDIR/PACKAGES.txt"MIRROR="$(<$DBDIR/last_mirror)"#Some Functionserr_msg() {  echo "$1"  exit 1}usage() {  echo "Usage: managepkg [options]"  echo  echo "Options:"  echo "  -h, --help            Show this dialog"  echo "  -i, --info <package>  Display information about package"  echo "  -l, --list <package>  List all the files in package"  echo "  -o, --owns <file>     Display which package owns file"  echo "  -v, --version         Display the version of managepkg"  echo  exit 0}version_msg() {  echo "managepkg version: $VERSION"  exit}#Quick error check before I shift out all of the positional parameters[ "$#" -lt "1" ] && err_msg "Incorrect usage, see managepkg --help."#Parse options and reset variables accordinglywhile [ "$#" -gt "0" ]; do  param="$1"  if [ "${param:0:2}" = "--" ]; then    case "${param:2}" in      info)    INFO="1" ; PACKAGE="$2" ; shift ;;      list)    LIST="1" ; PACKAGE="$2" ; shift ;;      owns)    OWNS="1" ; FILE="$2"    ; shift ;;      help)    usage       ;;      version) version_msg ;;      *)       err_msg "Option \`${param:2}' not recognized, see managepkg --help." ;;    esac  elif [ "${param:0:1}" = "-" ]; then    shortparam="$(sed 's/./& /g' <<<${param:1})"    for character in $shortparam; do      case $character in        i) INFO="1" ; PACKAGE="$2" ; shift ;;        l) LIST="1" ; PACKAGE="$2" ; shift ;;        o) OWNS="1" ; FILE="$2"    ; shift ;;        h) usage       ;;        v) version_msg ;;        *) err_msg "Option \`$character' not recognized, see managepkg --help." ;;      esac    done  else    err_msg "Error when parsing \`$param', see managepkg --help."  fi  shiftdone#Universal error checks[ "$((INFO+LIST+OWNS))" -ne "1" ] && err_msg "Must have only one option selected."[ "${PACKAGE:0:1}" = "-" ]        && err_msg "Package must directly follow option."[ "${FILE:0:1}" = "-" ]           && err_msg "File must directly follow option."