stagitbuild

builder-manager for stagit pages
git clone git://git.ckyln.com/stagitbuild.git
Log | Files | Refs | README | LICENSE

commit 90af94343da8b7cf08c9a3bf22c62d6b11c34962
Author: Cem Keylan <cem@ckyln.com>
Date:   Wed,  2 Oct 2019 18:23:47 +0300

initial commit

Diffstat:
ALICENSE | 21+++++++++++++++++++++
AMakefile | 38++++++++++++++++++++++++++++++++++++++
AREADME | 35+++++++++++++++++++++++++++++++++++
Aconfig.mk | 8++++++++
Astagitbuild | 138+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Astagitbuild.1 | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 292 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,21 @@ +MIT/X Consortium License + +© 2019 Cem Keylan <cem@ckyln.com> + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/Makefile b/Makefile @@ -0,0 +1,38 @@ +# stagitbuild - easy builder - manager for your stagit site +# see LICENSE file for details + +include config.mk + +options: + @echo stagitbuild options: + @echo "PREFIX = ${PREFIX}" + +clean: + @echo cleaning + @rm -f stagitbuild-${VERSION}.tar.gz + +dist: + @echo creating dist tarball + @mkdir -p stagitbuild-${VERSION} + @cp -R LICENSE Makefile README config.mk stagitbuild.1 stagitbuild stagitbuild-${VERSION} + tar -cf stagitbuild-${VERSION}.tar stagitbuild-${VERSION} + gzip stagitbuild-${VERSION}.tar + @rm -rf stagitbuild-${VERSION} + +install: + @echo installing executable file to ${DESTDIR}${PREFIX}/bin + @mkdir -p ${DESTDIR}${PREFIX}/bin + @cp -f stagitbuild ${DESTDIR}${PREFIX}/bin + @chmod 755 ${DESTDIR}${PREFIX}/bin/stagitbuild + @echo installing manual page to ${DESTDIR}${MANPREFIX}/man1 + @mkdir -p ${DESTDIR}${MANPREFIX}/man1 + @sed "s/VERSION/${VERSION}/g" < stagitbuild.1 > ${DESTDIR}${MANPREFIX}/man1/stagitbuild.1 + @chmod 644 ${DESTDIR}${MANPREFIX}/man1/stagitbuild.1 + +uninstall: + @echo removing executable file from ${DESTDIR}${PREFIX}/bin + @rm -f ${DESTDIR}${PREFIX}/bin/stagitbuild + @echo removing manual page from ${DESTDIR}${MANPREFIX}/man1 + @ rm -f ${DESTDIR}${MANPREFIX}/man1/stagitbuild.1 + +.PHONY: options install uninstall dist diff --git a/README b/README @@ -0,0 +1,35 @@ +stagitbuild +=========== + +Builder - manager for you stagit page. + + +Description +----------- + +stagitbuild generates a configuration file that you can +fill in order to not deal with writing hook-scripts to +get it to work. It works pretty straight-forward. + + +Installation +------------ +You can install the script with (if necessary as root): + + make install + +and start using the script right away. + + +Configuration +------------- +The script reads the generated configuration from +~/.stagitconf , which explains all the configuration +options. More detailed information is in the man page. + +Dependencies +------------ + +* git +* stagit +* (optional) rsync [for syncing git repo to another place] diff --git a/config.mk b/config.mk @@ -0,0 +1,8 @@ +# stagitbuild version +VERSION=0.1 + +# Customize below to your liking + +# paths +PREFIX = /usr/local +MANPREFIX = ${PREFIX}/share/man diff --git a/stagitbuild b/stagitbuild @@ -0,0 +1,138 @@ +#!/bin/bash + +out() { printf "$1 $2\n" "${@:3}"; } +error() { out "==> ERROR:" "$@"; } >&2 +warning() { out "==> WARNING:" "$@"; } >&2 +msg() { out "==>" "$@"; } +msg2() { out " ->" "$@";} +die() { error "$@"; exit 1; } + +usage() { + cat << "EOF" +stagitbuild.sh - simple build script for stagit repositories + + Usage: stagitbuild.sh [options] + + -c <location> Set a different location for the config file + -s <location> Set an alternative source directory + -d <location> Set an alternative destination directory + -g [location] Generate configuration, with an optional location argument + + -h/--help Prints this help message + +EOF +} + +createconf() { + [ -e $1 ] && die 'A configuration file already exists in %s' "$1" + cat > $1 <<EOF +# Add your git repos inside e.g. (something someotherthing thirdthing) +GITREPOS=() + +# Add the source directory e.g. "/home/git" +SRC="" + +# Add the destination directory e.g. "/srv/http" +# This is the directory where stagit will be served +DEST="" + +# Add a destination if you want your git repositories to be rsynced somewhere (optional) +DESTGIT="" + +# Add the location to your style.css here "/home/bar/style.css" (Optional) +CSS="" + +# Add your favicon.png (Optional) +FAVI="" + +# Add your logo.png [32x32] (Optional) +LOGO="" + +## Uncomment this if you want stagitbuild to create +## archives from the tags of your repository +#ARCHIVE="yes" + +EOF + cat <<EOF +Configuration file is created to $1 +EOF +} + +getrepogit() { + for repo in ${GITREPOS[*]}; do + repogit+=("${SRC}/${repo}.git") + done +} + +stylepage() { + [ -n "$CSS" ] && [ -e "$CSS" ] && cp -uf $CSS $1/style.css + [ -n "$FAVI" ] && [ -e "$FAVI" ] && cp -uf $FAVI $1/favicon.png + [ -n "$LOGO" ] && [ -e "$LOGO" ] && cp -uf $LOGO $1/logo.png +} + +rsyncrepos() { + for repo in ${GITREPOS[*]}; do + rsync -a ${SRC}/${repo}.git ${DESTGIT} || die 'There was an error while rsyncing %s' "${repo}" + done +} + +gitarchive() { + name="$1" + cd ${SRC}/${1}.git + if [ -n "$(git tag -l)" ]; then + mkdir -p ${DEST}/archives/${name} + git tag -l | while read -r t; do + f="${DEST}/archives/${name}/${name}-$(echo "${t}" | tr '/' '_').tar.gz" + test -f "${f}" && continue + git archive \ + --format tar.gz \ + --prefix "${name}-${t}/" \ + -o "${f}" \ + -- \ + "${t}" + done + fi +} + +buildgit() { + for repo in ${GITREPOS[*]}; do + mkdir ${DEST}/${repo} 2>/dev/null + cd ${DEST}/${repo} + stagit ${SRC}/${repo}.git + stylepage $PWD + [ "$ARCHIVE" = "yes" ] && gitarchive ${repo} + done + cd $DEST + stagit-index ${repogit[*]} > $DEST/index.html + stylepage $PWD +} + +if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then + usage + exit +fi + +while getopts ':c::s::d:g' flag; do + case $flag in + c) realpath -e $OPTARG 2>/dev/null && CONFIG=$(realpath ${OPTARG}) || die 'Could not find configuration' ;; + s) realpath -e $OPTARG 2>/dev/null && ALTSRC=$(realpath ${OPTARG}) || die 'Could not find source directory' ;; + d) realpath -e $OPTARG 2>/dev/null && ALTDES=$(realpath ${OPTARG}) || die 'Could not find destination dir' ;; + g) gen=1; genloc=$OPTARG ;; + :) die '%s: option requires an argument -- '\''%s'\' "${0##*/}" "$OPTARG" ;; + ?) die '%s: invalid option -- '\''%s'\' "${0##*/}" "$OPTARG" ;; + esac +done +[ -z $genloc ] && genloc="$HOME/.stagitconf" +[ "$gen" = 1 ] && createconf $genloc && exit +[ -z "$CONFIG" ] && CONFIG="$HOME/.stagitconf" +[ -e "$CONFIG" ] || createconf $CONFIG && exit +[ -n "$ALTSRC" ] && SRC=$ALTSRC +[ -n "$ALTDES" ] && DES=$ALTDES +if [ -z "$SRC" ] || [ -z "$GITREPOS" ] || [ -z "$DEST" ]; then + die 'Required variables are not set' +fi +declare -a repogit + +getrepogit +[ -n "$DESTGIT" ] && rsyncrepos +buildgit diff --git a/stagitbuild.1 b/stagitbuild.1 @@ -0,0 +1,52 @@ +.TH STAGITBUILD 1 stagitbuild\-VERSION +.SH NAME +stagitbuild \- builder - manager for stagit +.SH SYNOPSIS +.B stagitbuild +.RB [ \-c +.IR location ] +.RB [ \-s +.IR location ] +.RB [ \-d +.IR location ] +.RB [ \-g +.IR location ] +.RB [ \-h ] +.SH DESCRIPTION +.B stagitbuild +is a simple bash script for managing your stagit page. Stagitbuild +will read a configuration file and will generate a stagit page. It will +also read your git tags to generate tar.gz archives and put them to the +.B /archives/reponame +directory + +stagitbuild can rsync selected repos to a different location, which is useful in cases +where you have public and private repositories in a certain location and want +to sync your public repositories to a place where you can serve them. +.SH OPTIONS +.TP +.B SRC + \- source directory +.TP +.B DEST + \- stagit webpage directory +.TP +.B GITREPOS + \- (array) name of your git repos (without .git part) +.TP +.B DESTGIT + \- (optional) place to rsync git repos +.TP +.B CSS + \- (optional) location of style.css file +.TP +.B FAVI + \- (optional) location of favicon.png file +.TP +.B LOGO + \- (optional) location of logo.png file +.TP +.B ARCHIVE + \- option whether to create archives from git tags +.SH AUTHOR +Cem Keylan <cem@ckyln.com>