forked from illwieckz/debian_copyist_brother
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_brother.sh
executable file
·801 lines (719 loc) · 22.9 KB
/
web_brother.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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
#! /usr/bin/env bash
# FILENAME: web_brother.sh
# AUTHOR: Thomas DEBESSE
# VERSION: 20140322
# LICENSE: ISC
# DEPENDENCIES: bash, wget, sed, dos2unix
#############################################################################
##
## Constants, Configuration, Initialisation
##
BROTHER_TRADEMARK='Brother™'
BROTHER_PAGES_DIR='http://welcome.solutions.brother.com/bsc/public_s/id/linux/en/'
BROTHER_REPOSITORY='http://www.brother.com/pub/bsc/linux/dlf/'
BROTHER_LICENSE_DIR='http://www.brother.com/agreement/'
BROTHER_LICENSE_FILE='agree.html'
WEBARCHIVE_DOMAIN='http://web.archive.org'
WEBARCHIVE_ROOT='/web/20140319074031/'
USE_WEBARCHIVE='true'
# You can override default workspace directory via "WEBBROTHER_WORKSPACE" env variable
if [ "${WEBBROTHER_WORKSPACE}" != '' ]
then
WORKSPACE="${WEBBROTHER_WORKSPACE}"
else
WORKSPACE="$(cd "$(dirname $0)"; pwd)/../material/"
fi
FILES_DIR="${WORKSPACE}/files/"
LISTS_DIR="${WORKSPACE}/lists/"
PAGES_DIR="${WORKSPACE}/pages/"
LICENSES_DIR="${WORKSPACE}/licenses/"
mkdir -p "${WORKSPACE}"
mkdir -p "${FILES_DIR}"
mkdir -p "${LISTS_DIR}"
mkdir -p "${PAGES_DIR}"
mkdir -p "${LICENSES_DIR}"
#############################################################################
##
## PRECIOUS MAGICAL REGEXP HERE
##
function _parse_sources_archives_with_licenses {
# for each line containing file (tar.gz)
# -> extract archive name
print_page sources | grep 'dlfile=' | grep '\.tar.gz' | sed -e 's#^.*/linux/dlf/\(.*\)\&lang=\(.*\)"><b>.*#\1\t\2#' \
| sort | uniq
}
function _parse_printers_archives_with_licenses {
# for each line containing file (deb or ppd)
# -> extract archive name
print_page printers | grep 'dlfile=' | grep '\.deb\|\.ppd.gz' | sed -e 's#^.*/linux/dlf/\(.*\)\&lang=\(.*\)">.*#\1\t\2#' \
| sort | uniq
}
function _parse_labelers_archives_with_licenses {
# for each line containing file (deb or ppd)
# -> extract archive name
print_page labelers | grep 'dlfile=' | grep '\.deb\|\.ppd.gz' | sed -e 's#^.*/linux/dlf/\(.*\)\&lang=\(.*\)">.*#\1\t\2#' \
| sort | uniq
}
function _parse_scanners_archives_with_licenses {
# for each line containing file (deb)
# -> extract archive name
print_page scanners | grep 'dlfile=' | grep '\.deb' | sed -e 's#^.*/linux/dlf/\(.*\)\&lang=\(.*\)"><b>.*#\1\t\2#' \
| sort | uniq
}
function _parse_pcfaxes_archives_with_licenses {
# for each line containing file (deb)
# -> extract archive name
print_page pcfaxes | grep 'dlfile=' | grep '\.deb' | sed -e 's#^.*/linux/dlf/\(.*\)\&lang=\(.*\)"><b>.*#\1\t\2#' \
| sort | uniq
}
function _parse_printers_variant_models {
# for each line containing both variant and original model name
# -> extract variant model name
print_page printers | grep '^<p><a name=' | grep ' / ' | sed -e 's#^<p><a name="[A-Za-z0-9-]* / \([A-Za-z0-9-]*\)"></a><b>.*</b></p>#\1#' \
| sort | uniq
}
function _parse_printers_alternative_models {
# for each advertising itself as an alternative model
# -> extract model name
print_page printers | grep '^<div id="AltDriver"><p><a name=' | sed -e 's#^<div id="AltDriver"><p><a name="\([A-Za-z0-9-]*\)"></a><b>.*</b></p>#\1#' \
| sort | uniq
}
function _parse_printers_original_model_from_variant {
# for each line containing both variant and original model name and containing the given variant model name
# -> extract the original model name
print_page printers | grep '^<p><a name=' | grep " / ${1}" | sed -e 's#<p><a name="\([A-Za-z0-9-]*\) / '"${1}"'"></a><b>.*</b></p>$#\1#' \
| sort | uniq
}
function _parse_printers_original_model_from_alternative {
# for each line advertising itself as an alternative model and containing the given alternative model name
# -> get the second line containing the original model name
# -> extract model name
print_page printers | grep '<div id="AltDriver"><p><a name="'"${1}"'"></a><b>' -A 2 | grep '^<td>Please use ' \
| sed -e 's#^<td>Please use <a href=".*"><b>\([A-Za-z0-9-]*\)</a> driver.</td></table></div>$#\1#' \
| sort | uniq
}
function _parse_printers_primary_models {
# for each line containing model name
# -> drop variant name
# -> extract model name
print_page printers | grep '^<p><a name=' | sed -e 's# / [A-Za-z0-9-]*##;s#^<p><a name="\([A-Za-z0-9-]*\)"></a><b>.*</b></p>#\1#' \
| sort | uniq
}
function _parse_labelers_primary_models {
# for each line containing model name
# -> drop variant name
# -> extract model name
print_page labelers | grep '^<p><a name=' | sed -e 's# / [A-Za-z0-9-]*##;s#^<p><a name="\([A-Za-z0-9-]*\)"></a><b>.*</b></p>#\1#' \
| sort | uniq
}
function _parse_printer_archives {
# for each line containing model name
# -> drop variant name for line if exists
# -> from this line to line containing "Page Top" words used as end marker (drop before, drop after, maximum 100 lines between)
# ---> for each line containing a file (deb, ppd)
# -----> extract archive name
# -----> for each line containing archive name
# -------> convert end of line char with tab char
# -------> drop trailing '\t' char
print_page printers | sed -e 's#\([A-Za-z0-9-]*\) / [A-Za-z0-9-]*#\1#' | grep -A 100 '^<p><a name="'"${1}"'"></a><b>' \
| grep -m 1 -B 100 '<div align=right><p><a href=".*#top">Page Top</a></p><p> </p></div>' \
| grep '\.deb\|\.ppd.gz' | sed -e 's#^.*/linux/dlf/\(.*\)\&lang=.*#\1#' | sort \
| sed -e ':a;N;$!ba;s/\n/\t/g' | sed -e 's/\t$//' \
| sort | uniq
}
function _parse_labeler_archives {
# for each line containing model name
# -> drop variant name for line if exists
# -> from this line to line containing "Page Top" words used as end marker (drop before, drop after, maximum 100 lines between)
# ---> for each line containing a file (deb, ppd)
# -----> extract archive name
# -----> for each line containing archive name
# -------> convert end of line char with tab char
# -------> drop trailing '\t' char
print_page labelers | sed -e 's#\([A-Za-z0-9-]*\) / [A-Za-z0-9-]*#\1#' | grep -A 100 '^<p><a name="'"${1}"'"></a><b>' \
| grep -m 1 -B 100 '<div align=right><p><a href=".*#top">Page Top</a></p><p> </p></div>' \
| grep '\.deb\|\.ppd.gz' | sed -e 's#^.*/linux/dlf/\(.*\)\&lang=.*#\1#' | sort \
| sed -e ':a;N;$!ba;s/\n/\t/g' | sed -e 's/\t$//' \
| sort | uniq
}
#############################################################################
##
## Some useful tricks
##
function _true { echo true; true; }
function _false { echo false; false;}
function _actions { echo $_actions; }
function _declare {
if [ "${_actions}" = '' ]
then
_actions="${1}"
else
_actions="${_actions} ${1}"
fi
}
function _describe {
if [ "${1}" = 'print_help' ]
then
echo "${2}"
true
else
false
fi
}
function _error {
if [ "${1}" = '' ]
then
echo "ERR: ${2}" 2>/dev/null
false
else
true
fi
}
_declare print_help
function print_help {
_describe "${1}" 'print this help' && return
printf "${0}:\n\tparse information from ${BROTHER_TRADEMARK} webpages, with many actions ($(_actions))\n\n"
for action in $(_actions)
do
printf "${action}:\n\t$(${action} print_help)\n\n"
done
}
#############################################################################
##
## Cache handling
##
function _cache {
# howto: _cache cache_file command
if [ -f "${1}" ]
then
cat "${1}"
else
eval "${@:2:${#@}}" | tee "${1}"
fi
}
_declare pre_cache
function pre_cache {
_describe "${1}" 'explicitly precache informations, by default caching is done just in time' && return
list_archives_with_licenses all > /dev/null
list_models all > /dev/null
list_primary_models_with_archives all > /dev/null
list_archives_urls all > /dev/null
list_licenses_urls all > /dev/null
for license in $(list_licenses all)
do
print_license "${license}" >/dev/null
done
list_cache
}
_declare list_cache
function list_cache {
_describe "${1}" 'list cached files' && return
find "${WORKSPACE}" -name '*.txt' -o -name '*.html' | sort
}
_declare drop_cache
function drop_cache {
_describe "${1}" 'delete cached files' && return
find "${WORKSPACE}" -name '*.txt' -exec rm -v {} \;
find "${WORKSPACE}" -name '*.html' -exec rm -v {} \;
}
#############################################################################
##
## Page handling
##
_declare get_page_url
function get_page_url {
_describe "${1}" "get page by type (sources printers labelers scanners pcfaxes)" && return
_error "${1}" 'missing type' || return
case "${1}" in
sources)
echo "${BROTHER_PAGES_DIR}download_src.html"
;;
printers)
echo "${BROTHER_PAGES_DIR}download_prn.html"
;;
labelers)
echo "${BROTHER_PAGES_DIR}download_esp.html"
;;
scanners)
echo "${BROTHER_PAGES_DIR}download_scn.html"
;;
pcfaxes)
echo "${BROTHER_PAGES_DIR}download_pcf.html"
;;
*)
_error '' 'bad type' || return
;;
esac
}
function _download_page {
if [ "${USE_WEBARCHIVE}" = 'true' ]
then
wget -q -O - "${WEBARCHIVE_DOMAIN}${WEBARCHIVE_ROOT}${1}" | sed -e 's#\(<a href=".*\)\&#\1\&#g;s#/web/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/##' | dos2unix
else
wget -q -O - "${1}" | dos2unix
fi
}
_declare print_page
function print_page {
_describe "${1}" "print page by type (sources printers labelers scanners pcfaxes)" && return
_error "${1}" 'missing type' || return
case "${1}" in
sources|printers|labelers|scanners|pcfaxes)
brother_page="$(get_page_url "${1}")"
page="${PAGES_DIR}/${1}.html"
_cache "${page}" _download_page "${brother_page}"
;;
*)
_error '' 'bad type' || return
;;
esac
}
#############################################################################
##
## Licenses handling
##
function _parse_archives_with_licenses {
case "${1}" in
sources|printers|labelers|scanners|pcfaxes)
"_parse_${1}_archives_with_licenses"
;;
esac
}
_declare list_archives_with_licenses
function list_archives_with_licenses {
_describe "${1}" "list all files with licenses by type (sources printers labelers scanners pcfaxes all)" && return
_error "${1}" 'missing type' || return
case "${1}" in
sources|printers|labelers|scanners|pcfaxes)
_cache "${LISTS_DIR}${1}_archives_with_licenses.txt" "_parse_archives_with_licenses '${1}'"
;;
all)
_cache "${LISTS_DIR}${1}_archives_with_licenses.txt" '(list_archives_with_licenses sources; list_archives_with_licenses printers; list_archives_with_licenses labelers; list_archives_with_licenses scanners; list_archives_with_licenses pcfaxes) | sort | uniq'
;;
*)
_error '' 'bad type' || return
;;
esac
}
_declare list_licenses
function list_licenses {
_describe "${1}" 'list licenses (sources printers labelers scanners pcfaxes all)' && return
_error "${1}" 'missing type' || return
case "${1}" in
sources|printers|labelers|scanners|pcfaxes)
_cache "${LISTS_DIR}${1}_licenses.txt" "list_archives_with_licenses ${1} | cut -f 2 | sort | uniq"
;;
all)
_cache "${LISTS_DIR}${1}_licenses.txt" '(list_licenses sources; list_licenses printers; list_licenses labelers; list_licenses scanners; list_licenses pcfaxes) | sort | uniq'
;;
*)
_error '' 'bad type' || return
;;
esac
}
_declare is_license
function is_license {
_describe "${1}" 'check if this license is used' && return
_error "${1}" 'missing license name' || return
list_licenses all | grep "^${1}$" >/dev/null && _true || _false
}
_declare get_license_url
function get_license_url {
_describe "${1}" 'get license url by name' && return
_error "${1}" 'missing license name' || return
is_license "${1}" >/dev/null || _error '' 'bad license name' || return
echo "${BROTHER_LICENSE_DIR}${1}/${BROTHER_LICENSE_FILE}"
}
_declare print_license
function print_license {
_describe "${1}" 'print license by name' && return
_error "${1}" 'missing license name' || return
is_license "${1}" >/dev/null || _error '' 'bad license name' || return
_cache "${LICENSES_DIR}${1}.html" "wget -q -O - '$(get_license_url "${1}")' | dos2unix"
}
function _list_licenses_urls {
for license in $(list_licenses "${1}")
do
get_license_url "${license}"
done
}
_declare list_licenses_urls
function list_licenses_urls {
_describe "${1}" 'list licenses urls (sources printers scanners pcfaxes all)' && return
_error "${1}" 'missing type' || return
case "${1}" in
sources|printers|labelers|scanners|pcfaxes)
_cache "${LISTS_DIR}${1}_licenses_urls.txt" "_list_licenses_urls ${1} | sort | uniq"
;;
all)
_cache "${LISTS_DIR}${1}_licenses_urls.txt" "(list_licenses_urls sources; list_licenses_urls printers; list_licenses_urls labelers; list_licenses_urls scanners; list_licenses_urls pcfaxes) | sort | uniq"
;;
*)
_error '' 'bad type' || return
;;
esac
}
#############################################################################
##
## Files handling
##
_declare list_archives
function list_archives {
_describe "${1}" "get files by type (sources printers scanners pcfaxes all)" && return
# _error by list_archives_with_licenses
list_archives_with_licenses "${1}" | cut -f 1
}
_declare get_file_license
function get_file_license {
_describe "${1}" 'get file by archive name' && return
_error "${1}" 'missing archive name' || return
list_archives_with_licenses all | grep "^${1}$(printf '\t')" | cut -f 2
}
_declare get_file_url
function get_file_url {
_describe "${1}" 'get file url by name' && return
_error "${1}" 'missing archive name' || return
is_file "${1}" >/dev/null || _error '' 'bad archive name' || return
echo "${BROTHER_REPOSITORY}${1}"
}
function _list_archives_urls {
for file in $(list_archives "${1}")
do
get_file_url "${file}"
done
}
_declare list_archives_urls
function list_archives_urls {
_describe "${1}" "list files urls by type (sources printers labelers scanners pcfaxes all)" && return
_error "${1}" 'missing type' || return
case "${1}" in
sources|printers|labelers|scanners|pcfaxes)
_cache "${LISTS_DIR}${1}_archives_urls.txt" "_list_archives_urls ${1} | sort | uniq"
;;
all)
_cache "${LISTS_DIR}${1}_archives_urls.txt" '(list_archives_urls sources; list_archives_urls printers; list_archives_urls labelers; list_archives_urls scanners; list_archives_urls pcfaxes) | sort | uniq'
;;
*)
_error '' 'bad type' || return
;;
esac
}
_declare is_file
function is_file {
_describe "${1}" 'check if file exists by name' && return
_error "${1}" 'missing archive name' || return
list_archives all | grep "^${1}$" >/dev/null && _true || _false
}
#############################################################################
##
## Models handling
##
# internals has no many checks because can't be called directly, checks are in caller
function _parse_primary_models {
case "${1}" in
printers|labelers)
"_parse_${1}_primary_models"
;;
scanners)
# STUB
printf ''
;;
pcfaxes)
# STUB
printf ''
;;
esac
}
_declare list_primary_models
function list_primary_models {
# all?
# NOT sources
_describe "${1}" "list models that have driver by type (printers labelers scanners pcfaxes)" && return
_error "${1}" 'missing type' || return
case "${1}" in
printers|labelers|scanners|pcfaxes)
_cache "${LISTS_DIR}${1}_primary_models.txt" "_parse_primary_models '${1}'"
;;
*)
_error '' 'bad type' || return
;;
esac
}
function _parse_secondary_models_with_primary {
case "${1}" in
printers)
for model in $(_parse_printers_variant_models)
do
printf "${model}\t"
_parse_printers_original_model_from_variant "${model}"
done
for model in $(_parse_printers_alternative_models)
do
printf "${model}\t"
_parse_printers_original_model_from_alternative "${model}"
done
;;
labelers)
# labelers don't have secondary models
printf ''
;;
scanners)
# STUB
printf ''
;;
pcfaxes)
# STUB
printf ''
;;
esac
}
_declare list_secondary_models_with_primary
function list_secondary_models_with_primary {
_describe "${1}" 'list models that uses driver from another model, by type (printers labelers scanners pcfaxes)' && return
_error "${1}" 'missing type' || return
case "${1}" in
printers|labelers|scanners|pcfaxes)
_cache "${LISTS_DIR}${1}_secondary_models_with_primary.txt" "_parse_secondary_models_with_primary '${1}'"
;;
*)
_error '' 'bad type' || return
;;
esac
}
_declare list_secondary_models
function list_secondary_models {
_describe "${1}" 'list models that uses driver from another model, by type (printers labelers scanners pcfaxes)' && return
_error "${1}" 'missing type' || return
case "${1}" in
printers|labelers|scanners|pcfaxes)
_cache "${LISTS_DIR}${1}_secondary_models.txt" "list_secondary_models_with_primary '${1}' | cut -f 1 | sort | uniq"
;;
*)
_error 'bad_type' || return
;;
esac
}
_declare list_models
function list_models {
_describe "${1}" 'list models' && return
_error "${1}" 'missing type (printers labelers scanners pcfaxes all)' || return
case "${1}" in
printers|labelers|scanners|pcfaxes)
_cache "${LISTS_DIR}${1}_models.txt" "(list_primary_models '${1}'; list_secondary_models '${1}') | sort | uniq"
;;
all)
_cache "${LISTS_DIR}${1}_models.txt" '(list_models printers; list_models labelers; list_models scanners; list_models pcfaxes) | sort | uniq'
;;
*)
_error '' 'bad type' || return
;;
esac
}
# not all because a secondary fax model can be a primary printer model
_declare is_primary_model
function is_primary_model {
_describe "${1}" 'check if model is a primary model by type and by name (printers labelers scanners pcfaxes) (model name)' && return
_error "${1}" 'missing type' || return
_error "${2}" 'missing model name' || return
case "${1}" in
printers|labelers|scanners|pcfaxes)
list_primary_models "${1}" | grep "^${2}$" >/dev/null && _true || _false
;;
*)
_error '' 'bad type' || return
;;
esac
}
_declare is_secondary_model
function is_secondary_model {
_describe "${1}" 'check if model is a secondary model by type and by name (printers labelers scanners pcfaxes) (model name)' && return
_error "${1}" 'missing type' || return
_error "${2}" 'missing model name' || return
case "${1}" in
printers|labelers|scanners|pcfaxes)
list_secondary_models "${1}" | grep "^${2}$" >/dev/null && _true || _false
;;
*)
_error '' 'bad type' || return
;;
esac
}
_declare is_model
function is_model {
_describe "${1}" 'check if model is a true model by type and by name (printers labelers scanners pcfaxes all) (model name)' && return
_error "${1}" 'missing type' || return
_error "${2}" 'missing model name' || return
case "${1}" in
printers|labelers|scanners|pcfaxes|all)
list_models "${1}" | grep "^${2}$" >/dev/null && _true || _false
;;
*)
_error '' 'bad type'
;;
esac
}
_declare get_primary_model
function get_primary_model {
_describe "${1}" 'get model that has a driver for this model by type and by name (printers labelers scanners pcfaxes) (model name)' && return
_error "${1}" 'missing type' || return
_error "${2}" 'missing model name' || return
is_model "${1}" "${2}" >/dev/null || _error '' "bad ${1} model name" || return
is_primary_model "${1}" "${2}" >/dev/null && echo "${2}"
case "${1}" in
printers|labelers|scanners|pcfaxes)
list_secondary_models_with_primary "${1}" | grep "^${2}$(printf '\t')" | cut -f 2
;;
*)
_error '' 'bad type' || return
;;
esac
}
function _parse_primary_models_with_archives {
case "${1}" in
printers|labelers)
for model in $(list_primary_models "${1}")
do
printf "${model}\t"
"_parse_$(echo ${1} | sed -e 's/s$//')_archives" "${model}"
done
;;
scanners)
# STUB
printf ''
;;
pcfaxes)
# STUB
printf ''
;;
esac
}
_declare list_primary_models_with_archives
function list_primary_models_with_archives {
_describe "${1}" 'list models with files by type (printers labelers scanners pcfaxes all)' && return
_error "${1}" 'missing type' || return
case "${1}" in
printers|labelers|scanners|pcfaxes)
_cache "${LISTS_DIR}${1}_primary_models_with_archives.txt" _parse_primary_models_with_archives "${1}"
;;
all)
_cache "${LISTS_DIR}${1}_primary_models_with_archives.txt" '(list_primary_models_with_archives printers; list_primary_models_with_archives labelers; list_primary_models_with_archives scanners; list_primary_models_with_archives pcfaxes) | sort'
;;
*)
_error '' 'bad type' || return
;;
esac
}
# TODO: sources?
_declare list_model_archives
function list_model_archives {
_describe "${1}" 'get files by type and by model (printers labelers scanners pcfaxes all) (model name)' && return
_error "${1}" 'missing type' || return
_error "${2}" 'missing model name' || return
is_model "${1}" "${2}" >/dev/null || _error '' "bad ${1} model name" || return
case "${1}" in
printers|labelers|scanners|pcfaxes)
list_primary_models_with_archives "${1}" | grep "$(get_primary_model "${1}" "${2}")" | cut -f 2- | sed -e 's/\t/\n/'
;;
all)
( for type in printers labelers scanners pcfaxes
do
is_model "${type}" "${2}" >/dev/null && list_model_archives "${type}" "${2}"
done
) | sort | uniq
;;
*)
_error '' 'bad type' || return
;;
esac
}
# TODO: sources?
_declare list_model_archives_urls
function list_model_archives_urls {
_describe "${1}" 'list files url by type (printers labelers scanners pcfaxes all)' && return
_error "${1}" 'missing type' || return
case "${1}" in
printers|labelers|scanners|pcfaxes|all)
for file in $(list_model_archives "${1}" "${2}")
do
get_file_url "${file}"
done
;;
*)
_error '' 'bad type' || return
;;
esac
}
#############################################################################
##
## Downloading
##
function _download {
wget -nd -c -P "${FILES_DIR}" "${@}" # -nv
}
_declare download_file
function download_file {
_describe "${1}" 'download file by name' && return
_error "${1}" 'missing archive name' || return
_download "$(get_file_url ${1})"
}
_declare download_model_archives
function download_model_archives {
_describe "${1}" 'get files by type and by model (printers labelers scanners pcfaxes all) (model name)' && return
_error "${1}" 'missing type' || return
_error "${2}" 'missing model name' || return
is_model "${1}" "${2}" >/dev/null || _error '' "bad ${1} model name" || return
case "${1}" in
printers|labelers|scanners|pcfaxes|all)
_download $(list_model_archives_urls "${1}" "${2}")
;;
*)
_error '' 'bad type' || return
;;
esac
}
_declare download_archives
function download_archives {
_describe "${1}" 'download files by type (sources printers labelers scanners pcfaxes all)' && return
_error "${1}" 'missing type' || return
case "${1}" in
sources|printers|labelers|scanners|pcfaxes)
_download $(list_archives_urls "${1}")
;;
all)
download_archives sources
download_archives printers
download_archives labelers
download_archives scanners
download_archives pcfaxes
;;
*)
_error '' 'bad type' || return
;;
esac
}
#############################################################################
##
## Main
##
function _main {
valid_action=false
for action in $(_actions)
do
if [ "${1}" = "${action}" ]
then
valid_action=true
${@} && return 0 || return 1
fi
done
if ! $valid_action
then
_error "${1}" 'missing action' && _error '' 'bad action'
print_help > /dev/stderr
fi
}
#############################################################################
##
## Execution
##
_main $@
#EOF