Last active
December 15, 2025 02:02
-
-
Save EastArctica/73d92db7e3cd435e8ca30e1a5afecb72 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| group="${1:-}" | |
| if [[ -z "$group" ]]; then | |
| echo "Usage: $0 <package-group>" >&2 | |
| exit 1 | |
| fi | |
| base_dir="${ARCH_CONFIG_DIR:-$HOME/.config/arch-config}" | |
| modules_dir="$base_dir/modules/groups" | |
| out_file="$modules_dir/$group.yaml" | |
| # Fail early if the base config dir is missing. | |
| if [[ ! -d "$base_dir" ]]; then | |
| cat >&2 <<EOF | |
| Error: Base directory not found: $base_dir | |
| Create it first, or set ARCH_CONFIG_DIR to your correct location. | |
| Example: | |
| mkdir -p "$base_dir" | |
| or: | |
| ARCH_CONFIG_DIR=/path/to/arch-config $0 "$group" | |
| EOF | |
| exit 2 | |
| fi | |
| # Create modules/groups if needed. | |
| mkdir -p "$modules_dir" | |
| # If output exists, prompt before overwriting. | |
| if [[ -e "$out_file" ]]; then | |
| printf "File already exists: %s\nUpdate it? [y/N]: " "$out_file" >&2 | |
| read -r reply | |
| reply="${reply,,}" # lowercase | |
| if [[ "$reply" != "y" && "$reply" != "yes" ]]; then | |
| echo "Canceled. Left file unchanged." >&2 | |
| exit 0 | |
| fi | |
| fi | |
| # Query packages in the group. | |
| if ! pkgs="$(pacman -Sg "$group" 2>/dev/null | awk '{print $2}')"; then | |
| echo "Error: Failed to query pacman group: $group" >&2 | |
| exit 3 | |
| fi | |
| if [[ -z "$pkgs" ]]; then | |
| echo "Error: No packages found for group '$group' (or group does not exist)." >&2 | |
| exit 4 | |
| fi | |
| # Write to a temp file then move into place (avoids partial writes). | |
| tmp="$(mktemp)" | |
| trap 'rm -f "$tmp"' EXIT | |
| { | |
| printf 'description: %s package group\n\n' "$group" | |
| printf 'packages:\n' | |
| while IFS= read -r pkg; do | |
| [[ -n "$pkg" ]] || continue | |
| printf ' - %s\n' "$pkg" | |
| done <<< "$pkgs" | |
| } > "$tmp" | |
| mv -f "$tmp" "$out_file" | |
| trap - EXIT | |
| echo "Wrote: $out_file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment