1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-10 19:04:15 +00:00

merge defaultlink

This commit is contained in:
deadc0de6
2019-04-08 07:51:36 +02:00
22 changed files with 1295 additions and 84 deletions

140
tests-ng/deprecated-link.sh Executable file
View File

@@ -0,0 +1,140 @@
#!/usr/bin/env bash
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2017, deadc0de6
#
# test migration from link/link_children to single entry
# returns 1 in case of error
#
# exit on first error
set -e
# all this crap to get current path
rl="readlink -f"
if ! ${rl} "${0}" >/dev/null 2>&1; then
rl="realpath"
if ! hash ${rl}; then
echo "\"${rl}\" not found !" && exit 1
fi
fi
cur=$(dirname "$(${rl} "${0}")")
#hash dotdrop >/dev/null 2>&1
#[ "$?" != "0" ] && echo "install dotdrop to run tests" && exit 1
#echo "called with ${1}"
# dotdrop path can be pass as argument
ddpath="${cur}/../"
[ "${1}" != "" ] && ddpath="${1}"
[ ! -d ${ddpath} ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1
export PYTHONPATH="${ddpath}:${PYTHONPATH}"
bin="python3 -m dotdrop.dotdrop"
echo "dotdrop path: ${ddpath}"
echo "pythonpath: ${PYTHONPATH}"
# get the helpers
source ${cur}/helpers
echo -e "\e[96m\e[1m==> RUNNING $(basename $BASH_SOURCE) <==\e[0m"
################################################################
# this is the test
################################################################
# the dotfile source
tmps=`mktemp -d --suffix='-dotdrop-tests'`
mkdir -p ${tmps}/dotfiles
# the dotfile destination
tmpd=`mktemp -d --suffix='-dotdrop-tests'`
# create the config file
cfg="${tmps}/config.yaml"
cat > ${cfg} << _EOF
config:
backup: false
create: true
dotpath: dotfiles
link_by_default: true
dotfiles:
f_link:
dst: ${tmpd}/abc
src: abc
link: true
f_link1:
dst: ${tmpd}/abc
src: abc
link: true
f_nolink:
dst: ${tmpd}/abc
src: abc
link: false
f_nolink1:
dst: ${tmpd}/abc
src: abc
link: false
f_children:
dst: ${tmpd}/abc
src: abc
link_children: true
f_children2:
dst: ${tmpd}/abc
src: abc
link_children: true
f_children3:
dst: ${tmpd}/abc
src: abc
link_children: false
profiles:
p1:
dotfiles:
- f_link
- f_nolink
- f_nolink1
- f_children
- f_children2
- f_children3
_EOF
cat ${cfg}
# create the dotfiles
echo "test" > ${tmps}/dotfiles/abc
echo "test" > ${tmpd}/abc
# compare
cd ${ddpath} | ${bin} compare -c ${cfg} -p p1
# install
#cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
cat ${cfg}
# fail if find some of these entries
echo "========> test for bad entries"
set +e
grep 'link_children: true' ${cfg} >/dev/null && exit 1
grep 'link_children: false' ${cfg} >/dev/null && exit 1
grep 'link: true' ${cfg} >/dev/null && exit 1
grep 'link: false' ${cfg} >/dev/null && exit 1
grep 'link_by_default: true' ${cfg} >/dev/null && exit 1
grep 'link_by_default: false' ${cfg} >/dev/null && exit 1
set -e
# test values have been correctly updated
echo "========> test for updated entries"
dotfiles=`cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 | grep -v '^ '`
echo "${dotfiles}" | grep '^f_link ' | grep ', link: link)'
echo "${dotfiles}" | grep '^f_nolink ' | grep ', link: nolink)'
echo "${dotfiles}" | grep '^f_nolink1 ' | grep ', link: nolink)'
echo "${dotfiles}" | grep '^f_children ' | grep ', link: link_children)'
echo "${dotfiles}" | grep '^f_children2 ' | grep ', link: link_children)'
echo "${dotfiles}" | grep '^f_children3 ' | grep ', link: nolink)'
## CLEANING
rm -rf ${tmps} ${tmpd}
echo "OK"
exit 0

130
tests-ng/import-link-children.sh Executable file
View File

@@ -0,0 +1,130 @@
#!/usr/bin/env bash
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2017, deadc0de6
#
# test importing link_children
# returns 1 in case of error
#
# exit on first error
set -e
# all this crap to get current path
rl="readlink -f"
if ! ${rl} "${0}" >/dev/null 2>&1; then
rl="realpath"
if ! hash ${rl}; then
echo "\"${rl}\" not found !" && exit 1
fi
fi
cur=$(dirname "$(${rl} "${0}")")
#hash dotdrop >/dev/null 2>&1
#[ "$?" != "0" ] && echo "install dotdrop to run tests" && exit 1
#echo "called with ${1}"
# dotdrop path can be pass as argument
ddpath="${cur}/../"
[ "${1}" != "" ] && ddpath="${1}"
[ ! -d ${ddpath} ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1
export PYTHONPATH="${ddpath}:${PYTHONPATH}"
bin="python3 -m dotdrop.dotdrop"
echo "dotdrop path: ${ddpath}"
echo "pythonpath: ${PYTHONPATH}"
# get the helpers
source ${cur}/helpers
echo -e "\e[96m\e[1m==> RUNNING $(basename $BASH_SOURCE) <==\e[0m"
################################################################
# this is the test
################################################################
# the dotfile source
tmps=`mktemp -d --suffix='-dotdrop-tests'`
mkdir -p ${tmps}/dotfiles
# the dotfile destination
tmpd=`mktemp -d --suffix='-dotdrop-tests'`
# dotpath
dotpath="${tmps}/dotfiles"
mkdir -p ${dotpath}
# create the dotfile to import
dt="${tmpd}/directory"
mkdir -p ${dt}
# subdir
dtsub1="${dt}/sub1"
mkdir -p ${dtsub1}
dtsub2="${dt}/sub2"
mkdir -p ${dtsub2}
dtsub3="${dtsub1}/subsub1"
mkdir -p ${dtsub3}
# files
f1="${dt}/file"
subf1="${dtsub1}/file"
subf2="${dtsub2}/file"
subf3="${dtsub3}/file"
touch ${f1} ${subf1} ${subf2} ${subf3}
# create the config file
cfg="${tmps}/config.yaml"
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
dotfiles:
profiles:
_EOF
# import
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 -V --link=link_children ${dt}
# check is set to link_children
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "d_`basename ${dt}`")
echo ${line} | grep 'link: link_children'
# checks file exists in dotpath
[ ! -e ${dotpath}/${dt} ] && echo "dotfile not imported" && exit 1
[ ! -e ${dotpath}/${dtsub1} ] && echo "sub1 not found in dotpath" && exit 1
[ ! -e ${dotpath}/${dtsub2} ] && echo "sub2 not found in dotpath" && exit 1
[ ! -e ${dotpath}/${dtsub3} ] && echo "sub3 not found in dotpath" && exit 1
[ ! -e ${dotpath}/${f1} ] && echo "f1 not found in dotpath" && exit 1
[ ! -e ${dotpath}/${subf1} ] && echo "subf1 not found in dotpath" && exit 1
[ ! -e ${dotpath}/${subf2} ] && echo "subf2 not found in dotpath" && exit 1
[ ! -e ${dotpath}/${subf3} ] && echo "subf3 not found in dotpath" && exit 1
# checks file exists in fs
[ ! -e ${dt} ] && echo "dotfile not imported" && exit 1
[ ! -e ${dtsub1} ] && echo "sub1 not found in fs" && exit 1
[ ! -e ${dtsub2} ] && echo "sub2 not found in fs" && exit 1
[ ! -e ${dtsub3} ] && echo "sub3 not found in fs" && exit 1
[ ! -e ${f1} ] && echo "f1 not found in fs" && exit 1
[ ! -e ${subf1} ] && echo "subf1 not found in fs" && exit 1
[ ! -e ${subf2} ] && echo "subf2 not found in fs" && exit 1
[ ! -e ${subf3} ] && echo "subf3 not found in fs" && exit 1
# install
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
# checks file have correct type in fs
[ ! -h ${f1} ] && echo "f1 is not a symlink" && exit 1
[ -h ${subf1} ] && echo "subf1 is not a regular file" && exit 1
[ -h ${subf2} ] && echo "subf2 is not a regular file" && exit 1
[ -h ${subf3} ] && echo "subf3 is not a regular file" && exit 1
[ ! -h ${dtsub1} ] && echo "dtsub1 is not a symlink" && exit 1
[ ! -h ${dtsub2} ] && echo "dtsub2 is not a symlink" && exit 1
[ -h ${dtsub3} ] && echo "dtsub3 is not a regular directory" && exit 1
## CLEANING
rm -rf ${tmps} ${tmpd}
echo "OK"
exit 0

156
tests-ng/inst-link-default.sh Executable file
View File

@@ -0,0 +1,156 @@
#!/usr/bin/env bash
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2017, deadc0de6
#
# test link_dotfile_default
# returns 1 in case of error
#
# exit on first error
set -e
# all this crap to get current path
rl="readlink -f"
if ! ${rl} "${0}" >/dev/null 2>&1; then
rl="realpath"
if ! hash ${rl}; then
echo "\"${rl}\" not found !" && exit 1
fi
fi
cur=$(dirname "$(${rl} "${0}")")
#hash dotdrop >/dev/null 2>&1
#[ "$?" != "0" ] && echo "install dotdrop to run tests" && exit 1
#echo "called with ${1}"
# dotdrop path can be pass as argument
ddpath="${cur}/../"
[ "${1}" != "" ] && ddpath="${1}"
[ ! -d ${ddpath} ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1
export PYTHONPATH="${ddpath}:${PYTHONPATH}"
bin="python3 -m dotdrop.dotdrop"
echo "dotdrop path: ${ddpath}"
echo "pythonpath: ${PYTHONPATH}"
# get the helpers
source ${cur}/helpers
echo -e "\e[96m\e[1m==> RUNNING $(basename $BASH_SOURCE) <==\e[0m"
################################################################
# this is the test
################################################################
# the dotfile source
tmps=`mktemp -d --suffix='-dotdrop-tests'`
mkdir -p ${tmps}/dotfiles
# the dotfile destination
tmpd=`mktemp -d --suffix='-dotdrop-tests'`
#echo "dotfile destination: ${tmpd}"
# create the dotfile
mkdir -p ${tmps}/dotfiles/abc
echo "test link_dotfile_default 1" > ${tmps}/dotfiles/abc/file1
echo "test link_dotfile_default 2" > ${tmps}/dotfiles/abc/file2
# create a shell script
# create the config file
cfg="${tmps}/config.yaml"
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
link_dotfile_default: nolink
dotfiles:
d_abc:
dst: ${tmpd}/abc
src: abc
profiles:
p1:
dotfiles:
- d_abc
_EOF
#cat ${cfg}
# install
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
#cat ${cfg}
# ensure exists and is not link
[ ! -d ${tmpd}/abc ] && echo "not a directory" && exit 1
[ -h ${tmpd}/abc ] && echo "not a regular file" && exit 1
[ ! -e ${tmpd}/abc/file1 ] && echo "not exist" && exit 1
[ -h ${tmpd}/abc/file1 ] && echo "not a regular file" && exit 1
[ ! -e ${tmpd}/abc/file2 ] && echo "not exist" && exit 1
[ -h ${tmpd}/abc/file2 ] && echo "not a regular file" && exit 1
rm -rf ${tmpd}/abc
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
link_dotfile_default: link
dotfiles:
d_abc:
dst: ${tmpd}/abc
src: abc
profiles:
p1:
dotfiles:
- d_abc
_EOF
# install
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
#cat ${cfg}
# ensure exists and parent is a link
[ ! -e ${tmpd}/abc ] && echo "not exist" && exit 1
[ ! -h ${tmpd}/abc ] && echo "not a symlink" && exit 1
[ ! -e ${tmpd}/abc/file1 ] && echo "not exist" && exit 1
[ -h ${tmpd}/abc/file1 ] && echo "not a regular file" && exit 1
[ ! -e ${tmpd}/abc/file2 ] && echo "not exist" && exit 1
[ -h ${tmpd}/abc/file2 ] && echo "not a regular file" && exit 1
rm -rf ${tmpd}/abc
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
link_dotfile_default: link_children
dotfiles:
d_abc:
dst: ${tmpd}/abc
src: abc
profiles:
p1:
dotfiles:
- d_abc
_EOF
# install
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
#cat ${cfg}
# ensure exists and children are links
[ ! -e ${tmpd}/abc ] && echo "not exist" && exit 1
[ -h ${tmpd}/abc ] && echo "not a regular file" && exit 1
[ ! -e ${tmpd}/abc/file1 ] && echo "not exist" && exit 1
[ ! -h ${tmpd}/abc/file1 ] && echo "not a symlink" && exit 1
[ ! -e ${tmpd}/abc/file2 ] && echo "not exist" && exit 1
[ ! -h ${tmpd}/abc/file2 ] && echo "not a symlink" && exit 1
rm -rf ${tmpd}/abc
## CLEANING
rm -rf ${tmps} ${tmpd} ${scr}
echo "OK"
exit 0

View File

@@ -104,9 +104,11 @@ cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
#cat ${tmpd}/abc
grep '^this should exist' ${tmpd}/abc >/dev/null
grep -v '^this should not exist' ${tmpd}/abc >/dev/null
grep '^this should exist too' ${tmpd}/abc >/dev/null
grep -v '^this should not exist either' ${tmpd}/abc >/dev/null
set +e
grep '^this should not exist' ${tmpd}/abc >/dev/null && exit 1
grep '^this should not exist either' ${tmpd}/abc >/dev/null && exit 1
set -e
#cat ${tmpd}/abc

107
tests-ng/link-import-default.sh Executable file
View File

@@ -0,0 +1,107 @@
#!/usr/bin/env bash
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2019, deadc0de6
#
# test the use of the keyword "link_on_import"
# returns 1 in case of error
#
# exit on first error
set -e
# all this crap to get current path
rl="readlink -f"
if ! ${rl} "${0}" >/dev/null 2>&1; then
rl="realpath"
if ! hash ${rl}; then
echo "\"${rl}\" not found !" && exit 1
fi
fi
cur=$(dirname "$(${rl} "${0}")")
#hash dotdrop >/dev/null 2>&1
#[ "$?" != "0" ] && echo "install dotdrop to run tests" && exit 1
#echo "called with ${1}"
# dotdrop path can be pass as argument
ddpath="${cur}/../"
[ "${1}" != "" ] && ddpath="${1}"
[ ! -d ${ddpath} ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1
export PYTHONPATH="${ddpath}:${PYTHONPATH}"
bin="python3 -m dotdrop.dotdrop"
echo "dotdrop path: ${ddpath}"
echo "pythonpath: ${PYTHONPATH}"
# get the helpers
source ${cur}/helpers
echo -e "\e[96m\e[1m==> RUNNING $(basename $BASH_SOURCE) <==\e[0m"
################################################################
# this is the test
################################################################
# the dotfile source
tmps=`mktemp -d --suffix='-dotdrop-tests'`
mkdir -p ${tmps}/dotfiles
# the dotfile destination
tmpd=`mktemp -d --suffix='-dotdrop-tests'`
# create the config file
cfg="${tmps}/config.yaml"
# create the source
echo "abc" > ${tmpd}/abc
# import with nolink by default
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
link_on_import: nolink
dotfiles:
profiles:
_EOF
# import
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 -V ${tmpd}/abc
# checks
inside="${tmps}/dotfiles/${tmpd}/abc"
[ ! -e ${inside} ] && exit 1
set +e
cat ${cfg} | grep 'link:' && exit 1
set -e
# import with parent by default
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
link_on_import: link
dotfiles:
profiles:
_EOF
# import
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 -V ${tmpd}/abc
# checks
inside="${tmps}/dotfiles/${tmpd}/abc"
[ ! -e ${inside} ] && exit 1
cat ${cfg}
cat ${cfg} | grep 'link: link' >/dev/null
## CLEANING
rm -rf ${tmps} ${tmpd}
echo "OK"
exit 0

479
tests-ng/link-value-tests.sh Executable file
View File

@@ -0,0 +1,479 @@
#!/usr/bin/env bash
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2019, deadc0de6
#
# test the behavior when playing with link_dotfile_default
# and link_on_import on import
# returns 1 in case of error
#
# exit on first error
set -e
# all this crap to get current path
rl="readlink -f"
if ! ${rl} "${0}" >/dev/null 2>&1; then
rl="realpath"
if ! hash ${rl}; then
echo "\"${rl}\" not found !" && exit 1
fi
fi
cur=$(dirname "$(${rl} "${0}")")
#hash dotdrop >/dev/null 2>&1
#[ "$?" != "0" ] && echo "install dotdrop to run tests" && exit 1
#echo "called with ${1}"
# dotdrop path can be pass as argument
ddpath="${cur}/../"
[ "${1}" != "" ] && ddpath="${1}"
[ ! -d ${ddpath} ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1
export PYTHONPATH="${ddpath}:${PYTHONPATH}"
bin="python3 -m dotdrop.dotdrop"
echo "dotdrop path: ${ddpath}"
echo "pythonpath: ${PYTHONPATH}"
# get the helpers
source ${cur}/helpers
echo -e "\e[96m\e[1m==> RUNNING $(basename $BASH_SOURCE) <==\e[0m"
################################################################
# this is the test
################################################################
# the dotfile source
tmps=`mktemp -d --suffix='-dotdrop-tests'`
mkdir -p ${tmps}/dotfiles
# the dotfile destination
tmpd=`mktemp -d --suffix='-dotdrop-tests'`
# create the config file
cfg="${tmps}/config.yaml"
# ----------------------------------------------------------
echo -e "\n======> import with all default"
# create the source
rm -rf ${tmpd}/qwert
echo "test" > ${tmpd}/qwert
# clean
rm -rf ${tmps}/dotfiles
mkdir -p ${tmps}/dotfiles
# config file
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
dotfiles:
profiles:
_EOF
# import
df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V
# checks
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
echo ${line} | grep 'link: nolink'
# try to install
rm -rf ${tmpd}/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is symlink" && exit 1
# ----------------------------------------------------------
echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=nolink"
# create the source
rm -rf ${tmpd}/qwert
echo "test" > ${tmpd}/qwert
# clean
rm -rf ${tmps}/dotfiles
mkdir -p ${tmps}/dotfiles
# config file
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
link_on_import: nolink
link_dotfile_default: nolink
dotfiles:
profiles:
_EOF
# import
df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V
# checks
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
echo ${line} | grep 'link: nolink'
# try to install
rm -rf ${tmpd}/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is symlink" && exit 1
# ----------------------------------------------------------
echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=nolink and --link=nolink"
# create the source
rm -rf ${tmpd}/qwert
echo "test" > ${tmpd}/qwert
# clean
rm -rf ${tmps}/dotfiles
mkdir -p ${tmps}/dotfiles
# config file
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
link_on_import: nolink
link_dotfile_default: nolink
dotfiles:
profiles:
_EOF
# import
df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=nolink
# checks
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
echo ${line} | grep 'link: nolink'
# try to install
rm -rf ${tmpd}/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is symlink" && exit 1
# ----------------------------------------------------------
echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=nolink and --link=link"
# create the source
rm -rf ${tmpd}/qwert
echo "test" > ${tmpd}/qwert
# clean
rm -rf ${tmps}/dotfiles
mkdir -p ${tmps}/dotfiles
# config file
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
link_on_import: nolink
link_dotfile_default: nolink
dotfiles:
profiles:
_EOF
# import
df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=link
# checks
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
echo ${line} | grep 'link: link'
# try to install
rm -rf ${tmpd}/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1
[ ! -h ${df} ] && echo "not symlink" && exit 1
# ----------------------------------------------------------
echo -e "\n======> import with link_on_import=link and link_dotfile_default=nolink"
# create the source
rm -rf ${tmpd}/qwert
echo "test" > ${tmpd}/qwert
# clean
rm -rf ${tmps}/dotfiles
mkdir -p ${tmps}/dotfiles
# config file
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
link_on_import: link
link_dotfile_default: nolink
dotfiles:
profiles:
_EOF
# import
df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V
# checks
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
echo ${line} | grep 'link: link'
# try to install
rm -rf ${tmpd}/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1
[ ! -h ${df} ] && echo "not symlink" && exit 1
# ----------------------------------------------------------
echo -e "\n======> import with link_on_import=link and link_dotfile_default=nolink and --link=nolink"
# create the source
rm -rf ${tmpd}/qwert
echo "test" > ${tmpd}/qwert
# clean
rm -rf ${tmps}/dotfiles
mkdir -p ${tmps}/dotfiles
# config file
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
link_on_import: link
link_dotfile_default: nolink
dotfiles:
profiles:
_EOF
# import
df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=nolink
# checks
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
echo ${line} | grep 'link: nolink'
# try to install
rm -rf ${tmpd}/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is symlink" && exit 1
# ----------------------------------------------------------
echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=link"
# create the source
rm -rf ${tmpd}/qwert
echo "test" > ${tmpd}/qwert
# clean
rm -rf ${tmps}/dotfiles
mkdir -p ${tmps}/dotfiles
# config file
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
link_on_import: nolink
link_dotfile_default: link
dotfiles:
profiles:
_EOF
# import
df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=nolink
# checks
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
echo ${line} | grep 'link: nolink'
# try to install
rm -rf ${tmpd}/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is symlink" && exit 1
# ----------------------------------------------------------
echo -e "\n======> import with link_on_import=link and link_dotfile_default=nolink and --link=nolink"
# create the source
rm -rf ${tmpd}/qwert
echo "test" > ${tmpd}/qwert
# clean
rm -rf ${tmps}/dotfiles
mkdir -p ${tmps}/dotfiles
# config file
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
link_on_import: link
link_dotfile_default: nolink
dotfiles:
profiles:
_EOF
# import
df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=nolink
# checks
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
echo ${line} | grep 'link: nolink'
# try to install
rm -rf ${tmpd}/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is symlink" && exit 1
# ----------------------------------------------------------
echo -e "\n======> import with all default and --link=link"
# create the source
rm -rf ${tmpd}/qwert
echo "test" > ${tmpd}/qwert
# clean
rm -rf ${tmps}/dotfiles
mkdir -p ${tmps}/dotfiles
# config file
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
dotfiles:
profiles:
_EOF
# import
df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -c ${cfg} --link=link -p p1 ${df} -V
# checks
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
echo ${line} | grep 'link: link'
# try to install
rm -rf ${tmpd}/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1
[ ! -h ${df} ] && echo "not a symlink" && exit 1
# ----------------------------------------------------------
echo -e "\n======> import with all default and --link=link_children"
# create the source
rm -rf ${tmpd}/qwert
echo "test" > ${tmpd}/qwert
# clean
rm -rf ${tmps}/dotfiles
mkdir -p ${tmps}/dotfiles
# config file
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
dotfiles:
profiles:
_EOF
# import
df="${tmpd}/qwert"
set +e
cd ${ddpath} | ${bin} import -c ${cfg} --link=link_children -p p1 ${df} -V
[ "$?" = "0" ] && echo "link_children with file should fail" && exit 1
set -e
# ----------------------------------------------------------
echo -e "\n======> import with all default and --link=link_children"
# create the source
rm -rf ${tmpd}/qwert
mkdir -p ${tmpd}/qwert
echo "test" > ${tmpd}/qwert/file
mkdir -p ${tmpd}/qwert/directory
echo "test" > ${tmpd}/qwert/directory/file
# clean
rm -rf ${tmps}/dotfiles
mkdir -p ${tmps}/dotfiles
# config file
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
dotfiles:
profiles:
_EOF
# import
df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -c ${cfg} --link=link_children -p p1 ${df} -V
# checks
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "d_`basename ${df}`")
echo ${line} | grep 'link: link_children'
# try to install
rm -rf ${tmpd}/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is a symlink" && exit 1
[ ! -h ${df}/file ] && echo "file is not a symlink" && exit 1
[ ! -h ${df}/directory ] && echo "directory is not a symlink" && exit 1
[ -h ${df}/directory/file ] && echo "directory/file is a symlink" && exit 1
echo -e "\n======> import with link_on_import=link_children and link_dotfile_default=nolink"
# create the source
rm -rf ${tmpd}/qwert
mkdir -p ${tmpd}/qwert
echo "test" > ${tmpd}/qwert/file
mkdir -p ${tmpd}/qwert/directory
echo "test" > ${tmpd}/qwert/directory/file
# clean
rm -rf ${tmps}/dotfiles
mkdir -p ${tmps}/dotfiles
# config file
cat > ${cfg} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
link_on_import: link_children
link_dotfile_default: nolink
dotfiles:
profiles:
_EOF
# import
df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V
# checks
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "d_`basename ${df}`")
echo ${line} | grep 'link: link_children'
# try to install
rm -rf ${tmpd}/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is a symlink" && exit 1
[ ! -h ${df}/file ] && echo "file is not a symlink" && exit 1
[ ! -h ${df}/directory ] && echo "directory is not a symlink" && exit 1
[ -h ${df}/directory/file ] && echo "directory/file is a symlink" && exit 1
## CLEANING
rm -rf ${tmps} ${tmpd}
echo "OK"
exit 0