2022-05-15 01:36:38 -07:00
|
|
|
|
#!/bin/bash
|
2024-01-17 03:42:55 -08:00
|
|
|
|
# updates some important repositories in my home folder (and elsewhere) that exist on multiple devices
|
2022-05-15 01:36:38 -07:00
|
|
|
|
|
2022-10-04 17:53:42 -07:00
|
|
|
|
set -eu
|
2022-05-22 18:57:27 -07:00
|
|
|
|
|
|
|
|
|
# Check for git
|
|
|
|
|
if ! command -v git > /dev/null; then
|
|
|
|
|
echo "git is not installed, please install git and try again"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Set colors
|
2022-05-15 02:05:37 -07:00
|
|
|
|
if command -v tput > /dev/null; then
|
2022-10-04 17:53:42 -07:00
|
|
|
|
YELLOW="$(tput setaf 3)"
|
2022-05-15 02:05:37 -07:00
|
|
|
|
GREEN="$(tput setaf 2)"
|
|
|
|
|
NC="$(tput sgr0)"
|
2022-06-22 11:12:33 -07:00
|
|
|
|
elif [ -n "$TERMUX_VERSION" ]; then
|
2022-10-04 17:53:42 -07:00
|
|
|
|
YELLOW="[33m"
|
2022-06-22 00:36:53 -07:00
|
|
|
|
GREEN="[32m"
|
|
|
|
|
NC="(B[m"
|
2022-05-15 02:05:37 -07:00
|
|
|
|
fi
|
|
|
|
|
|
2022-10-04 17:53:42 -07:00
|
|
|
|
# Avoiding copy pasting this over and over
|
|
|
|
|
g() { git -C "$REPO" "$@"; }
|
|
|
|
|
|
2025-01-25 23:34:46 -08:00
|
|
|
|
REPOS_TO_UPDATE="${REPOS_TO_UPDATE:-}"
|
|
|
|
|
|
2025-01-22 11:40:10 -08:00
|
|
|
|
# path_append from https://superuser.com/questions/39751/add-directory-to-path-if-its-not-already-there
|
|
|
|
|
# checks if a path is already in the PATH and if it exists
|
|
|
|
|
path_append() {
|
|
|
|
|
if [ -d "$1" ]; then
|
|
|
|
|
# shellcheck disable=SC3010
|
|
|
|
|
if command '[[' > /dev/null 2>&1 && [[ ":$REPOS_TO_UPDATE:" != *":$1:"* ]]; then
|
|
|
|
|
REPOS_TO_UPDATE="${REPOS_TO_UPDATE:+"$REPOS_TO_UPDATE:"}$1"
|
|
|
|
|
else
|
|
|
|
|
REPOS_TO_UPDATE="$REPOS_TO_UPDATE:$1"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-04 17:53:42 -07:00
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
|
REPO_ABBR='echo ${REPO/"$HOME"/"~"}'
|
|
|
|
|
|
2025-01-22 11:40:10 -08:00
|
|
|
|
path_append "${DOCS_DIR:-}"
|
|
|
|
|
path_append "$HOME/bin"
|
|
|
|
|
path_append "${NIXOS_DIR:-}"
|
|
|
|
|
path_append "$HOME/code/faust-ideas"
|
|
|
|
|
path_append "$HOME/code/nixvim-config"
|
|
|
|
|
path_append "$HOME/.config/nvim"
|
|
|
|
|
|
2022-05-24 22:28:03 -07:00
|
|
|
|
# `git pull` everything mentioned in the REPOS_TO_UPDATE variable
|
2025-01-22 11:40:10 -08:00
|
|
|
|
IFS=: read -ra REPOS_TO_UPDATE_ARR <<< "${REPOS_TO_UPDATE:-}"
|
2022-05-15 01:36:38 -07:00
|
|
|
|
for REPO in "${REPOS_TO_UPDATE_ARR[@]}"; do
|
2022-05-22 18:57:27 -07:00
|
|
|
|
if [ -n "$REPO" ]; then
|
2022-10-04 17:53:42 -07:00
|
|
|
|
if g rev-parse > /dev/null 2>&1; then
|
|
|
|
|
echo " ${GREEN}Pulling $(eval "$REPO_ABBR")‥${NC}"
|
|
|
|
|
g pull
|
|
|
|
|
g diff --quiet || echo "${YELLOW}Warning: Working tree for $(eval "$REPO_ABBR") is dirty${NC}"
|
2022-05-22 18:57:27 -07:00
|
|
|
|
fi
|
2022-05-15 02:05:37 -07:00
|
|
|
|
fi
|
2022-10-04 17:53:42 -07:00
|
|
|
|
UPDATED_STUFF=true
|
2022-05-15 01:36:38 -07:00
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# check for dotfiles updates
|
2022-10-04 17:53:42 -07:00
|
|
|
|
${UPDATED_STUFF:-false} && echo
|
2022-05-22 18:57:27 -07:00
|
|
|
|
echo " ${GREEN}Updating dotfiles…${NC}"
|
|
|
|
|
dotfiles pull
|
2022-10-04 17:53:42 -07:00
|
|
|
|
dotfiles diff --quiet || echo "${YELLOW}Warning: Working tree for dotfiles is dirty${NC}"
|