diff --git a/CHANGES b/CHANGES index 8038bca..c5a08e6 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,12 @@ +1.11.0 + * Option for Cygwin to copy files instead of symlink (#62) + * Support `YADM_DISTRO` in Jinja templates (#68) + * Support pre/post hooks for every command (#70) + +1.10.0 + * Fix `COMP_WORDS bad array subscript` bug (#64) + * Transition to semantic versioning + 1.09 * Add Bash completion script (#60) * Support WSL detection (#61) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 409ba19..32b93a4 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -2,6 +2,7 @@ CONTRIBUTORS Tim Byrne Espen Henriksen +Cameron Eagans Jan Schulz Patrick Hof Satoshi Ohki @@ -10,4 +11,5 @@ Sébastien Gross Tomas Cernaj Uroš Golja Franciszek Madej +Klas Mellbourn Paraplegic Racehorse diff --git a/Dockerfile b/Dockerfile index d0ec689..74700c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM ubuntu:yakkety MAINTAINER Tim Byrne # Install prerequisites -RUN apt-get update && apt-get install -y git gnupg1 make shellcheck bats expect curl python-pip +RUN apt-get update && apt-get install -y git gnupg1 make shellcheck bats expect curl python-pip lsb-release RUN pip install envtpl # Force GNUPG version 1 at path /usr/bin/gpg diff --git a/completion/yadm.bash_completion b/completion/yadm.bash_completion index e538cbc..1091e55 100644 --- a/completion/yadm.bash_completion +++ b/completion/yadm.bash_completion @@ -9,8 +9,14 @@ if declare -F _git > /dev/null; then _yadm() { local current=${COMP_WORDS[COMP_CWORD]} - local penultimate=${COMP_WORDS[COMP_CWORD-1]} - local antepenultimate=${COMP_WORDS[COMP_CWORD-2]} + local penultimate + if [ "$((COMP_CWORD-1))" -ge "0" ]; then + penultimate=${COMP_WORDS[COMP_CWORD-1]} + fi + local antepenultimate + if [ "$((COMP_CWORD-2))" -ge "0" ]; then + antepenultimate=${COMP_WORDS[COMP_CWORD-2]} + fi local GIT_DIR # shellcheck disable=SC2034 diff --git a/test/007_unit_query_distro.bats b/test/007_unit_query_distro.bats new file mode 100644 index 0000000..639ab29 --- /dev/null +++ b/test/007_unit_query_distro.bats @@ -0,0 +1,49 @@ +load common +load_fixtures + +@test "Query distro (lsb_release present)" { + echo " + Use value of lsb_release -si + " + + #shellcheck source=/dev/null + YADM_TEST=1 source "$T_YADM" + status=0 + { output=$( query_distro ); } || { + status=$? + true + } + + expected="${T_DISTRO}" + + echo "output=$output" + echo "expect=$expected" + + [ "$status" == 0 ] + [ "$output" = "$expected" ] +} + +@test "Query distro (lsb_release missing)" { + echo " + Empty value if lsb_release is missing + " + + #shellcheck source=/dev/null + YADM_TEST=1 source "$T_YADM" + LSB_RELEASE_PROGRAM="missing_lsb_release" + echo "Using $LSB_RELEASE_PROGRAM as lsb_release" + + status=0 + { output=$( query_distro ); } || { + status=$? + true + } + + expected="" + + echo "output=$output" + echo "expect=$expected" + + [ "$status" == 0 ] + [ "$output" = "$expected" ] +} diff --git a/test/100_accept_version.bats b/test/100_accept_version.bats index 8c9b219..962b91f 100644 --- a/test/100_accept_version.bats +++ b/test/100_accept_version.bats @@ -5,7 +5,7 @@ status=;output=; #; populated by bats run() @test "Command 'version'" { echo " When 'version' command is provided, - Print the current version with format 'yadm x.xx' + Print the current version with format 'yadm x.x.x' Exit with 0 " @@ -20,6 +20,6 @@ status=;output=; #; populated by bats run() #; validate status and output [ $status -eq 0 ] [ "$output" = "yadm $VERSION" ] - version_regex="^yadm [[:digit:]\.]+$" + version_regex="^yadm [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$" [[ "$output" =~ $version_regex ]] } diff --git a/test/113_accept_jinja_alt.bats b/test/113_accept_jinja_alt.bats index 6ed6c63..8cfe343 100644 --- a/test/113_accept_jinja_alt.bats +++ b/test/113_accept_jinja_alt.bats @@ -21,11 +21,11 @@ function test_alt() { case $alt_type in base) real_name="alt-jinja" - file_content_match="-${T_SYS}-${T_HOST}-${T_USER}" + file_content_match="-${T_SYS}-${T_HOST}-${T_USER}-${T_DISTRO}" ;; override_all) real_name="alt-jinja" - file_content_match="custom_class-custom_system-custom_host-custom_user" + file_content_match="custom_class-custom_system-custom_host-custom_user-${T_DISTRO}" ;; esac diff --git a/test/115_accept_introspect.bats b/test/115_accept_introspect.bats index c283f6d..0d1922b 100644 --- a/test/115_accept_introspect.bats +++ b/test/115_accept_introspect.bats @@ -73,7 +73,7 @@ function count_introspect() { Exit with 0 " - count_introspect "configs" 0 11 'yadm\.auto-alt' + count_introspect "configs" 0 12 'yadm\.auto-alt' } @test "Command 'introspect' (repo)" { diff --git a/test/116_accept_cygwin_copy.bats b/test/116_accept_cygwin_copy.bats new file mode 100644 index 0000000..8d1ff04 --- /dev/null +++ b/test/116_accept_cygwin_copy.bats @@ -0,0 +1,131 @@ +load common +load_fixtures +status=;output=; #; populated by bats run() + +IN_REPO=(alt*) +export TEST_TREE_WITH_CYGWIN=1 +export SIMULATED_CYGWIN="CYGWIN_NT-6.1-WOW64" + +setup() { + destroy_tmp + build_repo "${IN_REPO[@]}" +} + +test_alt() { + local cygwin_copy="$1" + local is_cygwin="$2" + local expect_link="$3" + local preexisting_link="$4" + + case "$cygwin_copy" in + true|false) + git config --file="$T_YADM_CONFIG" "yadm.cygwin-copy" "$cygwin_copy" + ;; + esac + + if [ "$is_cygwin" = "true" ]; then + echo '#!/bin/sh' > "$T_TMP/uname" + echo "echo $SIMULATED_CYGWIN" >> "$T_TMP/uname" + chmod a+x "$T_TMP/uname" + fi + + local expected_content + expected_content="$T_DIR_WORK/alt-test##$(PATH="$T_TMP:$PATH" uname -s)" + + if [ "$preexisting_link" = 'symlink' ]; then + ln -s "$expected_content" "$T_DIR_WORK/alt-test" + elif [ "$preexisting_link" = 'file' ]; then + touch "$T_DIR_WORK/alt-test" + fi + + PATH="$T_TMP:$PATH" run "${T_YADM_Y[@]}" alt + + echo "Alt output:$output" + echo "Alt status:$status" + + if [ -L "$T_DIR_WORK/alt-test" ] && [ "$expect_link" != 'true' ] ; then + echo "ERROR: Alt should be a simple file, but isn't" + return 1 + fi + if [ ! -L "$T_DIR_WORK/alt-test" ] && [ "$expect_link" = 'true' ] ; then + echo "ERROR: Alt should use symlink, but doesn't" + return 1 + fi + + if ! diff "$T_DIR_WORK/alt-test" "$expected_content"; then + echo "ERROR: Alt contains different data than expected" + return 1 + fi +} + +@test "Option 'yadm.cygwin-copy' (unset, non-cygwin)" { + echo " + When the option 'yadm.cygwin-copy' is unset + and the OS is not CYGWIN + Verify alternate is a symlink + " + test_alt 'unset' 'false' 'true' +} + +@test "Option 'yadm.cygwin-copy' (true, non-cygwin)" { + echo " + When the option 'yadm.cygwin-copy' is true + and the OS is not CYGWIN + Verify alternate is a symlink + " + test_alt 'true' 'false' 'true' +} + +@test "Option 'yadm.cygwin-copy' (false, non-cygwin)" { + echo " + When the option 'yadm.cygwin-copy' is false + and the OS is not CYGWIN + Verify alternate is a symlink + " + test_alt 'false' 'false' 'true' +} + +@test "Option 'yadm.cygwin-copy' (unset, cygwin)" { + echo " + When the option 'yadm.cygwin-copy' is unset + and the OS is CYGWIN + Verify alternate is a symlink + " + test_alt 'unset' 'true' 'true' +} + +@test "Option 'yadm.cygwin-copy' (true, cygwin)" { + echo " + When the option 'yadm.cygwin-copy' is true + and the OS is CYGWIN + Verify alternate is a copy + " + test_alt 'true' 'true' 'false' +} + +@test "Option 'yadm.cygwin-copy' (false, cygwin)" { + echo " + When the option 'yadm.cygwin-copy' is false + and the OS is CYGWIN + Verify alternate is a symlink + " + test_alt 'false' 'true' 'true' +} + +@test "Option 'yadm.cygwin-copy' (preexisting symlink) " { + echo " + When the option 'yadm.cygwin-copy' is true + and the OS is CYGWIN + Verify alternate is a copy + " + test_alt 'true' 'true' 'false' 'symlink' +} + +@test "Option 'yadm.cygwin-copy' (preexisting file) " { + echo " + When the option 'yadm.cygwin-copy' is true + and the OS is CYGWIN + Verify alternate is a copy + " + test_alt 'true' 'true' 'false' 'file' +} diff --git a/test/117_accept_hooks.bats b/test/117_accept_hooks.bats new file mode 100644 index 0000000..5e8f348 --- /dev/null +++ b/test/117_accept_hooks.bats @@ -0,0 +1,181 @@ +load common +load_fixtures +status=;output=; #; populated by bats run() + +version_regex="yadm [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+" + +setup() { + destroy_tmp + build_repo + mkdir -p "$T_DIR_HOOKS" +} + +function create_hook() { + hook_name="$1" + hook_exit="$2" + hook_file="$T_DIR_HOOKS/$hook_name" + { + echo "#!/bin/sh" + echo "echo ran $hook_name" + echo "env" + echo "exit $hook_exit" + } > "$hook_file" + chmod a+x "$hook_file" +} + +@test "Hooks (no hook)" { + echo " + When no hook is present + do no not run the hook + run command + Exit with 0 + " + + #; run yadm with no command + run "${T_YADM_Y[@]}" version + + [ $status -eq 0 ] + [[ "$output" =~ $version_regex ]] +} + +@test "Hooks (successful pre hook)" { + echo " + When hook is present + run hook + run command + Exit with 0 + " + + create_hook "pre_version" "0" + + #; run yadm with no command + run "${T_YADM_Y[@]}" version + + [ $status -eq 0 ] + [[ "$output" =~ ran\ pre_version ]] + [[ "$output" =~ $version_regex ]] +} + +@test "Hooks (unsuccessful pre hook)" { + echo " + When hook is present + run hook + report hook failure + do no not run command + Exit with 13 + " + + create_hook "pre_version" "13" + + #; run yadm with no command + run "${T_YADM_Y[@]}" version + + [ $status -eq 13 ] + [[ "$output" =~ ran\ pre_version ]] + [[ "$output" =~ pre_version\ was\ not\ successful ]] + [[ ! "$output" =~ $version_regex ]] +} + +@test "Hooks (successful post hook)" { + echo " + When hook is present + run command + run hook + Exit with 0 + " + + create_hook "post_version" "0" + + #; run yadm with no command + run "${T_YADM_Y[@]}" version + + [ $status -eq 0 ] + [[ "$output" =~ $version_regex ]] + [[ "$output" =~ ran\ post_version ]] +} + +@test "Hooks (unsuccessful post hook)" { + echo " + When hook is present + run command + run hook + Exit with 0 + " + + create_hook "post_version" "13" + + #; run yadm with no command + run "${T_YADM_Y[@]}" version + + [ $status -eq 0 ] + [[ "$output" =~ $version_regex ]] + [[ "$output" =~ ran\ post_version ]] +} + +@test "Hooks (successful pre hook + post hook)" { + echo " + When hook is present + run hook + run command + run hook + Exit with 0 + " + + create_hook "pre_version" "0" + create_hook "post_version" "0" + + #; run yadm with no command + run "${T_YADM_Y[@]}" version + + [ $status -eq 0 ] + [[ "$output" =~ ran\ pre_version ]] + [[ "$output" =~ $version_regex ]] + [[ "$output" =~ ran\ post_version ]] +} + +@test "Hooks (unsuccessful pre hook + post hook)" { + echo " + When hook is present + run hook + report hook failure + do no not run command + do no not run post hook + Exit with 13 + " + + create_hook "pre_version" "13" + create_hook "post_version" "0" + + #; run yadm with no command + run "${T_YADM_Y[@]}" version + + [ $status -eq 13 ] + [[ "$output" =~ ran\ pre_version ]] + [[ "$output" =~ pre_version\ was\ not\ successful ]] + [[ ! "$output" =~ $version_regex ]] + [[ ! "$output" =~ ran\ post_version ]] +} + +@test "Hooks (environment variables)" { + echo " + When hook is present + run command + run hook + hook should have access to environment variables + Exit with 0 + " + + create_hook "post_version" "0" + + #; run yadm with no command + run "${T_YADM_Y[@]}" version extra_args + + [ $status -eq 0 ] + [[ "$output" =~ $version_regex ]] + [[ "$output" =~ ran\ post_version ]] + [[ "$output" =~ YADM_HOOK_COMMAND=version ]] + [[ "$output" =~ YADM_HOOK_EXIT=0 ]] + [[ "$output" =~ YADM_HOOK_FULL_COMMAND=version\ extra_args ]] + [[ "$output" =~ YADM_HOOK_REPO=${T_DIR_REPO} ]] + [[ "$output" =~ YADM_HOOK_WORK=${T_DIR_WORK} ]] +} diff --git a/test/common.bash b/test/common.bash index 5670ed0..32ba8e1 100644 --- a/test/common.bash +++ b/test/common.bash @@ -13,6 +13,7 @@ function load_fixtures() { export T_DIR_YADM="$T_TMP/.yadm" export T_DIR_WORK="$T_TMP/yadm-work" export T_DIR_REPO="$T_DIR_YADM/repo.git" + export T_DIR_HOOKS="$T_DIR_YADM/hooks" export T_YADM_CONFIG="$T_DIR_YADM/config" export T_YADM_ENCRYPT="$T_DIR_YADM/encrypt" export T_YADM_ARCHIVE="$T_DIR_YADM/files.gpg" @@ -27,6 +28,8 @@ function load_fixtures() { T_HOST=$(hostname -s) export T_USER T_USER=$(id -u -n) + export T_DISTRO + T_DISTRO=$(lsb_release -si 2>/dev/null || true) } function configure_git() { @@ -202,9 +205,21 @@ function create_worktree() { make_parents "$DIR_WORKTREE/$f" echo "$f" > "$DIR_WORKTREE/$f" done - echo "{{ YADM_CLASS }}-{{ YADM_OS }}-{{ YADM_HOSTNAME }}-{{ YADM_USER }}" > "$DIR_WORKTREE/alt-jinja##yadm.j2" + echo "{{ YADM_CLASS }}-{{ YADM_OS }}-{{ YADM_HOSTNAME }}-{{ YADM_USER }}-{{ YADM_DISTRO }}" > "$DIR_WORKTREE/alt-jinja##yadm.j2" fi + #; for some cygwin tests + if [ ! -z "$TEST_TREE_WITH_CYGWIN" ] ; then + for f in \ + "alt-test##" \ + "alt-test##$T_SYS" \ + "alt-test##$SIMULATED_CYGWIN" \ + ; + do + make_parents "$DIR_WORKTREE/$f" + echo "$f" > "$DIR_WORKTREE/$f" + done + fi if [ ! -z "$TEST_TREE_WITH_WILD" ] ; then #; wildcard test data - yes this is a big mess :( diff --git a/yadm b/yadm index d03af71..1b8608f 100755 --- a/yadm +++ b/yadm @@ -19,7 +19,7 @@ if [ -z "$BASH_VERSION" ]; then [ "$YADM_TEST" != 1 ] && exec bash "$0" "$@" fi -VERSION=1.09 +VERSION=1.11.0 YADM_WORK="$HOME" YADM_DIR="$HOME/.yadm" @@ -30,10 +30,14 @@ YADM_ENCRYPT="encrypt" YADM_ARCHIVE="files.gpg" YADM_BOOTSTRAP="bootstrap" +HOOK_COMMAND="" +FULL_COMMAND="" + GPG_PROGRAM="gpg" GIT_PROGRAM="git" LS_PROGRAM="/bin/ls" ENVTPL_PROGRAM="envtpl" +LSB_RELEASE_PROGRAM="lsb_release" PROC_VERSION="/proc/version" OPERATING_SYSTEM="Unknown" @@ -52,6 +56,9 @@ function main() { require_git + #; capture full command, for passing to hooks + FULL_COMMAND="$*" + #; create the YADM_DIR if it doesn't exist yet [ -d "$YADM_DIR" ] || mkdir -p "$YADM_DIR" @@ -96,9 +103,13 @@ function main() { shift done [ ! -d "$YADM_WORK" ] && error_out "Work tree does not exist: [$YADM_WORK]" + HOOK_COMMAND="$YADM_COMMAND" + invoke_hook "pre" $YADM_COMMAND "${YADM_ARGS[@]}" else #; any other commands are simply passed through to git + HOOK_COMMAND="$1" + invoke_hook "pre" git_command "$@" retval="$?" fi @@ -108,7 +119,7 @@ function main() { auto_perms auto_bootstrap - exit $retval + exit_with_hook $retval } @@ -175,6 +186,14 @@ function alt() { done < "$YADM_ENCRYPT" fi + #; decide if a copy should be done instead of a symbolic link + local do_copy=0 + if [[ $OPERATING_SYSTEM == CYGWIN* ]] ; then + if [[ $(config --bool yadm.cygwin-copy) == "true" ]] ; then + do_copy=1 + fi + fi + #; loop over all "tracked" files #; for every file which matches the above regex, create a symlink for match in $match1 $match2; do @@ -190,7 +209,14 @@ function alt() { new_link="${BASH_REMATCH[1]}" debug "Linking $alt_path to $new_link" [ -n "$loud" ] && echo "Linking $alt_path to $new_link" - ln -nfs "$alt_path" "$new_link" + if [ "$do_copy" -eq 1 ]; then + if [ -L "$new_link" ]; then + rm -f "$new_link" + fi + cp -f "$alt_path" "$new_link" + else + ln -nfs "$alt_path" "$new_link" + fi last_linked="$alt_path" fi fi @@ -215,6 +241,7 @@ function alt() { YADM_OS="$local_system" \ YADM_HOSTNAME="$local_host" \ YADM_USER="$local_user" \ + YADM_DISTRO=$(query_distro) \ "$ENVTPL_PROGRAM" < "$tracked_file" > "$real_file" else debug "envtpl not available, not creating $real_file from template $tracked_file" @@ -525,7 +552,7 @@ Files: Use "man yadm" for complete documentation. EOF - exit 1 + exit_with_hook 1 } @@ -586,6 +613,7 @@ local.os local.user yadm.auto-alt yadm.auto-perms +yadm.cygwin-copy yadm.git-program yadm.gpg-perms yadm.gpg-program @@ -676,12 +704,20 @@ function perms() { function version() { echo "yadm $VERSION" - exit 0 + exit_with_hook 0 } #; ****** Utility Functions ****** +function query_distro() { + distro="" + if command -v "$LSB_RELEASE_PROGRAM" >/dev/null 2>&1; then + distro=$($LSB_RELEASE_PROGRAM -si 2>/dev/null) + fi + echo "$distro" +} + function process_global_args() { #; global arguments are removed before the main processing is done @@ -823,7 +859,50 @@ function debug() { function error_out() { echo -e "ERROR: $*" - exit 1 + exit_with_hook 1 + +} + +function exit_with_hook() { + + invoke_hook "post" "$1" + exit "$1" + +} + +function invoke_hook() { + + mode="$1" + exit_status="$2" + hook_command="$YADM_DIR/hooks/${mode}_$HOOK_COMMAND" + + if [ -x "$hook_command" ] ; then + debug "Invoking hook: $hook_command" + + #; expose some internal data to all hooks + work=$(unix_path "$("$GIT_PROGRAM" config core.worktree)") + YADM_HOOK_COMMAND=$HOOK_COMMAND + YADM_HOOK_EXIT=$exit_status + YADM_HOOK_FULL_COMMAND=$FULL_COMMAND + YADM_HOOK_REPO=$YADM_REPO + YADM_HOOK_WORK=$work + export YADM_HOOK_COMMAND + export YADM_HOOK_EXIT + export YADM_HOOK_FULL_COMMAND + export YADM_HOOK_REPO + export YADM_HOOK_WORK + + "$hook_command" + hook_status=$? + + #; failing "pre" hooks will prevent commands from being run + if [ "$mode" = "pre" ] && [ "$hook_status" -ne 0 ]; then + echo "Hook $hook_command was not successful" + echo "$HOOK_COMMAND will not be run" + exit "$hook_status" + fi + + fi } diff --git a/yadm.1 b/yadm.1 index 68758a9..ff0e65b 100644 --- a/yadm.1 +++ b/yadm.1 @@ -1,5 +1,5 @@ ." vim: set spell so=8: -.TH yadm 1 "4 May 2017" "1.09" +.TH yadm 1 "10 July 2017" "1.11.0" .SH NAME yadm \- Yet Another Dotfiles Manager .SH SYNOPSIS @@ -376,6 +376,11 @@ By default, the first "gpg" found in $PATH is used. .B yadm.git-program Specify an alternate program to use instead of "git". By default, the first "git" found in $PATH is used. +.TP +.B yadm.cygwin-copy +If set to "true", for Cygwin hosts, alternate files will be copies instead of +symbolic links. This might be desirable, because non-Cygwin software may not +properly interpret Cygwin symlinks. .RE These last four "local" configurations are not stored in the @@ -526,6 +531,12 @@ according to the rules explained in the ALTERNATES section: YADM_HOSTNAME YADM_USER +In addition YADM_DISTRO is exposed as the value of +.I lsb_release -si +if +.B lsb_release +is locally available. + For example, a file named .I whatever##yadm.j2 with the following content @@ -624,6 +635,62 @@ Even if disabled, permissions can be manually updated by running The SSH directory processing can be disabled using the .I yadm.ssh-perms configuration. +.SH HOOKS +For every command +.B yadm +supports, a program can be provided to run before or after that command. These +are referred to as "hooks". +.B yadm +looks for +hooks in the directory +.IR $HOME/.yadm/hooks . +Each hook is named using a prefix of +.I pre_ +or +.IR post_ , +followed by the command which should trigger the hook. For +example, to create a hook which is run after every +.I yadm pull +command, create a hook named +.IR post_pull. +Hooks must have the executable file permission set. + +If a +.I pre_ +hook is defined, and the hook terminates with a non-zero exit status, +.B yadm +will refuse to run the +.B yadm +command. For example, if a +.I pre_commit +hook is defined, but that command ends with a non-zero exit status, the +.I yadm commit +will never be run. This allows one to "short-circuit" any operation using a +.I pre_ +hook. + +Hooks have the following environment variables available to them at runtime: +.TP +.B YADM_HOOK_COMMAND +The command which triggered the hook +.TP +.B YADM_HOOK_EXIT +The exit status of the +.B yadm +command +.TP +.B YADM_HOOK_FULL_COMMAND +The +.B yadm +command with all command line arguments +.TP +.B YADM_HOOK_REPO +The path to the +.B yadm +repository +.TP +.B YADM_HOOK_WORK +The path to the work-tree .SH FILES The following are the default paths .B yadm diff --git a/yadm.md b/yadm.md index aca8c7d..63eeb5b 100644 --- a/yadm.md +++ b/yadm.md @@ -239,19 +239,25 @@ Specify an alternate program to use instead of "git". By default, the first "git" found in $PATH is used. - These last four "local" configurations are not stored in the + yadm.cygwin-copy + If set to "true", for Cygwin hosts, alternate files will be + copies instead of symbolic links. This might be desirable, + because non-Cygwin software may not properly interpret Cygwin + symlinks. + + These last four "local" configurations are not stored in the $HOME/.yadm/config, they are stored in the local repository. local.class - Specify a CLASS for the purpose of symlinking alternate files. + Specify a CLASS for the purpose of symlinking alternate files. By default, no CLASS will be matched. local.os Override the OS for the purpose of symlinking alternate files. local.hostname - Override the HOSTNAME for the purpose of symlinking alternate + Override the HOSTNAME for the purpose of symlinking alternate files. local.user @@ -262,7 +268,7 @@ to have an automated way of choosing an alternate version of a file for a different operating system, host, or user. yadm implements a feature which will automatically create a symbolic link to the appropriate ver- - sion of a file, as long as you follow a specific naming convention. + sion of a file, as long as you follow a specific naming convention. yadm can detect files with names ending in any of the following: ## @@ -274,10 +280,10 @@ ##OS.HOSTNAME ##OS.HOSTNAME.USER - If there are any files managed by yadm's repository, or listed in + If there are any files managed by yadm's repository, or listed in $HOME/.yadm/encrypt, which match this naming convention, symbolic links - will be created for the most appropriate version. This may best be - demonstrated by example. Assume the following files are managed by + will be created for the most appropriate version. This may best be + demonstrated by example. Assume the following files are managed by yadm's repository: - $HOME/path/example.txt## @@ -299,7 +305,7 @@ $HOME/path/example.txt -> $HOME/path/example.txt##Darwin - Since the hostname doesn't match any of the managed files, the more + Since the hostname doesn't match any of the managed files, the more generic version is chosen. If running on a Linux server named "host4", the link will be: @@ -317,42 +323,42 @@ If no "##" version exists and no files match the current CLASS/OS/HOST- NAME/USER, then no link will be created. - Links are also created for directories named this way, as long as they + Links are also created for directories named this way, as long as they have at least one yadm managed file within them. - CLASS must be manually set using yadm config local.class . OS - is determined by running uname -s, HOSTNAME by running hostname, and - USER by running id -u -n. yadm will automatically create these links + CLASS must be manually set using yadm config local.class . OS + is determined by running uname -s, HOSTNAME by running hostname, and + USER by running id -u -n. yadm will automatically create these links by default. This can be disabled using the yadm.auto-alt configuration. Even if disabled, links can be manually created by running yadm alt. - It is possible to use "%" as a "wildcard" in place of CLASS, OS, HOST- - NAME, or USER. For example, The following file could be linked for any + It is possible to use "%" as a "wildcard" in place of CLASS, OS, HOST- + NAME, or USER. For example, The following file could be linked for any host when the user is "harvey". $HOME/path/example.txt##%.%.harvey - CLASS is a special value which is stored locally on each host (inside - the local repository). To use alternate symlinks using CLASS, you must - set the value of class using the configuration local.class. This is + CLASS is a special value which is stored locally on each host (inside + the local repository). To use alternate symlinks using CLASS, you must + set the value of class using the configuration local.class. This is set like any other yadm configuration with the yadm config command. The following sets the CLASS to be "Work". yadm config local.class Work - Similarly, the values of OS, HOSTNAME, and USER can be manually over- - ridden using the configuration options local.os, local.hostname, and + Similarly, the values of OS, HOSTNAME, and USER can be manually over- + ridden using the configuration options local.os, local.hostname, and local.user. ## JINJA - If the envtpl command is available, Jinja templates will also be pro- + If the envtpl command is available, Jinja templates will also be pro- cessed to create or overwrite real files. yadm will treat files ending in ##yadm.j2 - as Jinja templates. During processing, the following variables are set + as Jinja templates. During processing, the following variables are set according to the rules explained in the ALTERNATES section: YADM_CLASS @@ -360,6 +366,9 @@ YADM_HOSTNAME YADM_USER + In addition YADM_DISTRO is exposed as the value of lsb_release -si if + lsb_release is locally available. + For example, a file named whatever##yadm.j2 with the following content {% if YADM_USER == 'harvey' -%} @@ -434,9 +443,42 @@ missions can be manually updated by running yadm perms. The SSH direc- tory processing can be disabled using the yadm.ssh-perms configuration. +## HOOKS + For every command yadm supports, a program can be provided to run + before or after that command. These are referred to as "hooks". yadm + looks for hooks in the directory $HOME/.yadm/hooks. Each hook is named + using a prefix of pre_ or post_, followed by the command which should + trigger the hook. For example, to create a hook which is run after + every yadm pull command, create a hook named post_pull. Hooks must + have the executable file permission set. + + If a pre_ hook is defined, and the hook terminates with a non-zero exit + status, yadm will refuse to run the yadm command. For example, if a + pre_commit hook is defined, but that command ends with a non-zero exit + status, the yadm commit will never be run. This allows one to "short- + circuit" any operation using a pre_ hook. + + Hooks have the following environment variables available to them at + runtime: + + YADM_HOOK_COMMAND + The command which triggered the hook + + YADM_HOOK_EXIT + The exit status of the yadm command + + YADM_HOOK_FULL_COMMAND + The yadm command with all command line arguments + + YADM_HOOK_REPO + The path to the yadm repository + + YADM_HOOK_WORK + The path to the work-tree + ## FILES - The following are the default paths yadm uses for its own data. These - paths can be altered using universal options. See the OPTIONS section + The following are the default paths yadm uses for its own data. These + paths can be altered using universal options. See the OPTIONS section for details. $HOME/.yadm diff --git a/yadm.spec b/yadm.spec index 7c90e7b..ae18f39 100644 --- a/yadm.spec +++ b/yadm.spec @@ -1,6 +1,6 @@ Summary: Yet Another Dotfiles Manager Name: yadm -Version: 1.09 +Version: 1.11.0 Release: 1%{?dist} URL: https://github.com/TheLocehiliosan/yadm License: GPLv3 @@ -37,6 +37,13 @@ install -m 644 yadm.1 ${RPM_BUILD_ROOT}%{_mandir}/man1 %doc CHANGES CONTRIBUTORS README.md completion/yadm.bash_completion %changelog +* Mon July 10 2017 Tim Byrne - 1.11.0-1 +- Bump version to 1.11.0 + +* Wed May 10 2017 Tim Byrne - 1.10.0-1 +- Bump version to 1.10.0 +- Transition to semantic versioning + * Thu May 4 2017 Tim Byrne - 1.09-1 - Bump version to 1.09 - Add yadm.bash_completion