updated project 2
This commit is contained in:
@@ -42,6 +42,7 @@ check_requirements() {
|
|||||||
echo -e "${RED}Error: Missing required commands: ${missing_commands[*]}${NC}"
|
echo -e "${RED}Error: Missing required commands: ${missing_commands[*]}${NC}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to clean up previous environment
|
# Function to clean up previous environment
|
||||||
@@ -65,7 +66,7 @@ setup_environment() {
|
|||||||
if ! check_requirements; then
|
if ! check_requirements; then
|
||||||
echo -e "${RED}Error: Setup failed - missing requirements${NC}"
|
echo -e "${RED}Error: Setup failed - missing requirements${NC}"
|
||||||
return 1
|
return 1
|
||||||
}
|
fi
|
||||||
|
|
||||||
# Clean up first
|
# Clean up first
|
||||||
cleanup_environment
|
cleanup_environment
|
||||||
@@ -215,6 +216,11 @@ EOF
|
|||||||
|
|
||||||
# Main execution with error handling
|
# Main execution with error handling
|
||||||
main() {
|
main() {
|
||||||
|
if [[ $# -eq 0 ]]; then
|
||||||
|
show_help
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
"setup")
|
"setup")
|
||||||
setup_environment
|
setup_environment
|
||||||
@@ -240,7 +246,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
list_challenges
|
list_challenges
|
||||||
;;
|
;;
|
||||||
"help"|"--help"|"-h"|"")
|
"help"|"--help"|"-h")
|
||||||
show_help
|
show_help
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|||||||
@@ -11,10 +11,9 @@ declare -A CHALLENGE_CATEGORIES=(
|
|||||||
["net"]="Network Operations"
|
["net"]="Network Operations"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Challenge definitions with detailed metadata
|
# Challenge definitions with metadata
|
||||||
# Format: type|name|difficulty|skills|task|hints|setup_requirements|verification_criteria
|
# Format: type|name|difficulty|skills|task|hints|setup_requirements|verification_criteria
|
||||||
declare -A CHALLENGES=(
|
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.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.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"
|
["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))
|
echo $((time_bonus + efficiency_bonus))
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get challenge details with color formatting
|
# Get challenge details
|
||||||
get_challenge_details() {
|
get_challenge_details() {
|
||||||
local challenge_id=$1
|
local challenge_id=$1
|
||||||
IFS='|' read -r type name difficulty skills task hints requirements _ <<< "${CHALLENGES[$challenge_id]}"
|
if [[ -n "${CHALLENGES[$challenge_id]:-}" ]]; then
|
||||||
|
IFS='|' read -r type name difficulty skills task hints requirements criteria <<< "${CHALLENGES[$challenge_id]}"
|
||||||
cat << EOF
|
echo -e "${BLUE}Challenge $challenge_id:${NC} $name"
|
||||||
${BOLD}Challenge ${challenge_id}${NC}: ${YELLOW}$name${NC}
|
echo -e "${BLUE}Difficulty:${NC} $(printf '★%.0s' $(seq 1 "$difficulty"))"
|
||||||
${BLUE}Difficulty${NC}: $(printf '★%.0s' $(seq 1 "$difficulty"))
|
echo -e "${BLUE}Skills:${NC} $skills"
|
||||||
${BLUE}Skills${NC}: $skills
|
echo -e "${BLUE}Task:${NC} $task"
|
||||||
${BLUE}Task${NC}: $task
|
return 0
|
||||||
${BLUE}Hint${NC}: $hints
|
fi
|
||||||
EOF
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Update challenge status
|
# Update challenge status
|
||||||
@@ -254,10 +253,10 @@ update_challenge_status() {
|
|||||||
|
|
||||||
# List available challenges
|
# List available challenges
|
||||||
list_challenges() {
|
list_challenges() {
|
||||||
echo -e "\n${BOLD}Available Challenges:${NC}"
|
echo -e "\n${BLUE}Available Challenges:${NC}"
|
||||||
for challenge_id in "${!CHALLENGES[@]}"; do
|
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
|
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 -e "\n${YELLOW}Challenge $challenge_id${NC} ($difficulty★)"
|
||||||
echo "Type: $type"
|
echo "Type: $type"
|
||||||
echo "Skills: $skills"
|
echo "Skills: $skills"
|
||||||
|
|||||||
@@ -60,18 +60,8 @@ log_message() {
|
|||||||
local severity=$1
|
local severity=$1
|
||||||
local message=$2
|
local message=$2
|
||||||
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
local color
|
echo "[$timestamp] [$severity] $message" >> "$DATA_DIR/challenge.log"
|
||||||
|
echo -e "${BLUE}[$severity]${NC} $message"
|
||||||
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"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Initialize environment with comprehensive setup
|
# Initialize environment with comprehensive setup
|
||||||
@@ -254,6 +244,14 @@ show_recommendations() {
|
|||||||
# Check if challenge is completed
|
# Check if challenge is completed
|
||||||
is_challenge_completed() {
|
is_challenge_completed() {
|
||||||
local challenge=$1
|
local challenge=$1
|
||||||
grep -q "^$challenge," "$SCORE_FILE" && return 0
|
grep -q "^$challenge," "$SCORE_FILE"
|
||||||
return 1
|
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
|
# Challenge-specific setup
|
||||||
setup_file_challenges() {
|
setup_file_challenges() {
|
||||||
log_message "Setting up file system challenges..."
|
log_message "INFO" "Setting up file system challenges..."
|
||||||
|
|
||||||
# Create complex directory structure
|
# Create project directories
|
||||||
for dir in {1..5}; do
|
for i in {1..5}; do
|
||||||
mkdir -p "$CHALLENGE_DIR/files/project$dir/{src,config,logs,data}"
|
mkdir -p "$CHALLENGE_DIR/files/project$i"/{src,config,logs,data}
|
||||||
|
|
||||||
# Create various file types
|
# Create various file types
|
||||||
touch "$CHALLENGE_DIR/files/project$dir/src/main.py"
|
touch "$CHALLENGE_DIR/files/project$i/src/main.py"
|
||||||
touch "$CHALLENGE_DIR/files/project$dir/src/test.py"
|
touch "$CHALLENGE_DIR/files/project$i/src/test.py"
|
||||||
echo "debug=true" > "$CHALLENGE_DIR/files/project$dir/config/settings.conf"
|
echo "debug=true" > "$CHALLENGE_DIR/files/project$i/config/settings.conf"
|
||||||
|
|
||||||
# Create log files with realistic content
|
# Create log files with realistic content
|
||||||
for severity in INFO WARN ERROR DEBUG; do
|
for severity in INFO WARN ERROR DEBUG; do
|
||||||
for i in {1..10}; do
|
for j 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"
|
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
|
done
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_permission_challenges() {
|
setup_permission_challenges() {
|
||||||
log_message "Setting up permission challenges..."
|
log_message "INFO" "Setting up permission challenges..."
|
||||||
|
|
||||||
# Create test users and groups
|
# Create test files with specific permissions
|
||||||
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
|
|
||||||
mkdir -p "$CHALLENGE_DIR/files/permissions_test"
|
mkdir -p "$CHALLENGE_DIR/files/permissions_test"
|
||||||
for i in {1..5}; do
|
for i in {1..5}; do
|
||||||
echo "content$i" > "$CHALLENGE_DIR/files/permissions_test/file$i.txt"
|
echo "content$i" > "$CHALLENGE_DIR/files/permissions_test/file$i.txt"
|
||||||
@@ -159,7 +153,7 @@ main() {
|
|||||||
create_verification_functions
|
create_verification_functions
|
||||||
create_challenge_tracker
|
create_challenge_tracker
|
||||||
|
|
||||||
log_message "Challenge environment ready!"
|
log_message "SUCCESS" "Level 1 Setup Complete!"
|
||||||
cat << EOF
|
cat << EOF
|
||||||
${GREEN}Level 1 Setup Complete!${NC}
|
${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"' {} \;
|
||||||
Reference in New Issue
Block a user