Skip to content

Commit

Permalink
Merge pull request #3 from eseiler/infra/test
Browse files Browse the repository at this point in the history
[INFRA] Add test
  • Loading branch information
SGSSGene authored Feb 23, 2024
2 parents c3891b7 + 34c5cb4 commit dfdafd6
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 7 deletions.
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: CC0-1.0

# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
50 changes: 50 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: CC0-1.0

name: CI

on:
push:
pull_request:
workflow_dispatch:

env:
TZ: Europe/Berlin

defaults:
run:
shell: bash -Eeuo pipefail {0}

jobs:
build:
name: "Scavenger Hunt"
runs-on: ubuntu-22.04
timeout-minutes: 120
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Tool Versions
run: |
set -x +eu
echo $LANG
echo $LC_ALL
bash --version
awk -W version
diff --version
comm --version
sed --version
sort --version
uniq --version
wget --version
curl --version
grep --version
zip --version
- name: Create Scavenger Hunt
run: ./create_scavenger_hunt.sh

- name: Solve Scavenger Hunt
run: ./test.sh

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/start/
/start.zip
22 changes: 15 additions & 7 deletions create_scavenger_hunt.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/bin/bash
set -euo pipefail

PATH_LEVEL_0="start"
for i in $(seq 1 1 15); do
eval "PATH_LEVEL_${i}=\${PATH_LEVEL_$((i-1))}/level${i}";
done
PATH_END_BOSS="${PATH_LEVEL_15}/end_boss"
SCRIPT_ROOT=$(dirname $(readlink -f $0))
source ${SCRIPT_ROOT}/paths.sh

mkdir -p ${PATH_END_BOSS}

Expand Down Expand Up @@ -41,7 +38,18 @@ echo "less, head, tail" >> ${PATH_LEVEL_3}/README.txt

# Level 5
PASSWORD5="needle"
curl -s -X POST https://lipsum.com/feed/json -d "amount=3000" | sed -e "s/.\{100\}/&\n/g" > ${PATH_LEVEL_4}/password_raw.txt
retry_command ()
{
for i in 1 2 3 4 5; do
if [[ $i -eq 5 ]]; then
"$@"
else
"$@" && break || sleep $((i * 5))
fi
done
}
# The jq will reformat the json a bit, but its main purpose is to check that curl returned valid json (no server error).
retry_command curl -s -X POST https://lipsum.com/feed/json -d "amount=3000" | jq . | sed -e "s/.\{100\}/&\n/g" > ${PATH_LEVEL_4}/password_raw.txt
awk -v new_word=" password:${PASSWORD5}" 'NR==512 {gsub(substr($0, 10, length($0)-9), new_word)} {print}' ${PATH_LEVEL_4}/password_raw.txt > ${PATH_LEVEL_4}/password.txt
rm ${PATH_LEVEL_4}/password_raw.txt
echo "The password is somewhere in the file. It is prefixed "password:"." > ${PATH_LEVEL_4}/README.txt
Expand Down Expand Up @@ -145,7 +153,7 @@ echo "sort, uniq" >> ${PATH_LEVEL_10}/README.txt
# Level 12
PASSWORD12="moly"
cat ${PATH_LEVEL_4}/password.txt | tr '\s' '\n' | awk 'NR==300 {$0="holy"} {print}' > ${PATH_LEVEL_11}/password_A.txt
cat ${PATH_LEVEL_4}/password.txt | tr '\s' '\n' | awk -v word="${PASSWORD12}" 'NR==300 {$0="word"} {print}' > ${PATH_LEVEL_11}/password_B.txt
cat ${PATH_LEVEL_4}/password.txt | tr '\s' '\n' | awk -v word="${PASSWORD12}" 'NR==300{$0=word}1' > ${PATH_LEVEL_11}/password_B.txt

echo "The password is the one word that is ONLY present in file password_B.txt but not in password_A.txt." > ${PATH_LEVEL_11}/README.txt
echo "" >> ${PATH_LEVEL_11}/README.txt
Expand Down
18 changes: 18 additions & 0 deletions paths.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -u

if [ "$0" = "$BASH_SOURCE" ]; then
echo "$0: This script must be sourced, not executed."
exit 1
fi

if [ "" = "$SCRIPT_ROOT" ]; then
echo "$0: SCRIPT_ROOT cannot be empty."
exit 1
fi

PATH_LEVEL_0="${SCRIPT_ROOT}/start"
for i in $(seq 1 1 15); do
eval "PATH_LEVEL_${i}=\${PATH_LEVEL_$((i-1))}/level${i}";
done
PATH_END_BOSS="${PATH_LEVEL_15}/end_boss"
93 changes: 93 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash
set -euo pipefail

SCRIPT_ROOT=$(dirname $(readlink -f $0))
source ${SCRIPT_ROOT}/paths.sh

PASSWORD0="go"
echo "The password for start.zip is \"${PASSWORD0}\""
unzip -q -P ${PASSWORD0} start.zip
cd ${PATH_LEVEL_0}

PASSWORD1=$(cat password.txt)
echo "The password for level1.zip is \"${PASSWORD1}\""
unzip -q -P ${PASSWORD1} level1.zip
cd ${PATH_LEVEL_1}

PASSWORD2=$(tail -n 1 password_is_on_last_line.txt)
echo "The password for level2.zip is \"${PASSWORD2}\""
unzip -q -P ${PASSWORD2} level2.zip
cd ${PATH_LEVEL_2}

PASSWORD3=$(cat .password.txt)
echo "The password for level3.zip is \"${PASSWORD3}\""
unzip -q -P ${PASSWORD3} level3.zip
cd ${PATH_LEVEL_3}

PASSWORD4=$(head -n12345 password.txt | tail -n1)
echo "The password for level4.zip is \"${PASSWORD4}\""
unzip -q -P ${PASSWORD4} level4.zip
cd ${PATH_LEVEL_4}

PASSWORD5=$(awk '/password:/{for(i=1;i<=NF;i++){if($i ~ /password:/){sub("password:", "", $i); print $i; exit}}}' password.txt)
echo "The password for level5.zip is \"${PASSWORD5}\""
unzip -q -P ${PASSWORD5} level5.zip
cd ${PATH_LEVEL_5}

PASSWORD6=$(wc -l how_many_lines_do_I_have.txt | cut -f1 -d' ')
echo "The password for level6.zip is \"${PASSWORD6}\""
unzip -q -P ${PASSWORD6} level6.zip
cd ${PATH_LEVEL_6}

PASSWORD7=$(head -n123 password.tsv | tail -n1 | cut -f567)
echo "The password for level7.zip is \"${PASSWORD7}\""
unzip -q -P ${PASSWORD7} level7.zip
cd ${PATH_LEVEL_7}

PASSWORD8=$(zcat password.txt.gz)
echo "The password for level8.zip is \"${PASSWORD8}\""
unzip -q -P ${PASSWORD8} level8.zip
cd ${PATH_LEVEL_8}

PASSWORD9=$(grep -c "turpis" password.txt)
echo "The password for level9.zip is \"${PASSWORD9}\""
unzip -q -P ${PASSWORD9} level9.zip
cd ${PATH_LEVEL_9}

PASSWORD10=$(basename $(dirname $(find . -name "password.txt")))
echo "The password for level10.zip is \"${PASSWORD10}\""
unzip -q -P ${PASSWORD10} level10.zip
cd ${PATH_LEVEL_10}

PASSWORD11=$(sort password.txt | uniq -u)
echo "The password for level11.zip is \"${PASSWORD11}\""
unzip -q -P ${PASSWORD11} level11.zip
cd ${PATH_LEVEL_11}

PASSWORD12=$(comm -23 <(sort password_B.txt) <(sort password_A.txt))
echo "The password for level12.zip is \"${PASSWORD12}\""
unzip -q -P ${PASSWORD12} level12.zip
cd ${PATH_LEVEL_12}

PASSWORD13=$(head -n3 password.txt | tail -n1 | sed 's/xsbhjlasbdghasl//g')
echo "The password for level13.zip is \"${PASSWORD13}\""
unzip -q -P ${PASSWORD13} level13.zip
cd ${PATH_LEVEL_13}

wget --quiet https://ftp.ncbi.nlm.nih.gov/ReferenceSamples/giab/current.tree
PASSWORD14=$(grep "AshkenazimTrio.*vcf.gz\s" current.tree | grep "HG002" | grep "VariationHunter" | cut -f4 | cut -d' ' -f4)
echo "The password for level14.zip is \"${PASSWORD14}\""
unzip -q -P ${PASSWORD14} level14.zip
cd ${PATH_LEVEL_14}

PASSWORD15=$(awk '{ sum += $8 } END { print sum }' password.tsv)
echo "The password for level15.zip is \"${PASSWORD15}\""
unzip -q -P ${PASSWORD15} level15.zip
cd ${PATH_LEVEL_15}

PASSWORD_END_BOSS=$(zcat .password.txt.gz | tr -c '[:alnum:]' '[\n*]' | grep . | sort | uniq -c | sort -nr | awk 'NR==1 {print $2}')
echo "The password for end_boss.zip is \"${PASSWORD_END_BOSS}\""
unzip -q -P ${PASSWORD_END_BOSS} end_boss.zip
cd ${PATH_END_BOSS}

test -f congrats.txt

0 comments on commit dfdafd6

Please sign in to comment.