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

modes install and compare

This commit is contained in:
deadc0de6
2020-11-12 22:24:09 +01:00
parent c07a865809
commit 2bb684d3da
8 changed files with 349 additions and 108 deletions

View File

@@ -76,16 +76,12 @@ On `install` the following rules are applied:
* if `chmod` is specified, it will be applied to the installed dotfile * if `chmod` is specified, it will be applied to the installed dotfile
* if file exists and its permissions differ from `umask` and no `chmod` is specified user needs * if file exists and its permissions differ from `umask` and no `chmod` is specified user needs
to confirm installation (unless `-f --force` is used) **TODO unless permissions match existing file** to confirm installation (unless `-f --force` is used or the permission match the dotfile in the `dotpath`)
On `update`: On `update`:
* **TODO** * **TODO**
One `compare`:
* **TODO**
## Symlink dotfiles ## Symlink dotfiles
Dotdrop is able to install dotfiles in three different ways Dotdrop is able to install dotfiles in three different ways

View File

@@ -657,10 +657,6 @@ class CfgYaml:
err = 'bad format for chmod: {}'.format(val) err = 'bad format for chmod: {}'.format(val)
self._log.err(err) self._log.err(err)
raise YamlException('config content error: {}'.format(err)) raise YamlException('config content error: {}'.format(err))
if v[self.key_dotfile_link] == self.lnk_children:
err = 'incompatible use of chmod and link_children'
self._log.err(err)
raise YamlException('config content error: {}'.format(err))
v[self.key_dotfile_chmod] = val v[self.key_dotfile_chmod] = val
return new return new

View File

@@ -10,7 +10,8 @@ import filecmp
# local imports # local imports
from dotdrop.logger import Logger from dotdrop.logger import Logger
from dotdrop.utils import must_ignore, uniq_list, diff from dotdrop.utils import must_ignore, uniq_list, diff, \
get_file_perm
class Comparator: class Comparator:
@@ -31,6 +32,7 @@ class Comparator:
if self.debug: if self.debug:
self.log.dbg('comparing {} and {}'.format(left, right)) self.log.dbg('comparing {} and {}'.format(left, right))
self.log.dbg('ignore pattern(s): {}'.format(ignore)) self.log.dbg('ignore pattern(s): {}'.format(ignore))
# test type of file # test type of file
if os.path.isdir(left) and not os.path.isdir(right): if os.path.isdir(left) and not os.path.isdir(right):
return '\"{}\" is a dir while \"{}\" is a file\n'.format(left, return '\"{}\" is a dir while \"{}\" is a file\n'.format(left,
@@ -38,14 +40,32 @@ class Comparator:
if not os.path.isdir(left) and os.path.isdir(right): if not os.path.isdir(left) and os.path.isdir(right):
return '\"{}\" is a file while \"{}\" is a dir\n'.format(left, return '\"{}\" is a file while \"{}\" is a dir\n'.format(left,
right) right)
# test content # test content
if not os.path.isdir(left): if not os.path.isdir(left):
if self.debug: if self.debug:
self.log.dbg('is file') self.log.dbg('is file')
return self._comp_file(left, right, ignore) ret = self._comp_file(left, right, ignore)
if not ret:
ret = self._comp_mode(left, right)
return ret
if self.debug: if self.debug:
self.log.dbg('is directory') self.log.dbg('is directory')
return self._comp_dir(left, right, ignore)
ret = self._comp_dir(left, right, ignore)
if not ret:
ret = self._comp_mode(left, right)
return ret
def _comp_mode(self, left, right):
"""compare mode"""
left_mode = get_file_perm(left)
right_mode = get_file_perm(right)
if left_mode == right_mode:
return ''
ret = 'modes differ ({} vs {})\n'.format(left_mode, right_mode)
return ret
def _comp_file(self, left, right, ignore): def _comp_file(self, left, right, ignore):
"""compare a file""" """compare a file"""

View File

@@ -108,7 +108,8 @@ def _dotfile_install(o, dotfile, tmpdir=None):
# link_children # link_children
r, err = inst.link_children(t, dotfile.src, dotfile.dst, r, err = inst.link_children(t, dotfile.src, dotfile.dst,
actionexec=pre_actions_exec, actionexec=pre_actions_exec,
template=dotfile.template) template=dotfile.template,
chmod=dotfile.chmod)
else: else:
# nolink # nolink
src = dotfile.src src = dotfile.src
@@ -342,7 +343,6 @@ def cmd_compare(o, tmp):
def cmd_update(o): def cmd_update(o):
"""update the dotfile(s) from path(s) or key(s)""" """update the dotfile(s) from path(s) or key(s)"""
# TODO chmod
ret = True ret = True
paths = o.update_path paths = o.update_path
iskey = o.update_iskey iskey = o.update_iskey

View File

@@ -73,36 +73,41 @@ class Installer:
- False, error_msg : error - False, error_msg : error
- False, None : ignored - False, None : ignored
""" """
if not self._check_chmod(dst, chmod): if not self._check_chmod(src, dst, chmod):
err = 'ignoring "{}", nothing installed'.format(dst) err = 'ignoring "{}", not installed'.format(dst)
return False, err return False, err
r, err = self._install(templater, src, dst, r, err = self._install(templater, src, dst,
actionexec=actionexec, actionexec=actionexec,
noempty=noempty, noempty=noempty,
ignore=ignore, ignore=ignore,
template=template) template=template,
chmod=chmod)
if r and chmod:
os.chmod(dst, int(chmod, 8))
return self._log_install(r, err) return self._log_install(r, err)
def _install(self, templater, src, dst, def _install(self, templater, src, dst,
actionexec=None, noempty=False, actionexec=None, noempty=False,
ignore=[], template=True): ignore=[], template=True,
chmod=None):
"""install link:nolink""" """install link:nolink"""
if self.debug: if self.debug:
self.log.dbg('installing \"{}\" to \"{}\"'.format(src, dst)) self.log.dbg('installing \"{}\" to \"{}\"'.format(src, dst))
# check dst exists in config
if not dst or not src: if not dst or not src:
if self.debug: if self.debug:
self.log.dbg('empty dst for {}'.format(src)) self.log.dbg('empty dst for {}'.format(src))
return True, None return True, None
self.action_executed = False self.action_executed = False
# check source file exists
src = os.path.join(self.base, os.path.expanduser(src)) src = os.path.join(self.base, os.path.expanduser(src))
if not os.path.exists(src): if not os.path.exists(src):
err = 'source dotfile does not exist: {}'.format(src) err = 'source dotfile does not exist: {}'.format(src)
return False, err return False, err
# check dst is valid
dst = os.path.expanduser(dst) dst = os.path.expanduser(dst)
if self.totemp: if self.totemp:
dst = self._pivot_path(dst, self.totemp) dst = self._pivot_path(dst, self.totemp)
@@ -110,20 +115,23 @@ class Installer:
# symlink loop # symlink loop
err = 'dotfile points to itself: {}'.format(dst) err = 'dotfile points to itself: {}'.format(dst)
return False, err return False, err
isdir = os.path.isdir(src) isdir = os.path.isdir(src)
if self.debug: if self.debug:
self.log.dbg('install {} to {}'.format(src, dst)) self.log.dbg('install {} to {}'.format(src, dst))
self.log.dbg('is a directory \"{}\": {}'.format(src, isdir)) self.log.dbg('\"{}\" is a directory: {}'.format(src, isdir))
if isdir: if isdir:
b, e = self._install_dir(templater, src, dst, b, e = self._deploy_dir(templater, src, dst,
actionexec=actionexec, actionexec=actionexec,
noempty=noempty, ignore=ignore, noempty=noempty, ignore=ignore,
template=template) template=template,
chmod=chmod)
return b, e return b, e
b, e = self._install_file(templater, src, dst, b, e = self._deploy_file(templater, src, dst,
actionexec=actionexec, actionexec=actionexec,
noempty=noempty, ignore=ignore, noempty=noempty, ignore=ignore,
template=template) template=template,
chmod=chmod)
return b, e return b, e
def link(self, templater, src, dst, actionexec=None, def link(self, templater, src, dst, actionexec=None,
@@ -142,15 +150,16 @@ class Installer:
- False, error_msg : error - False, error_msg : error
- False, None : ignored - False, None : ignored
""" """
if not self._check_chmod(dst, chmod): if not self._check_chmod(src, dst, chmod):
err = 'ignoring "{}", nothing installed'.format(dst) err = 'ignoring "{}", nothing installed'.format(dst)
return False, err return False, err
r, err = self._link(templater, src, dst, r, err = self._link(templater, src, dst,
actionexec=actionexec, actionexec=actionexec,
template=template) template=template)
if chmod: if chmod and not self.dry:
os.chmod(dst, int(chmod, 8)) # apply mode
utils.chmod(dst, chmod, self.debug)
return self._log_install(r, err) return self._log_install(r, err)
def _link(self, templater, src, dst, actionexec=None, def _link(self, templater, src, dst, actionexec=None,
@@ -189,7 +198,7 @@ class Installer:
return b, e return b, e
def link_children(self, templater, src, dst, actionexec=None, def link_children(self, templater, src, dst, actionexec=None,
template=True): template=True, chmod=None):
""" """
link all files under a given directory link all files under a given directory
@templater: the templater @templater: the templater
@@ -197,19 +206,23 @@ class Installer:
@dst: dotfile destination path in the FS @dst: dotfile destination path in the FS
@actionexec: action executor callback @actionexec: action executor callback
@template: template this dotfile @template: template this dotfile
@chmod: file mode to apply
return return
- True, None: success - True, None: success
- False, error_msg: error - False, error_msg: error
- False, None, ignored - False, None, ignored
""" """
if not self._check_chmod(src, dst, chmod):
err = 'ignoring "{}", nothing installed'.format(dst)
return False, err
r, err = self._link_children(templater, src, dst, r, err = self._link_children(templater, src, dst,
actionexec=actionexec, actionexec=actionexec,
template=template) template=template, chmod=chmod)
return self._log_install(r, err) return self._log_install(r, err)
def _link_children(self, templater, src, dst, actionexec=None, def _link_children(self, templater, src, dst, actionexec=None,
template=True): template=True, chmod=None):
"""install link:link_children""" """install link:link_children"""
if self.debug: if self.debug:
self.log.dbg('link_children \"{}\" to \"{}\"'.format(src, dst)) self.log.dbg('link_children \"{}\" to \"{}\"'.format(src, dst))
@@ -245,7 +258,7 @@ class Installer:
]).format(dst) ]).format(dst)
if self.safe and not self.log.ask(msg): if self.safe and not self.log.ask(msg):
err = 'ignoring "{}", nothing installed'.format(dst) err = 'ignoring "{}", not installed'.format(dst)
return False, err return False, err
os.unlink(dst) os.unlink(dst)
os.mkdir(dst) os.mkdir(dst)
@@ -258,25 +271,26 @@ class Installer:
installed = 0 installed = 0
for i in range(len(children)): for i in range(len(children)):
src = srcs[i] subsrc = srcs[i]
dst = dsts[i] subdst = dsts[i]
if self.debug: if self.debug:
self.log.dbg('symlink child {} to {}'.format(src, dst)) self.log.dbg('symlink child {} to {}'.format(subsrc, subdst))
if template and Templategen.is_template(src): if template and Templategen.is_template(subsrc):
if self.debug: if self.debug:
self.log.dbg('dotfile is a template') self.log.dbg('dotfile is a template')
self.log.dbg('install to {} and symlink' self.log.dbg('install to {} and symlink'
.format(self.workdir)) .format(self.workdir))
tmp = self._pivot_path(dst, self.workdir, striphome=True) tmp = self._pivot_path(subdst, self.workdir, striphome=True)
r, e = self.install(templater, src, tmp, actionexec=actionexec, r, e = self.install(templater, subsrc, tmp,
actionexec=actionexec,
template=template) template=template)
if not r and e and not os.path.exists(tmp): if not r and e and not os.path.exists(tmp):
continue continue
src = tmp subsrc = tmp
ret, err = self._symlink(src, dst, actionexec=actionexec) ret, err = self._symlink(subsrc, subdst, actionexec=actionexec)
if ret: if ret:
installed += 1 installed += 1
# void actionexec if dotfile installed # void actionexec if dotfile installed
@@ -286,6 +300,10 @@ class Installer:
if err: if err:
return ret, err return ret, err
if chmod and not self.dry:
# apply mode
utils.chmod(dst, chmod, debug=self.debug)
return installed > 0, None return installed > 0, None
def _symlink(self, src, dst, actionexec=None): def _symlink(self, src, dst, actionexec=None):
@@ -350,9 +368,10 @@ class Installer:
tmp['_dotfile_sub_abs_dst'] = dst tmp['_dotfile_sub_abs_dst'] = dst
return tmp return tmp
def _install_file(self, templater, src, dst, def _deploy_file(self, templater, src, dst,
actionexec=None, noempty=False, actionexec=None, noempty=False,
ignore=[], template=True): ignore=[], template=True,
chmod=None):
"""install src to dst when is a file""" """install src to dst when is a file"""
if self.debug: if self.debug:
self.log.dbg('deploy file: {}'.format(src)) self.log.dbg('deploy file: {}'.format(src))
@@ -367,7 +386,7 @@ class Installer:
return False, None return False, None
if utils.samefile(src, dst): if utils.samefile(src, dst):
# symlink loop # loop
err = 'dotfile points to itself: {}'.format(dst) err = 'dotfile points to itself: {}'.format(dst)
return False, err return False, err
@@ -386,6 +405,7 @@ class Installer:
return False, str(e) return False, str(e)
finally: finally:
templater.restore_vars(saved) templater.restore_vars(saved)
# test is empty
if noempty and utils.content_empty(content): if noempty and utils.content_empty(content):
if self.debug: if self.debug:
self.log.dbg('ignoring empty template: {}'.format(src)) self.log.dbg('ignoring empty template: {}'.format(src))
@@ -393,10 +413,13 @@ class Installer:
if content is None: if content is None:
err = 'empty template {}'.format(src) err = 'empty template {}'.format(src)
return False, err return False, err
# write the file
ret, err = self._write(src, dst, ret, err = self._write(src, dst,
content=content, content=content,
actionexec=actionexec, actionexec=actionexec,
template=template) template=template,
chmod=chmod)
# build return values # build return values
if ret < 0: if ret < 0:
@@ -416,29 +439,36 @@ class Installer:
err = 'installing {} to {}'.format(src, dst) err = 'installing {} to {}'.format(src, dst)
return False, err return False, err
def _install_dir(self, templater, src, dst, def _deploy_dir(self, templater, src, dst,
actionexec=None, noempty=False, actionexec=None, noempty=False,
ignore=[], template=True): ignore=[], template=True, chmod=None):
"""install src to dst when is a directory""" """install src to dst when is a directory"""
if self.debug: if self.debug:
self.log.dbg('install dir {}'.format(src)) self.log.dbg('deploy dir {}'.format(src))
self.log.dbg('ignore empty: {}'.format(noempty))
# default to nothing installed and no error # default to nothing installed and no error
ret = False, None ret = False, None
# create the directory anyway
if self.debug:
self.log.dbg('mkdir -p {}'.format(dst))
if not self._create_dirs(dst): if not self._create_dirs(dst):
err = 'creating directory for {}'.format(dst) err = 'creating directory for {}'.format(dst)
return False, err return False, err
# handle all files in dir # handle all files in dir
for entry in os.listdir(src): for entry in os.listdir(src):
f = os.path.join(src, entry) f = os.path.join(src, entry)
if self.debug:
self.log.dbg('deploy sub from {}: {}'.format(dst, entry))
if not os.path.isdir(f): if not os.path.isdir(f):
# is file # is file
res, err = self._install_file(templater, f, res, err = self._deploy_file(templater, f,
os.path.join(dst, entry), os.path.join(dst, entry),
actionexec=actionexec, actionexec=actionexec,
noempty=noempty, noempty=noempty,
ignore=ignore, ignore=ignore,
template=template) template=template,
chmod=None)
if not res and err: if not res and err:
# error occured # error occured
ret = res, err ret = res, err
@@ -448,12 +478,13 @@ class Installer:
ret = True, None ret = True, None
else: else:
# is directory # is directory
res, err = self._install_dir(templater, f, res, err = self._deploy_dir(templater, f,
os.path.join(dst, entry), os.path.join(dst, entry),
actionexec=actionexec, actionexec=actionexec,
noempty=noempty, noempty=noempty,
ignore=ignore, ignore=ignore,
template=template) template=template,
chmod=None)
if not res and err: if not res and err:
# error occured # error occured
ret = res, err ret = res, err
@@ -461,20 +492,15 @@ class Installer:
elif res: elif res:
# something got installed # something got installed
ret = True, None ret = True, None
if chmod and not self.dry:
# apply mode
utils.chmod(dst, chmod, debug=self.debug)
return ret return ret
def _fake_diff(self, dst, content):
"""
fake diff by comparing file content with content
returns True if same
"""
cur = ''
with open(dst, 'br') as f:
cur = f.read()
return cur == content
def _write(self, src, dst, content=None, def _write(self, src, dst, content=None,
actionexec=None, template=True): actionexec=None, template=True,
chmod=None):
""" """
copy dotfile / write content to file copy dotfile / write content to file
return 0, None: for success, return 0, None: for success,
@@ -487,11 +513,16 @@ class Installer:
if self.dry: if self.dry:
self.log.dry('would install {}'.format(dst)) self.log.dry('would install {}'.format(dst))
return 0, None return 0, None
if os.path.lexists(dst): if os.path.lexists(dst):
rights = os.stat(src).st_mode if chmod:
rights = chmod
else:
rights = utils.get_file_perm(src)
samerights = False samerights = False
try: try:
samerights = os.stat(dst).st_mode == rights dstrights = utils.get_file_perm(dst)
samerights = dstrights == rights
except OSError as e: except OSError as e:
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
# broken symlink # broken symlink
@@ -531,7 +562,7 @@ class Installer:
if not r: if not r:
return -1, e return -1, e
if self.debug: if self.debug:
self.log.dbg('install dotfile to \"{}\"'.format(dst)) self.log.dbg('install file to \"{}\"'.format(dst))
# re-check in case action created the file # re-check in case action created the file
if self.safe and not overwrite and os.path.lexists(dst): if self.safe and not overwrite and os.path.lexists(dst):
if not self.log.ask('Overwrite \"{}\"'.format(dst)): if not self.log.ask('Overwrite \"{}\"'.format(dst)):
@@ -556,6 +587,9 @@ class Installer:
shutil.copymode(src, dst) shutil.copymode(src, dst)
except Exception as e: except Exception as e:
return -1, str(e) return -1, str(e)
if chmod:
utils.chmod(dst, chmod, debug=self.debug)
return 0, None return 0, None
def _diff_before_write(self, src, dst, content=None, quiet=False): def _diff_before_write(self, src, dst, content=None, quiet=False):
@@ -595,6 +629,7 @@ class Installer:
return True return True
if self.debug: if self.debug:
self.log.dbg('mkdir -p {}'.format(directory)) self.log.dbg('mkdir -p {}'.format(directory))
os.makedirs(directory) os.makedirs(directory)
return os.path.exists(directory) return os.path.exists(directory)
@@ -681,12 +716,19 @@ class Installer:
self.log.dbg('install: IGNORED') self.log.dbg('install: IGNORED')
return boolean, err return boolean, err
def _check_chmod(self, path, chmod): def _check_chmod(self, src, dst, chmod):
"""chmod file if needed and return True to continue""" """chmod file if needed and return True to continue"""
if chmod: if chmod:
return True return True
if os.path.exists(path) and self.safe: if not os.path.exists(dst):
perms = utils.get_file_perm(path) return True
if not os.path.exists(src):
return True
cperms = utils.get_file_perm(src)
perms = utils.get_file_perm(dst)
if perms == cperms:
return True
if self.safe:
if perms & self.umask: if perms & self.umask:
# perms and umask differ # perms and umask differ
msg = 'File mode ({}) differs from umask ({})' msg = 'File mode ({}) differs from umask ({})'

View File

@@ -315,3 +315,10 @@ def get_umask():
def get_file_perm(path): def get_file_perm(path):
"""return file permission""" """return file permission"""
return os.stat(path).st_mode & 0o777 return os.stat(path).st_mode & 0o777
def chmod(path, mode, debug=False):
cm = int(mode, 8)
if debug:
LOG.dbg('chmod {} {}'.format(oct(cm), path))
os.chmod(path, cm)

121
tests-ng/chmod-compare.sh Executable file
View 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

View File

@@ -6,13 +6,21 @@
# with files and directories # with files and directories
# with different link # with different link
# #
# TODO
# - test for symlink templates
# - check for mode difference when install
# exit on first error # exit on first error
set -e 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 # all this crap to get current path
rl="readlink -f" rl="readlink -f"
if ! ${rl} "${0}" >/dev/null 2>&1; then if ! ${rl} "${0}" >/dev/null 2>&1; then
@@ -73,6 +81,23 @@ chmod 644 ${tmpd}/exists
echo "existslink" > ${tmps}/dotfiles/existslink echo "existslink" > ${tmps}/dotfiles/existslink
chmod 644 ${tmpd}/exists 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 cat > ${cfg} << _EOF
config: config:
backup: true backup: true
@@ -101,6 +126,25 @@ dotfiles:
dst: ${tmpd}/existslink dst: ${tmpd}/existslink
chmod: 777 chmod: 777
link: link 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: profiles:
p1: p1:
dotfiles: dotfiles:
@@ -109,45 +153,60 @@ profiles:
- d_dir - d_dir
- f_exists - f_exists
- f_existslink - f_existslink
- d_direxists
- d_linkchildren
- f_symlinktemplate
- d_symlinktemplatedir
p2: p2:
dotfiles: dotfiles:
- f_exists - f_exists
- f_existslink - f_existslink
- d_linkchildren
- f_symlinktemplate
_EOF _EOF
#cat ${cfg} #cat ${cfg}
# install # install
echo "first install round"
cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 -V ${i} cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 -V ${i}
mode=`stat -c '%a' "${tmpd}/f777"` has_rights "${tmpd}/f777" "777"
[ "${mode}" != "777" ] && echo "bad mode for f777" && exit 1 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"` grep 'p1' ${tmpd}/symlinktemplate
[ "${mode}" != "777" ] && echo "bad mode for link" && exit 1 grep 'p1' ${tmpd}/symlinktemplatedir/t
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
## second round
echo "exists" > ${tmps}/dotfiles/exists echo "exists" > ${tmps}/dotfiles/exists
chmod 644 ${tmps}/dotfiles/exists chmod 600 ${tmps}/dotfiles/exists
echo "exists" > ${tmpd}/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"` chmod 600 ${tmpd}/symlinktemplate
[ "${mode}" != "777" ] && echo "bad mode for exists" && exit 1
mode=`stat -c '%a' "${tmpd}/existslink"` echo "second install round"
[ "${mode}" != "777" ] && echo "bad mode for existslink" && exit 1 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 ## CLEANING
rm -rf ${tmps} ${tmpd} rm -rf ${tmps} ${tmpd}