Improved fallback, for when DOTFILES_DIR not set

This commit is contained in:
Alicia Sykes 2022-11-18 00:08:45 +00:00
parent e1bae4e2cb
commit 2ec0bdbb3d

View File

@ -194,30 +194,40 @@ function pre_setup_tasks () {
echo -e "${YELLOW_B}XDG_DATA_HOME is not yet set. Will use ~/.local/share${RESET}" echo -e "${YELLOW_B}XDG_DATA_HOME is not yet set. Will use ~/.local/share${RESET}"
export XDG_DATA_HOME="${HOME}/.local/share" export XDG_DATA_HOME="${HOME}/.local/share"
fi fi
# Ensure dotfiles source directory is set and valid
if [[ ! -d "$SRC_DIR" ]] && [[ ! -d "$DOTFILES_DIR" ]]; then
echo -e "${YELLOW_B}Destination direcory not set,"\
"defaulting to $HOME/.dotfiles\n"\
"${CYAN_B}To specify where you'd like dotfiles to be downloaded to,"\
"set the DOTFILES_DIR environmental variable, and re-run.${RESET}"
DOTFILES_DIR="${HOME}/.dotfiles"
fi
} }
# Downloads / updates dotfiles and symlinks them # Downloads / updates dotfiles and symlinks them
function setup_dot_files () { function setup_dot_files () {
# Download / update dotfiles repo with git # If dotfiles not yet present, clone the repo
if [[ ! -d "$DOTFILES_DIR" ]] if [[ ! -d "$DOTFILES_DIR" ]]; then
then echo -e "${PURPLE}Dotfiles not yet present."\
echo -e "${PURPLE}Dotfiles not yet present. \ "Downloading ${REPO_NAME} into ${DOTFILES_DIR}${RESET}"
Will download ${REPO_NAME} into ${DOTFILES_DIR}${RESET}" echo -e "${YELLOW_B}You can change where dotfiles will be saved to,"\
mkdir -p "${DOTFILES_DIR}" "by setting the DOTFILES_DIR env var${RESET}"
git clone --recursive ${DOTFILES_REPO} ${DOTFILES_DIR} mkdir -p "${DOTFILES_DIR}" && \
else git clone --recursive ${DOTFILES_REPO} ${DOTFILES_DIR} && \
cd "${DOTFILES_DIR}"
else # Dotfiles already downloaded, just fetch latest changes
echo -e "${PURPLE}Pulling changes from ${REPO_NAME} into ${DOTFILES_DIR}${RESET}" echo -e "${PURPLE}Pulling changes from ${REPO_NAME} into ${DOTFILES_DIR}${RESET}"
cd "${DOTFILES_DIR}" && \ cd "${DOTFILES_DIR}" && \
git pull origin master && \ git pull origin master && \
echo -e "${PURPLE}Updating submodules${RESET}" && \
git submodule update --recursive --remote --init git submodule update --recursive --remote --init
fi fi
# If git clone / pull failed, then exit with error # If git clone / pull failed, then exit with error
ret=$? if ! test "$?" -eq 0; then
if ! test "$ret" -eq 0 echo -e >&2 "${RED_B}Failed to fetch dotfiels from git${RESET}"
then
echo -e >&2 "${RED_B}Failed to fetch dotfiels $ret${RESET}"
terminate terminate
fi fi