ref(install-script): install many targets with new tmp dir for each

This commit is contained in:
TheK4n 2023-10-12 01:48:25 +03:00
parent 691c7fef6c
commit 29cb008821

33
install
View File

@ -1,8 +1,6 @@
#!/bin/bash !/bin/bash
set -ue set -ueo pipefail
readonly SANDBOX_PATH="$(mktemp -d)"
readonly TARGET_PATH="$HOME" readonly TARGET_PATH="$HOME"
@ -15,10 +13,15 @@ declare -A TARGETS=(
["tmux"]=".tmux.conf" ["tmux"]=".tmux.conf"
["alacritty"]=".config/alacritty" ["alacritty"]=".config/alacritty"
["nvim"]=".config/nvim .local/bin/vim_askpass_helper .local/bin/vim_askpass_helper_python" ["nvim"]=".config/nvim .local/bin/vim_askpass_helper .local/bin/vim_askpass_helper_python"
["ssh"]=""
["git"]=".gitconfig .githooks .gitignore" ["git"]=".gitconfig .githooks .gitignore"
["ranger"]=".config/ranger" ["ranger"]=".config/ranger"
["gpg"]=""
["i3"]=".config/i3 .config/i3status .local/bin/i3status_wrapper .config/picom .local/bin/slm" ["i3"]=".config/i3 .config/i3status .local/bin/i3status_wrapper .config/picom .local/bin/slm"
["bat"]=".config/bat" ["bat"]=".config/bat"
["font"]=""
["termux"]=""
["arch"]=""
["psql"]=".psqlrc" ["psql"]=".psqlrc"
["docker"]=".docker/cli-plugins" ["docker"]=".docker/cli-plugins"
) )
@ -54,7 +57,9 @@ _compare_sandbox_to_home() {
} }
_merge_sandbox_to_home() { _merge_sandbox_to_home() {
set +e
cp -RTnP "$SANDBOX_PATH" "$TARGET_PATH" cp -RTnP "$SANDBOX_PATH" "$TARGET_PATH"
set -e
} }
__install_from_sandbox() { __install_from_sandbox() {
@ -64,13 +69,11 @@ __install_from_sandbox() {
if [ -n "$comparisons" ]; then if [ -n "$comparisons" ]; then
echo "$comparisons" >&2 echo "$comparisons" >&2
echo "Reverting..." >&2 echo "Reverting..." >&2
rm -rf "$SANDBOX_PATH"
_die "Found conflicting files. Exiting" 1 _die "Found conflicting files. Exiting" 1
fi fi
echo "Merging to home..." echo "Merging to home..."
_merge_sandbox_to_home _merge_sandbox_to_home
rm -rf "$SANDBOX_PATH"
} }
cmd_bash() { cmd_bash() {
@ -219,6 +222,7 @@ cmd_list() {
cmd_install() { cmd_install() {
for target in "$@"; do for target in "$@"; do
SANDBOX_PATH="$(mktemp -d)"
case "$target" in case "$target" in
bash) shift; cmd_bash "$@" ;; bash) shift; cmd_bash "$@" ;;
zsh) shift; cmd_zsh "$@" ;; zsh) shift; cmd_zsh "$@" ;;
@ -238,24 +242,27 @@ cmd_install() {
docker) shift; cmd_docker "$@" ;; docker) shift; cmd_docker "$@" ;;
*) shift; cmd_no_target "$@" ;; *) shift; cmd_no_target "$@" ;;
esac esac
rm -rf "$SANDBOX_PATH"
done done
} }
cmd_help() { cmd_help() {
echo "Dotfiles installation script: echo "Dotfiles installation script:
Usage: ./install.sh install TARGET... Usage: ./install TARGET...
Usage: ./install.sh unlink TARGET Usage: ./install unlink TARGET
Usage: ./install.sh check TARGET" Usage: ./install check TARGET
Usage: ./install list"
} }
unset executed_command
readonly executed_command="$1"
case "$1" in case "$executed_command" in
install) shift; cmd_install "$@" ;;
unlink) shift; cmd_unlink "$@" ;; unlink) shift; cmd_unlink "$@" ;;
check) shift; cmd_check "$@" ;; check) shift; cmd_check "$@" ;;
list) shift; cmd_list "$@" ;; list) shift; cmd_list "$@" ;;
help) shift; cmd_help "$@" ;; help) shift; cmd_help "$@" ;;
*) shift; cmd_help "$@" ;; *) shift; cmd_install "$executed_command" "$@" ;;
esac esac
exit 0 exit 0