- Follow XDG standard: ~/.config and ~/.local folders - Set environment variables and define aliases within ~/.config/shell - Add installation script for easy setup - Add README.md with info on the installation and general notes
91 lines
2.3 KiB
Bash
Executable file
91 lines
2.3 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
# Installation script to make the dotfiles available in ~/
|
|
#
|
|
# `git` is the only dependency for this script to run (See: https://git-scm.com)
|
|
#
|
|
# See: https://code.webartifex.biz/alexander/dotfiles#installation
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" # also set in ~/.config/shell/env
|
|
|
|
DOTFILES_DIR="$XDG_DATA_HOME/dotfiles" # also set in ~/.config/shell/env
|
|
|
|
# Defaults to the minimal/server version on the "main" branch
|
|
# => Set DOTFILES_BRANCH=desktop explicitly when installing on a desktop machine
|
|
DOTFILES_BRANCH="${DOTFILES_BRANCH:-main}"
|
|
|
|
DOTFILES_HTTPS="https://code.webartifex.biz/alexander/dotfiles"
|
|
DOTFILES_SSH="git@git.webartifex.biz:alexander/dotfiles.git"
|
|
|
|
BACKUP_DIR="$HOME/.dotfiles-backup-$(date +%Y%m%d-%H%M%S)"
|
|
|
|
|
|
if [ -d "$DOTFILES_DIR" ]; then
|
|
|
|
if [ "${FORCE_INSTALL:-}" != "1" ]; then
|
|
echo ""
|
|
echo "The dotfiles are already installed at: $DOTFILES_DIR"
|
|
echo ""
|
|
echo "Options:"
|
|
echo " - Set 'export FORCE_INSTALL=1' and run installation again"
|
|
echo " - Update with 'dotfiles pull' and continue using them"
|
|
echo ""
|
|
|
|
exit 0
|
|
fi
|
|
|
|
echo "Backing up the existing repository to: $BACKUP_DIR"
|
|
mkdir -p "$BACKUP_DIR"
|
|
mv "$DOTFILES_DIR" "$BACKUP_DIR/dotfiles"
|
|
|
|
fi
|
|
|
|
|
|
git clone --bare "$DOTFILES_HTTPS" "$DOTFILES_DIR"
|
|
|
|
|
|
_git() {
|
|
git --git-dir="$DOTFILES_DIR" --work-tree="$HOME" "$@"
|
|
}
|
|
|
|
|
|
if ! _git show-ref --verify --quiet "refs/heads/$DOTFILES_BRANCH"; then
|
|
echo ""
|
|
echo "Branch '$DOTFILES_BRANCH' does not exist in the repository"
|
|
echo ""
|
|
echo "Available branches:"
|
|
_git branch --format=' %(refname:short)'
|
|
echo ""
|
|
|
|
exit 1
|
|
fi
|
|
|
|
|
|
# Do not checkout project documentation intended for web GUIs
|
|
_git config core.sparseCheckout true
|
|
{
|
|
echo "/*"
|
|
echo "!LICENSE.txt"
|
|
echo "!README.md"
|
|
} > "$DOTFILES_DIR/info/sparse-checkout"
|
|
|
|
# Put the dotfiles in the user's $HOME folder
|
|
_git checkout --force "$DOTFILES_BRANCH"
|
|
|
|
# Do not show files not tracked in the dotfiles repository because there are simply too many
|
|
_git config --local status.showUntrackedFiles no
|
|
|
|
# Prefer `ssh` for syncing between the machines
|
|
_git remote set-url origin "$DOTFILES_SSH"
|
|
|
|
|
|
echo ""
|
|
echo "The dotfiles were installed successfully (branch: $DOTFILES_BRANCH)"
|
|
echo ""
|
|
echo "Reload your shell to start using them:"
|
|
echo " exec \$SHELL -l"
|
|
echo ""
|