update dotfiles install script
This commit is contained in:
parent
01c80bc374
commit
4dbfc602bf
1 changed files with 17 additions and 11 deletions
|
@ -2,21 +2,22 @@
|
||||||
# this script will install the dotfiles from the target git repository, and back up any conflicting files
|
# this script will install the dotfiles from the target git repository, and back up any conflicting files
|
||||||
# credit for the basic outline of this script goes to https://www.atlassian.com/git/tutorials/dotfiles
|
# credit for the basic outline of this script goes to https://www.atlassian.com/git/tutorials/dotfiles
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
DOTFILES_REPO_DIR="$HOME/git/dotfiles"
|
DOTFILES_REPO_DIR="$HOME/git/dotfiles"
|
||||||
DOTFILES_REPO_URL="https://git.blakenorth.net/dotfiles"
|
DOTFILES_REPO_URL="https://git.blakenorth.net/dotfiles"
|
||||||
DOTFILES_BACKUP_DIR="$HOME/.dotfiles-backup_$(date +'%Y-%m-%d_%H:%m:%S')"
|
DOTFILES_BACKUP_DIR="$HOME/.dotfiles-backup_$(date +'%Y-%m-%d_%H:%m:%S')"
|
||||||
|
|
||||||
set -e
|
printf "\n Installing dotfiles from %s\n\n" "$DOTFILES_REPO_URL"
|
||||||
|
|
||||||
printf "\n Installing dotfiles from $DOTFILES_REPO_URL\n\n"
|
|
||||||
|
|
||||||
# check for the git command and exit if it doesn't exist
|
# check for the git command and exit if it doesn't exist
|
||||||
if ! command -v git > /dev/null;then
|
if ! command -v git > /dev/null;then
|
||||||
echo 'git is not installed or could not be found in PATH, please install git to proceed'
|
echo 'Error: git is not installed or could not be found in PATH. Please install git to proceed.' >&2
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git clone --bare "$DOTFILES_REPO_URL" "$DOTFILES_REPO_DIR" || echo "Resuming installation"
|
mkdir -p "$DOTFILES_REPO_DIR"
|
||||||
|
git clone --bare "$DOTFILES_REPO_URL" "$DOTFILES_REPO_DIR" || echo " Resuming installation"
|
||||||
|
|
||||||
dot() {
|
dot() {
|
||||||
git --git-dir="$DOTFILES_REPO_DIR" --work-tree="$HOME" "$@"
|
git --git-dir="$DOTFILES_REPO_DIR" --work-tree="$HOME" "$@"
|
||||||
|
@ -24,18 +25,23 @@ dot() {
|
||||||
|
|
||||||
# remove the '> /dev/null' part if things don't seem to work right
|
# remove the '> /dev/null' part if things don't seem to work right
|
||||||
if ! dot checkout > /dev/null 2>&1; then
|
if ! dot checkout > /dev/null 2>&1; then
|
||||||
echo "Backing up pre-existing dotfiles."
|
echo " Backing up pre-existing dotfiles."
|
||||||
mkdir -p "$DOTFILES_BACKUP_DIR"
|
mkdir -p "$DOTFILES_BACKUP_DIR"
|
||||||
|
|
||||||
# get the list of files that need to be backed up
|
# get the list of files that need to be backed up
|
||||||
while read -r LINE; do
|
dot checkout 2>&1 \
|
||||||
|
| grep -Po '\t\K.*$' \
|
||||||
|
| while read -r LINE; do
|
||||||
LINE_DIR="$(dirname "$LINE")" # No file
|
LINE_DIR="$(dirname "$LINE")" # No file
|
||||||
|
[ "$LINE_DIR" = '.' ] || [ "$LINE_DIR" = '..' ] && continue
|
||||||
mkdir -p "$DOTFILES_BACKUP_DIR/$LINE_DIR"
|
mkdir -p "$DOTFILES_BACKUP_DIR/$LINE_DIR"
|
||||||
mv "$HOME/$LINE" "$DOTFILES_BACKUP_DIR/$LINE_DIR"
|
mv "$HOME/$LINE" "$DOTFILES_BACKUP_DIR/$LINE_DIR"
|
||||||
done <<< "$(dot checkout 2>&1 | grep -Po '\t\K.*$')"
|
done
|
||||||
|
|
||||||
|
# now that all the files are out of the way, we can do one final checkout
|
||||||
|
dot checkout
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dot checkout
|
|
||||||
dot config status.showUntrackedFiles no
|
dot config status.showUntrackedFiles no
|
||||||
|
|
||||||
printf "\nInstallation complete!\n"
|
printf "\n Installation complete!\n"
|
||||||
|
|
Loading…
Add table
Reference in a new issue