Merge pull request #1 from TheLocehiliosan/master
bringing fork up to date
This commit is contained in:
commit
ddea904630
15 changed files with 628 additions and 40 deletions
9
CHANGES
9
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
|
1.09
|
||||||
* Add Bash completion script (#60)
|
* Add Bash completion script (#60)
|
||||||
* Support WSL detection (#61)
|
* Support WSL detection (#61)
|
||||||
|
|
|
@ -2,6 +2,7 @@ CONTRIBUTORS
|
||||||
|
|
||||||
Tim Byrne
|
Tim Byrne
|
||||||
Espen Henriksen
|
Espen Henriksen
|
||||||
|
Cameron Eagans
|
||||||
Jan Schulz
|
Jan Schulz
|
||||||
Patrick Hof
|
Patrick Hof
|
||||||
Satoshi Ohki
|
Satoshi Ohki
|
||||||
|
@ -10,4 +11,5 @@ Sébastien Gross
|
||||||
Tomas Cernaj
|
Tomas Cernaj
|
||||||
Uroš Golja
|
Uroš Golja
|
||||||
Franciszek Madej
|
Franciszek Madej
|
||||||
|
Klas Mellbourn
|
||||||
Paraplegic Racehorse
|
Paraplegic Racehorse
|
||||||
|
|
|
@ -2,7 +2,7 @@ FROM ubuntu:yakkety
|
||||||
MAINTAINER Tim Byrne <sultan@locehilios.com>
|
MAINTAINER Tim Byrne <sultan@locehilios.com>
|
||||||
|
|
||||||
# Install prerequisites
|
# 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
|
RUN pip install envtpl
|
||||||
|
|
||||||
# Force GNUPG version 1 at path /usr/bin/gpg
|
# Force GNUPG version 1 at path /usr/bin/gpg
|
||||||
|
|
|
@ -9,8 +9,14 @@ if declare -F _git > /dev/null; then
|
||||||
_yadm() {
|
_yadm() {
|
||||||
|
|
||||||
local current=${COMP_WORDS[COMP_CWORD]}
|
local current=${COMP_WORDS[COMP_CWORD]}
|
||||||
local penultimate=${COMP_WORDS[COMP_CWORD-1]}
|
local penultimate
|
||||||
local antepenultimate=${COMP_WORDS[COMP_CWORD-2]}
|
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
|
local GIT_DIR
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
|
|
49
test/007_unit_query_distro.bats
Normal file
49
test/007_unit_query_distro.bats
Normal file
|
@ -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" ]
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ status=;output=; #; populated by bats run()
|
||||||
@test "Command 'version'" {
|
@test "Command 'version'" {
|
||||||
echo "
|
echo "
|
||||||
When 'version' command is provided,
|
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
|
Exit with 0
|
||||||
"
|
"
|
||||||
|
|
||||||
|
@ -20,6 +20,6 @@ status=;output=; #; populated by bats run()
|
||||||
#; validate status and output
|
#; validate status and output
|
||||||
[ $status -eq 0 ]
|
[ $status -eq 0 ]
|
||||||
[ "$output" = "yadm $VERSION" ]
|
[ "$output" = "yadm $VERSION" ]
|
||||||
version_regex="^yadm [[:digit:]\.]+$"
|
version_regex="^yadm [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$"
|
||||||
[[ "$output" =~ $version_regex ]]
|
[[ "$output" =~ $version_regex ]]
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,11 @@ function test_alt() {
|
||||||
case $alt_type in
|
case $alt_type in
|
||||||
base)
|
base)
|
||||||
real_name="alt-jinja"
|
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)
|
override_all)
|
||||||
real_name="alt-jinja"
|
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
|
esac
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ function count_introspect() {
|
||||||
Exit with 0
|
Exit with 0
|
||||||
"
|
"
|
||||||
|
|
||||||
count_introspect "configs" 0 11 'yadm\.auto-alt'
|
count_introspect "configs" 0 12 'yadm\.auto-alt'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Command 'introspect' (repo)" {
|
@test "Command 'introspect' (repo)" {
|
||||||
|
|
131
test/116_accept_cygwin_copy.bats
Normal file
131
test/116_accept_cygwin_copy.bats
Normal file
|
@ -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'
|
||||||
|
}
|
181
test/117_accept_hooks.bats
Normal file
181
test/117_accept_hooks.bats
Normal file
|
@ -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} ]]
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ function load_fixtures() {
|
||||||
export T_DIR_YADM="$T_TMP/.yadm"
|
export T_DIR_YADM="$T_TMP/.yadm"
|
||||||
export T_DIR_WORK="$T_TMP/yadm-work"
|
export T_DIR_WORK="$T_TMP/yadm-work"
|
||||||
export T_DIR_REPO="$T_DIR_YADM/repo.git"
|
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_CONFIG="$T_DIR_YADM/config"
|
||||||
export T_YADM_ENCRYPT="$T_DIR_YADM/encrypt"
|
export T_YADM_ENCRYPT="$T_DIR_YADM/encrypt"
|
||||||
export T_YADM_ARCHIVE="$T_DIR_YADM/files.gpg"
|
export T_YADM_ARCHIVE="$T_DIR_YADM/files.gpg"
|
||||||
|
@ -27,6 +28,8 @@ function load_fixtures() {
|
||||||
T_HOST=$(hostname -s)
|
T_HOST=$(hostname -s)
|
||||||
export T_USER
|
export T_USER
|
||||||
T_USER=$(id -u -n)
|
T_USER=$(id -u -n)
|
||||||
|
export T_DISTRO
|
||||||
|
T_DISTRO=$(lsb_release -si 2>/dev/null || true)
|
||||||
}
|
}
|
||||||
|
|
||||||
function configure_git() {
|
function configure_git() {
|
||||||
|
@ -202,9 +205,21 @@ function create_worktree() {
|
||||||
make_parents "$DIR_WORKTREE/$f"
|
make_parents "$DIR_WORKTREE/$f"
|
||||||
echo "$f" > "$DIR_WORKTREE/$f"
|
echo "$f" > "$DIR_WORKTREE/$f"
|
||||||
done
|
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
|
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
|
if [ ! -z "$TEST_TREE_WITH_WILD" ] ; then
|
||||||
#; wildcard test data - yes this is a big mess :(
|
#; wildcard test data - yes this is a big mess :(
|
||||||
|
|
89
yadm
89
yadm
|
@ -19,7 +19,7 @@ if [ -z "$BASH_VERSION" ]; then
|
||||||
[ "$YADM_TEST" != 1 ] && exec bash "$0" "$@"
|
[ "$YADM_TEST" != 1 ] && exec bash "$0" "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
VERSION=1.09
|
VERSION=1.11.0
|
||||||
|
|
||||||
YADM_WORK="$HOME"
|
YADM_WORK="$HOME"
|
||||||
YADM_DIR="$HOME/.yadm"
|
YADM_DIR="$HOME/.yadm"
|
||||||
|
@ -30,10 +30,14 @@ YADM_ENCRYPT="encrypt"
|
||||||
YADM_ARCHIVE="files.gpg"
|
YADM_ARCHIVE="files.gpg"
|
||||||
YADM_BOOTSTRAP="bootstrap"
|
YADM_BOOTSTRAP="bootstrap"
|
||||||
|
|
||||||
|
HOOK_COMMAND=""
|
||||||
|
FULL_COMMAND=""
|
||||||
|
|
||||||
GPG_PROGRAM="gpg"
|
GPG_PROGRAM="gpg"
|
||||||
GIT_PROGRAM="git"
|
GIT_PROGRAM="git"
|
||||||
LS_PROGRAM="/bin/ls"
|
LS_PROGRAM="/bin/ls"
|
||||||
ENVTPL_PROGRAM="envtpl"
|
ENVTPL_PROGRAM="envtpl"
|
||||||
|
LSB_RELEASE_PROGRAM="lsb_release"
|
||||||
|
|
||||||
PROC_VERSION="/proc/version"
|
PROC_VERSION="/proc/version"
|
||||||
OPERATING_SYSTEM="Unknown"
|
OPERATING_SYSTEM="Unknown"
|
||||||
|
@ -52,6 +56,9 @@ function main() {
|
||||||
|
|
||||||
require_git
|
require_git
|
||||||
|
|
||||||
|
#; capture full command, for passing to hooks
|
||||||
|
FULL_COMMAND="$*"
|
||||||
|
|
||||||
#; create the YADM_DIR if it doesn't exist yet
|
#; create the YADM_DIR if it doesn't exist yet
|
||||||
[ -d "$YADM_DIR" ] || mkdir -p "$YADM_DIR"
|
[ -d "$YADM_DIR" ] || mkdir -p "$YADM_DIR"
|
||||||
|
|
||||||
|
@ -96,9 +103,13 @@ function main() {
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
[ ! -d "$YADM_WORK" ] && error_out "Work tree does not exist: [$YADM_WORK]"
|
[ ! -d "$YADM_WORK" ] && error_out "Work tree does not exist: [$YADM_WORK]"
|
||||||
|
HOOK_COMMAND="$YADM_COMMAND"
|
||||||
|
invoke_hook "pre"
|
||||||
$YADM_COMMAND "${YADM_ARGS[@]}"
|
$YADM_COMMAND "${YADM_ARGS[@]}"
|
||||||
else
|
else
|
||||||
#; any other commands are simply passed through to git
|
#; any other commands are simply passed through to git
|
||||||
|
HOOK_COMMAND="$1"
|
||||||
|
invoke_hook "pre"
|
||||||
git_command "$@"
|
git_command "$@"
|
||||||
retval="$?"
|
retval="$?"
|
||||||
fi
|
fi
|
||||||
|
@ -108,7 +119,7 @@ function main() {
|
||||||
auto_perms
|
auto_perms
|
||||||
auto_bootstrap
|
auto_bootstrap
|
||||||
|
|
||||||
exit $retval
|
exit_with_hook $retval
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,6 +186,14 @@ function alt() {
|
||||||
done < "$YADM_ENCRYPT"
|
done < "$YADM_ENCRYPT"
|
||||||
fi
|
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
|
#; loop over all "tracked" files
|
||||||
#; for every file which matches the above regex, create a symlink
|
#; for every file which matches the above regex, create a symlink
|
||||||
for match in $match1 $match2; do
|
for match in $match1 $match2; do
|
||||||
|
@ -190,7 +209,14 @@ function alt() {
|
||||||
new_link="${BASH_REMATCH[1]}"
|
new_link="${BASH_REMATCH[1]}"
|
||||||
debug "Linking $alt_path to $new_link"
|
debug "Linking $alt_path to $new_link"
|
||||||
[ -n "$loud" ] && echo "Linking $alt_path to $new_link"
|
[ -n "$loud" ] && echo "Linking $alt_path to $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"
|
ln -nfs "$alt_path" "$new_link"
|
||||||
|
fi
|
||||||
last_linked="$alt_path"
|
last_linked="$alt_path"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -215,6 +241,7 @@ function alt() {
|
||||||
YADM_OS="$local_system" \
|
YADM_OS="$local_system" \
|
||||||
YADM_HOSTNAME="$local_host" \
|
YADM_HOSTNAME="$local_host" \
|
||||||
YADM_USER="$local_user" \
|
YADM_USER="$local_user" \
|
||||||
|
YADM_DISTRO=$(query_distro) \
|
||||||
"$ENVTPL_PROGRAM" < "$tracked_file" > "$real_file"
|
"$ENVTPL_PROGRAM" < "$tracked_file" > "$real_file"
|
||||||
else
|
else
|
||||||
debug "envtpl not available, not creating $real_file from template $tracked_file"
|
debug "envtpl not available, not creating $real_file from template $tracked_file"
|
||||||
|
@ -525,7 +552,7 @@ Files:
|
||||||
Use "man yadm" for complete documentation.
|
Use "man yadm" for complete documentation.
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
exit 1
|
exit_with_hook 1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -586,6 +613,7 @@ local.os
|
||||||
local.user
|
local.user
|
||||||
yadm.auto-alt
|
yadm.auto-alt
|
||||||
yadm.auto-perms
|
yadm.auto-perms
|
||||||
|
yadm.cygwin-copy
|
||||||
yadm.git-program
|
yadm.git-program
|
||||||
yadm.gpg-perms
|
yadm.gpg-perms
|
||||||
yadm.gpg-program
|
yadm.gpg-program
|
||||||
|
@ -676,12 +704,20 @@ function perms() {
|
||||||
function version() {
|
function version() {
|
||||||
|
|
||||||
echo "yadm $VERSION"
|
echo "yadm $VERSION"
|
||||||
exit 0
|
exit_with_hook 0
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#; ****** Utility Functions ******
|
#; ****** 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() {
|
function process_global_args() {
|
||||||
|
|
||||||
#; global arguments are removed before the main processing is done
|
#; global arguments are removed before the main processing is done
|
||||||
|
@ -823,7 +859,50 @@ function debug() {
|
||||||
function error_out() {
|
function error_out() {
|
||||||
|
|
||||||
echo -e "ERROR: $*"
|
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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
69
yadm.1
69
yadm.1
|
@ -1,5 +1,5 @@
|
||||||
." vim: set spell so=8:
|
." vim: set spell so=8:
|
||||||
.TH yadm 1 "4 May 2017" "1.09"
|
.TH yadm 1 "10 July 2017" "1.11.0"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
yadm \- Yet Another Dotfiles Manager
|
yadm \- Yet Another Dotfiles Manager
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
|
@ -376,6 +376,11 @@ By default, the first "gpg" found in $PATH is used.
|
||||||
.B yadm.git-program
|
.B yadm.git-program
|
||||||
Specify an alternate program to use instead of "git".
|
Specify an alternate program to use instead of "git".
|
||||||
By default, the first "git" found in $PATH is used.
|
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
|
.RE
|
||||||
These last four "local" configurations are not stored in the
|
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_HOSTNAME
|
||||||
YADM_USER
|
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
|
For example, a file named
|
||||||
.I whatever##yadm.j2
|
.I whatever##yadm.j2
|
||||||
with the following content
|
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
|
The SSH directory processing can be disabled using the
|
||||||
.I yadm.ssh-perms
|
.I yadm.ssh-perms
|
||||||
configuration.
|
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
|
.SH FILES
|
||||||
The following are the default paths
|
The following are the default paths
|
||||||
.B yadm
|
.B yadm
|
||||||
|
|
42
yadm.md
42
yadm.md
|
@ -239,6 +239,12 @@
|
||||||
Specify an alternate program to use instead of "git". By
|
Specify an alternate program to use instead of "git". By
|
||||||
default, the first "git" found in $PATH is used.
|
default, the first "git" found in $PATH is used.
|
||||||
|
|
||||||
|
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
|
These last four "local" configurations are not stored in the
|
||||||
$HOME/.yadm/config, they are stored in the local repository.
|
$HOME/.yadm/config, they are stored in the local repository.
|
||||||
|
|
||||||
|
@ -360,6 +366,9 @@
|
||||||
YADM_HOSTNAME
|
YADM_HOSTNAME
|
||||||
YADM_USER
|
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
|
For example, a file named whatever##yadm.j2 with the following content
|
||||||
|
|
||||||
{% if YADM_USER == 'harvey' -%}
|
{% if YADM_USER == 'harvey' -%}
|
||||||
|
@ -434,6 +443,39 @@
|
||||||
missions can be manually updated by running yadm perms. The SSH direc-
|
missions can be manually updated by running yadm perms. The SSH direc-
|
||||||
tory processing can be disabled using the yadm.ssh-perms configuration.
|
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
|
## FILES
|
||||||
The following are the default paths yadm uses for its own data. These
|
The following are the default paths yadm uses for its own data. These
|
||||||
paths can be altered using universal options. See the OPTIONS section
|
paths can be altered using universal options. See the OPTIONS section
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Summary: Yet Another Dotfiles Manager
|
Summary: Yet Another Dotfiles Manager
|
||||||
Name: yadm
|
Name: yadm
|
||||||
Version: 1.09
|
Version: 1.11.0
|
||||||
Release: 1%{?dist}
|
Release: 1%{?dist}
|
||||||
URL: https://github.com/TheLocehiliosan/yadm
|
URL: https://github.com/TheLocehiliosan/yadm
|
||||||
License: GPLv3
|
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
|
%doc CHANGES CONTRIBUTORS README.md completion/yadm.bash_completion
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon July 10 2017 Tim Byrne <sultan@locehilios.com> - 1.11.0-1
|
||||||
|
- Bump version to 1.11.0
|
||||||
|
|
||||||
|
* Wed May 10 2017 Tim Byrne <sultan@locehilios.com> - 1.10.0-1
|
||||||
|
- Bump version to 1.10.0
|
||||||
|
- Transition to semantic versioning
|
||||||
|
|
||||||
* Thu May 4 2017 Tim Byrne <sultan@locehilios.com> - 1.09-1
|
* Thu May 4 2017 Tim Byrne <sultan@locehilios.com> - 1.09-1
|
||||||
- Bump version to 1.09
|
- Bump version to 1.09
|
||||||
- Add yadm.bash_completion
|
- Add yadm.bash_completion
|
||||||
|
|
Loading…
Reference in a new issue