270 lines
9.9 KiB
Bash
Executable file
270 lines
9.9 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -o errexit
|
|
set -o pipefail
|
|
set -o nounset
|
|
|
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
backup_dir="$HOME/.dotfiles/backups"
|
|
|
|
# Colors for output. So fancy.
|
|
|
|
COLOR_SUCCESS='\033[0;32m'
|
|
COLOR_ERROR='\033[0;31m'
|
|
COLOR_NOTIFY='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Default settings for this script:
|
|
# - Do not create backups automatically.
|
|
# - Install everything.
|
|
|
|
auto_backup=false
|
|
config_selection="all"
|
|
|
|
# Dotfile locations. Note that these locations should be identical between the
|
|
# home directory and the dotfile directory.
|
|
|
|
bashrc=".bashrc"
|
|
bashrc_name="bashrc"
|
|
bashrc_source="${__dir}/${bashrc}"
|
|
bashrc_target="${HOME}/${bashrc}"
|
|
bashrc_backup="${backup_dir}/${bashrc_name}"
|
|
|
|
ps1=".startup/ps1"
|
|
ps1_name="ps1"
|
|
ps1_source="${__dir}/${ps1}"
|
|
ps1_target="${HOME}/${ps1}"
|
|
ps1_backup="${backup_dir}/${ps1_name}"
|
|
|
|
profile=".profile"
|
|
profile_name="profile"
|
|
profile_source="${__dir}/${profile}"
|
|
profile_target="${HOME}/${profile}"
|
|
profile_backup="${backup_dir}/${profile_name}"
|
|
|
|
i3=".config/i3/config"
|
|
i3_name="i3"
|
|
i3_source="${__dir}/${i3}"
|
|
i3_target="${HOME}/${i3}"
|
|
i3_backup="${backup_dir}/${i3_name}"
|
|
|
|
i3status=".config/i3status/config"
|
|
i3status_name="i3status"
|
|
i3status_source="${__dir}/${i3status}"
|
|
i3status_target="${HOME}/${i3status}"
|
|
i3status_backup="${backup_dir}/${i3status_name}"
|
|
|
|
xresources=".Xresources"
|
|
xresources_name="xresources"
|
|
xresources_source="${__dir}/${xresources}"
|
|
xresources_target="${HOME}/${xresources}"
|
|
xresources_backup="${backup_dir}/${xresources_name}"
|
|
|
|
gitconfig=".gitconfig"
|
|
gitconfig_name="gitconfig"
|
|
gitconfig_source="${__dir}/${gitconfig}"
|
|
gitconfig_target="${HOME}/${gitconfig}"
|
|
gitconfig_backup="${backup_dir}/${gitconfig_name}"
|
|
|
|
gitignore=".gitignore"
|
|
gitignore_name="gitignore"
|
|
gitignore_source="${__dir}/${gitignore}"
|
|
gitignore_target="${HOME}/${gitignore}"
|
|
gitignore_backup="${backup_dir}/${gitignore_name}"
|
|
|
|
alacritty=".config/alacritty/alacritty.yml"
|
|
alacritty_name="alacritty"
|
|
alacritty_source="${__dir}/${alacritty}"
|
|
alacritty_target="${HOME}/${alacritty}"
|
|
alacritty_backup="${backup_dir}/${alacritty_name}"
|
|
|
|
fontconfig=".config/fontconfig/fonts.conf"
|
|
fontconfig_name="fontconfig"
|
|
fontconfig_source="${__dir}/${fontconfig}"
|
|
fontconfig_target="${HOME}/${fontconfig}"
|
|
fontconfig_backup="${backup_dir}/${fontconfig_name}"
|
|
|
|
ssh_agent=".startup/start-ssh-agent"
|
|
ssh_agent_name="ssh_agent"
|
|
ssh_agent_source="${__dir}/${ssh_agent}"
|
|
ssh_agent_target="${HOME}/${ssh_agent}"
|
|
ssh_agent_backup="${backup_dir}/${ssh_agent_name}"
|
|
|
|
# Note: neovim is spread across several files, and this might be a rather
|
|
# inefficient way to do this. Alas, will deal with it for now.
|
|
nvim=".config/nvim/init.vim"
|
|
nvim_name="nvim"
|
|
nvim_source="${__dir}/${nvim}"
|
|
nvim_target="${HOME}/${nvim}"
|
|
nvim_backup="${backup_dir}/${nvim_name}"
|
|
|
|
nvim_json=".local/share/nvim/site/ftplugin/json.vim"
|
|
nvim_json_name="nvim_json"
|
|
nvim_json_source="${__dir}/${nvim_json}"
|
|
nvim_json_target="${HOME}/${nvim_json}"
|
|
nvim_json_backup="${backup_dir}/${nvim_json_name}"
|
|
|
|
nvim_tex=".local/share/nvim/site/ftplugin/tex.vim"
|
|
nvim_tex_name="nvim_tex"
|
|
nvim_tex_source="${__dir}/${nvim_tex}"
|
|
nvim_tex_target="${HOME}/${nvim_tex}"
|
|
nvim_tex_backup="${backup_dir}/${nvim_tex_name}"
|
|
|
|
nvim_lint=".local/share/nvim/site/plugin/nvim-lint.vim"
|
|
nvim_lint_name="nvim_lint"
|
|
nvim_lint_source="${__dir}/${nvim_lint}"
|
|
nvim_lint_target="${HOME}/${nvim_lint}"
|
|
nvim_lint_backup="${backup_dir}/${nvim_lint_name}"
|
|
|
|
nvim_web_devicons=".local/share/nvim/site/plugin/nvim-web-devicons.vim"
|
|
nvim_web_devicons_name="nvim_web_devicons"
|
|
nvim_web_devicons_source="${__dir}/${nvim_web_devicons}"
|
|
nvim_web_devicons_target="${HOME}/${nvim_web_devicons}"
|
|
nvim_web_devicons_backup="${backup_dir}/${nvim_web_devicons_name}"
|
|
|
|
nvim_telescope=".local/share/nvim/site/plugin/telescope.nvim.vim"
|
|
nvim_telescope_name="nvim_telescope"
|
|
nvim_telescope_source="${__dir}/${nvim_telescope}"
|
|
nvim_telescope_target="${HOME}/${nvim_telescope}"
|
|
nvim_telescope_backup="${backup_dir}/${nvim_telescope_name}"
|
|
|
|
nvim_trouble=".local/share/nvim/site/plugin/trouble.nvim.vim"
|
|
nvim_trouble_name="nvim_trouble"
|
|
nvim_trouble_source="${__dir}/${nvim_trouble}"
|
|
nvim_trouble_target="${HOME}/${nvim_trouble}"
|
|
nvim_trouble_backup="${backup_dir}/${nvim_trouble_name}"
|
|
|
|
nvim_gitgutter=".local/share/nvim/site/plugin/vim-gitgutter.vim"
|
|
nvim_gitgutter_name="nvim_gitgutter"
|
|
nvim_gitgutter_source="${__dir}/${nvim_gitgutter}"
|
|
nvim_gitgutter_target="${HOME}/${nvim_gitgutter}"
|
|
nvim_gitgutter_backup="${backup_dir}/${nvim_gitgutter_name}"
|
|
|
|
nvim_vimtex=".local/share/nvim/site/plugin/vimtex.vim"
|
|
nvim_vimtex_name="nvim_vimtex"
|
|
nvim_vimtex_source="${__dir}/${nvim_vimtex}"
|
|
nvim_vimtex_target="${HOME}/${nvim_vimtex}"
|
|
nvim_vimtex_backup="${backup_dir}/${nvim_vimtex_name}"
|
|
|
|
function display_configs {
|
|
echo 'Supported config targets: all, bashrc, ps1, profile, i3, i3status, xresources, gitconfig, gitignore, alacritty, fontconfig, ssh_agent, nvim, nvim_json, nvim_tex, nvim_lint, nvim_web_devicons, nvim_telescope, nvim_trouble, nvim_gitgutter, nvim_vimtex'
|
|
}
|
|
|
|
function display_usage {
|
|
echo 'Usage: install.sh [-c|--config <target>] [-a|--auto-backup]'
|
|
echo ' [-h|--help]'
|
|
echo ''
|
|
echo 'Install configurations.'
|
|
echo ''
|
|
echo ' -c|--config Describes what to install: Default=all'
|
|
echo ' -l|--list List available configs.'
|
|
echo ' -a|--auto-backup Automatically backup existing configs.'
|
|
echo ' -h|--help Display this usage text.'
|
|
echo ''
|
|
echo 'Examples:'
|
|
echo ''
|
|
echo "./install.sh --config=all --auto-backup"
|
|
}
|
|
|
|
# Install some singular configuration file by creating a symbolic link. Handles
|
|
# automatic backups if the file already exists.
|
|
function install_config {
|
|
|
|
# Used for diagnostic purposes only - describes the configuration.
|
|
local config_name="$1"
|
|
|
|
# The location of the configuration to install.
|
|
local config_source="$2"
|
|
|
|
# The destination where the symbolic link should be created.
|
|
local config_target="$3"
|
|
|
|
# The backup file for this piece of configuration.
|
|
local config_backup="$4"
|
|
|
|
if [ "$config_selection" = "all" ] || [ "${config_selection}" = "${config_name}" ]; then
|
|
echo -n -e "${COLOR_SUCCESS}[+]${NC} Installing '${config_name}' to '${config_target}'... "
|
|
if [ -f "${config_target}" ]; then
|
|
if $auto_backup; then
|
|
# The file exists, so create a backup and remove the file.
|
|
echo -e "\n\t${COLOR_NOTIFY}[Note]${NC} creating a backup of '${config_target}'"
|
|
cp "${config_target}" "${config_backup}"
|
|
rm "${config_target}"
|
|
ln -s "${config_source}" "${config_target}"
|
|
echo -e "\t${COLOR_SUCCESS}[Success]${NC}"
|
|
else
|
|
# The caller does not want backups/deletions, so we must abort.
|
|
echo -e "\n\t${COLOR_ERROR}[Error]${NC} Could not install configuration '${config_name}'. File '${config_target}' already exists. Please manually remove it or set --auto-backup"
|
|
fi
|
|
else
|
|
# The file doesn't exist, we can safely create a symlink.
|
|
ln -s "${config_source}" "${config_target}"
|
|
echo -e "${COLOR_SUCCESS}[Success]${NC}"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]
|
|
do
|
|
key="$1"
|
|
|
|
case $key in
|
|
-c|--config)
|
|
config_selection="$2"
|
|
shift
|
|
shift
|
|
;;
|
|
-a|--auto-backup)
|
|
auto_backup=true
|
|
shift
|
|
;;
|
|
-l|--list)
|
|
display_configs
|
|
exit 0
|
|
;;
|
|
-h|--help)
|
|
display_usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "Unrecognized option: $1"
|
|
display_usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Ensure the backup directory exists (if backups are requested).
|
|
if $auto_backup; then
|
|
if [ ! -d $backup_dir ]; then
|
|
if `mkdir $backup_dir`; then
|
|
echo -e "${COLOR_NOTIFY}[Note]${NC} created '$backup_dir' to store dotfile backups."
|
|
else
|
|
echo -e "${COLOR_ERROR}[Error]${NC} Failed to create backup directory '$backup_dir'."
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# Install all requested configurations.
|
|
install_config "${bashrc_name}" "${bashrc_source}" "${bashrc_target}" "${bashrc_backup}"
|
|
install_config "${ps1_name}" "${ps1_source}" "${ps1_target}" "${ps1_backup}"
|
|
install_config "${profile_name}" "${profile_source}" "${profile_target}" "${profile_backup}"
|
|
install_config "${i3_name}" "${i3_source}" "${i3_target}" "${i3_backup}"
|
|
install_config "${i3status_name}" "${i3status_source}" "${i3status_target}" "${i3status_backup}"
|
|
install_config "${gitconfig_name}" "${gitconfig_source}" "${gitconfig_target}" "${gitconfig_backup}"
|
|
install_config "${gitignore_name}" "${gitignore_source}" "${gitignore_target}" "${gitignore_backup}"
|
|
install_config "${xresources_name}" "${xresources_source}" "${xresources_target}" "${xresources_backup}"
|
|
install_config "${alacritty_name}" "${alacritty_source}" "${alacritty_target}" "${alacritty_backup}"
|
|
install_config "${fontconfig_name}" "${fontconfig_source}" "${fontconfig_target}" "${fontconfig_backup}"
|
|
install_config "${ssh_agent_name}" "${ssh_agent_source}" "${ssh_agent_target}" "${ssh_agent_backup}"
|
|
|
|
# Note that all of these configurations are Neovim-related:
|
|
install_config "${nvim_name}" "${nvim_source}" "${nvim_target}" "${nvim_backup}"
|
|
install_config "${nvim_json_name}" "${nvim_json_source}" "${nvim_json_target}" "${nvim_json_backup}"
|
|
install_config "${nvim_tex_name}" "${nvim_tex_source}" "${nvim_tex_target}" "${nvim_tex_backup}"
|
|
install_config "${nvim_lint_name}" "${nvim_lint_source}" "${nvim_lint_target}" "${nvim_lint_backup}"
|
|
install_config "${nvim_web_devicons_name}" "${nvim_web_devicons_source}" "${nvim_web_devicons_target}" "${nvim_web_devicons_backup}"
|
|
install_config "${nvim_telescope_name}" "${nvim_telescope_source}" "${nvim_telescope_target}" "${nvim_telescope_backup}"
|
|
install_config "${nvim_trouble_name}" "${nvim_trouble_source}" "${nvim_trouble_target}" "${nvim_trouble_backup}"
|
|
install_config "${nvim_gitgutter_name}" "${nvim_gitgutter_source}" "${nvim_gitgutter_target}" "${nvim_gitgutter_backup}"
|
|
install_config "${nvim_vimtex_name}" "${nvim_vimtex_source}" "${nvim_vimtex_target}" "${nvim_vimtex_backup}"
|