updated project 2
This commit is contained in:
@@ -261,28 +261,29 @@ setup_challenge_env() {
|
|||||||
local challenge_id=$1
|
local challenge_id=$1
|
||||||
echo -e "${BLUE}Setting up challenge files...${NC}"
|
echo -e "${BLUE}Setting up challenge files...${NC}"
|
||||||
|
|
||||||
# Source the setup script instead of executing it
|
# Create necessary directories
|
||||||
if ! source "$CHALLENGE_DIR/.tracking/level1-setup.sh"; then
|
mkdir -p "$CHALLENGE_DIR/files"
|
||||||
echo -e "${RED}Error: Failed to setup challenge environment${NC}"
|
|
||||||
echo -e "${YELLOW}Try running: $0 clean && $0 setup${NC}"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run the setup function from the sourced script
|
# Setup files for the challenge
|
||||||
if ! init_environment; then
|
case "$challenge_id" in
|
||||||
echo -e "${RED}Error: Failed to initialize environment${NC}"
|
"1.1")
|
||||||
return 1
|
# Create some .conf files with different timestamps
|
||||||
fi
|
for i in {1..15}; do
|
||||||
|
echo "config$i=value$i" > "$CHALLENGE_DIR/files/config$i.conf"
|
||||||
if ! setup_file_challenges; then
|
# Set random timestamps within the last 48 hours
|
||||||
echo -e "${RED}Error: Failed to setup file challenges${NC}"
|
touch -d "@$(($(date +%s) - RANDOM % 172800))" "$CHALLENGE_DIR/files/config$i.conf"
|
||||||
return 1
|
done
|
||||||
fi
|
;;
|
||||||
|
"1.2")
|
||||||
if ! setup_permission_challenges; then
|
# Create various file types
|
||||||
echo -e "${RED}Error: Failed to setup permission challenges${NC}"
|
for ext in txt conf log py js json yml; do
|
||||||
return 1
|
for i in {1..5}; do
|
||||||
fi
|
echo "content" > "$CHALLENGE_DIR/files/file$i.$ext"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
# Add more challenge setups as needed
|
||||||
|
esac
|
||||||
|
|
||||||
echo -e "${GREEN}Challenge environment ready!${NC}"
|
echo -e "${GREEN}Challenge environment ready!${NC}"
|
||||||
return 0
|
return 0
|
||||||
@@ -346,7 +347,9 @@ start_challenge() {
|
|||||||
bind 'set show-all-if-ambiguous on' 2>/dev/null || true
|
bind 'set show-all-if-ambiguous on' 2>/dev/null || true
|
||||||
|
|
||||||
echo -e "\n${YELLOW}Your challenge environment is ready!${NC}"
|
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
|
print_help_menu
|
||||||
|
|
||||||
# Start command loop with improved prompt
|
# Start command loop with improved prompt
|
||||||
@@ -354,8 +357,18 @@ start_challenge() {
|
|||||||
while true; do
|
while true; do
|
||||||
cmd_count=$((cmd_count + 1))
|
cmd_count=$((cmd_count + 1))
|
||||||
echo -ne "\n${GREEN}challenge${BLUE}[$challenge_id]${GREEN}>${NC} "
|
echo -ne "\n${GREEN}challenge${BLUE}[$challenge_id]${GREEN}>${NC} "
|
||||||
read -e -r cmd args # -e enables readline for command history
|
read -e -r cmd args || true # Add || true to prevent exit on Ctrl+D
|
||||||
history -s "$cmd $args" # Add command to history
|
|
||||||
|
# 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
|
if ! handle_command "$cmd" $args; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user