#!/bin/sh # --- SDE-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: bin/sde-config-package # Copyright (C) 2009 The OpenSDE Project # # More information can be found in the files COPYING and README. # # 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; version 2 of the License. A copy of the # GNU General Public License can be found in the file COPYING. # --- SDE-COPYRIGHT-NOTE-END --- #Description: Alters the description of a package #Alias: pkg [ -n "$SDEROOT" ] || export SDEROOT=$( cd "${0%/*}/.."; pwd -P ) . "$SDEROOT/lib/libsde.in" . "$SDEROOT/lib/sde-package.in" config_usage() { local progname=$(echo ${0##*/} | tr '-' ' ') [ $# -eq 0 ] || echo_error "$@" cat <<-EOT Usage: $progname * [ []]* Actions: get returns the content of a tag set sets a tag value, removing any previous value add appends a new value for a tag remove removes a tag, optionally matching a pattern show dumps the fully description lint cleans the description EOT exit 1 } # parse arguments shortopts='?' longopts='help' options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" ) [ $? -eq 0 ] || config_usage eval set -- "$options" while [ $# -gt 0 ]; do case "$1" in --help) config_usage ;; --) shift; break ;; -*) config_usage "$1: Not implemented" ;; *) break esac shift done # extract packages list # pkgs= while [ $# -gt 1 ]; do case "$1" in get|set|add|remove|show|list) # action break; esac x=$(package_parse "$1" | tr '\n' ' ') if [ -n "$x" ]; then pkgs="$pkgs $x" shift else config_usage "$1: Invalid package" fi done pkgs=$(echo "$pkgs" | sed -e 's,^ \+,,' -e 's, \+$,,') [ -n "$pkgs" -a $# -gt 0 ] || config_usage action="$1"; shift tag2pattern() { local tag=$(echo "$tag" | tr 'a-z' 'A-Z') local pattern=$(grep -e '^\[' "$SDEROOT/etc/desc_format" | grep -e "\[$tag\]" | sed -e 's, *(\*) *$,,' -e 's, \+,\\|,g' | tr -d '[]') if [ -z "$pattern" ]; then return; elif expr "$pattern" : '.*|' > /dev/null; then pattern="\\($pattern\\)" fi echo "^\[$pattern\]" } case "$action" in get) # extract given tags pattern= for tag; do x=$(tag2pattern "$tag") if [ -n "$x" ]; then pattern="$pattern -e '$x'" else echo_error "$tag: Invalid tag" fi done files= for x in $pkgs; do files="$files $x/${x#*/}.desc" done cd "$SDEROOT/package" eval "grep $pattern $files" ;; *) echo_error "$action: Not yet implemented." esac