3 # Please send bug reports to pzurowski@pld-linux.org or pld-devel-* lists
7 # >> PLACE STANDARD GPL DISCLAIMER H E R E . <<
9 CONFIG=/etc/sysconfig/banner
11 ####################################################### CONFIG ########
14 ##########################
16 BANNERDIR="/var/lib/banner/"
18 EXCLUDEFILES="(rpmnew$|rpmsave$|~$)"
19 STDOUT="1" # stdout by default
20 #STDOUT="2" # stderr by default
23 ##########################
25 if [ -r $CONFIG ]; then
31 ##########################
51 #################################################### FUNCTIONS ########
55 Usage: $(basename $0) [options] [banners]
62 -a, --all - all banners
63 -d, --delete - delete specified banners
64 -e, --exclude - exclude following banners (useful with -a)
65 -h, --help - show this help
66 -i, --include - cancel effect of -e (EXCLUDED banners will remain excluded)
67 -m, --make - make a brand-new banner named as following parameter [1] (from stdin)
68 -M - same as above, but append if file exists
69 -n, --names - show names of the banners
70 --newer - all choosen banners should be newer than following parameter in seconds
71 --older - all choosen banners should be older than following parameter in seconds
72 -s, --show - show specified banners
73 --stderr - send banner to stderr instead of stdout (or other)
74 --stdout - send banner to stdout instead of stderr (or other)
75 -u, --usage - show short help
77 [1] if there is no slash ('/') in the given name default dir ($BANNERDIR) is used,
78 otherwise the one that's specified
89 check_banners_mtime() {
94 for BANNER in $BANNERS;do
95 STAT=$(stat -c %Y "$BANNERDIR/$BANNER")
96 if [ $OLDER != "no" -a $(( $DATE - $STAT )) -lt $OLDER ]; then
99 if [ $NEWER != "no" -a $(( $DATE - $STAT )) -gt $NEWER ]; then
108 rm -rf $(get_banner_location_list "$BANNER")
111 get_all_banner_list() {
112 ls "$BANNERDIR" | grep -E -v "$EXCLUDEFILES"
118 for BANNER in $BANNERS; do
119 if [ -r "$BANNERDIR/$BANNER" ]; then
120 echo $NOBANNERS | grep -q $BANNER || echo $BANNER
125 get_banner_location_list() {
127 for BANNER in $BANNERS; do
128 echo "$BANNERDIR/$BANNER"
135 if [ ! -d "${BANNER%/*}" ]; then
136 mkdir -p "${BANNER%/*}"
139 if [ $NEW_APPEND -eq 0 ]; then
140 echo "$data" > $BANNER
142 echo "$data" >> $BANNER
144 if [ $SHOW -eq 1 ]; then
150 cat "$BANNERDIR/$1" >&$STDOUT
159 ######################################################### MAIN ########
160 while [ -n "$1" ]; do
181 if [[ "$2" != */* ]]; then
182 NEW_BANNER="$BANNERDIR/${2##*/}"
187 if [ "$1" = "-M" ]; then
192 if [ -z "$NEW_BANNER" ]; then
205 if [ -z "$CHOOSE_NEWER" ]; then
214 if [ -z "$CHOOSE_OLDER" ]; then
240 if [ $EXCLUDE_FLAG -eq 0 ]; then
241 BANNERS="$BANNERS ${1##*/}"
243 NOBANNERS="$NOBANNERS ${1##*/}"
250 if [ $ALL_BANNERS -ne 0 ]; then
251 BANNERS=`get_all_banner_list`
253 if [ $NEED_BANNER_LIST -ne 0 ]; then
254 BANNER_LIST=`get_banner_list "$BANNERS" "$NOBANNERS"`
256 if [ $NEED_MTIME_CHECK -ne 0 ]; then
257 BANNER_LIST=`check_banners_mtime "$BANNER_LIST" "$CHOOSE_OLDER" "$CHOOSE_NEWER"`
262 delete_banners $BANNER_LIST
265 make_banner $NEW_BANNER $NEW_SHOW
271 show_banners $BANNER_LIST