Update lxc-prehook.sh
This commit is contained in:
@@ -141,6 +141,10 @@ create_main_config() {
|
|||||||
# Space-separated CTIDs to skip entirely
|
# Space-separated CTIDs to skip entirely
|
||||||
IGNORE_IDS=""
|
IGNORE_IDS=""
|
||||||
|
|
||||||
|
# If set to 1, CT tags are evaluated (profile_*, pkg_*, feature_*).
|
||||||
|
# If set to 0, customization runs purely from config values below.
|
||||||
|
USE_TAGS=0
|
||||||
|
|
||||||
# If set to 1, customization will only run once per CT unless the marker is removed
|
# If set to 1, customization will only run once per CT unless the marker is removed
|
||||||
RUN_ONCE=1
|
RUN_ONCE=1
|
||||||
|
|
||||||
@@ -216,6 +220,10 @@ ENABLE_BASHRC_TUNING=1
|
|||||||
ENABLE_BASH_COMPLETION_LINE=1
|
ENABLE_BASH_COMPLETION_LINE=1
|
||||||
ENABLE_FASTFETCH_LINE=1
|
ENABLE_FASTFETCH_LINE=1
|
||||||
|
|
||||||
|
# Config-first feature toggles (work without tags)
|
||||||
|
ENABLE_SHELLRC_FEATURE=0
|
||||||
|
ENABLE_FASTFETCH_FEATURE=0
|
||||||
|
|
||||||
# If set to 1 and nala exists, apt/apt-get aliases will be added
|
# If set to 1 and nala exists, apt/apt-get aliases will be added
|
||||||
ENABLE_NALA_ALIASES=0
|
ENABLE_NALA_ALIASES=0
|
||||||
|
|
||||||
@@ -269,6 +277,11 @@ create_example_override() {
|
|||||||
# Add extra packages regardless of tags:
|
# Add extra packages regardless of tags:
|
||||||
# EXTRA_PACKAGES="mc htop"
|
# EXTRA_PACKAGES="mc htop"
|
||||||
#
|
#
|
||||||
|
# Run without tags (recommended for normal users):
|
||||||
|
# USE_TAGS=0
|
||||||
|
# ENABLE_SHELLRC_FEATURE=1
|
||||||
|
# ENABLE_FASTFETCH_FEATURE=1
|
||||||
|
#
|
||||||
# Disable shellrc tuning for this CT:
|
# Disable shellrc tuning for this CT:
|
||||||
# ENABLE_BASHRC_TUNING=0
|
# ENABLE_BASHRC_TUNING=0
|
||||||
#
|
#
|
||||||
@@ -313,6 +326,7 @@ load_config() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
: "${IGNORE_IDS:=}"
|
: "${IGNORE_IDS:=}"
|
||||||
|
: "${USE_TAGS:=0}"
|
||||||
: "${RUN_ONCE:=1}"
|
: "${RUN_ONCE:=1}"
|
||||||
: "${ALWAYS_RUN:=0}"
|
: "${ALWAYS_RUN:=0}"
|
||||||
: "${MARKER_DIR:=/var/lib/pve-auto-customize}"
|
: "${MARKER_DIR:=/var/lib/pve-auto-customize}"
|
||||||
@@ -328,6 +342,8 @@ load_config() {
|
|||||||
: "${ENABLE_BASHRC_TUNING:=1}"
|
: "${ENABLE_BASHRC_TUNING:=1}"
|
||||||
: "${ENABLE_BASH_COMPLETION_LINE:=1}"
|
: "${ENABLE_BASH_COMPLETION_LINE:=1}"
|
||||||
: "${ENABLE_FASTFETCH_LINE:=1}"
|
: "${ENABLE_FASTFETCH_LINE:=1}"
|
||||||
|
: "${ENABLE_SHELLRC_FEATURE:=0}"
|
||||||
|
: "${ENABLE_FASTFETCH_FEATURE:=0}"
|
||||||
: "${ENABLE_NALA_ALIASES:=0}"
|
: "${ENABLE_NALA_ALIASES:=0}"
|
||||||
: "${PROFILE_shell_PACKAGES:=bash-completion plocate}"
|
: "${PROFILE_shell_PACKAGES:=bash-completion plocate}"
|
||||||
: "${PROFILE_ops_PACKAGES:=curl wget unzip jq}"
|
: "${PROFILE_ops_PACKAGES:=curl wget unzip jq}"
|
||||||
@@ -399,34 +415,36 @@ resolve_requested_packages() {
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local tag
|
if [[ "$USE_TAGS" == "1" ]]; then
|
||||||
local tag_list="${tags//;/ }"
|
local tag
|
||||||
for tag in $tag_list; do
|
local tag_list="${tags//;/ }"
|
||||||
case "$tag" in
|
for tag in $tag_list; do
|
||||||
profile_*)
|
case "$tag" in
|
||||||
local profile="${tag#profile_}"
|
profile_*)
|
||||||
local var="PROFILE_${profile}_PACKAGES"
|
local profile="${tag#profile_}"
|
||||||
local profile_pkgs="${!var:-}"
|
local var="PROFILE_${profile}_PACKAGES"
|
||||||
if [[ -n "$profile_pkgs" ]]; then
|
local profile_pkgs="${!var:-}"
|
||||||
for pkg in $profile_pkgs; do
|
if [[ -n "$profile_pkgs" ]]; then
|
||||||
if [[ ! " $seen " =~ [[:space:]]$pkg[[:space:]] ]]; then
|
for pkg in $profile_pkgs; do
|
||||||
pkgs+=("$pkg")
|
if [[ ! " $seen " =~ [[:space:]]$pkg[[:space:]] ]]; then
|
||||||
seen+=" $pkg"
|
pkgs+=("$pkg")
|
||||||
fi
|
seen+=" $pkg"
|
||||||
done
|
fi
|
||||||
else
|
done
|
||||||
log "Profile '$profile' has no package definition"
|
else
|
||||||
fi
|
log "Profile '$profile' has no package definition"
|
||||||
;;
|
fi
|
||||||
pkg_*)
|
;;
|
||||||
local pkg="${tag#pkg_}"
|
pkg_*)
|
||||||
if [[ -n "$pkg" ]] && [[ ! " $seen " =~ [[:space:]]$pkg[[:space:]] ]]; then
|
local pkg="${tag#pkg_}"
|
||||||
pkgs+=("$pkg")
|
if [[ -n "$pkg" ]] && [[ ! " $seen " =~ [[:space:]]$pkg[[:space:]] ]]; then
|
||||||
seen+=" $pkg"
|
pkgs+=("$pkg")
|
||||||
fi
|
seen+=" $pkg"
|
||||||
;;
|
fi
|
||||||
esac
|
;;
|
||||||
done
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
printf '%s\n' "${pkgs[@]:-}"
|
printf '%s\n' "${pkgs[@]:-}"
|
||||||
}
|
}
|
||||||
@@ -488,15 +506,18 @@ run_optional_cleanup() {
|
|||||||
apply_shellrc_features() {
|
apply_shellrc_features() {
|
||||||
local tags="$1"
|
local tags="$1"
|
||||||
local tag_list="${tags//;/ }"
|
local tag_list="${tags//;/ }"
|
||||||
local enable_shellrc=0
|
local enable_shellrc="$ENABLE_SHELLRC_FEATURE"
|
||||||
local enable_fastfetch=0
|
local enable_fastfetch="$ENABLE_FASTFETCH_FEATURE"
|
||||||
|
|
||||||
for tag in $tag_list; do
|
if [[ "$USE_TAGS" == "1" ]]; then
|
||||||
case "$tag" in
|
local tag
|
||||||
feature_shellrc) enable_shellrc=1 ;;
|
for tag in $tag_list; do
|
||||||
feature_fastfetch) enable_fastfetch=1 ;;
|
case "$tag" in
|
||||||
esac
|
feature_shellrc) enable_shellrc=1 ;;
|
||||||
done
|
feature_fastfetch) enable_fastfetch=1 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$ENABLE_BASHRC_TUNING" != "1" ]]; then
|
if [[ "$ENABLE_BASHRC_TUNING" != "1" ]]; then
|
||||||
log "Shellrc tuning globally disabled"
|
log "Shellrc tuning globally disabled"
|
||||||
@@ -579,8 +600,19 @@ main() {
|
|||||||
|
|
||||||
local tags
|
local tags
|
||||||
tags="$(get_tags)"
|
tags="$(get_tags)"
|
||||||
if [[ -z "$tags" && -z "${EXTRA_PACKAGES:-}" ]]; then
|
local should_process=0
|
||||||
log "No tags and no EXTRA_PACKAGES configured. Nothing to do."
|
if [[ -n "${EXTRA_PACKAGES:-}" ]]; then
|
||||||
|
should_process=1
|
||||||
|
fi
|
||||||
|
if [[ "$ENABLE_SHELLRC_FEATURE" == "1" || "$ENABLE_FASTFETCH_FEATURE" == "1" ]]; then
|
||||||
|
should_process=1
|
||||||
|
fi
|
||||||
|
if [[ "$USE_TAGS" == "1" && -n "$tags" ]]; then
|
||||||
|
should_process=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$should_process" != "1" ]]; then
|
||||||
|
log "No active config/tags found. Nothing to do."
|
||||||
if [[ "$RUN_ONCE" == "1" ]]; then
|
if [[ "$RUN_ONCE" == "1" ]]; then
|
||||||
write_marker
|
write_marker
|
||||||
fi
|
fi
|
||||||
@@ -588,7 +620,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
log "--- Starting guest customization ---"
|
log "--- Starting guest customization ---"
|
||||||
[[ "$VERBOSE" == "1" ]] && log "Tags: ${tags:-<none>}"
|
[[ "$VERBOSE" == "1" ]] && log "USE_TAGS=$USE_TAGS, Tags: ${tags:-<none>}"
|
||||||
|
|
||||||
local package_lines
|
local package_lines
|
||||||
mapfile -t package_lines < <(resolve_requested_packages "$tags")
|
mapfile -t package_lines < <(resolve_requested_packages "$tags")
|
||||||
@@ -722,6 +754,8 @@ On container start, the hookscript can optionally:
|
|||||||
|
|
||||||
Tag formats
|
Tag formats
|
||||||
-----------
|
-----------
|
||||||
|
Optional when USE_TAGS=1.
|
||||||
|
|
||||||
profile_<name>
|
profile_<name>
|
||||||
Uses PROFILE_<name>_PACKAGES from config
|
Uses PROFILE_<name>_PACKAGES from config
|
||||||
|
|
||||||
@@ -736,6 +770,9 @@ feature_fastfetch
|
|||||||
|
|
||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
|
Config-only (no tags):
|
||||||
|
Set USE_TAGS=0 and EXTRA_PACKAGES="fastfetch" in config or per-CT override.
|
||||||
|
|
||||||
tags: profile_shell;profile_ops
|
tags: profile_shell;profile_ops
|
||||||
tags: pkg_fastfetch;pkg_jq
|
tags: pkg_fastfetch;pkg_jq
|
||||||
tags: profile_shell;pkg_fastfetch;feature_shellrc;feature_fastfetch
|
tags: profile_shell;pkg_fastfetch;feature_shellrc;feature_fastfetch
|
||||||
@@ -859,10 +896,10 @@ print_summary() {
|
|||||||
echo " /etc/systemd/system/pve-auto-customize.service"
|
echo " /etc/systemd/system/pve-auto-customize.service"
|
||||||
echo
|
echo
|
||||||
echo -e "${BL}Next steps:${CL}"
|
echo -e "${BL}Next steps:${CL}"
|
||||||
echo " 1. Edit /etc/default/pve-auto-customize if needed"
|
echo " 1. Edit /etc/default/pve-auto-customize (or /etc/pve-auto-customize/<VMID>.conf)"
|
||||||
echo " 2. Add tags to a CT, for example:"
|
echo " 2. For simple usage without tags: set USE_TAGS=0 and EXTRA_PACKAGES='fastfetch'"
|
||||||
echo " pct set 101 --tags 'profile_shell;profile_ops;pkg_fastfetch;feature_shellrc;feature_fastfetch'"
|
echo " 3. Optional tag mode: USE_TAGS=1 and set CT tags (profile_*/pkg_*/feature_*)"
|
||||||
echo " 3. Restart the CT"
|
echo " 4. Restart the CT"
|
||||||
echo
|
echo
|
||||||
echo -e "${BL}Useful commands:${CL}"
|
echo -e "${BL}Useful commands:${CL}"
|
||||||
echo " pct config 101"
|
echo " pct config 101"
|
||||||
|
|||||||
Reference in New Issue
Block a user