-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-sem.sh
executable file
·78 lines (63 loc) · 1.22 KB
/
make-sem.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
#!/bin/bash
# TODO: add entries to ~/school/courses index file
help() {
echo -n """make-sem.sh - create sem. directory structure
USAGE: make-sem.sh -s semester < courses
where courses consists of lines: name code [text only dir.]
"""
}
[[ $# -eq 0 ]] && { help; exit; }
#
# fce
#
SCHDIR="$HOME/school/"
PREFIX="${SCHDIR}sem."
# SEMDIR=${PREFIX}${SEM}
TEXTY="$HOME/texty/school.all/"
make_course() {
CODE=$1
NAME=$2
TEXT_ONLY=$3
mkdir ${TEXTY}/$CODE
if [[ $TEXT_ONLY ]]; then
cd $SEMDIR
ln -s ${TEXTY}/$CODE $NAME
else
DIR="${SEMDIR}/$NAME"
mkdir $DIR
cd $DIR
ln -s ${TEXTY}/$CODE texty
fi
}
#
# getopts
#
while getopts s:h VOLBA; do
case $VOLBA in
s) SEM=$OPTARG;;
h) help;
exit 1;;
esac
done
shift $(($OPTIND-1))
if ! [[ $SEM ]]; then
echo "error: semester spec. missing" >&2
help;
exit 2
fi
#
# main
#
SEMDIR=${PREFIX}${SEM}
if [[ -d $SEMDIR ]]; then
echo "note: directory $SEMDIR already exists" >&2
else
mkdir $SEMDIR || { echo "error: semdir can't be created" >&2; help; exit 3; }
fi
IFS=$'\n'
for i in $(grep -v ^#); do
CODE=$(echo $i | cut -d' ' -f 1)
NAME=$(echo $i | cut -d' ' -f 2)
TEXT_ONLY=$(echo $i | cut -d' ' -f 3)
make_course $CODE $NAME $TEXT_ONLY
done