minor update
[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 shopt -s nullglob
38
39 _git_desc_readme() {
40 while read -r line; do
41 [[ $line ]] || continue
42 if echo "$line" | grep "^ *[#*]" &>/dev/null; then
43 continue
44 fi
45 echo "$line" > .git/description
46 break
47 done < README*
48 }
49
50 gitweb-descriptions() {
51 for d in ${dirs[@]}; do
52 cd $(readlink -f $d)/..
53 [[ -e .git ]] || echo $d
54 if [[ ${personalized[${d##*/}]} ]]; then
55 echo "$pcategory" >.git/category
56 fi
57 f=(!(LICENSE|COPYING|README|.git))
58 if [[ ${#f[@]} == 1 && ! -d $f ]]; then
59 if [[ ! -x $f ]]; then
60 if [[ $f == *-function ]]; then
61 ${f%-function} --help | sed -n '2p' > .git/description
62 else
63 _git_desc_readme
64 fi
65 else
66 ./$f --help | sed -n '2p' > .git/description
67 fi
68 else
69 _git_desc_readme
70 fi
71 done
72 }
73
74 tmp=(
75 bashrc
76 automated-distro-installer
77 buildscripts
78 config-files
79 distro-setup
80 dot-emacs
81 fai-basefiles
82 ian-misc-bash
83 iankelling.org
84 )
85 declare -A personalized
86 for p in ${tmp[@]}; do personalized[$p]=true; done
87 pcategory="Personalized for my use. Useful as examples or to copy specific parts"
88
89
90 dirs=()
91 for d in $gitroot/*; do
92 if [[ ! -L $d ]]; then
93 continue
94 fi
95 dirs+=($d)
96 done
97
98 gitweb-descriptions "$@"