Refactor the install procedure and structure.

This commit is contained in:
Hans Goor 2024-09-01 16:16:05 +02:00
parent cf3ef623ad
commit f105f890ce
Signed by: eyedevelop
SSH key fingerprint: SHA256:Td89veptDEwCV8J3fjqnknNk7SbwzedYhauyC2nFBYg
39 changed files with 107 additions and 37 deletions

4
.gitmodules vendored
View file

@ -1,6 +1,6 @@
[submodule "tmux/dot-tmux/plugins/tpm"] [submodule "tmux/dot-tmux/plugins/tpm"]
path = tmux/dot-tmux/plugins/tpm path = stowers/tmux/dot-tmux/plugins/tpm
url = https://github.com/tmux-plugins/tpm url = https://github.com/tmux-plugins/tpm
[submodule "zsh/dot-oh-my-zsh"] [submodule "zsh/dot-oh-my-zsh"]
path = zsh/dot-oh-my-zsh path = stowers/zsh/dot-oh-my-zsh
url = https://github.com/ohmyzsh/ohmyzsh url = https://github.com/ohmyzsh/ohmyzsh

View file

@ -1,50 +1,102 @@
#!/bin/bash #!/bin/bash
function do_stow() { set -euo pipefail
local package="$1"
local opts=( "--dotfiles" "--dir" "${DOTFILES_DIR}" )
if [[ "$#" -ge 2 ]]; then DOTFILES_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
opts+=( "--target" "$2" ) STOWERS_DIR="${DOTFILES_DIR}/stowers"
fi MODULES_DIR="${DOTFILES_DIR}/modules"
TARGET_DIR="${HOME}"
stow "${opts[@]}" "$package" install_stower() {
} if ! command -v stow &>/dev/null; then
echo "[!] GNU Stow is not installed!" >&2
function basic_git_setup() {
if ! command -v git &> /dev/null; then
echo "[!] Git is not installed! Not running git setup."
return 1 return 1
fi fi
git config --global user.name "Hans Goor" if [[ "$#" -lt 1 ]]; then
git config --global user.email "me@eyedevelop.org" echo "[!] No stower given!" >&2
git config --global push.autoSetupRemote true return 1
git config --global pull.rebase true fi
git config --global commit.gpgsign true
git config --global merge.ff no local stower_name stower_dir
git config --global init.defaultBranch main stower_name="$1"
stower_dir="${STOWERS_DIR}/${stower_name}"
if [[ ! -d "${stower_dir}" ]]; then
echo "[!] Stower (${stower_dir}) is not a directory!" >&2
return 1
fi
local COMMAND_DEPS
COMMAND_DEPS=()
if [[ -f "${stower_dir}"/config.sh ]]; then
source "${stower_dir}"/config.sh
fi
for required_cmd in "${COMMAND_DEPS[@]}"; do
if ! command -v "${required_cmd}" &>/dev/null; then
echo "[${stower_name}] Missing required command: ${required_cmd}" >&2
return 1
fi
done
stow --dotfiles \
--dir "${STOWERS_DIR}" \
--target "${TARGET_DIR}" \
--ignore "config.sh" "${stower_name}" || \
{ echo "[!] [${stower_name}] Failed to install!" >&2; return 1; }
echo "[+] [${stower_name}] Installed!"
} }
set -eo pipefail install_module() {
if [[ "$#" -lt 1 ]]; then
echo "[!] No module given!" >&2
return 1
fi
DOTFILES_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" local module_dir
TARGET_DIR="${HOME}" module_dir="${MODULES_DIR}/$1"
if ! command -v stow &> /dev/null; then if [[ ! -d "${module_dir}" ]] || [[ ! -f "${module_dir}/install.sh" ]]; then
echo "[!] Stow is not installed!" echo "[!] Module (${module_dir}) is not a module!" >&2
exit 1 return 1
fi
/bin/bash "${module_dir}/install.sh"
}
STOWERS=()
MODULES=()
if [[ "$#" -gt 0 ]]; then
for stower_or_module in "$@"; do
if [[ -e "${STOWERS_DIR}/${stower_or_module}" ]]; then
STOWERS+=("${stower_or_module}")
elif [[ -e "${MODULES_DIR}/${stower_or_module}" ]]; then
MODULES+=("${stower_or_module}")
else
echo "[!] No such stower/module: ${stower_or_module}" >&2
return 1
fi
done
else
for stower in "${STOWERS_DIR}"/*/; do
stower_name="$(basename -- "${stower}")"
STOWERS+=("${stower_name}")
done
for module in "${MODULES_DIR}"/*/; do
module_name="$(basename -- "${module}")"
MODULES+=("$module")
done
fi fi
# Make sure directories exist. for stower in "${STOWERS[@]}"; do
mkdir -p "${TARGET_DIR}/.ssh" install_stower "${stower}" || true
mkdir -p "${TARGET_DIR}/.config" done
# Install SSH separately, as it requres a different target. for module in "${MODULES[@]}"; do
do_stow ssh "${TARGET_DIR}/.ssh" || true install_module "${module}" || true
do_stow tmux || true done
do_stow git || (basic_git_setup || true)
do_stow zsh || true
do_stow nvim "${TARGET_DIR}/.config" || true
echo "[+] Installed!" echo "[!] Installed everything!"

3
stowers/bash/config.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
COMMAND_DEPS=("bash")

3
stowers/git/config.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
COMMAND_DEPS=("git")

3
stowers/nvim/config.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
COMMAND_DEPS=("nvim")

3
stowers/ssh/config.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
COMMAND_DEPS=("ssh")

3
stowers/tmux/config.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
COMMAND_DEPS=("tmux")

3
stowers/zsh/config.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
COMMAND_DEPS=("zsh")