From 66921867111b7dc3f403b7e73002d4810581a2b7 Mon Sep 17 00:00:00 2001 From: thek4n Date: Sat, 10 Feb 2024 15:59:29 +0300 Subject: [PATCH] migrate to stow --- README.md | 28 +--- install | 210 ------------------------------ install-hooks/arch/pre-install | 4 - install-hooks/font/pre-install | 11 -- install-hooks/git/post-install | 8 -- install-hooks/gpg/post-install | 4 - install-hooks/i3/pre-install | 3 - install-hooks/nvim/pre-install | 3 - install-hooks/ranger/post-install | 4 - install-hooks/ranger/pre-install | 3 - install-hooks/ssh/post-install | 3 - install-hooks/termux/post-install | 7 - install-hooks/termux/pre-install | 3 - install-hooks/zsh/post-install | 5 - 14 files changed, 2 insertions(+), 294 deletions(-) delete mode 100755 install delete mode 100755 install-hooks/arch/pre-install delete mode 100755 install-hooks/font/pre-install delete mode 100644 install-hooks/git/post-install delete mode 100755 install-hooks/gpg/post-install delete mode 100755 install-hooks/i3/pre-install delete mode 100755 install-hooks/nvim/pre-install delete mode 100755 install-hooks/ranger/post-install delete mode 100755 install-hooks/ranger/pre-install delete mode 100755 install-hooks/ssh/post-install delete mode 100755 install-hooks/termux/post-install delete mode 100755 install-hooks/termux/pre-install delete mode 100755 install-hooks/zsh/post-install diff --git a/README.md b/README.md index 107402d..1094111 100644 --- a/README.md +++ b/README.md @@ -50,31 +50,7 @@ echo "Hello $USER!" ```bash git clone https://github.com/TheK4n/dotfiles cd dotfiles -./install zsh nvim ... +stow -R --target ~/.config home/user/.config ``` - -## Installation script -Per-user dotfiles "package" manager - -### Features -1. Installing files from dotfiles/home/user to $HOME -2. Uninstalling installed files -3. Check installation integrity -4. Transaction based installation -5. Does not overwrite your configs - -### Dependencies -* bash -* coreutils -* diffutils -* grep - - -### Optional dependencies -* git -* wget -* unzip - - -

+

\ No newline at end of file diff --git a/install b/install deleted file mode 100755 index baa5540..0000000 --- a/install +++ /dev/null @@ -1,210 +0,0 @@ -#!/bin/bash - -set -ueo pipefail -shopt -s nullglob - -declare -r TARGET_PATH="$HOME" -declare -r DOTFILES_ROOT="$PWD" -declare -xr SUB="$DOTFILES_ROOT/home/user" - - -declare -r -A TARGETS=( - ["bash"]=".config/bash .bashrc .profile" - ["zsh"]="%bash .config/zsh .zshenv .inputrc" - ["tmux"]=".tmux.conf" - ["alacritty"]=".config/alacritty" - ["nvim"]=".config/nvim .editorconfig .local/bin/vim_askpass_helper" - ["ssh"]="" - ["less"]=".lesskey" - ["git"]=".config/git" - ["ranger"]=".config/ranger" - ["gpg"]="" - ["i3"]=".xinitrc .xprofile .Xresources .config/i3 .config/i3status .local/bin/i3status_wrapper .config/rofi .config/picom .local/bin/slm .local/bin/slm_rofi.sh .local/bin/power_rofi.sh .local/bin/wifi .local/bin/bluetooth .local/bin/i3_switch_workspace.sh" - ["bat"]=".config/bat" - ["font"]="" - ["termux"]=".termux" - ["arch"]="" - ["psql"]=".psqlrc" - ["docker"]=".docker/cli-plugins" - ["ipython"]=".ipython/profile_default/ipython_config.py" - ["gdb"]=".config/gdb" -) - -_die() { - echo "$0: $1" >&2 - exit $2 -} - -test "$0" = "./install" || _die "Error: Please, run this file from root of dotfiles, like this './install.sh TARGET" 1 - - -_link_files_in_sandbox() { - local targetfile - for targetfile in "$@" - do - echo "installing: $targetfile" - if [ "${targetfile::1}" = "%" ]; then - _link_files_in_sandbox ${TARGETS["${targetfile:1}"]} - else - if [ ! "$(dirname "$targetfile")" = "." ]; then - mkdir -p "$SANDBOX_PATH/$(dirname "$targetfile")" - fi - ln -sT "$SUB/$targetfile" "$SANDBOX_PATH/$targetfile" - fi - done -} - -_compare_sandbox_to_home() { - local comparisons - comparisons="$(diff -rq "$SANDBOX_PATH" "$TARGET_PATH")" - echo "$comparisons" | grep -vE "^Only in .+" || true -} - -_merge_sandbox_to_home() { - cp -RTnP "$SANDBOX_PATH" "$TARGET_PATH" || true -} - -__install_from_sandbox() { - local comparisons - comparisons="$(_compare_sandbox_to_home)" - - if [ -n "$comparisons" ]; then - echo "$comparisons" >&2 - _die "Found conflicting files. Exiting" 1 - fi - - echo "Merging to home..." - _merge_sandbox_to_home - echo "Successfully installed" -} - -_execute_hook_if_executable() { - local hook_path="$DOTFILES_ROOT/install-hooks/$1/$2" - if [ -x "$hook_path" ]; then - echo "Executing $2 for target '$1'" - "$hook_path" - fi -} - -execute_pre_hook() { - _execute_hook_if_executable "$1" "pre-install" -} - -execute_post_hook() { - _execute_hook_if_executable "$1" "post-install" -} - -install_target() { - execute_pre_hook "$1" - _link_files_in_sandbox ${TARGETS["$1"]} - __install_from_sandbox - execute_post_hook "$1" -} - -is_target_installed() { - local not_fully_installed=false - - local targetfile - for targetfile in ${TARGETS["$1"]} - do - if [ "${targetfile::1}" = "%" ]; then - is_target_installed "${targetfile:1}" || not_fully_installed=true - else - if [ ! -e "$TARGET_PATH/$targetfile" ]; then - echo "$targetfile not linked" - not_fully_installed=true - fi - fi - done - if $not_fully_installed; then - echo "Target '$1' not fully installed" - echo - return 1 - fi - return 0 -} - -find_targets_that_depend_on() { - local target - for target in "${!TARGETS[@]}" - do - if [[ " ${TARGETS["$target"]} " =~ " %$1 " ]]; then - echo "$target" - fi - done -} - -die_if_installed_targets_depend_on() { - for reverse_dependecy in $(find_targets_that_depend_on "$1") - do - if is_target_installed "$reverse_dependecy" >/dev/null; then - _die "target '$reverse_dependecy' is depends on installed target '$1'. Exiting..." 1 - fi - done -} - -cmd_unlink() { - local target targetfile - for target in "$@" - do - die_if_installed_targets_depend_on "$target" - - for targetfile in ${TARGETS["$target"]} - do - if [ "${targetfile::1}" = "%" ]; then - continue - fi - - if [ -e "$TARGET_PATH/$targetfile" ]; then - unlink "$TARGET_PATH/$targetfile" - fi - done - done -} - -cmd_no_target() { - _die "TARGET not exists" 1 -} - -cmd_list() { - echo "${!TARGETS[@]}" -} - -target_exists() { - [[ " ${!TARGETS[*]} " =~ " $1 " ]] -} - -cmd_install() { - local target - for target in "$@" - do - if target_exists "$target"; then - SANDBOX_PATH="$(mktemp -td "${USER:-user}.dotfiles_XXXXXXX")" - export SANDBOX_PATH - install_target "$target" - rm -rf "$SANDBOX_PATH" - else - cmd_no_target - fi - done -} - -cmd_help() { - echo "Dotfiles installation script: -Usage: ./install TARGET... -Usage: ./install unlink TARGET... -Usage: ./install check TARGET -Usage: ./install list" -} - -unset executed_command -readonly executed_command="$1" - -case "$executed_command" in - unlink) shift; cmd_unlink "$@" ;; - check) shift; is_target_installed "$@" ;; - list) shift; cmd_list "$@" ;; - help) shift; cmd_help "$@" ;; - *) shift; cmd_install "$executed_command" "$@" ;; -esac -exit 0 \ No newline at end of file diff --git a/install-hooks/arch/pre-install b/install-hooks/arch/pre-install deleted file mode 100755 index de3ce35..0000000 --- a/install-hooks/arch/pre-install +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -echo 'echo "ParallelDownloads = 5" >> /etc/pacman.conf' -echo 'sudo systemctl enable --now gpm' diff --git a/install-hooks/font/pre-install b/install-hooks/font/pre-install deleted file mode 100755 index 86331ee..0000000 --- a/install-hooks/font/pre-install +++ /dev/null @@ -1,11 +0,0 @@ -#!/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 diff --git a/install-hooks/git/post-install b/install-hooks/git/post-install deleted file mode 100644 index 5e943d3..0000000 --- a/install-hooks/git/post-install +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -git config --global user.name "$USER" -git config --global user.email "${USER}@${HOST:-$HOSTNAME}" -git config --global user.signingkey "$USER" - -git config --global github.user "$USER" -git config --global github.email "${USER}@${HOST:-$HOSTNAME}" diff --git a/install-hooks/gpg/post-install b/install-hooks/gpg/post-install deleted file mode 100755 index 43c11a3..0000000 --- a/install-hooks/gpg/post-install +++ /dev/null @@ -1,4 +0,0 @@ -#!/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 diff --git a/install-hooks/i3/pre-install b/install-hooks/i3/pre-install deleted file mode 100755 index b441701..0000000 --- a/install-hooks/i3/pre-install +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -echo "sudo pacman -S nitrogen picom compton ttf-font-awesome xdotool xclip maim playerctl rofi" diff --git a/install-hooks/nvim/pre-install b/install-hooks/nvim/pre-install deleted file mode 100755 index 0155204..0000000 --- a/install-hooks/nvim/pre-install +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -echo "sudo pacman -S npm ctags fzf glow; mkdir ~/.npm-global; npm config set prefix '~/.npm-global'" diff --git a/install-hooks/ranger/post-install b/install-hooks/ranger/post-install deleted file mode 100755 index 976870b..0000000 --- a/install-hooks/ranger/post-install +++ /dev/null @@ -1,4 +0,0 @@ -#!/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" diff --git a/install-hooks/ranger/pre-install b/install-hooks/ranger/pre-install deleted file mode 100755 index 6e0b939..0000000 --- a/install-hooks/ranger/pre-install +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -echo "sudo pacman -S highlight ttf-joypixels noto-fonts-emoji ueberzug poppler" diff --git a/install-hooks/ssh/post-install b/install-hooks/ssh/post-install deleted file mode 100755 index b07711b..0000000 --- a/install-hooks/ssh/post-install +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -cat "$SUB/.ssh/config" >> "$HOME/.ssh/config" diff --git a/install-hooks/termux/post-install b/install-hooks/termux/post-install deleted file mode 100755 index ae2ff5f..0000000 --- a/install-hooks/termux/post-install +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -cat > "$HOME/.config/bash/bashrc.d/01_tmux.sh" << EOF -if command -v tmux 1>/dev/null && [[ -z "\$TMUX" ]] && [[ ! "\$TERM" =~ tmux ]]; then - exec tmux new -fi -EOF diff --git a/install-hooks/termux/pre-install b/install-hooks/termux/pre-install deleted file mode 100755 index c86bb12..0000000 --- a/install-hooks/termux/pre-install +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -echo "apt install termux-api tsu" diff --git a/install-hooks/zsh/post-install b/install-hooks/zsh/post-install deleted file mode 100755 index 3470fd4..0000000 --- a/install-hooks/zsh/post-install +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env zsh - -for zfile in .zshenv .config/zsh/.zshrc .config/zsh/.zprofile .config/zsh/.zlogout .config/zsh/aliases .config/zsh/completion .config/zsh/history .config/zsh/options .config/zsh/other .config/zsh/plugin .config/zsh/prompt .config/zsh/sourcer; do - zcompile "$HOME/$zfile" -done