Skip to content

Instantly share code, notes, and snippets.

@AngelOnFira
Created June 29, 2023 21:34
Show Gist options
  • Select an option

  • Save AngelOnFira/08dcd6f9c41ed169775e21f1c129c8d9 to your computer and use it in GitHub Desktop.

Select an option

Save AngelOnFira/08dcd6f9c41ed169775e21f1c129c8d9 to your computer and use it in GitHub Desktop.
# !/bin/bash
# Go into every folder except `[template]`, `.git`, and `servers`. List all the
# sub folders. Go into each sub folder and remove the README.md file. Then, move
# any more files at that level into a subfolder called `files`. Next, go into
# the challenge folder and move the challenge.json file up one level. Next, go
# into the solution directory and move the solution.txt file up one level.
for d in backend/ctf/*; do
if [ "$d" != "backend/ctf/[template]" ] && [ "$d" != "backend/ctf/.git" ] && [ "$d" != "backend/ctf/servers" ]; then
# Check if it's a directory
if [ -d "$d" ]; then
# Find each sub folder that is a directory
for f in "$d"/*; do
if [ -d "$f" ]; then
echo "$f"
# Remove README.md
rm "$f/README.md"
# Move files into files folder as long as they aren't directories
mkdir "$f/files"
for g in "$f"/*; do
if [ -f "$g" ]; then
mv "$g" "$f/files"
fi
done
# If the files directory is empty, delete it
if [ -z "$(ls -A "$f/files")" ]; then
rm -rf "$f/files"
fi
# Move challenge.json up one level
mv "$f/challenge/challenge.json" "$f"
rm -rf "$f/challenge"
# Move solution.txt up one level
mv "$f/solution/solution.txt" "$f"
rm -rf "$f/solution"
fi
done
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment