ssh-treasure-hunt/exercices/init.sh

27 lines
1.3 KiB
Bash
Raw Permalink Normal View History

2022-01-20 16:09:04 +00:00
#!/bin/bash
2022-01-20 18:45:04 +00:00
if [ "$#" -ne 1 && "$#" -ne 2 ] ; then
echo -e "usage : $0 <FILE> [USER]\n Generate the exercice for a class.\nFILE must be a list containing identifiers (names) and passwords for each student, separated by a '='.\n Ex:\n Jean-claude-dus=mot_de_passe\n Jean-dus-claude=passe_de_mot\n Claude-jean-dus=azerty\nIf a USER is provided, init will only be run for that user (useful to add a student mid-class, reset a session when something went horribly wrong, or if a student finished early and wants to start over.\n\nThis file must be executed from the same folder as the files gen_arbo.sh, gen_seed.sh and gen_enonces.sh.\nFolders will be created in this directory, containing the exercices, their correction and the grades of the students."
2022-01-20 16:09:04 +00:00
exit 1;
fi
home=/home
2022-01-20 18:45:04 +00:00
#Little debug option for one of the devs. If we forgot to remove it before deployment, feel free to erase this line.
if [ $USER = karsaell ] ; then home=root ; fi
2022-01-20 16:09:04 +00:00
names=$(cut -d '=' -f 1 $1)
2022-01-20 18:45:04 +00:00
if [ "$#" -eq 2 ] ; then
names=$(grep $2 $1 | cut -d '=' -f 1)
if [ -z $names ] ; then
echo "Error : no user named $2 found in $1"
exit 1
fi
fi
2022-01-20 16:09:04 +00:00
for name in $names ; do
./gen_arbo.sh $home/$name $name
./gen_seed.sh $home/$name 4 0 5 1 $name seeds
./gen_enonces.sh seeds $name /dev/null $home/$name $1
done