-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadom_helper.sh
executable file
·329 lines (329 loc) · 11.7 KB
/
adom_helper.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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/bin/sh
################################################################################
#
# adom_helper - v0.1 - by pyllyukko ([email protected]) - 2002
#
# greets fly to amokrun - thanks for the logo!
#
################################################################################
trap 'echo ; echo -e "\033[1;31mctrl\033[0m-\033[1;31mc\033[0m!" ; exit 1' 2
################################################################################
function laskuri() {
echo -n "current attribute level? "
read STATS
[ -z ${STATS} ] && {
echo "try to type something!"
return 1
}
[ `expr ${STATS} - ${STATS} &>/dev/null ; echo $?` -eq 2 ] && {
echo "number! you nitwit!"
return 1
}
[ ${STATS} -lt 1 -o ${STATS} -gt 50 ] && {
echo "value out of range!"
return 1
}
[ ${STATS} -lt 16 ] && KERROIN=100
[ ${STATS} -gt 15 -a ${STATS} -lt 21 ] && KERROIN=200
[ ${STATS} -gt 20 -a ${STATS} -lt 26 ] && KERROIN=400
[ ${STATS} -gt 25 -a ${STATS} -lt 31 ] && KERROIN=800
[ ${STATS} -gt 30 -a ${STATS} -lt 36 ] && KERROIN=1600
[ ${STATS} -gt 35 -a ${STATS} -lt 41 ] && KERROIN=3200
[ ${STATS} -gt 40 -a ${STATS} -lt 46 ] && KERROIN=6400
[ ${STATS} -gt 45 ] && KERROIN=12800
echo "$[${STATS}*${KERROIN}]$"
}
################################################################################
function killadom() {
ADOM_PID=`/sbin/pidof adom` || {
echo "adom not running!"
return 1
}
echo -en "killing adom (pid: \033[1;31m${ADOM_PID}\033[0m) - "
kill -9 ${ADOM_PID} && echo "killed!" || {
echo "adom dodged the bullet!"
return 1
}
echo -n "removing temp - "
rm -f ~/.adom.data/.adom.prc &>/dev/null && echo "done!" || "echo failed!"
}
################################################################################
function help() {
PROGNAME=${0##*/}
echo -e "\033[0m \033[1;30m _.sxS\$\$\$P\"\033[0;37m \033[1;30m :: .s\$s. \033[0;37m"
echo -e " \033[1;30m .sSP^\033[0;35m.\033[1;30m.\$$^\033[0;37m \033[1;30m::\033[0;37m \033[1;30m .sdSP~ .sd$'\033[0;35m.\033[1;30m\`\$b \033[0;37m"
echo -e " \033[31m:\033[37m \033[1;30m:: .d\$P'\033[0;35m::\033[1;30md$^ \"\$Ss._\033[0;37m \033[31m,:\033[37m \033[1;30m.s\$\$\$P .s\$\$'\033[0;35m.:.:::\033[1;30m$: ::\033[0;37m \033[31m:\033[37m"
echo -e " \033[31m.\033[37m \033[31m:::::::\033[1;30m :\$\$'\033[0;35m::l\033[1;30mj$'\033[0;31m::::.\033[1;30m\`$~Tb.\033[0;31m:'\033[1;30md$'\033[0;35m.\033[1;30m\$\$'\033[0;31m:::\033[1;30m\`T$\033[0;35ml:l:II\033[1;30m\$l\033[0;37m \033[31m:::::\033[37m"
echo -e " \033[31m :IIIIIII\033[1;30m l$'\033[0;35mIl:\033[1;30m:\$\$ \033[0;31mI'\033[1;30m_.s $\033[0;35m::\033[1;30m\$l j$'\033[0;35m::\033[1;30m\`$\033[0;37m \033[31mI'\033[1;30m.s\033[0;31m.\033[1;30m\`$\033[0;35mXIIX\033[1;30mj$:\033[0;31m.IIIII::.\033[37m"
echo -e " \033[31m:::IXXXXXXX\033[1;30m \$\$\033[0;35mXIIXl\033[1;30m\$\$:.s\"\033[0;31m.X\033[1;30mj$\033[0;35mXl:\033[1;30m$ \$\$\033[0;35m:III\033[1;30m\`b\033[0;37m \033[1;30ms'\033[0;31mjXX\033[1;30m\`$\033[0;35mXXX\033[1;30m\$\$'\033[0;31mjXXXXXI:::\033[37m \033[31m;\033[37m"
echo -e " \033[31m:IIIIIII\033[1;30m :$\033[0;35mlXlXX\033[1;30m:\$l\033[0;37m \033[31mII'\033[1;30mj\$\$sd\$P l$\033[0;35mIXlXX:\033[1;30m\$s._\033[0;31mI'\033[1;30mj$\033[0;35mX'\033[1;30m\$P'\033[0;31mIIIIIII::\033[37m"
echo -e " \033[31m:\033[37m \033[31m.::::::::\033[1;30m \$\$\033[0;35mXX\033[1;30m.s\$\$\$b.\033[0;37m \033[1;30mjP^~\033[0;31m.::::\033[37m \033[1;30m\$\$\033[0;35m:XX'\033[1;30mxSP^\033[0;31m.'\033[1;30md\$\$\$P^\033[0;31m.::::::::\033[37m \033[31m':\033[37m"
echo -e " \033[31m':\033[37m \033[1;30m::\`\$\$\$\$S\"~ \033[0;37m \033[31m:'\033[37m \033[1;30m::\033[0;37m \033[1;30m\`\$\$\$P\"~ .s\$\$P^~\033[0;37m \033[1;30m::\033[0;37m \033[31m:'\033[37m"
echo -e " \033[1;30m \`$\"' .\033[0;35ma\033[1;30m.\033[0;35md\033[1;30m.\033[0;35mo\033[1;30m.\033[0;35mm\033[1;30m.\033[0;37m \033[1;30m\`$'\033[0;37m \033[1;30m.\033[0;35mh\033[1;30m.\033[0;35me\033[1;30m.\033[0;35ml\033[1;30m.\033[0;35mp\033[1;30m.\033[0;35me\033[1;30m.\033[0;35mr\033[1;30m.\033[0;37m"
#echo "adom_helper - by pyllyukko ([email protected])"
echo
echo -e "\033[1;30musage: \033[0;35m${PROGNAME}\033[1;30m [-\033[0;35mhSLslkcx\033[1;30m]\033[0m"
echo -e " \033[0;35mh\033[1;30m: this help text"
echo -e " \033[0;35mS\033[1;30m: quicksave"
echo -e " \033[0;35mL\033[1;30m: quickload"
echo -e " \033[0;35ms\033[1;30m: save"
echo -e " \033[0;35ml\033[1;30m: load"
echo -e " \033[0;35mk\033[1;30m: kill adom - to get your favorite month when creating character"
echo -e " \033[0;35mc\033[1;30m: counter - to know how much money you should pay for garth to advance"
echo -e "\033[15Cattribute level"
echo -e " \033[35mx\033[1;30m: starting a new game? set the date to 2nd of july to get lucky and"
echo -e "\033[15Cfate smiles upon you -instricts! (requires root password)"
echo
echo "send all suggestions, typo & bug reports, ideas, criticism & fixes"
echo -e "to [email protected] - all are welcome!\033[0m"
}
################################################################################
function yes_no() {
echo -n "$1 (y/n)? "
while read -r -s -n 1 CHOICE
do
case $CHOICE in
y)
echo "yes"
return 0
;;
n)
echo "no"
return 1
;;
*)
continue
;;
esac
done
}
################################################################################
function choose() {
LISTA=$*
AMOUNT=`echo ${LISTA} | wc | awk '{print $2}'`
select CHOICE in ${LISTA} `echo -e "\033[1;31mcancel\033[0m"`
do
case ${CHOICE} in
`echo -e "\033[1;31mcancel\033[0m"`)
return 1
;;
*)
expr ${REPLY} + 666 &>/dev/null || {
echo -e "\033[5;31mNITWIT\033[0m!" 1>&2
continue
}
[ ${REPLY} -lt 1 -o ${REPLY} -gt $((${AMOUNT}+1)) ] && {
echo -e "\033[5;31mNITWIT\033[0m!" 1>&2
continue
}
echo ${CHOICE}
return 0
;;
esac
done
}
################################################################################
function quickload() {
cd ~/.adom.data/savedg 2>/dev/null || {
echo "~/.adom.data/savedg - no such dir!"
return 1
}
LISTA=`ls *.bak 2>/dev/null | sed 's/.bak^*//'`
AMOUNT=`echo ${LISTA} | wc | awk '{print $2}'`
case ${AMOUNT} in
0)
echo -n "no quicksaves available - "
;;
1)
WHO=${LISTA}
;;
*)
WHO=`choose ${LISTA}`
esac
[ -z ${WHO} ] && echo -e "\033[1;31mcancelled\033[0m!" || {
[ -f ${WHO}.svg ] && {
yes_no "saved game exists, overwrite?"
case $? in
0)
echo -en "quickloading \033[1;31m${WHO}\033[0m - "
yes | cp ${WHO}.bak ${WHO}.svg && echo "loaded!" || echo "unknown error occured - check permissions!"
;;
1)
echo -e "\033[1;31mcancelled\033[0m!"
;;
*)
echo -e "unknown error - \033[5;31mTHIS SHOULDN'T HAPPEN\033[0m!"
esac
} || {
echo -en "quickloading \033[1;31m${WHO}\033[0m - "
cp ${WHO}.bak ${WHO}.svg && echo "loaded!" || echo "unknown error occured - check permissions!"
}
}
}
################################################################################
function quicksave() {
cd ~/.adom.data/savedg 2>/dev/null || {
echo "~/.adom.data/savedg - no such dir!"
return 1
}
LISTA=`ls *.svg 2>/dev/null | sed 's/.svg^*//'`
AMOUNT=`echo ${LISTA} | wc | awk '{print $2}'`
case ${AMOUNT} in
0)
echo -n "no saved games! - "
;;
1)
WHO=${LISTA}
;;
*)
WHO=`choose ${LISTA}`
esac
[ -z ${WHO} ] && {
echo -e "\033[1;31mcancelled\033[0m!"
} || {
echo -en "quicksaving \033[1;31m${WHO}\033[0m - "
yes | cp ${WHO}.svg ${WHO}.bak && echo "saved!" || echo "unknown error occured - check permissions!"
}
}
################################################################################
function _load() {
NAME=$1
LISTA=`ls -X ${NAME}`
AMOUNT=`echo ${LISTA} | wc | awk '{print $2}'`
echo ",-------------------."
echo -e "|\033[1;31m1\033[0m=\033[1;31moldest\033[0m - \033[1;31m${AMOUNT}\033[0m=\033[1;31mnewest\033[0m|"
echo "\`-------------------'"
PS3="which one to load? "
select CHOICE in `echo "${LISTA}" | sed 's/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-//g'` `echo -e "\033[1;31mcancel\033[0m"`
do
case ${CHOICE} in
`echo -e "\033[1;31mcancel\033[0m"`)
echo -e "\033[1;31mcancelled\033[0m!"
break
;;
*)
expr ${REPLY} + 666 &>/dev/null || {
echo -e "\033[5;31mNITWIT\033[0m!"
continue
}
[ ${REPLY} -lt 1 -o ${REPLY} -gt $((${AMOUNT}+1)) ] && {
echo -e "\033[5;31mNITWIT\033[0m!"
continue
}
LOAD_WHO=`echo ${LISTA} | awk --assign R=${REPLY} '{print $R}'`
[ -f ${NAME}.svg ] && {
yes_no "saved game exists, overwrite?"
case $? in
0)
echo -en "loading \033[1;31m${NAME}\033[0m - "
yes | cp ${NAME}/${LOAD_WHO} ${NAME}.svg && echo "loaded!" || echo "unknown error occured - check permissions!"
;;
1)
echo -e "\033[1;31mcancelled\033[0m!"
;;
*)
echo -e "unknown error - \033[5;31mTHIS SHOULDN'T HAPPEN\033[0m!"
esac
break
} || {
echo -en "loading \033[1;31m${NAME}\033[0m - "
cp ${NAME}/${LOAD_WHO} ${NAME}.svg && echo "loaded!" || echo "unknown error occured - check permissions!"
break
}
esac
done
}
################################################################################
function load() {
cd ~/.adom.data/savedg 2>/dev/null && {
LISTA=`du | awk '$1!="4" {print $2}' | sed '$d;s/^.\///g'`
AMOUNT=`echo ${LISTA} | wc | awk '{print $2}'`
case ${AMOUNT} in
0)
echo "no saved games!"
;;
1)
_load ${LISTA}
;;
*)
LOAD_WHO=`choose ${LISTA}`
[ -z ${LOAD_WHO} ] && echo -e "\033[1;31mcancelled\033[0m!" || _load ${LOAD_WHO}
esac
}
}
################################################################################
function _save() {
NAME=$1
[ -d ~/.adom.data/savedg/${NAME} ] || {
echo "save directory does not exist, creating one to ~/.adom.data/savedg/${NAME}"
mkdir ~/.adom.data/savedg/${NAME} && echo "directory created!" || {
echo "unknown error occured - check permissions!"
return 1
}
}
echo -en "description? \033[1;31m"
read DESCRIPTION
echo -en "\033[0m"
[ -z "${DESCRIPTION}" ] && {
echo "no description given!"
DESCRIPTION="no_description"
} || DESCRIPTION=`echo ${DESCRIPTION} | sed 's/ /_/g'`
echo -en "saving \033[1;31m${NAME}\033[0m - "
cp ~/.adom.data/savedg/${NAME}.svg ~/.adom.data/savedg/${NAME}/`date +%s`-${DESCRIPTION} && echo "saved!" || echo "unknown error occured - check permissions!"
}
################################################################################
function save() {
cd ~/.adom.data/savedg 2>/dev/null && {
LISTA=`ls *.svg 2>/dev/null | sed 's/.svg^*$//'`
AMOUNT=`echo ${LISTA} | wc | awk '{print $2}'`
case $AMOUNT in
0)
echo "no saved games!"
;;
1)
_save ${LISTA}
;;
*)
SAVE_WHO=`choose ${LISTA}`
[ -z ${SAVE_WHO} ] && echo -e "\033[1;31mcancelled\033[0m!" || _save ${SAVE_WHO}
;;
esac
} || {
echo "~/.adom.data/savedg - no such dir!"
}
}
################################################################################
while getopts ":lsSLhkcx" OPTION
do
case ${OPTION} in
l)
load
;;
s)
save
;;
L)
quickload
;;
S)
quicksave
;;
h)
help
;;
k)
killadom
;;
c)
laskuri
;;
x)
YEAR=`date +%Y`
echo -n "password? "
su --command="date --set=\"7/2/${YEAR}\" &>/dev/null" 2>/dev/null && echo "done!" || echo "failed!"
;;
*)
echo "invalid option!"
;;
esac
done