-
Notifications
You must be signed in to change notification settings - Fork 8
/
wizard.sh
executable file
·89 lines (74 loc) · 2.1 KB
/
wizard.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
cat<<EOF
_________________________________
/ Are you sure you want to ask me \
\ for help? /
---------------------------------
\
\
__
/ \
| |
@ @
| |
|| |/
|| ||
|\_/|
\___/
EOF
exit
# configuration wizard for bb-scripts
if ! command -v curl >/dev/null 2>&1; then
echo "Who am I? Why am I here? Am I on lilo? curl is missing!" >& 2
exit 1
fi
set -e
cd "${0%/*}"
echo Stop!
echo
echo Who would cross the BlackBoard of Death must answer me these questions three,
echo ere the other side he see.
echo
echo What... is your username?
read -p "User: " BBUSER
./bblogin2.sh "$BBUSER"
death() {
echo "What... is the airspeed-velocity of an unladen swallow?"
read -p "(African or European swallow): "
sleep 1
echo "..."
sleep 1
echo "You have to know these things when you are a king, you know."
exit 1
}
echo
echo What... is your quest?
CURL="curl --silent --cookie bb.cookie"
BBCOURSES="https://blackboard.ru.nl/webapps/blackboard/execute/globalCourseNavMenuSection?cmd=view"
QUESTS="$($CURL "$BBCOURSES" | sed -n '/a href/s/.*Course[^_]*_\([0-9]\+\)_1[^>]*>\([^<]*\).*/\2|\1/p' | grep "^\(..\)\?$(date +%y)" | sort -r | tr ' ' _)"
select course in $QUESTS; do
BBCOURSEID="${course#*|}"
course="$(echo "$course" | sed 'y/_/ /;s/[[:space:]]*([^)]*)//')"
if [ -z "$BBCOURSEID" ]; then
death
else
break
fi
done
echo
read -p "What... is your favorite editor: " -i "$EDITOR" edit
echo '# email addresses of all participating assistants' > bb.mail
grep '^email' verdeel.sh >> bb.mail
which "${edit:-vi}" || death
${edit:-vi} bb.mail
MAILFMT='email\[.*]=.*@.*'
if grep -q -v -e "^\($MAILFMT\|\)$" -e "^#" bb.mail || ! grep -q "$MAILFMT" bb.mail; then
death
fi
sed -i "/^email/d;/^typeset -A email/rbb.mail" verdeel.sh
sed -i "0,/^BBUSER=.*$/s//BBUSER=$BBUSER/" verdeel.sh
sed -i "0,/^BBCOURSEID=[0-9]\+/s//BBCOURSEID=$BBCOURSEID/" verdeel.sh upload.sh
sed -i "0,/BBCOURSEID:=[0-9]\+/s//BBCOURSEID:=$BBCOURSEID/" getsch.sh
sed -i "0,/^SUBJECT=.*$/s//SUBJECT=\"${course%|*}: \"/" verdeel.sh
echo Go on. Off you go.
rm -f bb.mail