#!/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 ; 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