-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdlclecs
49 lines (38 loc) · 1.4 KB
/
dlclecs
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
#!/bin/sh
#----------------------------------------------------------------------------------
# Project Name - miscellaneous/dlclecs
# Started On - Tue 19 Sep 13:00:16 BST 2017
# Last Change - Sun 8 Oct 21:02:17 BST 2017
# Author E-Mail - terminalforlife@yahoo.com
# Author GitHub - https://github.com/terminalforlife
#----------------------------------------------------------------------------------
# With this small shell program you can download some C programming teaching files.
#----------------------------------------------------------------------------------
XERR(){ echo "ERROR: $1" 1>&2; exit 1; }
ERR(){ echo "ERROR: $1" 1>&2; }
DEPCOUNT=0
for DEP in /usr/bin/id /usr/bin/basename /bin/grep /usr/bin/wget; do
[ -x "$DEP" ] || {
ERR "Dependency '$DEP' not met."
DEPCOUNT=$(( DEPCOUNT + 1 ))
}
done
[ $DEPCOUNT -eq 0 ] || exit 1
[ `/usr/bin/id -u` -eq 0 ] && XERR "Root access isn't required."
DOMAIN="https://ocw.mit.edu"
CATEGORY="electrical-engineering-and-computer-science"
COURSE="6-087-practical-programming-in-c-january-iap-2010"
URL1="/courses/$CATEGORY/$COURSE/lecture-notes/"
GREP_REGEX="${URL1}MIT6_087IAP10_lec"
DLINKS=$(
/usr/bin/wget -q "$DOMAIN/$URL1" -O -\
| /bin/grep -o "${GREP_REGEX}[0-9]\+.pdf"
)
for FILE in $DLINKS; do
FILENAME=`/usr/bin/basename $FILE`
/usr/bin/wget -q "${DOMAIN}${FILE}" && {
echo "FILE: $FILENAME"
} || {
XERR "$FILENAME"
}
done