Refactor the install procedure and structure.
This commit is contained in:
parent
cf3ef623ad
commit
f105f890ce
39 changed files with 107 additions and 37 deletions
4
.gitmodules
vendored
4
.gitmodules
vendored
|
|
@ -1,6 +1,6 @@
|
|||
[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
|
||||
[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
|
||||
|
|
|
|||
122
install.sh
122
install.sh
|
|
@ -1,50 +1,102 @@
|
|||
#!/bin/bash
|
||||
|
||||
function do_stow() {
|
||||
local package="$1"
|
||||
local opts=( "--dotfiles" "--dir" "${DOTFILES_DIR}" )
|
||||
set -euo pipefail
|
||||
|
||||
if [[ "$#" -ge 2 ]]; then
|
||||
opts+=( "--target" "$2" )
|
||||
fi
|
||||
DOTFILES_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
||||
STOWERS_DIR="${DOTFILES_DIR}/stowers"
|
||||
MODULES_DIR="${DOTFILES_DIR}/modules"
|
||||
TARGET_DIR="${HOME}"
|
||||
|
||||
stow "${opts[@]}" "$package"
|
||||
}
|
||||
|
||||
function basic_git_setup() {
|
||||
if ! command -v git &> /dev/null; then
|
||||
echo "[!] Git is not installed! Not running git setup."
|
||||
install_stower() {
|
||||
if ! command -v stow &>/dev/null; then
|
||||
echo "[!] GNU Stow is not installed!" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
git config --global user.name "Hans Goor"
|
||||
git config --global user.email "me@eyedevelop.org"
|
||||
git config --global push.autoSetupRemote true
|
||||
git config --global pull.rebase true
|
||||
git config --global commit.gpgsign true
|
||||
git config --global merge.ff no
|
||||
git config --global init.defaultBranch main
|
||||
if [[ "$#" -lt 1 ]]; then
|
||||
echo "[!] No stower given!" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local stower_name stower_dir
|
||||
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)"
|
||||
TARGET_DIR="${HOME}"
|
||||
local module_dir
|
||||
module_dir="${MODULES_DIR}/$1"
|
||||
|
||||
if ! command -v stow &> /dev/null; then
|
||||
echo "[!] Stow is not installed!"
|
||||
exit 1
|
||||
if [[ ! -d "${module_dir}" ]] || [[ ! -f "${module_dir}/install.sh" ]]; then
|
||||
echo "[!] Module (${module_dir}) is not a module!" >&2
|
||||
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
|
||||
|
||||
# Make sure directories exist.
|
||||
mkdir -p "${TARGET_DIR}/.ssh"
|
||||
mkdir -p "${TARGET_DIR}/.config"
|
||||
for stower in "${STOWERS[@]}"; do
|
||||
install_stower "${stower}" || true
|
||||
done
|
||||
|
||||
# Install SSH separately, as it requres a different target.
|
||||
do_stow ssh "${TARGET_DIR}/.ssh" || true
|
||||
do_stow tmux || true
|
||||
do_stow git || (basic_git_setup || true)
|
||||
do_stow zsh || true
|
||||
do_stow nvim "${TARGET_DIR}/.config" || true
|
||||
for module in "${MODULES[@]}"; do
|
||||
install_module "${module}" || true
|
||||
done
|
||||
|
||||
echo "[+] Installed!"
|
||||
echo "[!] Installed everything!"
|
||||
|
|
|
|||
3
stowers/bash/config.sh
Normal file
3
stowers/bash/config.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
COMMAND_DEPS=("bash")
|
||||
3
stowers/git/config.sh
Normal file
3
stowers/git/config.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
COMMAND_DEPS=("git")
|
||||
3
stowers/nvim/config.sh
Normal file
3
stowers/nvim/config.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
COMMAND_DEPS=("nvim")
|
||||
3
stowers/ssh/config.sh
Normal file
3
stowers/ssh/config.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
COMMAND_DEPS=("ssh")
|
||||
3
stowers/tmux/config.sh
Normal file
3
stowers/tmux/config.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
COMMAND_DEPS=("tmux")
|
||||
3
stowers/zsh/config.sh
Normal file
3
stowers/zsh/config.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
COMMAND_DEPS=("zsh")
|
||||
Loading…
Add table
Reference in a new issue