File: hamexam

package info (click to toggle)
hamexam 1.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 7,100 kB
  • sloc: sh: 119; awk: 37; makefile: 20
file content (166 lines) | stat: -rwxr-xr-x 4,577 bytes parent folder | download
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
#!/bin/sh
# study ham exam question pools
# Copyright (C) 2011-2019 John Nogatch AC6SL <jnogatch@gmail.com>

# dir where question pools reside?
INSTALLDIR="$(dirname "$(readlink -f $0)")"

# user specified png viewer?
if [ -n "${PNG_VIEWER+xxx}" ]; then
    if type "${PNG_VIEWER}" > /dev/null 2>&1; then
	echo "user specified PNG_VIEWER: ${PNG_VIEWER}"
    else
	echo "user specified PNG_VIEWER: ${PNG_VIEWER} is not executable"
	PNG_VIEWER=""
    fi
# try eog
elif type "eog" > /dev/null 2>&1; then
    PNG_VIEWER="eog"
# try gwenview
elif type "gwenview" > /dev/null 2>&1; then
    PNG_VIEWER="gwenview"
# try gpicview
elif type "gpicview" > /dev/null 2>&1; then
    PNG_VIEWER="gpicview"
# try ristretto
elif type "ristretto" > /dev/null 2>&1; then
    PNG_VIEWER="ristretto"
else
    echo "PNG_VIEWER was not specifed nor found"
    PNG_VIEWER=""
fi

# dir to keep user's unanswered questions
USERDIR=~/.hamexam

# create user dir, if needed
if [ ! -d "${USERDIR}" ]; then
    echo "creating ${USERDIR}"
    mkdir "${USERDIR}"
    if [ $? -ne 0 ]; then
	echo "unable to create ~/.hamexam directory"
	sleep 3
	exit 1
    fi
fi

# check argument for T, G, or E, default to showing usage, version, brief help
# set POOL within set {T,G,E}
case "$1" in

    "2" | [tT]* ) POOL="T";;
    "3" | [gG]* ) POOL="G";;
    "4" | [eE]* ) POOL="E";;

    "q" | *) echo "usage: hamexam {t|g|e|q}";
	echo "hamexam version 1.7.0";
	echo "Technician, Element 2 effective July-2018 until July-2022";
	echo "General, Element 3 effective July-2019 until July-2023";
	echo "Extra, Element 4 effective July-2016 until July-2020";
	echo "hamexam is an interactive study guide for USA FCC amateur radio (ham radio) examinations.";
	echo "The 3 question pools are:";
	echo "    t element 2, Technician Class (entry level),";
	echo "    g element 3, General Class (also requires element 2),";
	echo "    e element 4, Extra Class (also requires elements 2 and 3).";
	echo "Questions are chosen randomly from the selected pool.";
	echo "Incorrect answers cause the question to be asked again later.";
	echo "Licenses are issued by the FCC, but exams are conducted by Volunteer Examiners."
	echo "For more information about USA amateur radio licensing: http://www.arrl.org/licensing-preparation-exams";
	if [ "$1" != "q" ]; then
	    sleep 3
	    exit 1;
	fi;
	POOL="Q"
	while [ $POOL = "Q" ]:; do
	    # read -p "Which pool? {t,g,e} " POOL;  (Debian: read with option other than -r)
	    echo -n "Which pool? {t,g,e}: ";
	    read POOL;
	    case "$POOL" in
		"2" | [tT]* ) POOL="T";;
		"3" | [gG]* ) POOL="G";;
		"4" | [eE]* ) POOL="E";;
		* ) POOL="Q";;
	    esac;
	done
esac

# go to user dir so that question names are accessible
cd ${USERDIR}
if [ $? -ne 0 ]; then
    echo "unable to access ~/.hamexam directory"
    sleep 3
    exit 1
fi

# if no questions remain, reload all the questions
ls ${POOL}* >> /dev/null 2>&1
if [ $? -ne 0 ]; then
    case ${POOL} in
	"T" ) echo "reloading Technicican Class element 2";;
	"G" ) echo "reloading General Class element 3";;
	"E" ) echo "reloading Extra Class element 4";;
	"" | * ) echo "POOL variable was not set correctly";
	    sleep 3;
	    exit 1;;
    esac
    ls "${INSTALLDIR}"/${POOL} | xargs touch
else
    echo "resuming remaining questions"
fi

# no PNG_VIEWER available?
if [ "${PNG_VIEWER}" = "" ]; then
    echo "no PNG_VIEWER to display diagrams"
else
    # bring up diagrams for this element
    ${PNG_VIEWER} ${INSTALLDIR}/${POOL}pngs/${POOL}1.png 2>/dev/null &
    if [ $? -ne 0 ]; then
	echo "${PNG_VIEWER} failed to display diagrams"
    fi
fi

# report how many questions remain
ls ${POOL}* | wc | awk '{print $1 " questions remain in this pool\n"}'

while :; do
    # random choice from remaining questions
    Q=`shuf -n 1 -e ${POOL}*`

    # exit if no more questions
    if [ "${Q}" = "${POOL}*" ]; then
	echo "question pool ${POOL} completed"
	sleep 3
	break
    fi

    # if question still exists (might be stale name from old pool)...
    if [ -e "${INSTALLDIR}"/${POOL}/"${Q}" ]; then
	# no png viewer?
	if [ -z "${PNG_VIEWER}" ]; then
	    # question references figure?
	    egrep '[Ff]igure ' "${INSTALLDIR}"/${POOL}/"${Q}" >> /dev/null
	    if [ $? = 0 ]; then
		echo "question ${Q} refers to a figure"
		rm "${Q}"
		continue
	    fi
	fi

	# ...ask the question
	awk -f "${INSTALLDIR}"/ask.awk "${INSTALLDIR}"/${POOL}/"${Q}"
    else
	echo "question ${Q} not found"
    fi

    case $? in
	# if correct, remove the question
	0) rm "${Q}";;

	# check for quit or EOF
	2) break;;
    esac
done

exit 0

# end of hamexam