debian-atomic/scripts/apt-ostree-report.sh

263 lines
7 KiB
Bash
Executable file

#!/bin/bash
# apt-ostree Reporting Script
# Comprehensive reporting for Debian Atomic apt-ostree testing
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
REPORT_FILE="${REPORT_FILE:-apt-ostree-report.txt}"
VERBOSE="${VERBOSE:-false}"
# Helper functions
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Test functions
test_apt_ostree_version() {
log_info "Testing apt-ostree version..."
if apt-ostree --version >/dev/null 2>&1; then
local version=$(apt-ostree --version)
log_success "apt-ostree version: $version"
echo "VERSION: $version" >> "$REPORT_FILE"
return 0
else
log_error "apt-ostree --version failed"
echo "VERSION: FAILED" >> "$REPORT_FILE"
return 1
fi
}
test_apt_ostree_help() {
log_info "Testing apt-ostree help..."
if apt-ostree --help >/dev/null 2>&1; then
log_success "apt-ostree --help works"
echo "HELP: SUCCESS" >> "$REPORT_FILE"
return 0
else
log_error "apt-ostree --help failed"
echo "HELP: FAILED" >> "$REPORT_FILE"
return 1
fi
}
test_apt_ostree_status() {
log_info "Testing apt-ostree status..."
if apt-ostree status >/dev/null 2>&1; then
local status_output=$(apt-ostree status)
log_success "apt-ostree status works"
echo "STATUS: SUCCESS" >> "$REPORT_FILE"
if [ "$VERBOSE" = "true" ]; then
echo "STATUS_OUTPUT:" >> "$REPORT_FILE"
echo "$status_output" >> "$REPORT_FILE"
fi
return 0
else
log_error "apt-ostree status failed"
echo "STATUS: FAILED" >> "$REPORT_FILE"
return 1
fi
}
test_apt_ostree_list() {
log_info "Testing apt-ostree list..."
if apt-ostree list >/dev/null 2>&1; then
local list_output=$(apt-ostree list)
log_success "apt-ostree list works"
echo "LIST: SUCCESS" >> "$REPORT_FILE"
if [ "$VERBOSE" = "true" ]; then
echo "LIST_OUTPUT:" >> "$REPORT_FILE"
echo "$list_output" >> "$REPORT_FILE"
fi
return 0
else
log_error "apt-ostree list failed"
echo "LIST: FAILED" >> "$REPORT_FILE"
return 1
fi
}
test_apt_ostree_search() {
log_info "Testing apt-ostree search..."
if apt-ostree search htop >/dev/null 2>&1; then
local search_output=$(apt-ostree search htop)
log_success "apt-ostree search works"
echo "SEARCH: SUCCESS" >> "$REPORT_FILE"
if [ "$VERBOSE" = "true" ]; then
echo "SEARCH_OUTPUT:" >> "$REPORT_FILE"
echo "$search_output" >> "$REPORT_FILE"
fi
return 0
else
log_error "apt-ostree search failed"
echo "SEARCH: FAILED" >> "$REPORT_FILE"
return 1
fi
}
test_apt_ostree_info() {
log_info "Testing apt-ostree info..."
if apt-ostree info apt-ostree >/dev/null 2>&1; then
local info_output=$(apt-ostree info apt-ostree)
log_success "apt-ostree info works"
echo "INFO: SUCCESS" >> "$REPORT_FILE"
if [ "$VERBOSE" = "true" ]; then
echo "INFO_OUTPUT:" >> "$REPORT_FILE"
echo "$info_output" >> "$REPORT_FILE"
fi
return 0
else
log_error "apt-ostree info failed"
echo "INFO: FAILED" >> "$REPORT_FILE"
return 1
fi
}
test_apt_ostree_install() {
log_info "Testing apt-ostree install..."
if apt-ostree install htop >/dev/null 2>&1; then
log_success "apt-ostree install works"
echo "INSTALL: SUCCESS" >> "$REPORT_FILE"
return 0
else
log_error "apt-ostree install failed"
echo "INSTALL: FAILED" >> "$REPORT_FILE"
return 1
fi
}
test_apt_ostree_remove() {
log_info "Testing apt-ostree remove..."
if apt-ostree remove htop >/dev/null 2>&1; then
log_success "apt-ostree remove works"
echo "REMOVE: SUCCESS" >> "$REPORT_FILE"
return 0
else
log_error "apt-ostree remove failed"
echo "REMOVE: FAILED" >> "$REPORT_FILE"
return 1
fi
}
# Main reporting function
generate_report() {
log_info "Starting apt-ostree comprehensive testing..."
# Initialize report file
echo "=== apt-ostree Testing Report ===" > "$REPORT_FILE"
echo "Generated: $(date)" >> "$REPORT_FILE"
echo "Environment: $(uname -a)" >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
# Test counter
local total_tests=0
local passed_tests=0
local failed_tests=0
# Run all tests
local tests=(
"test_apt_ostree_version"
"test_apt_ostree_help"
"test_apt_ostree_status"
"test_apt_ostree_list"
"test_apt_ostree_search"
"test_apt_ostree_info"
"test_apt_ostree_install"
"test_apt_ostree_remove"
)
for test in "${tests[@]}"; do
total_tests=$((total_tests + 1))
if $test; then
passed_tests=$((passed_tests + 1))
else
failed_tests=$((failed_tests + 1))
fi
done
# Summary
echo "" >> "$REPORT_FILE"
echo "=== Test Summary ===" >> "$REPORT_FILE"
echo "Total Tests: $total_tests" >> "$REPORT_FILE"
echo "Passed: $passed_tests" >> "$REPORT_FILE"
echo "Failed: $failed_tests" >> "$REPORT_FILE"
echo "Success Rate: $((passed_tests * 100 / total_tests))%" >> "$REPORT_FILE"
# Display summary
echo ""
log_info "=== Testing Complete ==="
log_info "Total Tests: $total_tests"
log_success "Passed: $passed_tests"
if [ $failed_tests -gt 0 ]; then
log_error "Failed: $failed_tests"
fi
log_info "Success Rate: $((passed_tests * 100 / total_tests))%"
log_info "Report saved to: $REPORT_FILE"
return $failed_tests
}
# Main execution
main() {
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-v|--verbose)
VERBOSE="true"
shift
;;
-o|--output)
REPORT_FILE="$2"
shift 2
;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -v, --verbose Enable verbose output"
echo " -o, --output Specify output file (default: apt-ostree-report.txt)"
echo " -h, --help Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Check if apt-ostree is available
if ! command -v apt-ostree >/dev/null 2>&1; then
log_error "apt-ostree not found. Please ensure it's installed and in PATH."
exit 1
fi
# Generate report
generate_report
local exit_code=$?
# Exit with number of failed tests
exit $exit_code
}
# Run main function
main "$@"