This repository has been archived by the owner on Feb 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathidentify.sh
executable file
·63 lines (54 loc) · 2.11 KB
/
identify.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /bin/sh
# this script adds email addresses and student ids to folder names extracted
# from Brightspace, given a CSV file obtained via 'Enter Grades'
if [ -z "$1" ]; then
echo "Usage: identify.sh spreadsheet.csv [dir1] [dir2] ... [dirN]" 1>&2
exit 1
fi
CSV="$1"; shift
if [ ! -f "$CSV" ]; then
echo "Usage: identify.sh spreadsheet.csv [dir1] [dir2] ... [dirN]" 1>&2
exit 2
fi
# this is the old functionality of 'groepjes.sh': scrapes files for student ids
collect() {
find "$1"/* -type f -not -name "*.WARNING" -print0 | xargs --null grep -oihI '\<[usefz]\?[0-9]\{6,7\}\>' | sed 's/\<[0-9]/#s&/' | tr USEFZ usefz
}
# some students instead put their student ids only in the *filenames* they submit
collect_ls() {
find "$1"/* -type f -not -name "*.WARNING" -print | grep -oihI '[usefz]\?[0-9]\{6,7\}' | sed 's/\<[0-9]/#s&/' | tr USEFZ usefz
}
# note: column 5 is assumed to be 'OSIRIS CUR groups'
GROUP_COLUMN=6
group="${GROUP_COLUMN:+`head -n1 "$CSV" | sed 's/<[^>]*>//g' | cut -d, -f"$GROUP_COLUMN"`}"
# sanity check: if this CSV field is quoted, it is not a group
group="${group##\"*}"
# sanity check: does this column look like an actual group, or like a grade?
[ "$group" != "${group%Grade}" ] || group=""
# find a student by name in the CSV file
findstud() {
mawk -v student="$1" '$1~student || $3" "$2==student || $3" "$2==student { print; exit }' FS=, OFS=, "$CSV"
}
for dir in "$@"; do
name="${dir%/}"
name="${name#* - }"
name="${name% - *}"
if [ "$group" ]; then
groupid="$(findstud "$name" | cut -d, -f"$GROUP_COLUMN")"
touch "$dir/#group:$(basename "$groupid")"
fi
{ echo "$name"; collect "$dir"; collect_ls "$dir"; } | while read id; do
if info="$(findstud "$id")"; then
echo "${info#\#}" | cut -d, -f1,4
if [ "$group" ]; then
groupid2="$(echo "$info" | cut -d, -f"$GROUP_COLUMN")"
if [ "$groupid" != "$groupid2" ]; then
echo 1>&2 "$dir: conflicting groups, $groupid and $groupid2"
fi
fi
else
echo 1>&2 "could not find entry for student: $id"
fi
done | sort -u > "$dir/#address.txt"
[ -s "$dir/#address.txt" ] || rm -f "$dir/address.txt"
done