Files
linux-sysadmin-journey/projects/02-command-line-mastery/verify-scripts.sh
T

48 lines
1.2 KiB
Bash
Raw Normal View History

2025-02-09 02:33:45 -06:00
#!/bin/bash
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m'
# Get project directory
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Function to verify a shell script
verify_script() {
2025-02-09 02:54:59 -06:00
local script="$1"
2025-02-09 02:33:45 -06:00
echo -e "${BLUE}Checking: ${script}${NC}"
# Check if file exists
if [[ ! -f "$script" ]]; then
2025-02-09 02:54:59 -06:00
echo -e "${RED}Error: File not found - $script${NC}"
2025-02-09 02:33:45 -06:00
return 1
fi
2025-02-09 02:54:59 -06:00
# Check shell syntax
if ! bash -n "$script"; then
echo -e "${RED}Syntax error found in $script${NC}"
return 1
fi
# Check for common shell script issues
if command -v shellcheck >/dev/null 2>&1; then
if ! shellcheck "$script"; then
echo -e "${RED}ShellCheck found issues in $script${NC}"
return 1
fi
fi
echo -e "${GREEN}Script $script passed verification${NC}"
2025-02-09 02:33:45 -06:00
return 0
}
2025-02-09 02:54:59 -06:00
# Main execution
echo "Starting script verification..."
2025-02-09 02:33:45 -06:00
# Find and verify all shell scripts
2025-02-09 02:54:59 -06:00
find "$PROJECT_DIR" -type f -name "*.sh" | while read -r script; do
verify_script "$script"
done
2025-02-09 02:33:45 -06:00
find "$PROJECT_DIR" -type f -name "*.sh" -exec bash -c 'verify_script "$0"' {} \;