updated setup for latest apache script dependency
[iankelling.org] / gitweb-descriptions
1 #!/bin/bash -l
2 # Copyright (C) 2016 Ian Kelling
3
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 # my projects all have README or --help with a short single line
18 # description which I parse and put into the gitweb description.
19
20 # If it's a repo with just a single bash script or *-function script,
21 # then call it with --help, grap the 2nd line.
22 # else, parse the readme, find the first non blank, not starting with [#*],
23 # and use that line.
24
25 set -eE -o pipefail
26 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
27
28 if [[ ! $1 ]]; then
29 echo "need gitroot arg"
30 exit 1
31 fi
32
33 gitroot=$1
34 cd $gitroot
35
36 shopt -s extglob
37
38 _git_desc_readme() {
39 while read -r line; do
40 [[ $line ]] || continue
41 if echo "$line" | grep "^ *[#*]" &>/dev/null; then
42 continue
43 fi
44 echo "$line" > .git/description
45 break
46 done < README*
47 }
48
49 dirs=()
50 for d in $gitroot/*; do
51 if [[ -d $d && ! -L $d ]]; then
52 for sub in $d/*; do
53 dirs+=($sub)
54 done
55 else
56 dirs+=($d)
57 fi
58 done
59
60 gitweb-descriptions() {
61 for d in ${dirs[@]}; do
62 d=$(readlink -f $d)
63 cd $d/..
64 e ${PWD##*/}
65 shopt -s nullglob
66 f=(!(LICENSE|COPYING|README|.git))
67 shopt -u nullglob
68 if [[ ${#f[@]} == 1 && ! -d $f ]]; then
69 if [[ ! -x $f ]]; then
70 if [[ $f == *-function ]]; then
71 ${f%-function} --help | sed -n '2p' > .git/description
72 else
73 _git_desc_readme
74 fi
75 else
76 ./$f --help | sed -n '2p' > .git/description
77 fi
78 else
79 _git_desc_readme
80 fi
81 done
82 }
83 gitweb-descriptions "$@"