updated project 2

This commit is contained in:
Hugh Ratsch
2025-02-09 02:10:26 -06:00
parent 9ec69d3d83
commit 3c9ccbff33
3 changed files with 149 additions and 3 deletions
+108
View File
@@ -0,0 +1,108 @@
#!/bin/bash
# Get the absolute path to the project directory
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CHALLENGE_DIR=~/challenge
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Function to setup the environment
setup_environment() {
echo -e "${BLUE}Setting up challenge environment...${NC}"
# Create directory structure
mkdir -p "$CHALLENGE_DIR"/{files,backup,temp}
mkdir -p "$CHALLENGE_DIR/.tracking/data"
# Copy all setup scripts to tracking directory
cp "$PROJECT_DIR"/setup/*.sh "$CHALLENGE_DIR/.tracking/"
chmod +x "$CHALLENGE_DIR/.tracking/"*.sh
# Initialize tracking files
local data_dir="$CHALLENGE_DIR/.tracking/data"
touch "$data_dir"/{progress,score,challenge,commands,time,hints_used,achievements,attempts}.csv
echo -e "${GREEN}Environment setup complete!${NC}"
}
# Function to start a challenge
start_challenge() {
local challenge_id=$1
# Source required scripts
source "$CHALLENGE_DIR/.tracking/common.sh"
source "$CHALLENGE_DIR/.tracking/challenges.sh"
clear
echo -e "${GREEN}🎮 Command Line Mastery Challenge${NC}"
echo "=============================="
get_challenge_details "$challenge_id"
bash "$CHALLENGE_DIR/.tracking/level1-setup.sh"
local start_time=$(date +%s)
echo "$challenge_id,$start_time" > "$CHALLENGE_DIR/.tracking/current_challenge"
echo -e "\n${GREEN}Challenge ready!${NC}"
echo -e "Commands available:"
echo -e " ${YELLOW}verify${NC} - Check your solution"
echo -e " ${YELLOW}hint${NC} - Get a hint"
echo -e " ${YELLOW}status${NC} - Show progress"
}
# Function to show help
show_help() {
cat << EOF
Usage: $0 [command] [options]
Commands:
start <challenge-id> Start a specific challenge
list List available challenges
setup Setup/reset the environment
help Show this help message
Examples:
$0 setup # First time setup
$0 list # Show available challenges
$0 start 1.1 # Start challenge 1.1
EOF
}
# Main execution
case "$1" in
"setup")
setup_environment
;;
"start")
if [[ ! -d "$CHALLENGE_DIR/.tracking" ]]; then
echo -e "${YELLOW}Environment not set up. Running setup first...${NC}"
setup_environment
fi
if [[ -z "$2" ]]; then
echo "Error: Please specify a challenge ID"
echo "Example: $0 start 1.1"
exit 1
fi
start_challenge "$2"
;;
"list")
if [[ -f "$CHALLENGE_DIR/.tracking/challenges.sh" ]]; then
source "$CHALLENGE_DIR/.tracking/challenges.sh"
list_challenges
else
echo "Please run setup first: $0 setup"
fi
;;
"help"|"--help"|"-h"|"")
show_help
;;
*)
echo "Unknown command: $1"
show_help
exit 1
;;
esac