install.fairie/home/.chezmoiscripts/universal/run_onchange_after_06-configure-root-folder.sh.tmpl
Brian Zalewski 097396d750 Latest
2023-11-27 23:28:42 +00:00

31 lines
1.5 KiB
Cheetah

{{- if (ne .host.distro.family "windows") -}}
#!/usr/bin/env bash
# @file Configure Root Home Folder
# @brief Configures the root user's folder so that they have access to executables installed by provisioning user
# @description
# This script configures the root user's folder so that scripts running as the root user can:
#
# 1. Access binaries installed by the provisioning user (by setting the appropriate `~/.bashrc` and `~/.zshrc` symlinks)
# 2. Use the same shell profile rules that the provisioning user uses (by symlinking the `~/.config/shell`, `~/.bashrc`, and `~/.zshrc` locations)
{{ includeTemplate "universal/profile" }}
{{ includeTemplate "universal/logg" }}
### Detect root folder
if [ -d /var/root ]; then
ROOT_FOLDER="/var/root"
elif [ -d /root ]; then
ROOT_FOLDER="/root"
else
logg warn 'Unable to find root user folder location'
fi
### Copy minimal set of profile configuration files
if [ -n "$ROOT_FOLDER" ]; then
logg info "Copying ~/.bashrc to $ROOT_FOLDER/.bashrc" && sudo cp -f "$HOME/.bashrc" "$ROOT_FOLDER/.bashrc"
logg info "Copying ~/.zshrc to $ROOT_FOLDER/.zshrc" && sudo cp -f "$HOME/.zshrc" "$ROOT_FOLDER/.zshrc"
logg info "Ensuring ~/.config folder exists" && sudo mkdir -p "$ROOT_FOLDER/.config"
logg info "Copying ~/.config/shell to $ROOT_FOLDER/.config/shell" && sudo mkdir -p "$ROOT_FOLDER/.config" && sudo rm -rf "$ROOT_FOLDER/.config/shell" && sudo cp -rf "$HOME/.config/shell" "$ROOT_FOLDER/.config/shell"
fi
{{ end -}}