noxz-sites

A collection of a builder and various scripts creating the noxz.tech sites
git clone git://git.noxz.tech/noxz-sites
Log | Files | Refs | README | LICENSE

build-git.sh (3964B)


      1 #!/bin/sh
      2 
      3 [ ! -d "$(realpath ~/mnt/src/z0noxz)" ] && exit 1;
      4 
      5 reposdir="$(realpath ~/mnt/src/z0noxz)"
      6 basedir="$(realpath ./)"
      7 basedir_git="$(realpath ./git.noxz.tech)"
      8 basedir_root="$(realpath ./noxz.tech)"
      9 
     10 REPOS=$(for d in "${reposdir}/"*/; do [ ! -f $d/fork ] && [ ! -f $d/disc ] && echo $d; done)
     11 FORKS=$(for d in "${reposdir}/"*/; do [ -f $d/fork ] && echo $d; done)
     12 #DISCO=$(for d in "${reposdir}/"*/; do [ -f $d/disc ] && echo $d; done)
     13 
     14 REPOS=$(stagit-index $REPOS)
     15 REPOS=$(echo "$REPOS" | sed -e 's/<tr><td><b>/<tr class="nohi"><td><b>/')
     16 HEADR=$(echo "$REPOS" | grep -o '^.*</thead><tbody>' | sed -e 's|</thead.*$||')
     17 #DISCO=$(stagit-index $DISCO)
     18 
     19 if [ "$FORKS" != "" ]
     20 then
     21     FORKS=$(stagit-index $FORKS)
     22     FORKS=$(echo "$FORKS" | sed -n '/<table id="index">/,$p' | sed 1,2d)
     23     REPOS=$(echo "$REPOS" | awk -vN=2 '1;/<\/table>/&&--N<=0{exit}' | sed '$ d')
     24     REPOS="$REPOS<tr class=\"nohi\"><td colspan=\"4\">&nbsp;</td></tr>$HEADR$FORKS"
     25 fi
     26 
     27 echo "$REPOS" > "${basedir_git}/index.html"
     28 #stagit-index $REPOS > "${basedir_git}/index.html"
     29 
     30 for dir in "${reposdir}/"*/; do
     31     r=$(basename "${dir}")
     32     d=$(basename "${dir}" ".git")
     33 
     34     mkdir -p "${basedir_git}/${d}"
     35     cd "${basedir_git}/${d}"
     36     stagit -c ".cache" "${reposdir}/${r}"
     37 
     38     # rename hidden (dotfiles) so they can be accessed using quark
     39     for dotfile in $(grep -o 'href="file/[^"]*.html"' files.html \
     40         | grep '/\.' | sed -e 's|^href="||' -e 's|"$||')
     41     do
     42         new_name="$(echo $dotfile | sed -e 's|/\.|/_.|g')"
     43         new_dir="$(dirname $new_name)"
     44         [ ! -d "$new_dir" ] && mkdir -p "$new_dir"
     45         mv "$dotfile" "$new_name"
     46         sed -i -e "s|href=\"$dotfile\"|href=\"$new_name\"|g" files.html
     47         sed -i -e "s|href=\"../$dotfile\"|href=\"../$new_name\"|g" commit/*.html
     48     done
     49 
     50     # remove empty directories after rename
     51     find ./file -type d -empty -delete
     52 
     53     cp log.html index.html
     54 
     55     printf "[\033[1;32m+\033[m] git repo created: %s\n" "${d}"
     56 done
     57 
     58 find "${basedir_git}/." -name "*.html" -type f -print0 | \
     59     xargs -0 sed -i \
     60     -e 's,="[^a-zA-Z0-9]*style.css",="/pub/style.css",g' \
     61     -e 's,="[^a-zA-Z0-9]*logo.png",="/pub/logo.svg",g' \
     62     -e 's,="[^a-zA-Z0-9]*favicon.png",="/pub/logo.png",g'
     63 
     64 #> $basedir/repo-graph
     65 #printf '<h2>Commits in the last year</h2>\n' > $basedir/repo-graph
     66 #repo-graph -s $reposdir/* >> $basedir/repo-graph
     67 
     68 printf '<h2>Latest commits</h2>\n' > $basedir/repo-graph
     69 log=""
     70 for x in $reposdir/*
     71 do
     72     x="$(realpath $x)"
     73     a="${x##*/}"
     74     a="${a%%.*}"
     75     a="<a href=\"https://git.noxz.tech/$a/log.html\">$a</a>"
     76     cmd=$(printf 'cd "%s" && git log %s %s %s %s'                           \
     77         "$x"                                                                \
     78         '--no-merges'                                                       \
     79         '--date="format:%Y-%m-%d %H:%M:%S"'                                 \
     80         "--pretty=\"format:%at:%ad [$a] %s"\"                               \
     81         '--since="13 months"'                                               \
     82     )
     83     log=$(printf '%s\n%s' "$log" "$(eval "$cmd")")
     84 done
     85 
     86 echo "$log"                                                                 \
     87 | sort -r                                                                   \
     88 | sed 15q                                                                   \
     89 | sed -e 's/^[^:]*://g'                                                     \
     90 | awk '
     91     BEGIN {
     92         print "<ul class=\"repo-log\">";
     93     } {
     94         printf "<li><span class=\"log-date\">%s %s</span>",$1,$2;
     95         $1=$2="";
     96         $0=$0;
     97     } NF=NF {
     98         printf "%s</li>\n",$0
     99     } END {
    100         print "<li>[<a href=\"https://git.noxz.tech/\">...</a>]</li></ul>"
    101     }
    102 ' >> $basedir/repo-graph
    103 
    104 sed -i $basedir_root/index.html                                             \
    105     -e "/^.*!!placeholder:repo-graph!!.*$/r $basedir/repo-graph"            \
    106     -e "/^.*!!placeholder:repo-graph!!.*$/d"