packages-file improved
This commit is contained in:
parent
d11639ea8f
commit
efb8004253
1 changed files with 74 additions and 35 deletions
109
forge
109
forge
|
|
@ -8,7 +8,7 @@ set -euo pipefail
|
||||||
# Configuration
|
# Configuration
|
||||||
HOME_MANAGER_DIR="${HOME_MANAGER_DIR:-$HOME/.config/fedora-home-manager}"
|
HOME_MANAGER_DIR="${HOME_MANAGER_DIR:-$HOME/.config/fedora-home-manager}"
|
||||||
DOTFILES_DIR="$HOME_MANAGER_DIR/dotfiles"
|
DOTFILES_DIR="$HOME_MANAGER_DIR/dotfiles"
|
||||||
PACKAGES_FILE="$HOME_MANAGER_DIR/packages.txt"
|
PACKAGES_FILE="$HOME_MANAGER_DIR/packages.toml"
|
||||||
STATE_FILE="$HOME_MANAGER_DIR/state.json"
|
STATE_FILE="$HOME_MANAGER_DIR/state.json"
|
||||||
BACKUP_DIR="$HOME_MANAGER_DIR/backup"
|
BACKUP_DIR="$HOME_MANAGER_DIR/backup"
|
||||||
|
|
||||||
|
|
@ -51,17 +51,21 @@ init() {
|
||||||
log_success "Created state file: $STATE_FILE"
|
log_success "Created state file: $STATE_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create initial packages file with example content if it doesn't exist
|
# Create initial packages file with TOML format if it doesn't exist
|
||||||
if [[ ! -f "$PACKAGES_FILE" ]]; then
|
if [[ ! -f "$PACKAGES_FILE" ]]; then
|
||||||
cat >"$PACKAGES_FILE" <<'EOF'
|
cat >"$PACKAGES_FILE" <<'EOF'
|
||||||
# Fedora packages to install
|
# Fedora packages configuration
|
||||||
# One package per line
|
# TOML format for better package management
|
||||||
# Lines starting with # are comments
|
|
||||||
# Example:
|
[packages]
|
||||||
# git
|
# Core development tools
|
||||||
# vim
|
# git = "latest"
|
||||||
# curl
|
# vim = "latest"
|
||||||
# wget
|
# curl = "latest"
|
||||||
|
# wget = "latest"
|
||||||
|
|
||||||
|
# Additional packages can be added with version specifications
|
||||||
|
# Example: package_name = "version" or "latest"
|
||||||
EOF
|
EOF
|
||||||
log_success "Created packages file: $PACKAGES_FILE"
|
log_success "Created packages file: $PACKAGES_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
@ -131,18 +135,22 @@ install_packages() {
|
||||||
|
|
||||||
local current_packages=()
|
local current_packages=()
|
||||||
|
|
||||||
# Read packages and install them
|
# Parse TOML and extract package names
|
||||||
while IFS= read -r package; do
|
while IFS= read -r line; do
|
||||||
# Skip empty lines and comments
|
# Skip empty lines, comments, and section headers
|
||||||
[[ -z "$package" || "$package" == \#* ]] && continue
|
[[ -z "$line" || "$line" == \#* || "$line" == \[* ]] && continue
|
||||||
|
|
||||||
current_packages+=("$package")
|
|
||||||
|
|
||||||
log_info "Installing package: $package"
|
# Extract package name (before =)
|
||||||
if sudo dnf install -y "$package"; then
|
if [[ "$line" =~ ^[[:space:]]*([^=]+)[[:space:]]*= ]]; then
|
||||||
log_success "Installed $package"
|
local package="${BASH_REMATCH[1]// /}" # Remove whitespace
|
||||||
else
|
current_packages+=("$package")
|
||||||
log_error "Failed to install $package"
|
|
||||||
|
log_info "Installing package: $package"
|
||||||
|
if sudo dnf install -y "$package"; then
|
||||||
|
log_success "Installed $package"
|
||||||
|
else
|
||||||
|
log_error "Failed to install $package"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done <"$PACKAGES_FILE"
|
done <"$PACKAGES_FILE"
|
||||||
|
|
||||||
|
|
@ -150,16 +158,22 @@ install_packages() {
|
||||||
update_installed_packages "${current_packages[@]}"
|
update_installed_packages "${current_packages[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Uninstall packages that are no longer in packages.txt
|
# Uninstall packages that are no longer in packages.toml
|
||||||
cleanup_packages() {
|
cleanup_packages() {
|
||||||
log_info "Cleaning up packages that are no longer needed..."
|
log_info "Cleaning up packages that are no longer needed..."
|
||||||
|
|
||||||
# Get current packages from packages.txt
|
# Get current packages from packages.toml
|
||||||
local current_packages=()
|
local current_packages=()
|
||||||
if [[ -f "$PACKAGES_FILE" ]]; then
|
if [[ -f "$PACKAGES_FILE" ]]; then
|
||||||
while IFS= read -r package; do
|
while IFS= read -r line; do
|
||||||
[[ -z "$package" || "$package" == \#* ]] && continue
|
# Skip empty lines, comments, and section headers
|
||||||
current_packages+=("$package")
|
[[ -z "$line" || "$line" == \#* || "$line" == \[* ]] && continue
|
||||||
|
|
||||||
|
# Extract package name (before =)
|
||||||
|
if [[ "$line" =~ ^[[:space:]]*([^=]+)[[:space:]]*= ]]; then
|
||||||
|
local package="${BASH_REMATCH[1]// /}" # Remove whitespace
|
||||||
|
current_packages+=("$package")
|
||||||
|
fi
|
||||||
done <"$PACKAGES_FILE"
|
done <"$PACKAGES_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -353,7 +367,31 @@ list_managed() {
|
||||||
|
|
||||||
log_info "Managed packages:"
|
log_info "Managed packages:"
|
||||||
if [[ -f "$PACKAGES_FILE" ]]; then
|
if [[ -f "$PACKAGES_FILE" ]]; then
|
||||||
grep -v '^#' "$PACKAGES_FILE" | grep -v '^$' | sed 's/^/ /' || log_info " No packages"
|
while IFS= read -r line; do
|
||||||
|
# Skip empty lines, comments, and section headers
|
||||||
|
[[ -z "$line" || "$line" == \#* || "$line" == \[* ]] && continue
|
||||||
|
|
||||||
|
# Extract package name (before =)
|
||||||
|
if [[ "$line" =~ ^[[:space:]]*([^=]+)[[:space:]]*= ]]; then
|
||||||
|
local package="${BASH_REMATCH[1]// /}" # Remove whitespace
|
||||||
|
echo " $package"
|
||||||
|
fi
|
||||||
|
done <"$PACKAGES_FILE"
|
||||||
|
|
||||||
|
# Check if any packages were found
|
||||||
|
local package_count=0
|
||||||
|
while IFS= read -r line; do
|
||||||
|
[[ -z "$line" || "$line" == \#* || "$line" == \[* ]] && continue
|
||||||
|
if [[ "$line" =~ ^[[:space:]]*([^=]+)[[:space:]]*= ]]; then
|
||||||
|
((package_count++))
|
||||||
|
fi
|
||||||
|
done <"$PACKAGES_FILE"
|
||||||
|
|
||||||
|
if [[ $package_count -eq 0 ]]; then
|
||||||
|
log_info " No packages"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log_info " No packages"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -396,15 +434,16 @@ show_help() {
|
||||||
help Show this help message
|
help Show this help message
|
||||||
|
|
||||||
FEATURES:
|
FEATURES:
|
||||||
- Automatic package cleanup: When you remove a package from packages.txt and run switch,
|
- Automatic package cleanup: When you remove a package from packages.toml and run switch,
|
||||||
the package will be automatically uninstalled from your system.
|
the package will be automatically uninstalled from your system.
|
||||||
- Package state tracking: Previously installed packages are tracked to enable cleanup.
|
- Package state tracking: Previously installed packages are tracked to enable cleanup.
|
||||||
|
- TOML format: Packages are managed in TOML format for better organization and version support.
|
||||||
|
|
||||||
FILES:
|
FILES:
|
||||||
$HOME_MANAGER_DIR/ Main configuration directory
|
$HOME_MANAGER_DIR/ Main configuration directory
|
||||||
$DOTFILES_DIR/ Dotfiles to deploy
|
$DOTFILES_DIR/ Dotfiles to deploy
|
||||||
$PACKAGES_FILE List of packages to install (one per line)
|
$PACKAGES_FILE TOML file with packages to install (supports version specifications)
|
||||||
$STATE_FILE State tracking file for managed packages and files
|
$STATE_FILE State tracking file for managed packages and files
|
||||||
|
|
||||||
EXAMPLES:
|
EXAMPLES:
|
||||||
fedora-home-manager init
|
fedora-home-manager init
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue