From 0873b3e326586ff2b7b3b0e6cbdd85e1a31ec4ad Mon Sep 17 00:00:00 2001 From: Justin Davis Date: Mon, 5 Mar 2012 17:29:51 -0500 Subject: Make pkgtree scripts simpler still. --- bin/getpkgtree | 16 ++++++---------- bin/initpkgtree | 40 ---------------------------------------- bin/putpkgtree | 28 +++++++++++++++------------- 3 files changed, 21 insertions(+), 63 deletions(-) delete mode 100755 bin/initpkgtree diff --git a/bin/getpkgtree b/bin/getpkgtree index dd2517c..38d4930 100755 --- a/bin/getpkgtree +++ b/bin/getpkgtree @@ -8,15 +8,11 @@ then exit 2 fi -if ! [ -d "$1" ] +if ! [ -d PKGTREE ] then - echo "$prog: package file does not exist: $1" 1>&2 - exit 101 + echo "$prog: PKGTREE directory does not exist" 1>&2 + exit 100 fi -if ! [ -d "$1/$2" ] -then - echo "$prog: section does not exist: $2" 1>&2 - exit 102 -fi - -find "$1/$2" -maxdepth 1 -type f | sort | xargs cat +[ -d "PKGTREE/$1" ] || exit 101 +[ -d "PKGTREE/$1/$2" ] || exit 101 +find "PKGTREE/$1/$2" -maxdepth 1 -type f | sort | xargs cat diff --git a/bin/initpkgtree b/bin/initpkgtree deleted file mode 100755 index 77d8e47..0000000 --- a/bin/initpkgtree +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -# Initializes files and their sections in a package tree directory structure. -# Assumes we are already inside of a package tree's root directory. - -prog=initpkgtree - -if [ $# -eq 0 ] -then - echo "usage: $prog [filename] [section 1] [section 2] [...]" 1>&2 - exit 2 -fi - -if [ -d "$1" ] -then - echo "$prog: a file named $1 already exists in the package tree" 1>&2 - exit 101 -fi - -dups=`for sect; do echo "$sect"; done | awk ' -{ dups[$1]++ } END { for(d in dups) if(dups[d] > 1) printf d " " }' -` -if [ "$dups" ] -then - echo "$prog: duplicate sections not permitted: $dups" 1>&2 - exit 102 -fi - -mkdir "$1" -cd "$1" -shift - -for sect -do - d="$sect" - mkdir "$d" - for f in beg body end - do - touch "$d/$f" - done -done diff --git a/bin/putpkgtree b/bin/putpkgtree index f415108..2606460 100755 --- a/bin/putpkgtree +++ b/bin/putpkgtree @@ -2,25 +2,27 @@ prog=putpkgtree -err() -{ - code="$1" - shift - echo $@ 1>&2 - exit "$code" -} - if [ "$#" -ne 3 ] then echo "usage: $prog [file] [section] ['beg'/'body'/'end'] < [text to append]" 1>&2 exit 2 fi -[ -d "$1" ] || err 101 "$prog: package file does not exist: $1" -cd "$1" +case "$3" in +beg|body|end) ;; +*) echo "$prog: third parameter must be 'beg', 'body', or 'end'" 1>&2 + exit 2 +esac -[ -d "$2" ] || err 102 "$prog: section does not exist: $2" 1>&2 -cd "$2" +if ! [ -d PKGTREE ] +then + echo "$prog: PKGTREE directory does not exist" 1>&2 + exit 100 +fi +cd PKGTREE -[ -f "$3" ] || err 103 "$prog: subsection does not exist: $3" +[ -d "$1" ] || mkdir "$1" +cd "$1" +[ -d "$2" ] || mkdir "$2" +cd "$2" cat >> "$3" -- cgit v1.2.3-24-g4f1b