remgit-scripts

A collection of scripts for use with a simple remote git service.
Log | Files | Refs | README | LICENSE

upstagit.sh (2969B)


      1 #!/bin/bash
      2 
      3 # 'upsatgit.sh' - Script to update and format a stagit git web frontend
      4 # Intended for use with stagit: https://git.codemadness.org/stagit/file/README.html
      5 
      6 # Configure these values to match your web environment
      7 REPO_PATH="/srv/git"
      8 WEB_PATH="/var/www/html"
      9 WEB_REPO_DIR="repos"
     10 WEB_URL="https://example.com"
     11 GIT_ACCESS_URL="git://example.com" #For git protocol links
     12 HOME_PAGE_URL="https://example.com" #For making a link to a homepage besides the git index
     13 HOME_LINK_TEXT="Return home"
     14 LOGO_URL="$WEB_URL/example.jpg"
     15 LOGO_ALT="Alt text" #Alt text for logo image
     16 STYLE_URL="$WEB_URL/style.css"
     17 ICON_WIDTH="32"
     18 ICON_HEIGHT="32"
     19 STAGIT_COM="/usr/local/bin/stagit"
     20 STAGIT_INDEX_COM="$STAGIT_COM-index"
     21 INDEX_TITLE="Repositories"
     22 WEB_USER="root" #Who should own the webroot and the files therein?
     23 
     24 # Update web frontend for each repo
     25 for i in $(ls $REPO_PATH); do
     26     # Format away the '.git' at the end of the repo name, if it is there
     27     old_i=$i
     28     i=$(sed 's,\.git$,,' <<< $i)
     29     if [[ -d $WEB_PATH/$WEB_REPO_DIR/$i ]]; then
     30         cd $WEB_PATH/$WEB_REPO_DIR/$i
     31         rm -rd *
     32     else
     33         mkdir $WEB_PATH/$WEB_REPO_DIR/$i
     34         cd $WEB_PATH/$WEB_REPO_DIR/$i
     35     fi
     36     $STAGIT_COM $REPO_PATH/$old_i
     37 done
     38 unset i
     39 
     40 # Update index.html
     41 cd $WEB_PATH
     42 $STAGIT_INDEX_COM $REPO_PATH/* > $WEB_PATH/index.html
     43 
     44 # Update paths to stylesheets and logos in all web pages
     45 sed -i "s,class\=\"desc\">Repositories,class\=\"desc\"><h1>$INDEX_TITLE<\/h1>,g" "$WEB_PATH/index.html"
     46 sed -i "s,<td><a href\=\",<td><a href=\"$WEB_REPO_DIR\/,g" "$WEB_PATH/index.html"
     47 sed -i "s,<td><b>Owner<\/b><\/td>,<td><\/td>,g" "$WEB_PATH/index.html"
     48 sed -i "s,href\=\".*style\.css\",href\=\"$STYLE_URL\",g" "$WEB_PATH/index.html"
     49 sed -i "s,<img src\=\".* \/>,<img src\=\"$LOGO_URL\" alt\=\"$LOGO_ALT\" width\=\"$ICON_WIDTH\" height\=\"$ICON_HEIGHT\" \/>,g" "$WEB_PATH/index.html"
     50 sed -i "s,<table>,<table id\=\"title-head\">," "$WEB_PATH/index.html"
     51 sed -i "s,<\/span><\/td><\/tr>,<\/span><\/td><td><a href\=\"$HOME_PAGE_URL\">$HOME_LINK_TEXT<\/a><\/td><\/tr>," "$WEB_PATH/index.html"
     52 
     53 for j in $(ls $REPO_PATH); do
     54     jdir=$(sed 's,\.git$,,' <<< $j)
     55     for k in $(find $WEB_PATH/$WEB_REPO_DIR/$jdir | grep ".html$"); do
     56         sed -i "s,css\" href\=\".*style\.css\",css\" href\=\"$STYLE_URL\"," "$k"
     57         sed -i "s,<table>.*<img.*\/>,<table id\=\"title-head\"><tr><td><a href\=\"$WEB_URL\"><img src\=\"$LOGO_URL\" alt\=\"$LOGO_ALT\" width\=\"$ICON_WIDTH\" height\=\"$ICON_HEIGHT\" \/> ," "$k"
     58         sed -i "s,<\/a><\/td><\/tr><\/table>,<\/a> \| git clone: <a href\=\"$GIT_ACCESS_URL\/$j\">$GIT_ACCESS_URL\/$j<\/a><\/td><\/tr><\/table>," "$k"
     59         sed -i "0,/<\/td><\/tr>/{s,<\/td><\/tr>,<\/td><td><a href\=\"$HOME_PAGE_URL\">$HOME_LINK_TEXT<\/a><\/td><\/tr>,}" "$k"
     60         sed -i "0,/<td><\/td><td>/{s,<td><\/td><td>,<td><\/td><td id\=\"repolinks\">,}" "$k"
     61     done
     62     unset k
     63 done
     64 unset j
     65 
     66 # Set correct ownership rights
     67 chown -R $WEB_USER:$WEB_USER $WEB_PATH