Simplify dryrun variable.

This commit is contained in:
2016-03-06 17:20:01 +01:00
parent e12a8cf9cd
commit d75b21d516

View File

@@ -17,13 +17,13 @@ ignore_folders=('scripts' 'skel')
MAPPING_SEPARATOR='::' MAPPING_SEPARATOR='::'
dryrun="" dryrun=0
while [[ $# -gt 0 ]] ; do while [[ $# -gt 0 ]] ; do
case "$1" in case "$1" in
-n|--dry-run) -n|--dry-run)
echo "dry run" echo "dry run"
dryrun="yes" dryrun=1
;; ;;
*) *)
echo "invalid parameters" echo "invalid parameters"
@@ -80,19 +80,19 @@ while IFS= read -d $'\0' -r folder ; do
backup_destination="$(path_combine "$backup_dir" "$(basename "$destination")")" backup_destination="$(path_combine "$backup_dir" "$(basename "$destination")")"
if ! [[ -d "$backup_dir" ]] ; then if ! [[ -d "$backup_dir" ]] ; then
echo "mkdir -p \"$backup_dir\"" echo "mkdir -p \"$backup_dir\""
[[ $dryrun ]] || mkdir -p "$backup_dir" (( $dryrun )) || mkdir -p "$backup_dir"
fi fi
echo "mv \"$destination\" -> \"$backup_destination\"" echo "mv \"$destination\" -> \"$backup_destination\""
[[ $dryrun ]] || mv "$destination" "$backup_destination" (( $dryrun )) || mv "$destination" "$backup_destination"
fi fi
[[ -e "$destination" ]] && [[ "$(readlink "$destination")" == "$file" ]] && continue [[ -e "$destination" ]] && [[ "$(readlink "$destination")" == "$file" ]] && continue
echo "ln -sf \"$file\" -> \"$destination\"" echo "ln -sf \"$file\" -> \"$destination\""
[[ $dryrun ]] || ln -sf "$file" "$destination" (( $dryrun )) || ln -sf "$file" "$destination"
done done
done < <(find "$config_dir"/* -maxdepth 0 -mindepth 0 -type d -print0) done < <(find "$config_dir"/* -maxdepth 0 -mindepth 0 -type d -print0)
# copy everything from the skel directory into $HOME, but do not overwrite anything # copy everything from the skel directory into $HOME, but do not overwrite anything
# the /. at the end of source is some cp magic that copies the content of a directory # the /. at the end of source is some cp magic that copies the content of a directory
# instead of the directory inself # instead of the directory inself
[[ $dryrun ]] || rsync --archive --verbose --ignore-existing "$skel_dir/" "$HOME" (( $dryrun )) || rsync --archive --verbose --ignore-existing "$skel_dir/" "$HOME"