dot

packages and services management
Log | Files | Refs | README

commit 7ae8a09d39fd8850d0b48b2b82b565292fcc170a
parent 34564865b08edc75e58b5917eac7f1498684a921
Author: josuah <mail@josuah.net>
Date:   Wed, 28 Dec 2016 01:35:31 +0000

new bins

Diffstat:
M.local/bin/build | 4++--
M.local/bin/music-rename | 2+-
A.local/bin/version | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/.local/bin/build b/.local/bin/build @@ -12,14 +12,14 @@ export LD_LIBRARY_PATH="$LOCAL/lib:$LD_LIBRARY_PATH" # check wether if the script is being sourced or run -if [ "${0##*/}" == build ] +if [ "${0##*/}" = build ] then usage() { printf '%s\n' "\ -Usage: ${0##*/} COMMAND PACKAGE +usage: ${0##*/} COMMAND PACKAGE d[ownload] Download PACKAGE's sources i[nstall] Download then install PACKAGE diff --git a/.local/bin/music-rename b/.local/bin/music-rename @@ -3,7 +3,7 @@ transform() { printf '%s\n' "$1" | sed -r ' - s|([^[:alnum:]][[:digit:]]+) - |\1-|g + s|([^[:alnum:]][[:digit:]]+) - |\1--|g s| - |/|g s|&|and|g y| |-| diff --git a/.local/bin/version b/.local/bin/version @@ -0,0 +1,81 @@ +#!/bin/sh + + +usage() +{ + printf 'usage: %s COMMAND + +n[ew] create a new version entry +' "${0##*/}" + exit 1 +} + + +die() +{ + printf '%s: %s\n' "${0##*/}" "$*" + exit 1 +} + + +# +# Generate exclude rules for find(1) for every arguments +# +exclude() +{ + for path in "$@" + do + printf ' ! -name %s ! -path */%s/*' "$path" "$path" + done +} + + +# +# Find the root ".version" dir if any or return error. +# +root() +{ + while [ ! -d ".version" ] + do + [ "$PWD" = '/' ] && return 1 || cd .. + done + pwd +} + + +new() +{ + find . -type f $(exclude .git .version) | xargs md5sum > .version/tmp + md5="$(md5sum .version/tmp | cut -d ' ' -f 1)" + + if [ "$md5" = "$(tail -n 1 .version/history)" ] + then + rm .version/tmp + die 'already at latest version' + fi + + printf '%s\n' "$md5" >> .version/history + mv .version/tmp ".version/$md5" +} + + +main() +{ + case "$1" in + n | new ) + action='new' + ;; + * ) + usage + ;; + esac + shift + + TREE1="$(root)" + [ -d "$TREE1" ] && cd "$TREE1" || die "could find root tree" + + $action "$@" +} + + +main "$@"