ssh-treasure-hunt/exercices/gen_seed.sh

59 lines
1.5 KiB
Bash
Raw Permalink Normal View History

2022-01-18 21:16:31 +00:00
#!/bin/bash
2022-01-20 16:09:04 +00:00
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"
2022-01-18 21:16:31 +00:00
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
2022-01-20 16:09:04 +00:00
if echo $DIR | grep -v /$ > /dev/null ; then DIR=$DIR/ ; fi
2022-01-18 21:16:31 +00:00
2022-01-20 16:09:04 +00:00
mkdir -p $DIR$USER ;
2022-01-18 21:16:31 +00:00
2022-01-20 18:45:04 +00:00
if [[ ! -s $DIR$USER/folders.seed ]] ; then
find $root -type d | shuf | head -n $folders > $DIR$USER/folders.seed
echo folders
fi
if [[ ! -s $DIR$USER/files.seed ]] ; then
find $root -type f | shuf | head -n $files > $DIR$USER/files.seed
echo files
fi
if [[ ! -s $DIR$USER/filenames.seed ]] ; then
cat haddock.list | shuf | head -n $filenames > $DIR$USER/filenames.seed
echo names
fi
if [[ ! -s $DIR$USER/ints.seed ]] ; then
for i in $(seq 1 $ints) ; do
echo $((3 + $RANDOM % 13)) >> $DIR$USER/ints.seed
done
echo ints
fi
2022-01-18 21:16:31 +00:00