Skip to content

Commit

Permalink
Install template pre-requisites before templating
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrs committed Apr 28, 2024
1 parent 4262c2a commit bd12c59
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#!/bin/bash

# {{ include (joinPath .chezmoi.sourceDir ".chezmoitemplates/scripts-library") }}
# This script must not be a template, so that it gets executed before rendering
# the templates.

# The following line is for ShellCheck to correctly identify the above included library
true || source ../.chezmoitemplates/scripts-library
# shellcheck source=../.chezmoitemplates/scripts-library
source "${CHEZMOI_SOURCE_DIR?}/.chezmoitemplates/scripts-library"

readonly wanted_packages=(
wanted_packages=(
git # used to find the latest revisions of github repositories
curl # used to find the latest version of github repositories
zsh
# {{ if not .is_devcontainer }}
gpg # used to decrypt the gpg keys of the apt repositories
# {{ end }}
)

ROOTMOI="${ROOTMOI:-}"
if [[ "${ROOTMOI}" == 1 ]]; then
wanted_packages+=(
gpg # used to decrypt the gpg keys of the apt repositories
)
fi

missing_packages=()

for package in "${wanted_packages[@]}"; do
Expand All @@ -25,11 +31,11 @@ if [[ ${#missing_packages[@]} -gt 0 ]]; then
log_task "Installing missing packages with APT: ${missing_packages[*]}"

# This script also gets called when running rootmoi
# {{ if eq .chezmoi.username "root" }}
apt_command=(apt)
# {{ else }}
apt_command=(sudo apt)
# {{ end }}
if [[ "${ROOTMOI}" == 1 ]]; then
apt_command=(apt-get)
else
apt_command=(sudo apt-get)
fi

c "${apt_command[@]}" update
c "${apt_command[@]}" install --yes --no-install-recommends "${missing_packages[@]}"
Expand Down
2 changes: 1 addition & 1 deletion home/dot_local/bin/executable_rootmoi.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fi
# shellcheck disable=SC2016
mkdir -p '{{ $configDir }}' '{{ $cacheDir }}'

sudo exec --preserve-env=PATH -- \
sudo exec env "PATH=${PATH}" ROOTMOI=1 -- \
"${executable}" "$@" \
--config='{{ $configFile }}' \
--persistent-state='{{ $persistentStateFile }}' \
Expand Down

This file was deleted.

0 comments on commit bd12c59

Please sign in to comment.