updated project 2

This commit is contained in:
Hugh Ratsch
2025-02-09 03:46:16 -06:00
parent 6f8846ee95
commit 7f1c10a5a8
+37 -24
View File
@@ -261,28 +261,29 @@ setup_challenge_env() {
local challenge_id=$1
echo -e "${BLUE}Setting up challenge files...${NC}"
# Source the setup script instead of executing it
if ! source "$CHALLENGE_DIR/.tracking/level1-setup.sh"; then
echo -e "${RED}Error: Failed to setup challenge environment${NC}"
echo -e "${YELLOW}Try running: $0 clean && $0 setup${NC}"
return 1
fi
# Create necessary directories
mkdir -p "$CHALLENGE_DIR/files"
# Run the setup function from the sourced script
if ! init_environment; then
echo -e "${RED}Error: Failed to initialize environment${NC}"
return 1
fi
if ! setup_file_challenges; then
echo -e "${RED}Error: Failed to setup file challenges${NC}"
return 1
fi
if ! setup_permission_challenges; then
echo -e "${RED}Error: Failed to setup permission challenges${NC}"
return 1
fi
# Setup files for the challenge
case "$challenge_id" in
"1.1")
# Create some .conf files with different timestamps
for i in {1..15}; do
echo "config$i=value$i" > "$CHALLENGE_DIR/files/config$i.conf"
# Set random timestamps within the last 48 hours
touch -d "@$(($(date +%s) - RANDOM % 172800))" "$CHALLENGE_DIR/files/config$i.conf"
done
;;
"1.2")
# Create various file types
for ext in txt conf log py js json yml; do
for i in {1..5}; do
echo "content" > "$CHALLENGE_DIR/files/file$i.$ext"
done
done
;;
# Add more challenge setups as needed
esac
echo -e "${GREEN}Challenge environment ready!${NC}"
return 0
@@ -346,7 +347,9 @@ start_challenge() {
bind 'set show-all-if-ambiguous on' 2>/dev/null || true
echo -e "\n${YELLOW}Your challenge environment is ready!${NC}"
echo -e "You can use the following commands:"
echo -e "${BLUE}Current working directory: $CHALLENGE_DIR${NC}"
echo -e "${BLUE}Challenge: $(get_challenge_description "$challenge_id")${NC}"
echo -e "\nAvailable commands:"
print_help_menu
# Start command loop with improved prompt
@@ -354,8 +357,18 @@ start_challenge() {
while true; do
cmd_count=$((cmd_count + 1))
echo -ne "\n${GREEN}challenge${BLUE}[$challenge_id]${GREEN}>${NC} "
read -e -r cmd args # -e enables readline for command history
history -s "$cmd $args" # Add command to history
read -e -r cmd args || true # Add || true to prevent exit on Ctrl+D
# Handle Ctrl+D (EOF)
if [ $? -ne 0 ]; then
echo -e "\n${YELLOW}Use 'exit' or 'q' to quit${NC}"
continue
fi
# Add command to history
history -s "$cmd $args"
# Handle the command
if ! handle_command "$cmd" $args; then
break
fi