-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreassign-courses.sh
executable file
·33 lines (23 loc) · 1.16 KB
/
reassign-courses.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
#!/bin/bash
source _functions.sh
source config.sh
oldowner="${1:-}"
newowner="${2:-$REASSIGN_COURSES_TO}"
test "$oldowner" -a "$newowner" || die "Usage: $0 <old owner> [new owner, default: $REASSIGN_COURSES_TO]"
$gam info user "$oldowner" quick fields fullname || die "Please specify valid old owner"
$gam info user "$newowner" quick fields fullname || die "Please specify valid new owner"
info "Find courses owned by >$oldowner< and assigning to >$newowner<"
courses="$($gam print courses owneremailmatchpattern "$oldowner")" || : ignore errors about non-existant users
$gam loop - gam info course "~id" fields name,descriptionHeading,teachers <<<"$courses" || : ignore errors about non-existant users
course_count="$(wc -l <<<"$courses")"
# always have line with column headings, so count is one less
let course_count--
if [ "$course_count" -gt 0 ] ; then
# courses have @ and we strip off everything after the id in the first column
mapfile -t course_ids < <(sed -n "/@/s/,.*//p" <<<"$courses")
echo -n "Courses: "
echo "${course_ids[@]}" | tr " " ,
$gam loop - gam update course "~id" teacher "$newowner" <<<"$courses"
else
info "No courses found"
fi