|
|
@@ -0,0 +1,34 @@
|
|
|
+#!/bin/bash
|
|
|
+
|
|
|
+REPO=${1:-https://gogs.viktorgrahn.com/viktor/dotfiles.git}
|
|
|
+BRANCH=${2:-main}
|
|
|
+
|
|
|
+if [ -d $HOME/.dotfiles ]; then
|
|
|
+ echo "$HOME/.dotfiles already exists"
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+
|
|
|
+echo "Cloning ${REPO} to $HOME/.dotfiles"
|
|
|
+git clone --bare ${REPO} $HOME/.dotfiles > /tmp/setupDotfiles.log
|
|
|
+if (( $? > 0 )); then
|
|
|
+ echo "Unable to clone ${REPO}"
|
|
|
+ exit 2
|
|
|
+fi
|
|
|
+
|
|
|
+echo "Checkout ${BRANCH} to $HOME"
|
|
|
+git --git-dir=${HOME}/.dotfiles --work-tree=${HOME} checkout ${BRANCH} > /tmp/setupDotfiles.log
|
|
|
+if (( $? > 0 )); then
|
|
|
+ if grep "overwritten by checkout" /tmp/setupDotfiles.log >> /dev/null 2>&1; then
|
|
|
+ echo "Resolving conflicts and moving existing files to ${HOME}/.dotfiles_backup"
|
|
|
+ for FILE in $(grep -E "^\s+\." /tmp/setupDotfiles.log | awk '{print $1}'); do
|
|
|
+ echo "Moving ${FILE} to ${HOME}/.dotfiles_backup/${FILE}"
|
|
|
+ mkdir -p ${HOME}/.dotfiles_backup/$(dirname ${FILE})
|
|
|
+ mv ${FILE} ${HOME}/.dotfiles_backup/${FILE}
|
|
|
+ else
|
|
|
+ echo "Non conflict error at checkout"
|
|
|
+ exit 3
|
|
|
+ fi
|
|
|
+fi
|
|
|
+
|
|
|
+echo "Adding alias dotfiles"
|
|
|
+alias "dotfiles" "git --git-dir=${HOME}/.dotfiles --work-tree=${HOME}"
|