updated project 2

This commit is contained in:
Hugh Ratsch
2025-02-09 02:33:45 -06:00
parent 37c1f9c1c9
commit 8988f308c5
5 changed files with 79 additions and 48 deletions
+8 -2
View File
@@ -42,6 +42,7 @@ check_requirements() {
echo -e "${RED}Error: Missing required commands: ${missing_commands[*]}${NC}"
return 1
fi
return 0
}
# Function to clean up previous environment
@@ -65,7 +66,7 @@ setup_environment() {
if ! check_requirements; then
echo -e "${RED}Error: Setup failed - missing requirements${NC}"
return 1
}
fi
# Clean up first
cleanup_environment
@@ -215,6 +216,11 @@ EOF
# Main execution with error handling
main() {
if [[ $# -eq 0 ]]; then
show_help
return 0
fi
case "$1" in
"setup")
setup_environment
@@ -240,7 +246,7 @@ main() {
fi
list_challenges
;;
"help"|"--help"|"-h"|"")
"help"|"--help"|"-h")
show_help
;;
*)
@@ -11,10 +11,9 @@ declare -A CHALLENGE_CATEGORIES=(
["net"]="Network Operations"
)
# Challenge definitions with detailed metadata
# Challenge definitions with metadata
# Format: type|name|difficulty|skills|task|hints|setup_requirements|verification_criteria
declare -A CHALLENGES=(
# Level 1: File Operations
["1.1"]="file_search|Find Recent Files|1|file_ops,search|Find all .conf files modified in the last 24 hours and save the list to recent_configs.txt|Try using find with -mtime|none|output_file=recent_configs.txt;file_count=10"
["1.2"]="file_count|File Statistics|1|file_ops,search|Generate a report showing count of files by extension|Consider using find and awk|none|report_exists=true;extension_count=5"
["1.3"]="file_organize|Smart File Organizer|2|file_ops|Create directories for different file types and sort files accordingly|Look into file command|none|dir_structure=complete;files_sorted=true"
@@ -223,18 +222,18 @@ calculate_bonus_points() {
echo $((time_bonus + efficiency_bonus))
}
# Get challenge details with color formatting
# Get challenge details
get_challenge_details() {
local challenge_id=$1
IFS='|' read -r type name difficulty skills task hints requirements _ <<< "${CHALLENGES[$challenge_id]}"
cat << EOF
${BOLD}Challenge ${challenge_id}${NC}: ${YELLOW}$name${NC}
${BLUE}Difficulty${NC}: $(printf '★%.0s' $(seq 1 "$difficulty"))
${BLUE}Skills${NC}: $skills
${BLUE}Task${NC}: $task
${BLUE}Hint${NC}: $hints
EOF
if [[ -n "${CHALLENGES[$challenge_id]:-}" ]]; then
IFS='|' read -r type name difficulty skills task hints requirements criteria <<< "${CHALLENGES[$challenge_id]}"
echo -e "${BLUE}Challenge $challenge_id:${NC} $name"
echo -e "${BLUE}Difficulty:${NC} $(printf '★%.0s' $(seq 1 "$difficulty"))"
echo -e "${BLUE}Skills:${NC} $skills"
echo -e "${BLUE}Task:${NC} $task"
return 0
fi
return 1
}
# Update challenge status
@@ -254,10 +253,10 @@ update_challenge_status() {
# List available challenges
list_challenges() {
echo -e "\n${BOLD}Available Challenges:${NC}"
echo -e "\n${BLUE}Available Challenges:${NC}"
for challenge_id in "${!CHALLENGES[@]}"; do
IFS='|' read -r type name difficulty skills task hints requirements _ <<< "${CHALLENGES[$challenge_id]}"
if ! is_challenge_completed "$challenge_id"; then
IFS='|' read -r type name difficulty skills task _ <<< "${CHALLENGES[$challenge_id]}"
echo -e "\n${YELLOW}Challenge $challenge_id${NC} ($difficulty★)"
echo "Type: $type"
echo "Skills: $skills"
@@ -60,18 +60,8 @@ log_message() {
local severity=$1
local message=$2
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
local color
case $severity in
"INFO") color=$BLUE ;;
"SUCCESS") color=$GREEN ;;
"WARNING") color=$YELLOW ;;
"ERROR") color=$RED ;;
*) color=$NC ;;
esac
echo -e "${color}[$severity]${NC} $message"
echo "[$timestamp] [$severity] $message" >> "$LOG_FILE"
echo "[$timestamp] [$severity] $message" >> "$DATA_DIR/challenge.log"
echo -e "${BLUE}[$severity]${NC} $message"
}
# Initialize environment with comprehensive setup
@@ -254,6 +244,14 @@ show_recommendations() {
# Check if challenge is completed
is_challenge_completed() {
local challenge=$1
grep -q "^$challenge," "$SCORE_FILE" && return 0
return 1
grep -q "^$challenge," "$SCORE_FILE"
return $?
}
# Award points function
award_points() {
local challenge=$1
local points=$2
echo "$challenge,$points,$(date +%s)" >> "$SCORE_FILE"
log_message "INFO" "Awarded $points points for challenge $challenge"
}
@@ -5,36 +5,30 @@ source "$(dirname "$0")/common.sh"
# Challenge-specific setup
setup_file_challenges() {
log_message "Setting up file system challenges..."
log_message "INFO" "Setting up file system challenges..."
# Create complex directory structure
for dir in {1..5}; do
mkdir -p "$CHALLENGE_DIR/files/project$dir/{src,config,logs,data}"
# Create project directories
for i in {1..5}; do
mkdir -p "$CHALLENGE_DIR/files/project$i"/{src,config,logs,data}
# Create various file types
touch "$CHALLENGE_DIR/files/project$dir/src/main.py"
touch "$CHALLENGE_DIR/files/project$dir/src/test.py"
echo "debug=true" > "$CHALLENGE_DIR/files/project$dir/config/settings.conf"
touch "$CHALLENGE_DIR/files/project$i/src/main.py"
touch "$CHALLENGE_DIR/files/project$i/src/test.py"
echo "debug=true" > "$CHALLENGE_DIR/files/project$i/config/settings.conf"
# Create log files with realistic content
for severity in INFO WARN ERROR DEBUG; do
for i in {1..10}; do
echo "[$(date -d "@$(($(date +%s) - RANDOM % 86400))" '+%Y-%m-%d %H:%M:%S')] [$severity] Message $i" >> "$CHALLENGE_DIR/files/project$dir/logs/app.log"
for j in {1..10}; do
echo "[$(date -d "@$(($(date +%s) - RANDOM % 86400))" '+%Y-%m-%d %H:%M:%S')] [$severity] Message $j" >> "$CHALLENGE_DIR/files/project$i/logs/app.log"
done
done
done
}
setup_permission_challenges() {
log_message "Setting up permission challenges..."
log_message "INFO" "Setting up permission challenges..."
# Create test users and groups
for i in {1..3}; do
sudo groupadd -f "app_group$i" 2>/dev/null
sudo useradd -M -N -g "app_group$i" "app_user$i" 2>/dev/null
done
# Create files with specific permissions
# Create test files with specific permissions
mkdir -p "$CHALLENGE_DIR/files/permissions_test"
for i in {1..5}; do
echo "content$i" > "$CHALLENGE_DIR/files/permissions_test/file$i.txt"
@@ -159,7 +153,7 @@ main() {
create_verification_functions
create_challenge_tracker
log_message "Challenge environment ready!"
log_message "SUCCESS" "Level 1 Setup Complete!"
cat << EOF
${GREEN}Level 1 Setup Complete!${NC}
@@ -0,0 +1,34 @@
#!/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() {
local script=$1
echo -e "${BLUE}Checking: ${script}${NC}"
# Check if file exists
if [[ ! -f "$script" ]]; then
echo -e "${RED}Error: File not found${NC}"
return 1
}
# Check shell syntax
if ! bash -n "$script"; then
echo -e "${RED}Syntax error found${NC}"
return 1
fi
echo -e "${GREEN}Syntax OK${NC}"
return 0
}
# Find and verify all shell scripts
find "$PROJECT_DIR" -type f -name "*.sh" -exec bash -c 'verify_script "$0"' {} \;