mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-10 04:34:16 +00:00
modes install and compare
This commit is contained in:
121
tests-ng/chmod-compare.sh
Executable file
121
tests-ng/chmod-compare.sh
Executable file
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/env bash
|
||||
# author: deadc0de6 (https://github.com/deadc0de6)
|
||||
# Copyright (c) 2020, deadc0de6
|
||||
#
|
||||
# test chmod on compare
|
||||
#
|
||||
|
||||
# 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"
|
||||
hash coverage 2>/dev/null && bin="coverage run -a --source=dotdrop -m dotdrop.dotdrop" || true
|
||||
|
||||
echo "dotdrop path: ${ddpath}"
|
||||
echo "pythonpath: ${PYTHONPATH}"
|
||||
|
||||
# get the helpers
|
||||
source ${cur}/helpers
|
||||
|
||||
echo -e "$(tput setaf 6)==> RUNNING $(basename $BASH_SOURCE) <==$(tput sgr0)"
|
||||
|
||||
################################################################
|
||||
# this is the test
|
||||
################################################################
|
||||
|
||||
# the dotfile source
|
||||
tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
|
||||
mkdir -p ${tmps}/dotfiles
|
||||
# the dotfile destination
|
||||
tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
|
||||
#echo "dotfile destination: ${tmpd}"
|
||||
|
||||
# create the dotfile
|
||||
dnormal="${tmpd}/dir_normal"
|
||||
mkdir -p ${dnormal}
|
||||
echo "dir_normal/f1" > ${dnormal}/file1
|
||||
echo "dir_normal/f2" > ${dnormal}/file2
|
||||
chmod 777 ${dnormal}
|
||||
|
||||
dlink="${tmpd}/dir_link"
|
||||
mkdir -p ${dlink}
|
||||
echo "dir_link/f1" > ${dlink}/file1
|
||||
echo "dir_link/f2" > ${dlink}/file2
|
||||
chmod 777 ${dlink}
|
||||
|
||||
dlinkchildren="${tmpd}/dir_link_children"
|
||||
mkdir -p ${dlinkchildren}
|
||||
echo "dir_linkchildren/f1" > ${dlinkchildren}/file1
|
||||
echo "dir_linkchildren/f2" > ${dlinkchildren}/file2
|
||||
chmod 777 ${dlinkchildren}
|
||||
|
||||
fnormal="${tmpd}/filenormal"
|
||||
echo "filenormal" > ${fnormal}
|
||||
chmod 777 ${fnormal}
|
||||
|
||||
flink="${tmpd}/filelink"
|
||||
echo "filelink" > ${flink}
|
||||
chmod 777 ${flink}
|
||||
|
||||
toimport="${dnormal} ${dlink} ${dlinkchildren} ${fnormal} ${flink}"
|
||||
|
||||
# create the config file
|
||||
cfg="${tmps}/config.yaml"
|
||||
|
||||
cat > ${cfg} << _EOF
|
||||
config:
|
||||
backup: true
|
||||
create: true
|
||||
dotpath: dotfiles
|
||||
dotfiles:
|
||||
profiles:
|
||||
_EOF
|
||||
#cat ${cfg}
|
||||
|
||||
# import without --preserve-mode
|
||||
for i in ${toimport}; do
|
||||
cd ${ddpath} | ${bin} import -c ${cfg} -f -p p1 ${i}
|
||||
done
|
||||
|
||||
#cat ${cfg}
|
||||
|
||||
# patch rights
|
||||
chmod 700 ${dnormal}
|
||||
chmod 700 ${dlink}
|
||||
chmod 700 ${dlinkchildren}
|
||||
chmod 700 ${fnormal}
|
||||
chmod 700 ${flink}
|
||||
|
||||
set +e
|
||||
cnt=`cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 2>&1 | grep 'modes differ' | wc -l`
|
||||
set -e
|
||||
|
||||
[ "${cnt}" != "5" ] && echo "compare modes failed" && exit 1
|
||||
|
||||
## CLEANING
|
||||
rm -rf ${tmps} ${tmpd}
|
||||
|
||||
echo "OK"
|
||||
exit 0
|
||||
@@ -6,13 +6,21 @@
|
||||
# with files and directories
|
||||
# with different link
|
||||
#
|
||||
# TODO
|
||||
# - test for symlink templates
|
||||
# - check for mode difference when install
|
||||
|
||||
# exit on first error
|
||||
set -e
|
||||
|
||||
# $1 path
|
||||
# $2 rights
|
||||
has_rights()
|
||||
{
|
||||
echo "testing ${1} is ${2}"
|
||||
[ ! -e "$1" ] && echo "`basename $1` does not exist" && exit 1
|
||||
local mode=`stat -L -c '%a' "$1"`
|
||||
[ "${mode}" != "$2" ] && echo "bad mode for `basename $1`" && exit 1
|
||||
true
|
||||
}
|
||||
|
||||
# all this crap to get current path
|
||||
rl="readlink -f"
|
||||
if ! ${rl} "${0}" >/dev/null 2>&1; then
|
||||
@@ -73,6 +81,23 @@ chmod 644 ${tmpd}/exists
|
||||
echo "existslink" > ${tmps}/dotfiles/existslink
|
||||
chmod 644 ${tmpd}/exists
|
||||
|
||||
mkdir -p ${tmps}/dotfiles/direxists
|
||||
echo "f1" > ${tmps}/dotfiles/direxists/f1
|
||||
mkdir -p ${tmpd}/direxists
|
||||
echo "f1" > ${tmpd}/direxists/f1
|
||||
chmod 644 ${tmpd}/direxists/f1
|
||||
chmod 744 ${tmpd}/direxists
|
||||
|
||||
mkdir -p ${tmps}/dotfiles/linkchildren
|
||||
echo "f1" > ${tmps}/dotfiles/linkchildren/f1
|
||||
mkdir -p ${tmps}/dotfiles/linkchildren/d1
|
||||
echo "f2" > ${tmps}/dotfiles/linkchildren/d1/f2
|
||||
|
||||
echo '{{@@ profile @@}}' > ${tmps}/dotfiles/symlinktemplate
|
||||
|
||||
mkdir -p ${tmps}/dotfiles/symlinktemplatedir
|
||||
echo "{{@@ profile @@}}" > ${tmps}/dotfiles/symlinktemplatedir/t
|
||||
|
||||
cat > ${cfg} << _EOF
|
||||
config:
|
||||
backup: true
|
||||
@@ -101,6 +126,25 @@ dotfiles:
|
||||
dst: ${tmpd}/existslink
|
||||
chmod: 777
|
||||
link: link
|
||||
d_direxists:
|
||||
src: direxists
|
||||
dst: ${tmpd}/direxists
|
||||
chmod: 777
|
||||
d_linkchildren:
|
||||
src: linkchildren
|
||||
dst: ${tmpd}/linkchildren
|
||||
chmod: 777
|
||||
link: link_children
|
||||
f_symlinktemplate:
|
||||
src: symlinktemplate
|
||||
dst: ${tmpd}/symlinktemplate
|
||||
chmod: 777
|
||||
link: link
|
||||
d_symlinktemplatedir:
|
||||
src: symlinktemplatedir
|
||||
dst: ${tmpd}/symlinktemplatedir
|
||||
chmod: 777
|
||||
link: link
|
||||
profiles:
|
||||
p1:
|
||||
dotfiles:
|
||||
@@ -109,45 +153,60 @@ profiles:
|
||||
- d_dir
|
||||
- f_exists
|
||||
- f_existslink
|
||||
- d_direxists
|
||||
- d_linkchildren
|
||||
- f_symlinktemplate
|
||||
- d_symlinktemplatedir
|
||||
p2:
|
||||
dotfiles:
|
||||
- f_exists
|
||||
- f_existslink
|
||||
- d_linkchildren
|
||||
- f_symlinktemplate
|
||||
_EOF
|
||||
#cat ${cfg}
|
||||
|
||||
# install
|
||||
echo "first install round"
|
||||
cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 -V ${i}
|
||||
|
||||
mode=`stat -c '%a' "${tmpd}/f777"`
|
||||
[ "${mode}" != "777" ] && echo "bad mode for f777" && exit 1
|
||||
has_rights "${tmpd}/f777" "777"
|
||||
has_rights "${tmpd}/link" "777"
|
||||
has_rights "${tmpd}/dir" "777"
|
||||
has_rights "${tmpd}/exists" "777"
|
||||
has_rights "${tmpd}/existslink" "777"
|
||||
has_rights "${tmpd}/direxists" "777"
|
||||
has_rights "${tmpd}/direxists/f1" "644"
|
||||
has_rights "${tmpd}/linkchildren" "777"
|
||||
has_rights "${tmpd}/linkchildren/f1" "644"
|
||||
has_rights "${tmpd}/linkchildren/d1" "755"
|
||||
has_rights "${tmpd}/linkchildren/d1/f2" "644"
|
||||
has_rights "${tmpd}/symlinktemplate" "777"
|
||||
|
||||
mode=`stat -c '%a' "${tmpd}/link"`
|
||||
[ "${mode}" != "777" ] && echo "bad mode for link" && exit 1
|
||||
|
||||
mode=`stat -c '%a' "${tmpd}/dir"`
|
||||
[ "${mode}" != "777" ] && echo "bad mode for dir" && exit 1
|
||||
|
||||
mode=`stat -c '%a' "${tmpd}/exists"`
|
||||
[ "${mode}" != "777" ] && echo "bad mode for exists" && exit 1
|
||||
|
||||
mode=`stat -c '%a' "${tmpd}/existslink"`
|
||||
[ "${mode}" != "777" ] && echo "bad mode for existslink" && exit 1
|
||||
grep 'p1' ${tmpd}/symlinktemplate
|
||||
grep 'p1' ${tmpd}/symlinktemplatedir/t
|
||||
|
||||
## second round
|
||||
echo "exists" > ${tmps}/dotfiles/exists
|
||||
chmod 644 ${tmps}/dotfiles/exists
|
||||
chmod 600 ${tmps}/dotfiles/exists
|
||||
echo "exists" > ${tmpd}/exists
|
||||
chmod 644 ${tmpd}/exists
|
||||
chmod 600 ${tmpd}/exists
|
||||
|
||||
chmod 644 ${tmpd}/existslink
|
||||
chmod 600 ${tmpd}/existslink
|
||||
|
||||
cd ${ddpath} | ${bin} install -c ${cfg} -p p2 -V ${i}
|
||||
chmod 700 ${tmpd}/linkchildren
|
||||
|
||||
mode=`stat -c '%a' "${tmpd}/exists"`
|
||||
[ "${mode}" != "777" ] && echo "bad mode for exists" && exit 1
|
||||
chmod 600 ${tmpd}/symlinktemplate
|
||||
|
||||
mode=`stat -c '%a' "${tmpd}/existslink"`
|
||||
[ "${mode}" != "777" ] && echo "bad mode for existslink" && exit 1
|
||||
echo "second install round"
|
||||
cd ${ddpath} | ${bin} install -c ${cfg} -p p2 -f -V ${i}
|
||||
|
||||
has_rights "${tmpd}/exists" "777"
|
||||
has_rights "${tmpd}/existslink" "777"
|
||||
has_rights "${tmpd}/linkchildren/f1" "644"
|
||||
has_rights "${tmpd}/linkchildren/d1" "755"
|
||||
has_rights "${tmpd}/linkchildren/d1/f2" "644"
|
||||
has_rights "${tmpd}/symlinktemplate" "777"
|
||||
|
||||
## CLEANING
|
||||
rm -rf ${tmps} ${tmpd}
|
||||
|
||||
Reference in New Issue
Block a user