made a puzzle that creates a bunch of random files with one of the co…#9
made a puzzle that creates a bunch of random files with one of the co…#9jacobmccaughrin wants to merge 15 commits intogigamonkey:mainfrom
Conversation
…lors of the rainbow.
gigamonkey
left a comment
There was a problem hiding this comment.
Close but not quite right. To test this you can run first ./build/build.sh after you've added your script to STEPS. Then you can run ./progress like you were playing the game but you may want to use the ./copy-solutions.sh script to copy the existing solutions into the main directory so you don't have to solve the whole puzzle every time.
There was a problem hiding this comment.
Whoops. This shouldn't have been committed. I thought I had an entry in .gitignore to ignore it but maybe I don't. Anyway, can you git rm this file and then commit that change so it doesn't get added when I merge this PR.
| echo $PUZZLE/$FOLDER is a directory with some number of files. Each file has in its name one of the colors of the rainbow: red, orange, yellow, green, blue, indigo, and violet | ||
|
|
||
| echo "The secret is found by joining the names of the first file found for each color in the rainbow." |
There was a problem hiding this comment.
So this is not quite right. These scripts need to take a secret to hide as their single argument (so it will be $1) and then hide it somehow. You could hide it by splitting it into seven pieces and then putting each piece in the first file of each color so that catting those files together would retrieve the secret. (The way the puzzle is built is your script is given the secret/clue generated by the next puzzle in the sequence so you hide it and your clue tells how to find it.) If you want to go that way you should look at the split command which can split input into chunks. But it writes them out to files which you would then have to move to the appropriate files that you generated. And then, ideally, you'd also put fake secrets into all the other files so the user can't just cat all the files.
… the name of the first part of the hint.
…s commands are not working, but i think this works to solve the problem
gigamonkey
left a comment
There was a problem hiding this comment.
Please address the comments and get this script into a runnable state.
There was a problem hiding this comment.
Whoops. This file was generated by building the puzzle and shouldn't be checked in. You can git rm it and then commit and push to get rid of it.
|
|
||
| total_files=$(((RANDOM % 100 + 1) * 7 )) #picks a random amount of files | ||
|
|
||
| files_per_color=$((TOTAL_FILES / 7 )) #how many files per each color |
There was a problem hiding this comment.
I'm not sure why shellcheck doesn't notice this but TOTAL_FILES is not defined. I assume you meant total_files.
There was a problem hiding this comment.
This file needs to be chmod +x'd to be runnable by the ./build/build.sh script. But beyond that there are syntax errors that prevent this from running. You need to fix those to get this script to an actually runnable state.
| for color in "${rainbow_colors[@]}"; do #for every color | ||
| first_file_created=false | ||
| for ((i= 0; i<files_per_color; i++)); do #for every file per color | ||
| if [[ $first_file_created == false]]; then |
There was a problem hiding this comment.
I think you need a space before the ]] for bash to understand the syntax.
gigamonkey
left a comment
There was a problem hiding this comment.
Commented on a couple bash gotchas you ran into that are preventing your script from running to completion.
| ((count++)) | ||
| else | ||
|
|
||
| rand_str=$(tr -dc 'a-z0-9' </dev/urandom | head -c 5) #generate random string |
There was a problem hiding this comment.
There's a bit of a gotcha here. The head command shuts down it's input once it gets enough stuff. But that causes the next write by the tr command to it's output to fail which because of the set -o pipefail causes this pipeline to fail which causes this line to fail which causes your whole script to fail. One simple fix is to change this line to this:
| rand_str=$(tr -dc 'a-z0-9' </dev/urandom | head -c 5) #generate random string | |
| rand_str=$(tr -dc 'a-z0-9' </dev/urandom | head -c 5) || true #generate random string |
The || true causes the first command's failure to be in a context where failure is okay and true always succeeds so the line as a whole will succeed.
| FILENAME="${color}_${parts[$count]}.txt" | ||
| touch "$FOLDER/$FILENAME" | ||
| first_file_created=true | ||
| ((count++)) |
There was a problem hiding this comment.
This line is a gotcha. For various reasons, the success or failure of arithmetic expansions is determined by their arithmetic value with anything except 0 counting as success and 0 counting as failure. In a context like this where count starts at zero ((count++)) evaluates to 0 which is considered failure which causes your script to exit due to the set -e. One simple way to fix this is to use ((count += 1)) instead since it evaluates to the new value rather than the old value. Other possibilities include ((++count)) or ((count++)) || true
…in directory. Am i doing something wrong or do i need to make some files to get the ./progress to work?
…t to a runable state
…es and the player must parse through the file string and build the clue to. now they just dont have to worry about the random files.
gigamonkey
left a comment
There was a problem hiding this comment.
Your script as checked in still doesn't run because you're missing the || true on the other place you use tr and head in a pipeline.
…lors of the rainbow.