Added rysnc importer/exporter script with backup
This commit is contained in:
parent
e0f63d9e61
commit
76e2e75a9c
22
export
Executable file
22
export
Executable file
@ -0,0 +1,22 @@
|
||||
#! /bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
repo_root=$(git rev-parse --show-toplevel)
|
||||
|
||||
# Test for newer changes in the dotfiles. Protection against clobbering changes you might want to preserve.
|
||||
dry_run=$(rsync -avu --itemize-changes --dry-run --files-from=./tracked-files --exclude-from=./.gitignore . ~)
|
||||
if echo "${dry_run}" | grep -q '^<'; then
|
||||
echo "Some installed files have newer mtimes than the repository versions. Please import the changes first."
|
||||
exit 1
|
||||
elif echo "${dry_run}" | grep -q '^>'; then
|
||||
echo "Some installed files differ from the repository versions. Creating a backup..."
|
||||
backup_dir=$(mktemp -d -t backupXXXXXXXX)
|
||||
${repo_root}/import ${backup_dir} y > /dev/null
|
||||
mkdir -p ${repo_root}/.backup/
|
||||
tar -czf ${repo_root}/.backup/$(basename $backup_dir).tgz $backup_dir
|
||||
fi
|
||||
|
||||
# Actually perform the copy
|
||||
rsync -avu --itemize-changes --files-from=./tracked-files --exclude-from=./.gitignore . ~
|
||||
|
||||
49
import
Executable file
49
import
Executable file
@ -0,0 +1,49 @@
|
||||
#! /bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
function check_clean() {
|
||||
if ! git diff-index --quiet HEAD -- ; then
|
||||
echo "Git repository is dirty, aborting."
|
||||
git status --short --untracked-files=no
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function dry_run() {
|
||||
rsync -HPrlm \
|
||||
--itemize-changes \
|
||||
--dry-run \
|
||||
--files-from=./tracked-files \
|
||||
--exclude-from=./.gitignore \
|
||||
"${source}" "${destination}"
|
||||
}
|
||||
|
||||
|
||||
source=${HOME}
|
||||
repo_root=$(git rev-parse --show-toplevel)
|
||||
destination="${1:-$repo_root}"
|
||||
|
||||
echo "Importing working dotfiles to $destination"
|
||||
dry_run
|
||||
|
||||
if [ -z "${1+x}" ]; then
|
||||
echo "Performing git repository check..."
|
||||
check_clean
|
||||
fi
|
||||
|
||||
if [ -z "${2+x}" ]; then
|
||||
read -r -p "Are you sure? [y/N] " response
|
||||
response=${response,,}
|
||||
else
|
||||
response=$2
|
||||
fi
|
||||
|
||||
if [[ "$response" =~ ^(yes|y)$ ]]; then
|
||||
rsync -HPrlm \
|
||||
--itemize-changes \
|
||||
--files-from=./tracked-files \
|
||||
--exclude-from=./.gitignore \
|
||||
"${source}" "${destination}"
|
||||
fi
|
||||
|
||||
2
tracked-files
Normal file
2
tracked-files
Normal file
@ -0,0 +1,2 @@
|
||||
.vim/
|
||||
.vimrc
|
||||
Loading…
Reference in New Issue
Block a user