@@ -141,6 +141,10 @@ create_main_config() {
141141# Space-separated CTIDs to skip entirely
142142IGNORE_IDS=""
143143
144+ # If set to 1, CT tags are evaluated (profile_*, pkg_*, feature_*).
145+ # If set to 0, customization runs purely from config values below.
146+ USE_TAGS=0
147+
144148# If set to 1, customization will only run once per CT unless the marker is removed
145149RUN_ONCE=1
146150
@@ -216,6 +220,10 @@ ENABLE_BASHRC_TUNING=1
216220ENABLE_BASH_COMPLETION_LINE=1
217221ENABLE_FASTFETCH_LINE=1
218222
223+ # Config-first feature toggles (work without tags)
224+ ENABLE_SHELLRC_FEATURE=0
225+ ENABLE_FASTFETCH_FEATURE=0
226+
219227# If set to 1 and nala exists, apt/apt-get aliases will be added
220228ENABLE_NALA_ALIASES=0
221229
@@ -269,6 +277,11 @@ create_example_override() {
269277# Add extra packages regardless of tags:
270278# EXTRA_PACKAGES="mc htop"
271279#
280+ # Run without tags (recommended for normal users):
281+ # USE_TAGS=0
282+ # ENABLE_SHELLRC_FEATURE=1
283+ # ENABLE_FASTFETCH_FEATURE=1
284+ #
272285# Disable shellrc tuning for this CT:
273286# ENABLE_BASHRC_TUNING=0
274287#
@@ -313,6 +326,7 @@ load_config() {
313326 fi
314327
315328 : "${IGNORE_IDS:=}"
329+ : "${USE_TAGS:=0}"
316330 : "${RUN_ONCE:=1}"
317331 : "${ALWAYS_RUN:=0}"
318332 : "${MARKER_DIR:=/var/lib/pve-auto-customize}"
@@ -328,6 +342,8 @@ load_config() {
328342 : "${ENABLE_BASHRC_TUNING:=1}"
329343 : "${ENABLE_BASH_COMPLETION_LINE:=1}"
330344 : "${ENABLE_FASTFETCH_LINE:=1}"
345+ : "${ENABLE_SHELLRC_FEATURE:=0}"
346+ : "${ENABLE_FASTFETCH_FEATURE:=0}"
331347 : "${ENABLE_NALA_ALIASES:=0}"
332348 : "${PROFILE_shell_PACKAGES:=bash-completion plocate}"
333349 : "${PROFILE_ops_PACKAGES:=curl wget unzip jq}"
@@ -399,34 +415,36 @@ resolve_requested_packages() {
399415 done
400416 fi
401417
402- local tag
403- local tag_list="${tags//;/ }"
404- for tag in $tag_list; do
405- case "$tag" in
406- profile_*)
407- local profile="${tag#profile_}"
408- local var="PROFILE_${profile}_PACKAGES"
409- local profile_pkgs="${!var:-}"
410- if [[ -n "$profile_pkgs" ]]; then
411- for pkg in $profile_pkgs; do
412- if [[ ! " $seen " =~ [[:space:]]$pkg[[:space:]] ]]; then
413- pkgs+=("$pkg")
414- seen+=" $pkg"
415- fi
416- done
417- else
418- log "Profile '$profile' has no package definition"
419- fi
420- ;;
421- pkg_*)
422- local pkg="${tag#pkg_}"
423- if [[ -n "$pkg" ]] && [[ ! " $seen " =~ [[:space:]]$pkg[[:space:]] ]]; then
424- pkgs+=("$pkg")
425- seen+=" $pkg"
426- fi
427- ;;
428- esac
429- done
418+ if [[ "$USE_TAGS" == "1" ]]; then
419+ local tag
420+ local tag_list="${tags//;/ }"
421+ for tag in $tag_list; do
422+ case "$tag" in
423+ profile_*)
424+ local profile="${tag#profile_}"
425+ local var="PROFILE_${profile}_PACKAGES"
426+ local profile_pkgs="${!var:-}"
427+ if [[ -n "$profile_pkgs" ]]; then
428+ for pkg in $profile_pkgs; do
429+ if [[ ! " $seen " =~ [[:space:]]$pkg[[:space:]] ]]; then
430+ pkgs+=("$pkg")
431+ seen+=" $pkg"
432+ fi
433+ done
434+ else
435+ log "Profile '$profile' has no package definition"
436+ fi
437+ ;;
438+ pkg_*)
439+ local pkg="${tag#pkg_}"
440+ if [[ -n "$pkg" ]] && [[ ! " $seen " =~ [[:space:]]$pkg[[:space:]] ]]; then
441+ pkgs+=("$pkg")
442+ seen+=" $pkg"
443+ fi
444+ ;;
445+ esac
446+ done
447+ fi
430448
431449 printf '%s\n' "${pkgs[@]:-}"
432450}
@@ -488,15 +506,18 @@ run_optional_cleanup() {
488506apply_shellrc_features() {
489507 local tags="$1"
490508 local tag_list="${tags//;/ }"
491- local enable_shellrc=0
492- local enable_fastfetch=0
493-
494- for tag in $tag_list; do
495- case "$tag" in
496- feature_shellrc) enable_shellrc=1 ;;
497- feature_fastfetch) enable_fastfetch=1 ;;
498- esac
499- done
509+ local enable_shellrc="$ENABLE_SHELLRC_FEATURE"
510+ local enable_fastfetch="$ENABLE_FASTFETCH_FEATURE"
511+
512+ if [[ "$USE_TAGS" == "1" ]]; then
513+ local tag
514+ for tag in $tag_list; do
515+ case "$tag" in
516+ feature_shellrc) enable_shellrc=1 ;;
517+ feature_fastfetch) enable_fastfetch=1 ;;
518+ esac
519+ done
520+ fi
500521
501522 if [[ "$ENABLE_BASHRC_TUNING" != "1" ]]; then
502523 log "Shellrc tuning globally disabled"
@@ -579,16 +600,27 @@ main() {
579600
580601 local tags
581602 tags="$(get_tags)"
582- if [[ -z "$tags" && -z "${EXTRA_PACKAGES:-}" ]]; then
583- log "No tags and no EXTRA_PACKAGES configured. Nothing to do."
603+ local should_process=0
604+ if [[ -n "${EXTRA_PACKAGES:-}" ]]; then
605+ should_process=1
606+ fi
607+ if [[ "$ENABLE_SHELLRC_FEATURE" == "1" || "$ENABLE_FASTFETCH_FEATURE" == "1" ]]; then
608+ should_process=1
609+ fi
610+ if [[ "$USE_TAGS" == "1" && -n "$tags" ]]; then
611+ should_process=1
612+ fi
613+
614+ if [[ "$should_process" != "1" ]]; then
615+ log "No active config/tags found. Nothing to do."
584616 if [[ "$RUN_ONCE" == "1" ]]; then
585617 write_marker
586618 fi
587619 exit 0
588620 fi
589621
590622 log "--- Starting guest customization ---"
591- [[ "$VERBOSE" == "1" ]] && log "Tags: ${tags:-<none>}"
623+ [[ "$VERBOSE" == "1" ]] && log "USE_TAGS=$USE_TAGS, Tags: ${tags:-<none>}"
592624
593625 local package_lines
594626 mapfile -t package_lines < <(resolve_requested_packages "$tags")
@@ -722,6 +754,8 @@ On container start, the hookscript can optionally:
722754
723755Tag formats
724756-----------
757+ Optional when USE_TAGS=1.
758+
725759profile_<name>
726760 Uses PROFILE_<name>_PACKAGES from config
727761
@@ -736,6 +770,9 @@ feature_fastfetch
736770
737771Examples
738772--------
773+ Config-only (no tags):
774+ Set USE_TAGS=0 and EXTRA_PACKAGES="fastfetch" in config or per-CT override.
775+
739776tags: profile_shell;profile_ops
740777tags: pkg_fastfetch;pkg_jq
741778tags: profile_shell;pkg_fastfetch;feature_shellrc;feature_fastfetch
@@ -859,10 +896,10 @@ print_summary() {
859896 echo " /etc/systemd/system/pve-auto-customize.service"
860897 echo
861898 echo -e " ${BL} Next steps:${CL} "
862- echo " 1. Edit /etc/default/pve-auto-customize if needed "
863- echo " 2. Add tags to a CT, for example: "
864- echo " pct set 101 -- tags 'profile_shell;profile_ops;pkg_fastfetch;feature_shellrc;feature_fastfetch' "
865- echo " 3 . Restart the CT"
899+ echo " 1. Edit /etc/default/pve-auto-customize (or /etc/pve-auto-customize/<VMID>.conf) "
900+ echo " 2. For simple usage without tags: set USE_TAGS=0 and EXTRA_PACKAGES='fastfetch' "
901+ echo " 3. Optional tag mode: USE_TAGS=1 and set CT tags (profile_*/pkg_*/feature_*) "
902+ echo " 4 . Restart the CT"
866903 echo
867904 echo -e " ${BL} Useful commands:${CL} "
868905 echo " pct config 101"
0 commit comments