-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenroll_in_all.sh
executable file
·42 lines (36 loc) · 1.45 KB
/
enroll_in_all.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
# enroll a user in all of a program's courses in a particular semester
# including metacourses
usage () {
# shellcheck disable=SC2016
echo -e 'Usage:\n\t./enroll_in_all.sh $SEMESTER $PROGRAM $USER [ $ROLE ]\n'
echo -e 'Examples:\n\t./enroll_in_all.sh 2022SP GAMES ephetteplace'
echo -e '\t./enroll_in_all.sh 2022FA ANIMA nchan exportonlyteacher\n'
echo 'ROLE defaults to editingteacher if not provided. All other arguments are required.'
echo 'Note that this script only works for regular courses with correctly formatted shortnames, but that does include metacourses.'
}
if [[ -z ${1} || ${1} = "-h" || ${1} = "--help" || ${1} = "help" ]]; then
usage
exit 0
fi
SEMESTER=$1
PROGRAM=$2
USER=$3
ROLE=${4:-editingteacher}
if [[ -z ${SEMESTER} || -z ${PROGRAM} || -z ${USER} ]]; then
echo -e "ERROR: semester, program, and user arguments are required.\n" 1>&2
usage
exit 1
fi
cd /bitnami/moodle || exit
# Ensure moosh is on PATH
export PATH=${PATH}:/usr/bin:/usr/local/bin
echo "Enrolling user ${USER} in all ${SEMESTER} ${PROGRAM} courses with role ${ROLE}"
for course in $(moosh -n course-list -i "shortname LIKE \"%${PROGRAM}%-${SEMESTER}\""); do
message=$(moosh -n course-enrol -r "${ROLE}" "${course}" "${USER}")
if [[ -n "${message}" ]]; then
echo "${message}"
echo "Above error was with course number $course"
echo "https://moodle.cca.edu/course/view.php?id=$course"
fi
done