Merge branch 'install-script/install-hooks'

This commit is contained in:
TheK4n 2023-11-13 16:23:14 +03:00
commit 1a815688b6
10 changed files with 81 additions and 135 deletions

178
install
View File

@ -5,7 +5,9 @@ shopt -s nullglob
readonly TARGET_PATH="$HOME" readonly TARGET_PATH="$HOME"
readonly SUB="$(pwd)/home/user" readonly DOTFILES_ROOT="$(pwd)"
readonly SUB="$DOTFILES_ROOT/home/user"
export SUB
declare -A TARGETS=( declare -A TARGETS=(
@ -36,12 +38,6 @@ _die() {
test "$0" = "./install" || _die "Error: Please, run this file from root of dotfiles, like this './install.sh TARGET" 1 test "$0" = "./install" || _die "Error: Please, run this file from root of dotfiles, like this './install.sh TARGET" 1
_die_if_installed() {
if [ -e "$1" ]; then
_die "Already installed" 1
fi
}
_link_files_in_sandbox() { _link_files_in_sandbox() {
local targetfile local targetfile
for targetfile in "$@" for targetfile in "$@"
@ -61,7 +57,7 @@ _link_files_in_sandbox() {
_compare_sandbox_to_home() { _compare_sandbox_to_home() {
local comparisons local comparisons
comparisons="$(diff -rq "$SANDBOX_PATH" "$TARGET_PATH")" comparisons="$(diff -rq "$SANDBOX_PATH" "$TARGET_PATH")"
echo "$comparisons" | grep -vE "^Only in .+" echo "$comparisons" | grep -vE "^Only in .+" || true
} }
_merge_sandbox_to_home() { _merge_sandbox_to_home() {
@ -71,12 +67,11 @@ _merge_sandbox_to_home() {
} }
__install_from_sandbox() { __install_from_sandbox() {
local comparisons
local comparisons="$(_compare_sandbox_to_home)" comparisons="$(_compare_sandbox_to_home)"
if [ -n "$comparisons" ]; then if [ -n "$comparisons" ]; then
echo "$comparisons" >&2 echo "$comparisons" >&2
echo "Reverting..." >&2
_die "Found conflicting files. Exiting" 1 _die "Found conflicting files. Exiting" 1
fi fi
@ -85,107 +80,27 @@ __install_from_sandbox() {
echo "Successfully installed" echo "Successfully installed"
} }
cmd_bash() { _execute_hook_if_executable() {
_link_files_in_sandbox ${TARGETS["bash"]} local hook_path="$DOTFILES_ROOT/install-hooks/$1/$2"
__install_from_sandbox if [ -x "$hook_path" ]; then
} echo "Executing $2 for target '$1'"
"$hook_path"
cmd_zsh() { fi
_link_files_in_sandbox ${TARGETS["zsh"]} }
__install_from_sandbox
} execute_pre_hook() {
_execute_hook_if_executable "$1" "pre-install"
}
cmd_tmux() {
_link_files_in_sandbox ${TARGETS["tmux"]} execute_post_hook() {
__install_from_sandbox _execute_hook_if_executable "$1" "post-install"
} }
cmd_alacritty() { install_target() {
_link_files_in_sandbox ${TARGETS["alacritty"]} execute_pre_hook "$1"
__install_from_sandbox _link_files_in_sandbox ${TARGETS["$1"]}
}
cmd_nvim() {
echo "sudo pacman -S npm ctags fzf glow; mkdir ~/.npm-global; npm config set prefix '~/.npm-global'"
_link_files_in_sandbox ${TARGETS["nvim"]}
__install_from_sandbox
}
cmd_ssh() {
cat "$SUB/.ssh/config" >> "$HOME/.ssh/config"
}
cmd_git() {
_link_files_in_sandbox ${TARGETS["git"]}
__install_from_sandbox
}
cmd_ranger() {
echo "sudo pacman -S highlight ttf-joypixels noto-fonts-emoji ueberzug poppler"
_link_files_in_sandbox ${TARGETS["ranger"]}
mkdir -p "$SANDBOX_PATH/.config/ranger/plugins"
git clone https://github.com/alexanderjeurissen/ranger_devicons "$SANDBOX_PATH/.config/ranger/plugins/ranger_devicons"
__install_from_sandbox
ranger --copy-config=all
}
cmd_gpg() {
_die_if_installed "$HOME/.gnupg"
cat "$SUB/.gnupg/gpg.conf" >> "$HOME/.gnupg/gpg.conf"
echo -e "default-cache-ttl 1\nmax-cache-ttl 1" > "$HOME/.gnupg/gpg-agent.conf"; echo RELOADAGENT | gpg-connect-agent
}
cmd_i3() {
echo "sudo pacman -S nitrogen picom compton ttf-font-awesome xdotool xclip maim playerctl"
_link_files_in_sandbox ${TARGETS["i3"]}
__install_from_sandbox
}
cmd_bat() {
_link_files_in_sandbox ${TARGETS["bat"]}
__install_from_sandbox
}
cmd_ipython() {
_link_files_in_sandbox ${TARGETS["ipython"]}
__install_from_sandbox
}
cmd_font() {
local sub
sub="$HOME/.local/share/fonts"
mkdir -p "$sub"
cd "$sub"
wget 'https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/FiraCode.zip'
unzip FiraCode.zip -d "$sub"
git clone 'https://github.com/powerline/fonts.git' --depth=1
cd fonts
./install.sh
}
cmd_termux() {
echo "apt install termux-api tsu"
}
cmd_arch() {
echo 'echo "ParallelDownloads = 5" >> /etc/pacman.conf'
echo 'sudo systemctl enable --now gpm'
}
cmd_psql() {
_link_files_in_sandbox ${TARGETS["psql"]}
__install_from_sandbox
}
cmd_docker() {
_link_files_in_sandbox ${TARGETS["docker"]}
__install_from_sandbox __install_from_sandbox
execute_post_hook "$1"
} }
is_target_installed() { is_target_installed() {
@ -215,7 +130,7 @@ find_targets_that_depend_on() {
local target local target
for target in "${!TARGETS[@]}" for target in "${!TARGETS[@]}"
do do
if [[ " ${TARGETS["$target"]} " =~ %$1 ]]; then if [[ " ${TARGETS["$target"]} " =~ " %$1 " ]]; then
echo "$target" echo "$target"
fi fi
done done
@ -253,37 +168,30 @@ cmd_no_target() {
_die "TARGET not exists" 1 _die "TARGET not exists" 1
} }
cmd_list() { cmd_list() {
echo "${!TARGETS[@]}" echo "${!TARGETS[@]}"
} }
target_exists() {
if [[ " ${!TARGETS[*]} " =~ " $1 " ]]; then
true
else
false
fi
}
cmd_install() { cmd_install() {
local target local target
for target in "$@" for target in "$@"
do do
SANDBOX_PATH="$(mktemp -td "${USER:=user}.dotfiles_XXXXXXX")" if target_exists "$target"; then
case "$target" in SANDBOX_PATH="$(mktemp -td "${USER:=user}.dotfiles_XXXXXXX")"
bash) shift; cmd_bash "$@" ;; export SANDBOX_PATH
zsh) shift; cmd_zsh "$@" ;; install_target "$target"
tmux) shift; cmd_tmux "$@" ;; rm -rf "$SANDBOX_PATH"
alacritty) shift; cmd_alacritty "$@" ;; else
nvim) shift; cmd_nvim "$@" ;; cmd_no_target
ssh) shift; cmd_ssh "$@" ;; fi
git) shift; cmd_git "$@" ;;
ranger) shift; cmd_ranger "$@" ;;
gpg) shift; cmd_gpg "$@" ;;
i3) shift; cmd_i3 "$@" ;;
bat) shift; cmd_bat "$@" ;;
font) shift; cmd_font "$@" ;;
termux) shift; cmd_termux "$@" ;;
arch) shift; cmd_arch "$@" ;;
psql) shift; cmd_psql "$@" ;;
docker) shift; cmd_docker "$@" ;;
ipython) shift; cmd_ipython "$@" ;;
*) shift; cmd_no_target "$@" ;;
esac
rm -rf "$SANDBOX_PATH"
done done
} }

4
install-hooks/arch/pre-install Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
echo 'echo "ParallelDownloads = 5" >> /etc/pacman.conf'
echo 'sudo systemctl enable --now gpm'

11
install-hooks/font/pre-install Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
sub="$HOME/.local/share/fonts"
mkdir -p "$sub"
cd "$sub"
wget 'https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/FiraCode.zip'
unzip FiraCode.zip -d "$sub"
git clone 'https://github.com/powerline/fonts.git' --depth=1
cd fonts
./install.sh

4
install-hooks/gpg/post-install Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
cat "$SUB/.gnupg/gpg.conf" >> "$HOME/.gnupg/gpg.conf"
echo -e "default-cache-ttl 1\nmax-cache-ttl 1" > "$HOME/.gnupg/gpg-agent.conf"; echo RELOADAGENT | gpg-connect-agent

3
install-hooks/i3/pre-install Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
echo "sudo pacman -S nitrogen picom compton ttf-font-awesome xdotool xclip maim playerctl"

3
install-hooks/nvim/pre-install Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
echo "sudo pacman -S npm ctags fzf glow; mkdir ~/.npm-global; npm config set prefix '~/.npm-global'"

View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
mkdir -p "$SANDBOX_PATH/.config/ranger/plugins"
git clone https://github.com/alexanderjeurissen/ranger_devicons "$SANDBOX_PATH/.config/ranger/plugins/ranger_devicons"

View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
echo "sudo pacman -S highlight ttf-joypixels noto-fonts-emoji ueberzug poppler"

3
install-hooks/ssh/pre-install Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
cat "$SUB/.ssh/config" >> "$HOME/.ssh/config"

View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
echo "apt install termux-api tsu"