dot

packages and services management
Log | Files | Refs | README

commit 3abd057f24591adbc5d1ee552fe2cab688347396
parent 04bdfb044794456fb95e3791ddf3df0667b9cb74
Author: Josuah Demangeon <mail@josuah.net>
Date:   Wed, 12 Apr 2017 12:21:10 +0200

made version(1) accept commit messages

Diffstat:
Mbin/build | 93+++++++++++++++++++++++++++++++------------------------------------------------
Mbin/version | 43++++++++++++++++++++++++-------------------
Mman/version.1 | 9+++++++--
3 files changed, 67 insertions(+), 78 deletions(-)

diff --git a/bin/build b/bin/build @@ -18,36 +18,20 @@ export MANPATH="$LOCAL/share/man:$LOCAL/man:$MANPATH" usage() { printf 'build [-d pkg] [-i pkg] [-u pkg] [-l] [-v]\n' - exit 0 + exit 1 } view() { - find -L "$CONFIG/build" -type f | while IFS='' read -r f + find -L "$CONFIG/build" -type f | while IFS='' read -r file do - read -r comment description < "$f" - printf ' %-12s %s\n' "${f#$CONFIG/build/}" "$description" + read -r comment description < "$file" + printf ' %-12s %s\n' "${file#$CONFIG/build/}" "$description" done | sort | more - exit 0 -} - - -info() -{ - printf '%-12s %s\n' "$1" "$2" 1>&2 -} - - -die() -{ - info "$1" "$2" 1>&2 - exit 1 } -# Default build function, to be overriden in the build recipes scripts - build() { find "$CONFIG/$1" -name '*.diff' -exec patch -N -p 1 -i {} \; @@ -66,64 +50,58 @@ build() compile() { - name="$1" - PREFIX="$PROGRAMS/$name" script="$CONFIG/build/$name" + PREFIX="$PROGRAMS/$1" script="$CONFIG/build/$1" # export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 # export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 # export CFLAGS="-I$CPATH -L$LIBPATH -static" - [ -f "$script" ] || [ -h "$script" ] || die "$name" "no build script" + [ -f "$script" ] || [ -h "$script" ] || exit 1 . "$script" - info "$name" "installing" + printf '\n\nInstalling %s\n\n' "$1" cd "$PREFIX" && mkdir -p bin doc etc include lib libexec share man - cd src && build "$name" + cd src && build "$1" cd "$PREFIX" && rmdir -p ./* 2> /dev/null } download() { - name="$1" tar="$2" script="$CONFIG/build/$name" + script="$CONFIG/build/$1" - [ -d "$PROGRAMS/$name/src" ] && die "$name" "already in $PROGRAMS" - [ -f "$script" ] || [ -h "$script" ] || die "$name" "no build script" + [ -d "$PROGRAMS/$1/src" ] && exit 1 + [ -f "$script" ] || [ -h "$script" ] || exit 1 . "$script" - info "$name" "downloading" + printf '\n\nDownloading %s\n\n' "$1" case "$tar" in *.tar ) opt='' ;; *.tbz2 | *.tar.bz2 ) opt='j' ;; *.tgz | *.tar.gz ) opt='z' ;; *.txz | *.tar.xz ) opt='J' ;; - * ) die "$name" 'not a known tar extension' ;; + * ) exit 1 ;; esac - mkdir -p "$PROGRAMS/$name" - wget -O - "$tar" | tar -xv"$opt" -f - -C "$PROGRAMS/$name" 1> /dev/null + mkdir -p "$PROGRAMS/$1" + wget -O - "$tar" | tar -xv"$opt" -f - -C "$PROGRAMS/$1" 1> /dev/null - mv "$PROGRAMS/$name/"* "$PROGRAMS/$name/src" + mv "$PROGRAMS/$1/"* "$PROGRAMS/$1/src" } remove() { - info "$1" "removing" + printf '\n\nRemoving %s\n' "$1" rm -rf "${PROGRAMS:?}/$1" - - info '' "removing broken links from ~${LOCAL#$HOME}" find -L "$LOCAL" -type l -exec rm {} \; } -# 1: name of the program in "$PROGRAMS" to index in "$LOCAL" - index() { - info "$1" "updating index in ~${LOCAL#$HOME}" cd "$PROGRAMS/$1" || exit 1 find . -type d ! -path '*/src/*' -exec mkdir -p "$LOCAL/{}" \; find . ! -type d ! -path '*/src/*' -exec ln -sf "$PWD/{}" "$LOCAL/{}" \; @@ -135,36 +113,37 @@ main() mkdir -p "$PROGRAMS" case "$1" in - -d ) - download "$2" "$tar" - index "$2" + + -d ) [ $# = 2 ] || usage + download "$2"; index "$2" ;; - -i ) - [ ! -d "$PROGRAMS/$2/src" ] && download "$2" "$tar" - compile "$2" - index "$2" + + -i ) [ $# = 2 ] || usage + [ ! -d "$PROGRAMS/$2/src" ] && download "$2" + compile "$2"; index "$2" ;; - -r ) - remove "$2" + + -r ) [ $# = 2 ] || usage + remove "$2" ;; - -u ) - remove "$2" - download "$2" "$tar" - compile "$2" - index "$2" + + -u ) [ $# = 2 ] || usage + remove "$2"; download "$2"; compile "$2"; index "$2" ;; - -l ) + + -l ) [ $# = 1 ] || usage find "$PROGRAMS" -maxdepth 1 -mindepth 1 | while IFS='' read -r name do index "${name#$PROGRAMS/}" done ;; - -v ) + + -v ) [ $# = 1 ] || usage view ;; - * | '' ) - usage + + * | '' ) usage ;; esac } diff --git a/bin/version b/bin/version @@ -18,7 +18,7 @@ die() usage() { - printf 'version [-i] [-n] [-d rev1 rev2] [-r rev] [-p tree]\n' + printf 'version [-i] [-n msg] [-d rev1 rev2] [-r rev] [-p dir]\n' exit 1 } @@ -35,9 +35,11 @@ init() } +#1 - commit message + new() { - printf 'making a new revision\n' + printf 'new revision\n' find . -type f ! -path './v/*' | sort | xargs $SUM | tee v/tmp | while read -r hash path @@ -45,16 +47,19 @@ new() [ -f "v/obj/$hash" ] || cp "$path" "v/obj/$hash" done - mv -f v/tmp "v/rev/$($SUM v/tmp | cut -d ' ' -f 1 | tee -a v/log)" - tail -n 2 v/log - printf '%s\n' "$(uniq v/log)" > v/log + old="$([ -f v/log ] && tail -n 1 v/log | cut -d ' ' -f 1)" + new="$($SUM v/tmp | cut -d ' ' -f 1)" + + mv -f v/tmp "v/rev/$new" + + [ "$old" = "$new" ] || printf '%s %s\n' "$new" "$1" | tee -a v/log chmod -w v/obj/* v/rev/* } -# 1: old revision to diff -# 2: new revision to diff +#1 - old revision to diff +#2 - new revision to diff difftree() { @@ -72,7 +77,7 @@ difftree() } -# 1: revision to apply to the current tree +#1 - revision to apply to the current tree revision() { @@ -80,7 +85,8 @@ revision() printf 'applying revision "%s" to tree\n' "$1" - difftree "$(tail -n 1 v/log)" "$1" | while read -r f hash path + difftree "$(tail -n 1 v/log | cut -d ' ' -f 1)" "$1" | + while read -r f hash path do case "$f" in ( + ) mkdir -p "${path%/*}" && cp "v/obj/$hash" "$path" ;; @@ -88,13 +94,11 @@ revision() esac done - chmod +w "$path" - - printf '%s\n' "$1" >> v/log + printf '%s applying revision\n' "$1" >> v/log } -# 1: root of foreign tree to import in local tree +#1 - root of foreign tree to import in local tree pull() { @@ -105,12 +109,13 @@ pull() [ -f "${path#$1/}" ] || cp "$path" "${path#$1/}" || exit 1 done - for revision in $(tac v/log) + for revision in $(tac v/log | cut -d ' ' -f 1) do - grep "$revision" "$1/v/log" > /dev/null && break + cut -d ' ' -f 1 "$1/v/log" | grep "$revision" > /dev/null && + break done || die "no revision common to \"$1\" and \"$PWD\"" - new="$(tail -n 1 "$1/v/log")" + new="$(tail -n 1 "$1/v/log" | cut -d ' ' -f 1)" cp "$1/v/rev/$new" "v/rev/$new" revision "$new" @@ -132,8 +137,8 @@ main() init ;; - ( -n ) [ $# = 1 ] || usage - new + ( -n ) [ $# = 2 ] || usage + new "$2" ;; ( -d ) [ $# = 3 ] && [ -f "v/rev/$2" ] && [ -f "v/rev/$3" ] || usage @@ -145,7 +150,7 @@ main() ;; ( -p ) [ $# = 2 ] && [ -d "$2/v" ] && [ -f "$2/v/log" ] || usage - pull "$(cd "$2" || exit 1; pwd)" + pull "$(cd "$2" && pwd)" ;; ( * | '' ) usage diff --git a/man/version.1 b/man/version.1 @@ -15,7 +15,7 @@ . .Nm .Op Fl i -.Op Fl n +.Op Fl n Ar msg .Op Fl d Ar rev1 rev2 .Op Fl r Ar rev .Op Fl p Ar Pa tree @@ -60,9 +60,14 @@ Initialize a new .Nm directory at the root of current directory. . -.It Fl n +.It Fl n Ar msg New revision is created, saving all modifications form the last saved revision. +The commit message +.Ar msg +is used in the +.Pa v/log +file. . .It Fl p Ar Pa tree Pull the objects from the