From 467332a5ec46f087a35f62be91d6ffce9cfe4c56 Mon Sep 17 00:00:00 2001 From: Konstantin Demin Date: Sun, 21 Mar 2021 20:25:01 +0300 Subject: [PATCH] fix fresh install with git available --- .config/dotfiles/install.sh | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/.config/dotfiles/install.sh b/.config/dotfiles/install.sh index 7383241..f906d98 100755 --- a/.config/dotfiles/install.sh +++ b/.config/dotfiles/install.sh @@ -38,6 +38,7 @@ git_avail() { } dot_install() { + backup_unconditionally git_env mkdir -p "${GIT_DIR}" git init -b ${gh_br} @@ -88,7 +89,7 @@ dot_install_raw() { n_bak=$(find "${td_backup}/" -mindepth 1 | wc -l) if [ "${n_bak}" != 0 ] ; then echo "backed-up files are here: ${td_backup}/" - ls -lghAG "${td_backup}/" + find "${td_backup}/" -mindepth 1 -ls else rmdir "${td_backup}" fi @@ -142,4 +143,30 @@ cmp_files() { cmp -s "$1/$3" "$2/$3" >/dev/null 2>/dev/null } +backup_unconditionally() { + tf_list=$(mktemp) + curl -sSL "${u_gitignore}" | \ + sed -En '/^!\/(.+)$/{s//\1/;p;}' > "${tf_list}" + + td_backup=$(mktemp -d) + while read f ; do + if [ -f "${HOME}/$f" ] ; then + d=$(dirname "$f") + if [ -n "$d" ] ; then + mkdir -p "${td_backup}/$d" + fi + mv -f "${HOME}/$f" "${td_backup}/$f" + fi + done < "${tf_list}" + rm -f "${tf_list}" + + n_bak=$(find "${td_backup}/" -mindepth 1 | wc -l) + if [ "${n_bak}" != 0 ] ; then + echo "backed-up files are here: ${td_backup}/" + find "${td_backup}/" -mindepth 1 -ls + else + rmdir "${td_backup}" + fi +} + main "$@"