Repository navigation
Expand file tree
/
Copy pathinstall
More file actions
executable file
·93 lines (80 loc) · 3.35 KB
/
Copy pathinstall
File metadata and controls
executable file
·93 lines (80 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
#
# install - links this repo's configs into $HOME, one dotbot pass per
# selected module.
#
# ./install --roles desktop # first run on a machine of that kind
# ./install --roles desktop,wacom # a role plus an extra module
# ./install # re-apply the saved selection
#
# Roles live in roles/, modules in modules/ (see lib/roles.sh). The
# selection is saved to $XDG_CONFIG_HOME/dotfiles/roles so later runs need
# no flags. Any other argument is forwarded to dotbot itself (e.g. -v, -Q).
# Safe to re-run: links are relinked and pre-existing real files backed up.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=lib/common.sh
. "$REPO_ROOT/lib/common.sh"
# shellcheck source=lib/roles.sh
. "$REPO_ROOT/lib/roles.sh"
DOTBOT="$REPO_ROOT/dotbot/bin/dotbot"
PLUGIN_DIR="$REPO_ROOT/lib/dotbot-plugins"
CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
HOST_ENV="$CONFIG_HOME/dotfiles/host.env"
usage() {
cat <<EOF
usage: $0 [--roles <role>[,<role>...]] [--modules <module>[,<module>...]] [dotbot options]
Links the selected modules' configs into \$HOME, one dotbot pass per
module. With no selection, the one saved by the last run ($ROLES_FILE)
is re-applied.
--roles r[,r] roles to link (available: $(list_roles | paste -sd' '))
--modules m[,m] extra modules, or a selection with no role
-h, --help show this help
Any other argument is forwarded to dotbot (e.g. -v for verbose, -Q for
quiet); run dotbot/bin/dotbot --help for those.
EOF
}
parse_targets "$@"
mapfile -t MODULES < <(resolve_modules "${TARGETS[@]}")
check_requires "${MODULES[@]}"
cd "$REPO_ROOT"
git submodule sync --quiet --recursive
git submodule update --init --recursive
# Per-machine values (DPI, redshift location, network interface, ...) are
# merged from three layers into one generated file that templates and
# scripts read; later layers win. hosts/defaults.env is tracked and complete,
# hosts/<hostname>.env is tracked for machines it's fine to describe in
# public, and dotfiles/local.env is the untracked seam for a private overlay.
write_host_env() {
local host layer
host="$(hostname -s)"
mkdir -p "$(dirname "$HOST_ENV")"
{
printf '# Generated by ./install on %s - edit the layers, not this file:\n' "$(date '+%F %T')"
printf '# %s/hosts/defaults.env\n# %s/hosts/%s.env\n# %s/dotfiles/local.env\n' \
"$REPO_ROOT" "$REPO_ROOT" "$host" "$CONFIG_HOME"
for layer in "hosts/defaults.env" "hosts/$host.env" "$CONFIG_HOME/dotfiles/local.env"; do
[ -f "$layer" ] || continue
printf '\n# --- %s\n' "$layer"
cat "$layer"
done
} >"$HOST_ENV.tmp"
mv "$HOST_ENV.tmp" "$HOST_ENV"
}
write_host_env
export DOTFILES_HOST_ENV="$HOST_ENV"
log "Modules: ${MODULES[*]}"
for m in "${MODULES[@]}"; do
conf="modules/$m/install.conf.yaml"
[ -f "$conf" ] || continue
log "module $m"
# -d: sources in the manifest are relative to the module directory
"$DOTBOT" -d "$REPO_ROOT/modules/$m" -c "$conf" --plugin-dir "$PLUGIN_DIR" \
${PASSTHROUGH[@]+"${PASSTHROUGH[@]}"}
done
# Repo-local only: points this clone's hooks at the tracked identity guard
# (a relative hooksPath resolves against the repo root). Other repos on the
# machine are untouched.
git config core.hooksPath modules/git/hooks
save_targets "${TARGETS[@]}"
log "Done. Selection saved to $ROLES_FILE."