]> git.pld-linux.org Git - packages/rpm.git/blobdiff - banner.sh
- reflow help screen
[packages/rpm.git] / banner.sh
index 854f94bec4ae767e2f70dc296297b78463e9c7e8..49fd6876b942d4feabd6409346e2825652dc433a 100644 (file)
--- a/banner.sh
+++ b/banner.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# bug reports send to pzurowski@pld-linux.org or pld-devel-* lists
+# Please send bug reports to pzurowski@pld-linux.org or pld-devel-* lists
 #
 # 2004, GPL 2+
 #
@@ -10,7 +10,7 @@ CONFIG=/etc/sysconfig/banner
 
 ####################################################### CONFIG ########
 
-# default paramaters
+# default parameters
 ##########################
 
 BANNERDIR="/var/lib/banner/"
@@ -19,7 +19,7 @@ EXCLUDEFILES="(rpmnew$|rpmsave$|~$)"
 STDOUT="1"  # stdout by default
 #STDOUT="2" # stderr by default
 
-# config paramaeters
+# config parameters
 ##########################
 
 if [ -r $CONFIG ]; then
@@ -53,38 +53,30 @@ esac
 Usage()
 {
        cat << EOF
-Usage: $(basename $0) [opitions] [banners]
+Usage: $(basename $0) [options] [banners]
 EOF
 }
 Help()
 {
        Usage
        cat << EOF
--a
---all       - all banners
---delete    - delete wanted banners
--e
---exclude   - exclude following banners (useful with -a)
--h
---help      - show this help
--i
---include   - cancel effect of -e (EXCLUDED banners will remain excluded)
--m
---make      - make a brand-new banner named as following parameter [1] (from stdin)
--M          - same as above, but append if file exists
--n
---names     - show names of the banners
---newer     - all choosen banners should be newer than following parameter in seconds
---older     - all choosen banners should be older than following parameter in seconds
--s
---show      - show wanted banners
---stderr    - send banner to stderr instead of stdout (or other)
---stdout    - send banner to stdout instead of stderr (or other)
--u
---usage     - show short help
+-a, --all       - all banners
+-d, --delete    - delete specified banners
+-e, --exclude   - exclude following banners (useful with -a)
+-h, --help      - show this help
+-i, --include   - cancel effect of -e (EXCLUDED banners will remain excluded)
+-m, --make      - make a brand-new banner named as following parameter [1] (from stdin)
+-M              - same as above, but append if file exists
+-n, --names     - show names of the banners
+--newer         - all choosen banners should be newer than following parameter in seconds
+--older         - all choosen banners should be older than following parameter in seconds
+-s, --show      - show specified banners
+--stderr        - send banner to stderr instead of stdout (or other)
+--stdout        - send banner to stdout instead of stderr (or other)
+-u, --usage     - show short help
 
-[1] - if there will be no slash ('/') in name then config dir will be used,
-      else -- specified.
+[1] if there is no slash ('/') in the given name default dir ($BANNERDIR) is used,
+    otherwise the one that's specified
 EOF
 }
 Unknown_para()
@@ -94,10 +86,7 @@ Unknown parameter $1
 EOF
        Help
 }
-check_banner_name()
-{
-       echo "$1"|sed 's,.*/,,'
-}
+
 check_banners_mtime()
 {
        BANNERS="$1"
@@ -145,7 +134,9 @@ make_banner()
 {
        BANNER="$1"
        SHOW="$2"
-       mkdir -p $(echo $BANNER|sed 's,/[^/]*$,,')
+       if [ ! -d "${BANNER%/*}" ]; then
+               mkdir -p "${BANNER%/*}"
+       fi
        data=$(cat)
        if [ $NEW_APPEND -eq 0 ]; then
                echo "$data" > $BANNER
@@ -158,7 +149,7 @@ make_banner()
 }
 show_banner()
 {
-       cat $BANNERDIR/$1 >&$STDOUT
+       cat "$BANNERDIR/$1" >&$STDOUT
 }
 show_banners()
 {
@@ -167,12 +158,12 @@ show_banners()
        done
 }
 ######################################################## MAIN ########
-while [ ! -z $1 ]; do
-       case $1 in
+while [ -n "$1" ]; do
+       case "$1" in
                -a|--all)
                        ALL_BANNERS=1
                        ;;
-               --delete)
+               -d|--delete)
                        NEED_BANNER_LIST=1
                        ACTION="delete"
                        ;;
@@ -188,13 +179,13 @@ while [ ! -z $1 ]; do
                        ;;
                -m|--make|-M)
                        NEED_BANNER_LIST=0
-                       if [ "$(check_banner_name $2)" == "$2" ]; then
-                               NEW_BANNER=$BANNERDIR/$(check_banner_name "$2")
+                       if [[ "$2" != */* ]]; then
+                               NEW_BANNER="$BANNERDIR/${2##*/}"
                        else
                                NEW_BANNER="$2"
                        fi
                        ACTION="make"
-                       if [ "$1" == "-M" ];then
+                       if [ "$1" = "-M" ];then
                                NEW_APPEND=1
                        else
                                NEW_APPEND=0
@@ -248,9 +239,9 @@ while [ ! -z $1 ]; do
                        ;;
                *)
                        if [ $EXCLUDE_FLAG -eq 0 ];then
-                               BANNERS="$BANNERS $(check_banner_name $1)"
+                               BANNERS="$BANNERS ${1##*/}"
                        else
-                               NOBANNERS="$NOBANNERS $(check_banner_name $1)"
+                               NOBANNERS="$NOBANNERS ${1##*/}"
                        fi
                        ;;
        esac
@@ -280,6 +271,9 @@ case $ACTION in
        "show")
                show_banners $BANNER_LIST;
                ;;
+       "")
+               Help
+               ;;
 esac
 
 
This page took 0.116862 seconds and 4 git commands to generate.