File: insert-banner.sh

package info (click to toggle)
python-igraph 0.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,944 kB
  • sloc: ansic: 225,735; cpp: 23,208; python: 17,085; xml: 2,407; yacc: 1,164; sh: 531; lex: 486; pascal: 158; sed: 45; makefile: 23; javascript: 20; fortran: 8
file content (43 lines) | stat: -rwxr-xr-x 827 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash

## Insert a banner into a html file, right at the start of <body>

if [ $# != "2" -a $# != "3" ] || [ ! -d $1 ] || [ ! -f $2 ]; then
    printf "Usage: $0 <directory> <banner-file> [<exclude-file>]\n"
    exit 1
fi

banner=$2
exclude=/dev/null
if [ -n "$3" ]; then exclude=$3; fi

tmpfile=`mktemp -t XXXXXX`

function insert {
    printf "%b" "Doing $1..."

    if [ -n "$exclude" ] && (echo $1 | grep -q -f $exclude); then
        printf "%b" " excluded\n"
    else
        insert2 $1 > "$tmpfile"
        cp $tmpfile $1
        printf "%b" " DONE\n"
    fi
}

function insert2  {
    cat $1 |
    sed -n '1h;1!H;${;g;s/\(<body[^>]*>\)/\1\n<!--endbanner-->/g;p;}' |
    sed "/<!--endbanner-->/ {
        r $banner
        N
    }"
}

find $1 -name "*.html" |
while read; do
    insert $REPLY
done

rm "$tmpfile"