File: vice-getroms

package info (click to toggle)
vice 1.19-1etch1
  • links: PTS
  • area: contrib
  • in suites: etch
  • size: 27,132 kB
  • ctags: 33,406
  • sloc: ansic: 257,145; cpp: 13,395; sh: 3,674; makefile: 3,380; perl: 1,801; yacc: 622; lex: 258; asm: 4
file content (393 lines) | stat: -rw-r--r-- 11,115 bytes parent folder | download | duplicates (5)
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
#!/bin/bash

# This script is Copyright 1997-1999 by Giuliano P Procida
# It is released under the GNU GPL (version 2 or later).

# Changelog at end.

set -e

usage () {
    echo Run this script as $0 [dir]. The optional argument dir
    echo defaults to \"~/vice-getroms-tmp\" .
    echo
    echo This script attempts to download the various ROM images for
    echo the VICE emulators. The system administrator may choose to
    echo install the images for all to use. Individual users may do so
    echo for their own use, if the images are not installed by root.
}

declare -a FTPHOST
declare -a FTPFILE
declare LOCATIONS

setup_locations () {
    local site
    local file
    local rubbish
    LOCATIONS=0
    while read host file rubbish; do
	FTPHOST[$LOCATION]="$host"
	FTPFILE[$LOCATION]="$file"
	LOCATIONS=$[1+$LOCATIONS]
    done <<EOF
ftp.funet.fi /pub/cbm/crossplatform/emulators/VICE/vice-0.15.0-roms.tar.gz
EOF
}

yesno () {
    local response
    while true; do
	echo -n "$@" "[y] "
	read response </dev/tty
	case $response in
	    y*|Y*|"") return 0 ;;
	    n*|N*) return 1 ;;
	    *) echo Please respond with y or n.
	esac
    done
}

noyes () {
    local response
    while true; do
	echo -n "$@" "[n] "
	read response </dev/tty
	case $response in
	    y*|Y*) return 0 ;;
	    n*|N*|"") return 1 ;;
	    *) echo Please respond with y or n.
	esac
    done
}

die () {
    echo "$0: $1"
    exit 1
}

getmethods () {
    for i in wget lynx ftp; do
	METHOD="`which $i`" || true
	if [ -n "$METHOD" ]; then
	    return 0
	fi
    done
    return 1
}

md5check () {
    case `md5sum "$1" | sed s,[[:space:]].*$,,` in
	57af4ae21d4b705c2991d98ed5c1f7b8) echo "C64/basic";;
	12a4202f5331d45af846af6c58fba946) echo "C64/chargen";;
	39065497630802346bce17963f13c092) echo "C64/kernal";;

	e929eee180f24415fbee1c4d71d29675) echo "C128/basic";;
	637b0d14902620b6bb1f945fd3b2cb76) echo "C128/chargen";;
	03ab64f095184edd9d10e3d12354a10a) echo "C128/kernal";;

	8b9237706f47a9b3498d8f881ef0244d) echo "VIC20/basic";;
	d390e340e94e1bef0f2fdfe9fa850993) echo "VIC20/chargen";;
	f0587624dcd7685710a8fdb35939617f) echo "VIC20/kernal";;

	f328e785835907006604423222db7bbf) echo "PET/basic1";;
	b69739387bebe999227ae0cf25aa1e91) echo "PET/basic2";;
	d22d2a1912a0cdbd9e7c8b103541b2c6) echo "PET/basic4";;
	61b7e2fd04d63b0702951ba40899cd72) echo "PET/kernal1";;
	51a38bfef8f9e72cb64bf7d874b4c8c6) echo "PET/kernal2";;
	16ec21443ea5431ab63d511061054e6f) echo "PET/kernal4";;
	ef9bd0e62dfc47eb463fef20d0344826) echo "PET/edit1g";;
	cb8e8404c0b28eda10469792dfd1dbc2) echo "PET/edit2g";;
	7f87889ca7ee2537f0c1993d35d0fb18) echo "PET/edit2b";;
	b76d756e7ac8752ae0035f3ce5f1383c) echo "PET/edit4g40";;
	a09d11163a708b8dea90f1c5df33dca0) echo "PET/edit4b40";;
	3a0e2ef328040aa30b30a8134426879a) echo "PET/edit4b80";;
	9880432e633b15998d58884ff34c4e70) echo "PET/chargen";;
	f099504e32bec9e1e81b6d2600b15277) echo "PET/chargen.de";;

	3ad5c7182006bcad1597583dbc8505c9) echo "CBM-II/basic.128";;
	cc2789132e50674af0e7207e3a1dae97) echo "CBM-II/basic.256";;
	2818722af27ceae6952c08cf83a076f9) echo "CBM-II/chargen.600";;
	03f32477905d77e2135857076ec31efa) echo "CBM-II/chargen.700";;
	e0346953e77bd1353ebf53aaa5b6f0b0) echo "CBM-II/kernal";;

	ada295382a1f2df772a7e5c5c6f34215) echo "DRIVES/dos1541";;
	# ada295382a1f2df772a7e5c5c6f34215) echo "DRIVES/dos1541II";;
	dae964d64b7843ff86c008d396dda208) echo "DRIVES/dos1571";;
	6a82f92aea2a3afa190fe32d565f39e7) echo "DRIVES/dos1581";;
	3454c06fd2275f5bcbfe936dcdf8059b) echo "DRIVES/dos2031";;

	d41d8cd98f00b204e9800998ecf8427e) echo "empty";;
	f02e326f800ee26f04df7961adbf7c0a) echo "dummy";;
	*)                                echo "unknown";;
    esac
}

show () {
    local dir
    dir="$1"
    ( cd "$dir"
#      find -type f -not -name "*.distrib" | ( while read name; do echo -n "${name}"; echo -ne ":\t"; md5check "$name"; done )
      find -type f -not -name "*.vkm" -not -name "*.vpl" -not -name "*.vrs" | ( while read name; do echo -n "${name}"; echo -ne ":\t"; md5check "$name"; done )
    )
}

showcurrent () {
    if [ -d "$INSTALLDIR" ]; then
	echo Currently installed images in $INSTALLDIR:
	show "$INSTALLDIR"
    fi
}

shownew () {
    echo Images available in $BASE:
    show "$BASE"
}

unpackarchive () {
    while true; do
	case "`file rom-images`" in
	    *compressed*) zcat rom-images > rom-images.tmp && \
			  mv rom-images.tmp rom-images || return 1 ;;
	    *tar*)        tar xf rom-images; return ;;
	    *zip*)        unzip rom-images; return ;;
	    *)            echo unrecognised archive; return 1
	esac
    done
}

getarchive () {
    local index
    index=0
    while [ $index -lt $LOCATIONS ]; do
	echo $index ${FTPHOST[$index]} ${FTPFILE[$index]}
	index=$[1+$index]
    done

    echo 'Please notify <myxie@debian.org> of any other locations!'
    echo -n "Please select a number of ftp sites (by number and in order of preference): "
    local sites
    read -a sites

    local pass
    pass="`whoami`@`hostname -f`"

    index=0
    local host
    local file
    while [ -n "${sites[$index]}" ]; do
	host=${FTPHOST[${sites[$index]}]}
	file=${FTPFILE[${sites[$index]}]}
	echo trying: $host $file
	case $METHOD in
	    *wget) $METHOD -q -O - ftp://${host}${file} >rom-images || true ;;
	    *lynx) $METHOD -dump ftp://${host}${file} >rom-images 2>/dev/null || true ;;
	    *ftp)  ( $METHOD -n || true ) <<EOF ;;
open $host
user anonymous $pass
bin
get  $file rom-images
quit
EOF
	    *) die "bad method"
	esac
	if [ -s rom-images ] && unpackarchive; then
	    rm rom-images
	    return 0
	fi
	index=$[1+$index]
    done

    return 1
}

installrom () {
#    if [ "`whoami`" = root ]; then
#	if [ ! -e $2.distrib ]; then
#	    dpkg-divert --add --rename $2 || die "could not divert file: $2"
#	fi
#    fi
    rm -fr "$2"
    mkdir -p "$2" && rmdir "$2"	|| die "could not clear way for file: $2"
    echo "installing: $1 (as $2)"
    cp "$1" "$2"		|| die "could not install file: $2"
    chmod 644 "$2"		|| die "could not change mode of file: $2"
}

installroms () {
    local ask
    ask=0
    yesno "Would you like to install all recognised ROM images in $INSTALLDIR? Answer n to select only some." || ask=1
    find -type f | (
	local=md
	md=""
	# hackery to iterate through an extra value
	while { [ "$md" = DRIVES/dos1541 ] && md=DRIVES/dos1541II; } || \
	      { read name && md=`md5check "$name"`; } ; do
	    case "$md" in
		*/*) if [ -e "$INSTALLDIR/$md" ] && cmp -s "$name" "$INSTALLDIR/$md"; then
			echo "skipping: $name (already installed as $md)"
		    else
			if [ $ask -eq 0 ] || yesno "install $name as $INSTALLDIR/$md ?"; then
			    installrom "$name" "$INSTALLDIR/$md"
			fi
		    fi ;;
		dummy)   echo "skipping: $name (a dummy ROM image)" ;;
		unknown) echo "skipping: $name (unrecognised)" ;;
		empty)   echo "skipping: $name (empty)" ;;
	    esac
	done
    )
}

removerom () {
#    if [ "`whoami`" = root ]; then
#	if [ -e "$1.distrib" ]; then
#	    rm "$1"                            || die "could not remove file: $1"
#	    dpkg-divert --remove --rename "$1" || die "could not undivert file: $1"
#	else
#	    echo "Bad dummy ROM image $2, contact maintainer"
#	fi
#    else
	echo deleting: $1
	rm "$1" || die "could not delete $1"
#    fi
}

removeroms () {
    noyes "Would you like to remove any ROM images from $INSTALLDIR?" || return 0
    local ask
    ask=0
    noyes "Would you like to remove all recognised ROM images from $INSTALLDIR? Answer n to select only some." || ask=1
    find $INSTALLDIR -type f -not -name "*.vkm" -not -name "*.vpl" -not -name "*.vrs" | (
	local=md
	while read name; do
#	    if [ "${name:${#name}-8}" = ".distrib" ]; then continue; fi
	    md=`md5check "$name"`
	    case "$md" in
		*/*)    if [ $ask -eq 0 ] || noyes "delete $name ?"; then
			    removerom "$name"
			fi ;;
		dummy)   echo "skipping: $name (a dummy ROM image)" ;;
		unknown) echo "skipping: $name (unrecognised)" ;;
		empty)   echo "skipping: $name (empty)" ;;
	    esac
	done
    )
}

# program start

case $# in
    0) BASE="$HOME/vice-getroms-tmp" ;;
    1) case "$1" in
	   -h|-?|--help) usage
		         exit 0 ;;
	   *) BASE="$1" ;;
       esac ;;
    *) usage
       exit 1 ;;
esac

setup_locations

INSTALLDIR=$HOME/lib/vice
if [ "`whoami`" = root ]; then
    INSTALLDIR=/usr/lib/vice
fi

showcurrent

if [ -d $INSTALLDIR ]; then
    removeroms
#    ( find $INSTALLDIR -type d -empty | xargs -i rmdir "{}" ) || true
fi

if yesno "Would you like to try and install some ROM images?"; then

    if [ -d "$BASE" ]; then
	if yesno "May I delete and re-create the directory \"$BASE\" ?"; then
	    rm -fr -- "$BASE" || die "Could not delete directory $BASE"
	    mkdir -- "$BASE" || die "Could not create directory $BASE"
	else
	    die "aborting"
	fi
    else
	if [ -e "$BASE" ]; then
	    die "$BASE exists and is not a directory"
	fi
	if yesno "May I create the directory \"$BASE\" ?"; then
	    mkdir -p -- "$BASE" || die "Could not create directory $BASE"
	else
	    die "aborting"
	fi
    fi

    cd "$BASE" || die "Could not change directory to $BASE."

    echo Using temporary directory: $BASE

    getmethods || die "Could not find a means of downloading images.\nTry installing wget, lynx or ftp (netstd)."

    echo Using "$METHOD" to download files

    getarchive || die "Could not download the ROM images."

    shownew

    if [ "`whoami`" != root ]; then
	if [ ! -d "$INSTALLDIR" ]; then
	    if [ -e "$INSTALLDIR" ]; then
		die "$INSTALLDIR exists and is not a directory"
	    fi
	    if yesno "May I create the directory \"$INSTALLDIR\" ?"; then
		mkdir -p -- "$INSTALLDIR" || die "Could not create directory $INSTALLDIR"
	    else
		die "aborting"
	    fi
	fi
    fi
    
    installroms

    cd -

    if yesno "Remove temporary directory $BASE ?"; then
	rm -fr $BASE
    fi

fi

echo Finished.

if [ "`whoami`" != root -a -d "$INSTALLDIR" -a ! -f "$HOME/.vicerc" ]; then
    echo You will have to create a $HOME/.vicerc file to make use of
    echo any images stored under $INSTALLDIR. Please consult the
    echo VICE documentation for information on how to achieve this.
fi

exit 0

# Changelog.
# Some older history is in the Debian changelog for VICE.

# Version 1.1
# * Fixed INSTALDIR vs BASEDIR typo (remove and recreate message).
# * Disabled diversion code and stopped rmdir of empty dirs.
# * Added more md5sums; tweaked and debugged dos1541 handling.
# -- Giuliano Procida <myxie@debian.org> Wed, 26 Aug 1998 21:40:13 +0100

# Version 1.2
# * Updated (massacred) list of ROM locations in vice-getroms.
# * Adjusted rules and vice-getroms for new ROMs and file names.
# * The ROM locations array is now created from a here document.
# -- Giuliano P Procida <myxie@debian.org>  Wed, 12 May 1999 14:51:26 +0100

# Version 1.2.1
# * Trivial change to vice-getroms usage message.
# -- Giuliano P Procida <myxie@debian.org>  Tue, 18 May 1999 21:07:19 +0100

# Notes.
# Probably need to have a list of valid ROM names (RHS of md5sum table)
# to avoid all the skipping messages. <- I've forgotten what this means!
# Need to reinstate md5sums of obsolete images so that they can be removed.