ssh-treasure-hunt/exercices/gen_seed.sh
2022-01-20 17:09:04 +01:00

49 lines
1.3 KiB
Bash

#!/bin/bash
USAGE="$0 ROOT FOLDERS FILES FILENAMES INTEGERS USER DIR :\
\n\tgenerate a semi-random seed in the DIR folder, which can be then used to \n\
\trandomize exercises.\n\
Parameters:\n\
\tROOT : the folder in which to find folders, files, ... Usually, the student's\n\
\thome directory.\n\
\tFOLDERS : how many random folders to pick \n\
\tFILES : how many random files to pick\n\
\tFILENAMES : how many random filenames to pick from the dictionnary haddock.list\n\
\tINTEGERS : how many random integers to pick\n\
\tUSER : username of the student\n\
\tDIR : folder in which to store the generated seeds"
if [[ $# != 7 ]] ; then echo -e $USAGE ; exit 0 ; fi
# This users home
root=$1
# How many random folders, files, filenames and integers you need
folders=$2
files=$3
filenames=$4
ints=$5
# username
USER=$6
# Seeds storage
DIR=$7
if echo $DIR | grep -v /$ > /dev/null ; then DIR=$DIR/ ; fi
mkdir -p $DIR$USER ;
find $root -type d | shuf | head -n $folders > $DIR$USER/folders.seed
find $root -type f | shuf | head -n $files > $DIR$USER/files.seed
cat haddock.list | shuf | head -n $filenames > $DIR$USER/filenames.seed
if [[ -s $DIR$USER/ints.seed ]] ; then rm $DIR$USER/ints.seed ; fi
for i in $(seq 1 $ints) ; do
echo $((3 + $RANDOM % 13)) >> $DIR$USER/ints.seed
done