#!/usr/bin/env bash set -eu # Fallback values DOTFILES_FALLBACK_PATH="$HOME/.dotfiles" DOTFILES_FALLBACK_REPOSITORY="https://github.com/rokoucha/dotfiles" # Parse options and override fallback values while getopts p:r: OPT do case $OPT in p) DOTFILES_FALLBACK_PATH="$OPTARG" ;; r) DOTFILES_FALLBACK_REPOSITORY="$OPTARG" ;; \?) exit 1 ;; esac done shift $((OPTIND - 1)) # Get config path if [ "${XDG_CONFIG_HOME+defined}" ]; then DOTFILES_CONF_PATH="$XDG_CONFIG_HOME/dotfiles/config" else DOTFILES_CONF_PATH="$HOME/.config/dotfiles/config" fi # Load if config exists if [ -f "$DOTFILES_CONF_PATH" ]; then # shellcheck disable=SC1090 source "$DOTFILES_CONF_PATH" # Use fallback value elif [ -f "$DOTFILES_FALLBACK_PATH/Makefile" ]; then echo "===> Dotfiles config file doesn't exist, Use fallback path $DOTFILES_FALLBACK_PATH" echo "===> You have to execute 'dotfiles deploy' to fix this issue." DOTFILES_PATH="$DOTFILES_FALLBACK_PATH" # Fetch dotfiles else echo "===> Dotfiles doesn't exist..." echo "===> Fetch $DOTFILES_FALLBACK_REPOSITORY to $DOTFILES_FALLBACK_PATH" # Clone with git if type git >/dev/null 2>&1; then git clone "$DOTFILES_FALLBACK_REPOSITORY.git" "$DOTFILES_FALLBACK_PATH" # Fetch with curl & tar elif type curl >/dev/null 2>&1; then EXTRACT_PATH=$(dirname "$DOTFILES_FALLBACK_PATH") REPOSITORY_NAME=$(basename "$DOTFILES_FALLBACK_REPOSITORY") mkdir -p "$EXTRACT_PATH" curl -L "$DOTFILES_FALLBACK_REPOSITORY/archive/master.tar.gz" | tar vxz -C "$EXTRACT_PATH" mv "$EXTRACT_PATH/$REPOSITORY_NAME-master" "$DOTFILES_FALLBACK_PATH" # Cannot fetch dotfiles... else echo "===> You must install curl or git to fetch dotfiles..." exit 1 fi # Use fallback path DOTFILES_PATH="$DOTFILES_FALLBACK_PATH" fi pushd "$DOTFILES_PATH" > /dev/null || exit make --no-print-directory "$@" popd > /dev/null || exit