Refactored profiles and package lists into centralized config files.
This commit is contained in:
@@ -16,152 +16,106 @@
|
||||
|
||||
# registry.sh - Profile registry and management
|
||||
#
|
||||
# Defines installation profiles that customize the system for different use cases.
|
||||
# Each profile specifies which packages to install and services to enable.
|
||||
# Provides functions to list, select, and install profiles.
|
||||
# Profile definitions are loaded from config/profiles.conf.
|
||||
# Adding a new profile requires only adding entries to the config file.
|
||||
|
||||
# Source shared package definitions
|
||||
source "${SCRIPT_DIR}/profiles/packages.sh"
|
||||
# Get profile key by menu number (1-based)
|
||||
# Arguments:
|
||||
# $1 - menu selection number
|
||||
# Outputs:
|
||||
# Profile key to stdout
|
||||
get_profile_key() {
|
||||
local index=$(($1 - 1))
|
||||
echo "${PROFILES[$index]}"
|
||||
}
|
||||
|
||||
# Profile definitions
|
||||
declare -A PROFILE_NAMES=(
|
||||
[1]="Minimal"
|
||||
[2]="Server"
|
||||
[3]="Minimal Desktop"
|
||||
[4]="Home Theater PC"
|
||||
[5]="Home Theater PC with Gaming"
|
||||
[6]="Office Workstation"
|
||||
[7]="Software Development Workstation"
|
||||
)
|
||||
|
||||
declare -A PROFILE_DESCRIPTIONS=(
|
||||
[1]="Base Arch Linux system, no additional packages."
|
||||
[2]="Adds Restic, Docker, and Docker Compose."
|
||||
[3]="XFCE 4 with no additional applications."
|
||||
[4]="XFCE 4 with Chromium and VLC media player."
|
||||
[5]="XFCE 4 with Chromium, VLC media player, and Dolphin."
|
||||
[6]="XFCE 4 with a full suite of desktop applications aimed at general office work."
|
||||
[7]="XFCE 4 with a suite of software development applications."
|
||||
)
|
||||
|
||||
declare -A PROFILE_REQUIRES_XFCE=(
|
||||
[1]=false
|
||||
[2]=false
|
||||
[3]=true
|
||||
[4]=true
|
||||
[5]=true
|
||||
[6]=true
|
||||
[7]=true
|
||||
)
|
||||
|
||||
# Display available profiles
|
||||
# Display available profiles (auto-generated from PROFILES array)
|
||||
list_profiles() {
|
||||
print "Base install complete. Select profile to install for this system:"
|
||||
|
||||
for i in {1..7}; do
|
||||
print " $i - ${PROFILE_NAMES[$i]}"
|
||||
print " ${PROFILE_DESCRIPTIONS[$i]}"
|
||||
local i=1
|
||||
for profile in "${PROFILES[@]}"; do
|
||||
local name_var="PROFILE_${profile}_NAME"
|
||||
local desc_var="PROFILE_${profile}_DESC"
|
||||
print " $i - ${!name_var}"
|
||||
print " ${!desc_var}"
|
||||
((i++))
|
||||
done
|
||||
}
|
||||
|
||||
# Get packages for a profile
|
||||
# Arguments:
|
||||
# $1 - profile number
|
||||
# $1 - profile key
|
||||
# Outputs:
|
||||
# Package list to stdout
|
||||
get_profile_packages() {
|
||||
local profile="$1"
|
||||
|
||||
case "$profile" in
|
||||
"1")
|
||||
# Minimal - no additional packages
|
||||
;;
|
||||
"2")
|
||||
# Server
|
||||
echo "restic docker docker-compose"
|
||||
;;
|
||||
"3")
|
||||
# Minimal Desktop - XFCE only, no additional packages
|
||||
;;
|
||||
"4")
|
||||
# Home Theater PC
|
||||
echo "${PACKAGES_MEDIA[*]}"
|
||||
;;
|
||||
"5")
|
||||
# Home Theater PC with Gaming
|
||||
echo "dolphin-emu ${PACKAGES_MEDIA[*]}"
|
||||
;;
|
||||
"6")
|
||||
# Office Workstation
|
||||
echo "${PACKAGES_MEDIA[*]} ${PACKAGES_OFFICE[*]} ${PACKAGES_PRODUCTIVITY[*]} git gnucash"
|
||||
;;
|
||||
"7")
|
||||
# Software Development Workstation
|
||||
echo "${PACKAGES_MEDIA[*]} ${PACKAGES_OFFICE[*]} ${PACKAGES_PRODUCTIVITY[*]}"
|
||||
echo "${PACKAGES_DEV_BASE[*]} ${PACKAGES_DEV_PYTHON[*]} ${PACKAGES_DEV_JAVA[*]}"
|
||||
echo "${PACKAGES_DEV_GO[*]} ${PACKAGES_DEV_TOOLS[*]}"
|
||||
;;
|
||||
esac
|
||||
local profile_key="$1"
|
||||
local pkg_var="PROFILE_${profile_key}_PACKAGES[@]"
|
||||
echo "${!pkg_var}"
|
||||
}
|
||||
|
||||
# Get services to enable for a profile
|
||||
# Get services for a profile
|
||||
# Arguments:
|
||||
# $1 - profile number
|
||||
# $1 - profile key
|
||||
# Outputs:
|
||||
# Service list to stdout
|
||||
get_profile_services() {
|
||||
local profile="$1"
|
||||
|
||||
case "$profile" in
|
||||
"2"|"7")
|
||||
echo "docker.service"
|
||||
;;
|
||||
esac
|
||||
local profile_key="$1"
|
||||
local svc_var="PROFILE_${profile_key}_SERVICES[@]"
|
||||
echo "${!svc_var}"
|
||||
}
|
||||
|
||||
# Check if profile requires XFCE
|
||||
# Arguments:
|
||||
# $1 - profile number
|
||||
# $1 - profile key
|
||||
# Returns:
|
||||
# 0 if requires XFCE, 1 otherwise
|
||||
profile_requires_xfce() {
|
||||
local profile="$1"
|
||||
local profile_key="$1"
|
||||
local xfce_var="PROFILE_${profile_key}_XFCE"
|
||||
[ "${!xfce_var}" = "true" ]
|
||||
}
|
||||
|
||||
if [ "${PROFILE_REQUIRES_XFCE[$profile]}" = "true" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
# Validate profile selection
|
||||
# Arguments:
|
||||
# $1 - user selection
|
||||
# Returns:
|
||||
# 0 if valid, 1 otherwise
|
||||
validate_profile_selection() {
|
||||
local selection="$1"
|
||||
local max="${#PROFILES[@]}"
|
||||
[[ "$selection" =~ ^[1-9][0-9]*$ ]] && [ "$selection" -le "$max" ]
|
||||
}
|
||||
|
||||
# Install a profile
|
||||
# Arguments:
|
||||
# $1 - profile number
|
||||
# $1 - profile key
|
||||
# $2 - username
|
||||
install_profile() {
|
||||
local profile="$1"
|
||||
local profile_key="$1"
|
||||
local username="$2"
|
||||
local packages
|
||||
local services
|
||||
|
||||
# Install XFCE if required
|
||||
if profile_requires_xfce "$profile"; then
|
||||
if profile_requires_xfce "$profile_key"; then
|
||||
install_xfce "$username"
|
||||
prompt_install_graphics
|
||||
fi
|
||||
|
||||
# Get and install profile packages
|
||||
packages=$(get_profile_packages "$profile")
|
||||
packages=$(get_profile_packages "$profile_key")
|
||||
if [ -n "$packages" ]; then
|
||||
# shellcheck disable=SC2086
|
||||
chroot_pacman_install $packages
|
||||
fi
|
||||
|
||||
# Enable profile services
|
||||
services=$(get_profile_services "$profile")
|
||||
if [ -n "$services" ]; then
|
||||
# shellcheck disable=SC2086
|
||||
chroot_systemd_enable $services
|
||||
fi
|
||||
services=$(get_profile_services "$profile_key")
|
||||
for service in $services; do
|
||||
chroot_systemd_enable "$service"
|
||||
done
|
||||
}
|
||||
|
||||
# Prompt user for profile selection and install
|
||||
@@ -169,16 +123,18 @@ install_profile() {
|
||||
# $1 - username
|
||||
select_and_install_profile() {
|
||||
local username="$1"
|
||||
local profile
|
||||
local selection
|
||||
local profile_key
|
||||
|
||||
list_profiles
|
||||
read -r profile
|
||||
read -r selection
|
||||
|
||||
# Validate selection
|
||||
if ! [[ "$profile" =~ ^[1-7]$ ]]; then
|
||||
if ! validate_profile_selection "$selection"; then
|
||||
print_warning "Unknown profile, defaulting to minimal install."
|
||||
profile="1"
|
||||
selection="1"
|
||||
fi
|
||||
|
||||
install_profile "$profile" "$username"
|
||||
profile_key=$(get_profile_key "$selection")
|
||||
install_profile "$profile_key" "$username"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user