copr enbale

This commit is contained in:
kumar vaibhav 2025-11-21 20:22:02 +05:30
parent d59a4fe592
commit 75e8f2db85
2 changed files with 160 additions and 23 deletions

View file

@ -1,10 +1,11 @@
# Forge - A Home-Manager Like Tool for Fedora # Forge - A Home-Manager Like Tool for Fedora
A lightweight configuration management tool for Fedora that provides dotfile management and package installation functionality through a centralized TOML configuration. A lightweight configuration management tool for Fedora that provides COPR repository management, dotfile management and package installation functionality through a centralized TOML configuration.
## Overview ## Overview
Forge is a bash script that helps you manage your Fedora system configuration by: Forge is a bash script that helps you manage your Fedora system configuration by:
- Managing COPR repositories (enable/disable automatically)
- Installing and managing system packages via dnf - Installing and managing system packages via dnf
- Managing dotfiles through symlinks to actual files - Managing dotfiles through symlinks to actual files
- Centralized configuration via a single `forge.toml` file - Centralized configuration via a single `forge.toml` file
@ -53,17 +54,19 @@ Creates:
- `~/.config/forge/forge.toml` - Central configuration file - `~/.config/forge/forge.toml` - Central configuration file
### `switch` ### `switch`
Apply the current configuration (install packages, deploy dotfiles). Apply the current configuration (enable COPR, install packages, deploy dotfiles).
```bash ```bash
./forge switch ./forge switch
``` ```
This command: This command:
1. Installs all packages listed in `forge.toml` 1. Enables all COPR repositories listed in `forge.toml`
2. Creates symlinks for all configured dotfiles 2. Disables COPR repositories that are no longer configured
3. Creates backups of existing files before replacing them 3. Installs all packages listed in `forge.toml`
4. Updates the last switch timestamp 4. Creates symlinks for all configured dotfiles
5. Creates backups of existing files before replacing them
6. Updates the last switch timestamp
### `status` ### `status`
Show current configuration status and information. Show current configuration status and information.
@ -75,7 +78,7 @@ Show current configuration status and information.
Displays: Displays:
- Configuration directory paths - Configuration directory paths
- Last switch timestamp - Last switch timestamp
- List of configured packages and dotfiles - List of configured COPR repositories, packages and dotfiles
### `help` ### `help`
Show help message with all available commands. Show help message with all available commands.
@ -97,6 +100,12 @@ The central configuration file located at `~/.config/forge/forge.toml`:
version = "1.0" version = "1.0"
last_switch = null last_switch = null
[copr]
# COPR repositories to enable
# Just list COPR repository names - presence means enable, absence means don't enable
copr.fedorainfracloud.org/username/repository
copr.fedorainfracloud.org/anotheruser/anotherrepo
[packages] [packages]
# List of packages to install using dnf # List of packages to install using dnf
# Just list package names - presence means install, absence means don't install # Just list package names - presence means install, absence means don't install
@ -126,6 +135,18 @@ backup_dir = "backup"
- `version`: Configuration file version - `version`: Configuration file version
- `last_switch`: Timestamp of last switch operation (auto-updated) - `last_switch`: Timestamp of last switch operation (auto-updated)
#### `[copr]`
List of COPR repositories to enable via `dnf copr enable`. **Just list COPR repository names** - presence means enable, absence means don't enable.
**Examples:**
```toml
[copr]
copr.fedorainfracloud.org/username/repository
copr.fedorainfracloud.org/anotheruser/anotherrepo
```
To remove a COPR repository, simply delete the line containing the repository name. Forge will automatically disable it during the next switch.
#### `[packages]` #### `[packages]`
List of packages to install via dnf. **Just list package names** - presence means install, absence means don't install. List of packages to install via dnf. **Just list package names** - presence means install, absence means don't install.
@ -168,6 +189,13 @@ Additional configuration options:
## How It Works ## How It Works
### COPR Repository Management
COPR repositories are managed through the `[copr]` section in `forge.toml`:
- **Add COPR repo**: Simply add the repository name on a new line
- **Remove COPR repo**: Delete the line containing the repository name
- **Automatic cleanup**: Forge automatically disables COPR repos that are removed from configuration
- **No flags needed**: Just presence/absence of the repository name matters
### Package Management ### Package Management
Packages are managed through the `[packages]` section in `forge.toml`: Packages are managed through the `[packages]` section in `forge.toml`:
- **Add package**: Simply add the package name on a new line - **Add package**: Simply add the package name on a new line
@ -195,9 +223,12 @@ Before creating symlinks, Forge:
# Initialize forge # Initialize forge
./forge init ./forge init
# Edit forge.toml to add packages # Edit forge.toml to add COPR repos and packages
nano ~/.config/forge/forge.toml nano ~/.config/forge/forge.toml
# Add to [copr] section:
copr.fedorainfracloud.org/username/cool-repo
# Add to [packages] section: # Add to [packages] section:
git git
vim vim
@ -230,6 +261,17 @@ nano ~/.config/forge/forge.toml
./forge switch ./forge switch
``` ```
### COPR Repository Management Examples
```toml
[copr]
# Development tools COPR
copr.fedorainfracloud.org/development/tools
copr.fedorainfracloud.org/user/neovim-nightly
# To remove a COPR repo, just delete the line
# Forge will automatically disable it during the next switch
```
### Package Management Examples ### Package Management Examples
```toml ```toml
[packages] [packages]
@ -269,6 +311,7 @@ git commit -m "Updated vim configuration"
## Dependencies ## Dependencies
- `dnf` - Fedora package manager - `dnf` - Fedora package manager
- `dnf-plugins-core` - For COPR repository management
- `sed` - For updating configuration file (usually pre-installed) - `sed` - For updating configuration file (usually pre-installed)
## Migration from Previous Version ## Migration from Previous Version

124
forge
View file

@ -50,6 +50,13 @@ init() {
version = "1.0" version = "1.0"
last_switch = null last_switch = null
[copr]
# COPR repositories to enable
# Just list COPR repository names - presence means enable, absence means don't enable
# Examples:
# copr.fedorainfracloud.org/username/repository
# copr.fedorainfracloud.org/anotheruser/anotherrepo
[packages] [packages]
# List of packages to install using dnf # List of packages to install using dnf
# Just list package names - presence means install, absence means don't install # Just list package names - presence means install, absence means don't install
@ -102,10 +109,71 @@ parse_toml() {
elif [[ "$section" == "packages" && "$line" =~ ^([^=]+)$ ]]; then elif [[ "$section" == "packages" && "$line" =~ ^([^=]+)$ ]]; then
local package="${BASH_REMATCH[1]// /}" local package="${BASH_REMATCH[1]// /}"
echo "$section:$package" echo "$section:$package"
# Parse COPR repository names (just keys without values in copr section)
elif [[ "$section" == "copr" && "$line" =~ ^([^=]+)$ ]]; then
local copr_repo="${BASH_REMATCH[1]// /}"
echo "$section:$copr_repo"
fi fi
done <"$FORGE_TOML" done <"$FORGE_TOML"
} }
# Enable COPR repositories from forge.toml
enable_copr_repos() {
log_info "Enabling COPR repositories..."
local copr_enabled=false
while IFS='=' read -r entry; do
local section="${entry%%:*}"
local copr_repo="${entry#*:}"
if [[ "$section" == "copr" && -n "$copr_repo" ]]; then
copr_enabled=true
log_info "Enabling COPR repository: $copr_repo"
if sudo dnf copr enable -y "$copr_repo"; then
log_success "Enabled COPR: $copr_repo"
else
log_error "Failed to enable COPR: $copr_repo"
fi
fi
done < <(parse_toml)
if [[ "$copr_enabled" == false ]]; then
log_info "No COPR repositories to enable"
fi
}
# Disable COPR repositories that are no longer in forge.toml
disable_copr_repos() {
log_info "Checking for COPR repositories to disable..."
# Get currently enabled COPR repos
local enabled_repos=$(sudo dnf copr list --enabled 2>/dev/null | grep -E "copr\.fedorainfracloud\.org" | awk '{print $1}' || true)
# Get configured COPR repos from forge.toml
local configured_repos=""
while IFS='=' read -r entry; do
local section="${entry%%:*}"
local copr_repo="${entry#*:}"
if [[ "$section" == "copr" && -n "$copr_repo" ]]; then
configured_repos="$configured_repos $copr_repo"
fi
done < <(parse_toml)
# Disable repos that are enabled but not configured
for repo in $enabled_repos; do
if [[ ! " $configured_repos " =~ " $repo " ]]; then
log_info "Disabling COPR repository: $repo"
if sudo dnf copr disable -y "$repo"; then
log_success "Disabled COPR: $repo"
else
log_error "Failed to disable COPR: $repo"
fi
fi
done
}
# Install packages from forge.toml # Install packages from forge.toml
install_packages() { install_packages() {
log_info "Installing packages..." log_info "Installing packages..."
@ -194,6 +262,12 @@ switch() {
exit 1 exit 1
fi fi
# Enable COPR repositories
enable_copr_repos
# Disable COPR repositories that are no longer configured
disable_copr_repos
# Install packages # Install packages
install_packages install_packages
@ -226,6 +300,25 @@ status() {
echo " Last switch: Never" echo " Last switch: Never"
fi fi
echo
log_info "COPR Repositories:"
local copr_count=0
while IFS='=' read -r entry; do
local section="${entry%%:*}"
local copr_repo="${entry#*:}"
if [[ "$section" == "copr" && -n "$copr_repo" ]]; then
echo " $copr_repo"
((copr_count++))
fi
done < <(parse_toml)
if [[ $copr_count -eq 0 ]]; then
echo " No COPR repositories configured"
else
echo " Total: $copr_count COPR repositories"
fi
echo echo
log_info "Packages:" log_info "Packages:"
local package_count=0 local package_count=0
@ -279,27 +372,28 @@ show_help() {
forge <COMMAND> forge <COMMAND>
COMMANDS: COMMANDS:
init Initialize configuration structure (creates forge.toml) init Initialize configuration structure (creates forge.toml)
switch Apply configuration (install packages, deploy dotfiles) switch Apply configuration (enable COPR, install packages, deploy dotfiles)
status Show current configuration status status Show current configuration status
help Show this help message help Show this help message
FEATURES: FEATURES:
- TOML-based configuration in forge.toml - TOML-based configuration in forge.toml
- Package management via dnf - COPR repository management (enable/disable automatically)
- Dotfile management via symlinks - Package management via dnf
- Automatic backup of existing files - Dotfile management via symlinks
- User-level configuration like home-manager/nixos - Automatic backup of existing files
- User-level configuration like home-manager/nixos
FILES: FILES:
$FORGE_DIR/ Main configuration directory $FORGE_DIR/ Main configuration directory
$FORGE_TOML Configuration file for packages and dotfiles $FORGE_TOML Configuration file for COPR, packages and dotfiles
EXAMPLES: EXAMPLES:
forge init forge init
# Edit $FORGE_TOML to add packages and dotfiles # Edit $FORGE_TOML to add COPR repos, packages and dotfiles
forge switch forge switch
forge status forge status
EOF EOF
} }