1
0
Fork 0
dotfiles/.local/bin/dotsync

59 lines
1.5 KiB
Plaintext
Raw Normal View History

2023-03-28 14:24:58 +02:00
#!/bin/sh
BOLD='\033[1m'
GREEN='\033[32m'
BLUE='\033[34m'
RED='\033[31m'
NC='\033[0m'
2023-05-31 09:41:28 +02:00
printf "%b" "$BOLD${BLUE}Changing directory to $DOTFILES_DIR$NC\n"
if ! cd "$DOTFILES_DIR"; then
printf "%b" "${RED}Could not CD into $DOTFILES_DIR$NC\n"
2023-04-12 11:37:10 +02:00
exit
2023-03-28 19:13:13 +02:00
fi
2023-03-29 00:08:17 +02:00
printf "\n"
2023-03-28 14:24:58 +02:00
printf "%b" "$BOLD${BLUE}Stashing existing changes...$NC\n"
2023-03-28 14:24:58 +02:00
stash_result=$(git stash push -m "sync-dotfiles: Before syncing dotfiles")
needs_pop=1
if [ "$stash_result" = "No local changes to save" ]; then
2023-04-12 11:37:10 +02:00
needs_pop=0
2023-03-28 14:24:58 +02:00
fi
2023-03-29 00:08:17 +02:00
printf "\n"
2023-03-28 14:24:58 +02:00
printf "%b" "$BOLD${BLUE}Pulling updates from dotfiles repo...$NC\n"
git pull origin main --recurse-submodules=yes
2023-03-29 00:08:17 +02:00
printf "\n"
2023-03-28 14:24:58 +02:00
if [ $needs_pop -eq 1 ]; then
printf "%b" "$BOLD${BLUE}Popping stashed changes...$NC\n"
2023-04-12 11:37:10 +02:00
git stash pop
2023-03-28 14:24:58 +02:00
fi
2023-03-29 00:08:17 +02:00
printf "\n"
2023-03-28 14:24:58 +02:00
unmerged_files=$(git diff --name-only --diff-filter=U)
if [ -n "$unmerged_files" ]; then
printf "%b" "${RED}The following files have merge conflicts after popping the stash:$NC\n"
2023-04-12 11:37:10 +02:00
printf "\n"
printf "$unmerged_files\n"
2023-03-28 14:24:58 +02:00
else
stow --dotfiles -t "$HOME" . || printf "%b" "${RED}Failed to run stow!$NC\n"
2023-03-28 14:24:58 +02:00
fi
printf "%b" "$BOLD${BLUE}Generating firefox profiles...$NC\n\n"
2023-05-31 09:41:28 +02:00
"$DOTFILES_DIR/.mozilla/firefox/generate.sh"
2023-03-29 00:08:17 +02:00
printf "\n"
printf "${BOLD}Recompile/Install src files? ${GREEN}Y/N?$NC\n"
read ans
2023-05-31 09:41:28 +02:00
[ "$ans" = "y" ] && for f in "$DOTFILES_DIR"/.local/src/*; do
2023-04-12 11:37:10 +02:00
if ! cd "$f"; then
printf "%b" "${RED}Could not CD into $f$NC\n"
2023-04-12 11:37:10 +02:00
exit
fi
sudo make install
2023-03-29 00:09:07 +02:00
make clean
2023-03-29 00:08:17 +02:00
done
printf "%b" "$BOLD${BLUE}Dotfiles Synced Successfully!$NC\n"