summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/lsrc.in20
-rwxr-xr-xbin/mkrc.in25
-rwxr-xr-xbin/rcdn.in54
-rwxr-xr-xbin/rcup.in54
4 files changed, 86 insertions, 67 deletions
diff --git a/bin/lsrc.in b/bin/lsrc.in
index 6fb6162..7a531f0 100755
--- a/bin/lsrc.in
+++ b/bin/lsrc.in
@@ -144,7 +144,7 @@ handle_file() {
elif is_excluded "$dotfiles_subdir/$file" "$exclude_file_globs" "$include_file_globs"; then
$VERBOSE "skipping excluded file $file"
elif [ -d "$file" ] && is_excluded "$dotfiles_subdir/$file" "$symlink_dirs_file_globs" "$mk_dirs_file_globs"; then
- show_file "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted
+ show_file "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted "$symlink_dirs_file_globs"
elif [ -d "$file" ]; then
show_dir "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs" "$mk_dirs_file_globs"
else
@@ -166,7 +166,7 @@ dotfiles_dir_excludes() {
$DEBUG "dotfiles_dir_excludes $dotfiles_dir"
$DEBUG " with excludes: $excludes"
- for exclude in $excludes; do
+ for exclude in "$excludes"; do
if echo "$exclude" | grep ':' >/dev/null; then
dotfiles_dir_pat="$(echo "$exclude" | sed 's/:.*//')"
file_glob="$(echo "$exclude" | sed 's/.*://')"
@@ -259,17 +259,17 @@ handle_command_line() {
case "$opt" in
F) show_sigils=1;;
h) show_help ;;
- I) includes="$includes $OPTARG";;
- t) arg_tags="$arg_tags $OPTARG";;
+ I) includes="$(append_variable "$includes" "$OPTARG")" ;;
+ t) arg_tags="$(append_variable "$arg_tags" "$OPTARG")" ;;
v) verbosity=$(($verbosity + 1));;
q) verbosity=$(($verbosity - 1));;
- d) dotfiles_dirs="$dotfiles_dirs $OPTARG";;
+ d) dotfiles_dirs="$(append_variable "$dotfiles_dirs" "$OPTARG")" ;;
V) version=1;;
- x) excludes="$excludes $OPTARG";;
- S) symlink_dirs="$symlink_dirs $OPTARG";;
- s) never_symlink_dirs="$never_symlink_dirs $OPTARG";;
- U) undotted="$undotted $OPTARG";;
- u) never_undotted="$never_undotted $OPTARG";;
+ x) excludes="$(append_variable "$excludes" "$OPTARG")" ;;
+ S) symlink_dirs="$(append_variable "$symlink_dirs" "$OPTARG")" ;;
+ s) never_symlink_dirs="$(append_variable "$never_symlink_dirs" "$OPTARG")" ;;
+ U) undotted="$(append_variable "$undotted" "$OPTARG")" ;;
+ u) never_undotted="$(append_variable "$never_undotted" "$OPTARG")" ;;
B) hostname="$OPTARG";;
?) show_help 64 ;;
esac
diff --git a/bin/mkrc.in b/bin/mkrc.in
index 5d6af7e..5628f14 100755
--- a/bin/mkrc.in
+++ b/bin/mkrc.in
@@ -20,6 +20,28 @@ destination() {
fi
}
+exit_if_dangerous() {
+ local file="$1"
+
+ if [ -L "$file" ]; then
+ $ERROR 1 "'$file' is a symlink. Cannot process file."
+ elif is_nested "$file"; then
+ # Remove DEST_DIR in case $HOME is under a symlink
+ saved_ifs="$IFS"
+ IFS=/
+ set -- $(dirname "$file" | sed "s|$DEST_DIR/||")
+ IFS="$saved_ifs"
+
+ built_dir="$DEST_DIR"
+ for dir in $@; do
+ built_dir="$built_dir/$dir"
+ if [ -L "$built_dir" ]; then
+ $ERROR 1 "'$file' path contains a symlink ($dir). Cannot process file."
+ fi
+ done
+ fi
+}
+
show_help() {
local exit_code=${1:-0}
@@ -64,7 +86,7 @@ while getopts :ChSsUuVvqot:d:B: opt; do
B)
in_host=1
hostname="$OPTARG"
- install_args="-B $hostname"
+ install_args=$(append_variable "$install_args" "-B $hostname")
;;
?) show_help 64 ;;
esac
@@ -84,6 +106,7 @@ fi
files=""
for i; do
+ exit_if_dangerous "$i"
files="$(printf "$files\n$i")"
done
diff --git a/bin/rcdn.in b/bin/rcdn.in
index a2a8472..3ebbd27 100755
--- a/bin/rcdn.in
+++ b/bin/rcdn.in
@@ -48,19 +48,19 @@ handle_command_line() {
case "$opt" in
h) show_help ;;
B) hostname="$OPTARG" ;;
- I) includes="$includes $OPTARG";;
+ I) includes="$(append_variable "$includes" "$OPTARG")" ;;
k) run_hooks=1 ;;
K) run_hooks=0 ;;
- t) arg_tags="$arg_tags $OPTARG" ;;
- S) symlink_dirs="$symlink_dirs $OPTARG";;
- s) never_symlink_dirs="$never_symlink_dirs $OPTARG";;
- U) undotted="$undotted $OPTARG";;
- u) never_undotted="$never_undotted $OPTARG";;
+ t) arg_tags="$(append_variable "$arg_tags" "$OPTARG")" ;;
+ S) symlink_dirs="$(append_variable "$symlink_dirs" "$OPTARG")" ;;
+ s) never_symlink_dirs="$(append_variable "$never_symlink_dirs" "$OPTARG")" ;;
+ U) undotted="$(append_variable "$undotted" "$OPTARG")" ;;
+ u) never_undotted="$(append_variable "$never_undotted" "$OPTARG")";;
v) verbosity=$(($verbosity + 1));;
q) verbosity=$(($verbosity - 1));;
- d) dotfiles_dirs="$dotfiles_dirs $OPTARG" ;;
+ d) dotfiles_dirs="$(append_variable "$dotfiles_dirs" "$OPTARG")" ;;
V) version=1 ;;
- x) excludes="$excludes $OPTARG" ;;
+ x) excludes="$(append_variable "$excludes" "$OPTARG")" ;;
?) show_help 64 ;;
esac
done
@@ -72,34 +72,34 @@ handle_command_line() {
tags="${arg_tags:-$TAGS}"
dotfiles_dirs="${dotfiles_dirs:-$DOTFILES_DIRS}"
files="$@"
- RUN_HOOKS=$run_hooks
+ RUN_HOOKS="$run_hooks"
- for tag in $tags; do
- LS_ARGS="$LS_ARGS -t $tag"
+ for tag in "$tags"; do
+ LS_ARGS="$LS_ARGS -t \"$tag\""
done
- for dotfiles_dir in $dotfiles_dirs; do
- LS_ARGS="$LS_ARGS -d $dotfiles_dir"
+ for dotfiles_dir in "$dotfiles_dirs"; do
+ LS_ARGS="$LS_ARGS -d \"$dotfiles_dir\""
done
- for exclude in $excludes; do
- LS_ARGS="$LS_ARGS -x $exclude"
+ for exclude in "$excludes"; do
+ LS_ARGS="$LS_ARGS -x \"$exclude\""
done
- for include in $includes; do
- LS_ARGS="$LS_ARGS -I $include"
+ for include in "$includes"; do
+ LS_ARGS="$LS_ARGS -I \"$include\""
done
- for symlink_dir in $symlink_dirs; do
- LS_ARGS="$LS_ARGS -S $symlink_dir"
+ for symlink_dir in "$symlink_dirs"; do
+ LS_ARGS="$LS_ARGS -S \"$symlink_dir\""
done
- for never_symlink_dir in $symlink_dirs; do
- LS_ARGS="$LS_ARGS -s $never_symlink_dir"
+ for never_symlink_dir in "$symlink_dirs"; do
+ LS_ARGS="$LS_ARGS -s \"$never_symlink_dir\""
done
- for undot in $undotted; do
- LS_ARGS="$LS_ARGS -U $undot"
+ for undot in "$undotted"; do
+ LS_ARGS="$LS_ARGS -U \"$undot\""
done
- for never_undot in $never_undotted; do
- LS_ARGS="$LS_ARGS -u $never_undot"
+ for never_undot in "$never_undotted"; do
+ LS_ARGS="$LS_ARGS -u \"$never_undot\""
done
- LS_ARGS="$LS_ARGS -B $hostname $files"
+ LS_ARGS="$LS_ARGS -B \"$hostname\" $files"
$DEBUG "LS_ARGS: $LS_ARGS"
}
@@ -111,7 +111,7 @@ handle_command_line "$@"
run_hooks pre down
-dests_and_srcs="$(lsrc $LS_ARGS)"
+dests_and_srcs="$(eval "lsrc $LS_ARGS")"
saved_ifs="$IFS"
IFS='
diff --git a/bin/rcup.in b/bin/rcup.in
index 910e534..65f0ab8 100755
--- a/bin/rcup.in
+++ b/bin/rcup.in
@@ -121,10 +121,6 @@ replace_file() {
link_file "$src" "$dest" "$sigil"
}
-is_nested() {
- echo "$1" | sed "s:$DEST_DIR/::" | grep '/' >/dev/null
-}
-
is_identical() {
diff -c "$1" "$2" > /dev/null 2>&1
}
@@ -217,23 +213,23 @@ handle_command_line() {
case "$opt" in
B) hostname="$OPTARG" ;;
C) always_copy=1 ;;
- d) dotfiles_dirs="$dotfiles_dirs $OPTARG" ;;
+ d) dotfiles_dirs="$(append_variable "$dotfiles_dirs" "$OPTARG")" ;;
f) REPLACE_ALL=1 ;;
g) generate=1 ;;
h) show_help ;;
i) REPLACE_ALL=0 ;;
- I) includes="$includes $OPTARG" ;;
+ I) includes="$(append_variable "$includes" "$OPTARG")" ;;
k) run_hooks=1 ;;
K) run_hooks=0 ;;
q) verbosity=$(($verbosity - 1)) ;;
- t) arg_tags="$arg_tags $OPTARG" ;;
- S) symlink_dirs="$symlink_dirs $OPTARG";;
- s) never_symlink_dirs="$never_symlink_dirs $OPTARG";;
- U) undotted="$undotted $OPTARG";;
- u) never_undotted="$never_undotted $OPTARG";;
+ t) arg_tags="$(append_variable "$arg_tags" "$OPTARG")" ;;
+ S) symlink_dirs="$(append_variable "$symlink_dirs" "$OPTARG")" ;;
+ s) never_symlink_dirs="$(append_variable "$never_symlink_dirs" "$OPTARG")";;
+ U) undotted="$(append_variable "$undotted" "$OPTARG")" ;;
+ u) never_undotted="$(append_variable "$never_undotted" "$OPTARG")" ;;
v) verbosity=$(($verbosity + 1)) ;;
V) version=1 ;;
- x) excludes="$excludes $OPTARG" ;;
+ x) excludes="$(append_variable "$excludes" "$OPTARG")" ;;
?) show_help 64 ;;
esac
done
@@ -265,31 +261,31 @@ handle_command_line() {
done
for tag in $tags; do
- LS_ARGS="$LS_ARGS -t $tag"
+ LS_ARGS="$LS_ARGS -t \"$tag\""
done
- for dotfiles_dir in $DOTFILES_DIRS; do
- LS_ARGS="$LS_ARGS -d $dotfiles_dir"
+ for dotfiles_dir in "$DOTFILES_DIRS"; do
+ LS_ARGS="$LS_ARGS -d \"$dotfiles_dir\""
done
- for exclude in $excludes; do
- LS_ARGS="$LS_ARGS -x $exclude"
+ for exclude in "$excludes"; do
+ LS_ARGS="$LS_ARGS -x \"$exclude\""
done
- for include in $includes; do
- LS_ARGS="$LS_ARGS -I $include"
+ for include in "$includes"; do
+ LS_ARGS="$LS_ARGS -I \"$include\""
done
- for symlink_dir in $symlink_dirs; do
- LS_ARGS="$LS_ARGS -S $symlink_dir"
+ for symlink_dir in "$symlink_dirs"; do
+ LS_ARGS="$LS_ARGS -S \"$symlink_dir\""
done
- for never_symlink_dir in $never_symlink_dirs; do
- LS_ARGS="$LS_ARGS -s $never_symlink_dir"
+ for never_symlink_dir in "$never_symlink_dirs"; do
+ LS_ARGS="$LS_ARGS -s \"$never_symlink_dir\""
done
- for undot in $undotted; do
- LS_ARGS="$LS_ARGS -U $undot"
+ for undot in "$undotted"; do
+ LS_ARGS="$LS_ARGS -U \"$undot\""
done
- for never_undot in $never_undotted; do
- LS_ARGS="$LS_ARGS -u $never_undot"
+ for never_undot in "$never_undotted"; do
+ LS_ARGS="$LS_ARGS -u \"$never_undot\""
done
- LS_ARGS="$LS_ARGS -B $hostname $files"
+ LS_ARGS="$LS_ARGS -B \"$hostname\" $files"
$DEBUG "LS_ARGS: $LS_ARGS"
}
@@ -301,7 +297,7 @@ handle_command_line "$@"
run_hooks pre up
-dests_and_srcs="$(lsrc $LS_ARGS)"
+dests_and_srcs="$(eval "lsrc $LS_ARGS")"
saved_ifs="$IFS"
IFS='