From 6d7a482e9d2bd0538023f4507eb19c0f94b53a03 Mon Sep 17 00:00:00 2001 From: kevin zhuang Date: Sat, 9 May 2020 14:02:00 +1000 Subject: [PATCH] migration script --- scripts/finit | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/finit b/scripts/finit index fa75b37..70c6081 100755 --- a/scripts/finit +++ b/scripts/finit @@ -64,6 +64,24 @@ if [[ -z "${remote_url}" ]]; then fi else cd "${DOTBARE_TREE}" - echo "${DOTBARE_DIR}" >> .gitignore + basename "${DOTBARE_DIR}" >> .gitignore git clone --bare "${remote_url}" "${DOTBARE_DIR}" + if ! /usr/bin/git --git-dir "${DOTBARE_DIR}" --work-tree "${DOTBARE_TREE}" checkout 2> /dev/null; then + echo "File checkout failed" + echo "Backing up pre-existing dotfiles ..." + /usr/bin/git --git-dir "${DOTBARE_DIR}" --work-tree "${DOTBARE_TREE}" checkout 2>&1 \ + | awk '{ + if ($0 ~ /[\t].*/) { + gsub(/^[\t]/, "", $0) + print $0 + } + }' \ + | xargs -I __ "${mydir}"/fbackup -p __ -m + echo "dotfiles backup succeeded, checkout continue" + /usr/bin/git --git-dir "${DOTBARE_DIR}" --work-tree "${DOTBARE_TREE}" checkout + /usr/bin/git --git-dir "${DOTBARE_DIR}" --work-tree "${DOTBARE_TREE}" \ + config --local status.showUntrackedFiles no + fi + echo "File checkout succeeded" + echo "Migration completed" fi