-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-certificate.sh
More file actions
executable file
·200 lines (155 loc) · 5 KB
/
make-certificate.sh
File metadata and controls
executable file
·200 lines (155 loc) · 5 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/sh
LAST=6
CERT=certificate.txt
. .lib/shell-compat-test.sh
# Put tutorial library files into $PATH if they are not already added
if [[ -d "$PWD/.lib" && ":$PATH:" != *":$PWD/.lib:"* ]]; then
PATH=$PWD/.lib:$PATH
fi
source completed.sh
source progress.sh
source stdlib.sh
collect_logfiles() {
local LOG_FILE_DIR="$PWD/.logr/logfiles"
local COMPRESSED_FILE_NAME=shell-logs
if [[ -d "$LOG_FILE_DIR" ]]; then
if command -v tar &>/dev/null; then
tar -zcf $COMPRESSED_FILE_NAME.tgz -C "$LOG_FILE_DIR" .
if [[ $? == 0 ]]; then
cat <<-:
I also created the file '$COMPRESSED_FILE_NAME.tgz'
It contains information that helps us improve the shell tutor.
:
else
cat <<-:
I was unable to put the log files into a tarball.
Contact $_EMAIL for help.
:
return 1
fi
elif command -v zip &>/dev/null; then
zip --quiet --junk-paths --recurse-paths $COMPRESSED_FILE_NAME.zip "$LOG_FILE_DIR"
if [[ $? == 0 ]]; then
cat <<-:
I also created the file '$COMPRESSED_FILE_NAME.zip'
It contains information that helps us improve the shell tutor.
:
else
cat <<-:
I was unable to zip up the command logs for you.
Contact $_EMAIL for help.
:
return 1
fi
else
cat <<-:
I am unable to collect your command logs.
Contact $_EMAIL for help.
:
return 1
fi
fi
}
validate_completion() {
LESSONS=( [0-$LAST]*-*.sh )
MISSING=()
for L in ${LESSONS[@]}; do
if ! _completed $L; then
MISSING+=($L)
fi
done
case ${#MISSING[@]} in
0)
# "Here, The Cheat, have a trophy!"
return 0
;;
1)
cat <<-:
Wait a minute there! Aren't you forgetting something?
You still need to do lesson ${MISSING[0]}.
$(_tutr_progress)
Come back when you have done that.
:
exit 1
;;
${#LESSONS[@]})
cat <<-:
Um... it's customary to start at the beginning.
$(_tutr_progress)
That would be ${LESSONS[0]}.
:
exit ${#LESSONS[@]}
;;
*)
cat <<-:
Hold up! If my calculations are correct, you still need
to finish ${#MISSING[@]} lessons before you can have your certificate.
$(_tutr_progress)
Don't come back until you have completed
:
for ((I=0; I < ${#MISSING[@]} - 1; I++)); do
printf "${MISSING[I]}, "
done
printf "\b\b and ${MISSING[${#MISSING[@]} - 1]}\n"
exit ${#MISSING[@]}
;;
esac
}
congrats() {
local USER="$(whoami)"
cat <<-':'
_______________________________________________________________________
/ \ \
| | _____ __ __ __ _ __|
\_ | / ___/__ ___ ___ ________ _/ /___ __/ /__ _/ /_(_)__ ___ ___ / /|
|/ /__/ _ \/ _ \/ _ `/ __/ _ `/ __/ // / / _ `/ __/ / _ \/ _ \(_-</_/ |
|\___/\___/_//_/\_, /_/ \_,_/\__/\_,_/_/\_,_/\__/_/\___/_//_/___(_) |
| /___/ |
| _.-'`'-._ ________ |
|.-' _ '-. You completed the shell tutorial! (`\ `\ |
| `-.__ `\_.-' `-\ DIPLOMA \ |
| | `-``\| I am so proud of you right \ (@) \ |
| `-.....-# now that ASCII art cannot _\ |\ \ |
| jgs # capture my emotions. ( _)_________)|
| # `----------` |
| |
| |
:
cat <<-:
| Awarded to: $(printf '%-50.50s' $USER@$HOSTNAME) |
| Date: $(printf '%-56.56s' "$(command date '+%B %d, %Y')") |
:
cat <<-':'
| __ _____ _ |
| / ` / / ' // |
| /-- __ o /_ ,-/-,__. // __ __ |
| Signed: (___,/ (_<_/ <_ (_/ (_/|_</_(_)/ (_ |
| --------------------------------------------------- |
| |
| __________________________________________________________________|__
| / /
\_/dc__________________________________________________________________/
:
cat <<-:
This thing on the screen is just for fun.
The real certificate is a file named '$CERT'.
:
}
make_certificate() {
cat <<-: > $CERT
TUTR_REVISION=$_TUTR_REV
TIME=$(command date +%s)
UNAME=$(uname -s)
SHELL=$SHELL
${ZSH_VERSION:+ZSH_VERSION=$ZSH_VERSION}${BASH_VERSION:+BASH_VERSION=$BASH_VERSION}
$(git --version)
:
cat .[0-9]*-*.sh >> $CERT
git hash-object $CERT >> $CERT
}
validate_completion
make_certificate
congrats
[[ -z $DISABLE_TUTR_LOGR ]] && collect_logfiles
echo
# vim: set filetype=sh noexpandtab tabstop=4 shiftwidth=4 textwidth=76 colorcolumn=76: