#!/bin/bash # rpm-ostree Command Testing Script # This script tests all rpm-ostree commands and captures their output # for comparison with apt-ostree implementation set -e # Output file OUTPUT_FILE="rpm_ostree_commands_output.txt" LOG_FILE="rpm_ostree_test.log" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Function to log messages log() { echo -e "${BLUE}[$(date '+%Y-%m-%d %H:%M:%S')]${NC} $1" | tee -a "$LOG_FILE" } # Function to test a command test_command() { local cmd="$1" local description="$2" local args="$3" log "Testing: $cmd $args - $description" echo "=== $cmd $args - $description ===" >> "$OUTPUT_FILE" echo "" >> "$OUTPUT_FILE" # Test without sudo log " Testing without sudo..." echo "--- Without sudo ---" >> "$OUTPUT_FILE" if timeout 30s bash -c "$cmd $args" >> "$OUTPUT_FILE" 2>&1; then echo -e "${GREEN} ✓ Success without sudo${NC}" else echo -e "${YELLOW} ⚠ Failed without sudo (expected for some commands)${NC}" fi echo "" >> "$OUTPUT_FILE" # Test with sudo log " Testing with sudo..." echo "--- With sudo ---" >> "$OUTPUT_FILE" if timeout 30s sudo bash -c "$cmd $args" >> "$OUTPUT_FILE" 2>&1; then echo -e "${GREEN} ✓ Success with sudo${NC}" else echo -e "${YELLOW} ⚠ Failed with sudo (expected for some commands)${NC}" fi echo "" >> "$OUTPUT_FILE" # Test --help log " Testing --help..." echo "--- --help output ---" >> "$OUTPUT_FILE" if timeout 30s bash -c "$cmd --help" >> "$OUTPUT_FILE" 2>&1; then echo -e "${GREEN} ✓ --help successful${NC}" else echo -e "${RED} ✗ --help failed${NC}" fi echo "" >> "$OUTPUT_FILE" echo "==========================================" >> "$OUTPUT_FILE" echo "" >> "$OUTPUT_FILE" log "Completed testing: $cmd" echo "" } # Function to test commands with arguments test_command_with_args() { local cmd="$1" local description="$2" local args="$3" log "Testing: $cmd $args - $description" echo "=== $cmd $args - $description ===" >> "$OUTPUT_FILE" echo "" >> "$OUTPUT_FILE" # Test without sudo log " Testing without sudo..." echo "--- Without sudo ---" >> "$OUTPUT_FILE" if timeout 30s bash -c "$cmd $args" >> "$OUTPUT_FILE" 2>&1; then echo -e "${GREEN} ✓ Success without sudo${NC}" else echo -e "${YELLOW} ⚠ Failed without sudo (expected for some commands)${NC}" fi echo "" >> "$OUTPUT_FILE" # Test with sudo log " Testing with sudo..." echo "--- With sudo ---" >> "$OUTPUT_FILE" if timeout 30s sudo bash -c "$cmd $args" >> "$OUTPUT_FILE" 2>&1; then echo -e "${GREEN} ✓ Success with sudo${NC}" else echo -e "${YELLOW} ⚠ Failed with sudo (expected for some commands)${NC}" fi echo "" >> "$OUTPUT_FILE" echo "==========================================" >> "$OUTPUT_FILE" echo "" >> "$OUTPUT_FILE" log "Completed testing: $cmd $args" echo "" } # Main script main() { log "Starting rpm-ostree command testing..." log "Output will be saved to: $OUTPUT_FILE" log "Log will be saved to: $LOG_FILE" # Clear output file > "$OUTPUT_FILE" > "$LOG_FILE" # Header echo "rpm-ostree Command Testing Results" >> "$OUTPUT_FILE" echo "Generated on: $(date)" >> "$OUTPUT_FILE" echo "System: $(uname -a)" >> "$OUTPUT_FILE" echo "rpm-ostree version: $(rpm-ostree --version 2>/dev/null || echo 'Unknown')" >> "$OUTPUT_FILE" echo "" >> "$OUTPUT_FILE" echo "==========================================" >> "$OUTPUT_FILE" echo "" >> "$OUTPUT_FILE" # Test basic commands (no arguments) log "Testing basic commands..." test_command "rpm-ostree" "No arguments (should show usage)" test_command "rpm-ostree --version" "Version information" test_command "rpm-ostree --help" "Help information" test_command "rpm-ostree -h" "Short help" test_command "rpm-ostree -q" "Quiet mode" test_command "rpm-ostree --quiet" "Quiet mode long" # Test commands that don't require arguments log "Testing commands without required arguments..." test_command "rpm-ostree status" "System status" test_command "rpm-ostree cancel" "Cancel transaction" test_command "rpm-ostree cleanup" "Cleanup" test_command "rpm-ostree reload" "Reload configuration" test_command "rpm-ostree reset" "Reset mutations" test_command "rpm-ostree rollback" "Rollback system" test_command "rpm-ostree upgrade" "Upgrade system" test_command "rpm-ostree finalize-deployment" "Finalize deployment" # Test commands that require arguments log "Testing commands that require arguments..." test_command_with_args "rpm-ostree search" "Search packages" "apt" test_command_with_args "rpm-ostree install" "Install package" "vim" test_command_with_args "rpm-ostree uninstall" "Uninstall package" "vim" test_command_with_args "rpm-ostree deploy" "Deploy commit" "test-commit" test_command_with_args "rpm-ostree rebase" "Rebase to target" "test-target" test_command_with_args "rpm-ostree apply-live" "Apply live changes" "" # Test subcommand groups log "Testing subcommand groups..." test_command "rpm-ostree compose" "Compose commands" test_command "rpm-ostree db" "Database commands" test_command "rpm-ostree initramfs" "Initramfs commands" test_command "rpm-ostree initramfs-etc" "Initramfs-etc commands" test_command "rpm-ostree kargs" "Kernel args commands" test_command "rpm-ostree override" "Override commands" test_command "rpm-ostree usroverlay" "USR overlay commands" # Test specific subcommands log "Testing specific subcommands..." test_command_with_args "rpm-ostree db list" "Database list" "" test_command_with_args "rpm-ostree db diff" "Database diff" "" test_command_with_args "rpm-ostree kargs get" "Get kernel args" "" test_command_with_args "rpm-ostree kargs set" "Set kernel args" "test=value" test_command_with_args "rpm-ostree override add" "Add override" "test-package" test_command_with_args "rpm-ostree override remove" "Remove override" "test-package" test_command_with_args "rpm-ostree override reset" "Reset overrides" "" # Test compose subcommands log "Testing compose subcommands..." test_command "rpm-ostree compose start" "Start compose" test_command "rpm-ostree compose status" "Compose status" test_command "rpm-ostree compose cancel" "Cancel compose" # Test initramfs subcommands log "Testing initramfs subcommands..." test_command "rpm-ostree initramfs enable" "Enable initramfs" test_command "rpm-ostree initramfs disable" "Disable initramfs" test_command "rpm-ostree initramfs-etc add" "Add initramfs-etc" test_command "rpm-ostree initramfs-etc remove" "Remove initramfs-etc" # Test usroverlay subcommands log "Testing usroverlay subcommands..." test_command "rpm-ostree usroverlay apply" "Apply usroverlay" test_command "rpm-ostree usroverlay remove" "Remove usroverlay" # Test refresh-md log "Testing refresh-md..." test_command "rpm-ostree refresh-md" "Refresh metadata" # Test with sysroot option log "Testing with sysroot option..." test_command_with_args "rpm-ostree status" "Status with sysroot" "--sysroot=/" test_command_with_args "rpm-ostree status" "Status with peer" "--peer" # Test error conditions log "Testing error conditions..." test_command_with_args "rpm-ostree install" "Install without package (should fail)" "" test_command_with_args "rpm-ostree search" "Search without query (should fail)" "" test_command_with_args "rpm-ostree deploy" "Deploy without commit (should fail)" "" test_command_with_args "rpm-ostree rebase" "Rebase without target (should fail)" "" # Test invalid commands log "Testing invalid commands..." test_command "rpm-ostree invalid-command" "Invalid command (should fail)" test_command "rpm-ostree --invalid-flag" "Invalid flag (should fail)" # Footer echo "==========================================" >> "$OUTPUT_FILE" echo "Testing completed on: $(date)" >> "$OUTPUT_FILE" echo "Total commands tested: $(grep -c "===" "$OUTPUT_FILE")" >> "$OUTPUT_FILE" log "Testing completed!" log "Results saved to: $OUTPUT_FILE" log "Log saved to: $LOG_FILE" echo -e "${GREEN}✅ All tests completed successfully!${NC}" echo -e "${BLUE}📄 Results: $OUTPUT_FILE${NC}" echo -e "${BLUE}📝 Log: $LOG_FILE${NC}" } # Run main function main "$@"