Hide the CPU governor warning on FS-UAE 3.x
[amiga-uae-virus-scan.git] / amiga-uae-virus-scan.sh
1 #!/bin/bash
2
3 # Ensure we have something to scan
4 if [ $# -lt 1 ]
5 then
6         echo "Usage: $0 floppy-to-test.adf"
7         echo "Usage: $0 directory-to-scan"
8         exit 1
9 fi
10
11
12 # Ensure we have all native tools
13 if [ -z "$(which curl)" -o \
14      -z "$(which lha)" -o \
15      -z "$(which fs-uae)" -o \
16      -z "$(which sha256sum)" ]
17 then
18         echo -e "\033[1m\033[31mERROR:\033[0m"
19         echo "This script requires the following programs to be in $PATH:"
20         echo "  curl"
21         echo "  lha"
22         echo "  fs-uae"
23         echo "  sha256sum"
24         exit 1
25 fi
26
27
28 # Directories
29 CWD="$PWD"
30 INSTALLERS="$CWD/installers"
31 DHDIR=dh0
32
33
34 # Alias for curl
35 CURL="curl --progress-bar --location -o"
36
37
38
39
40 # Provide a way to bail.
41 # This does NOT clean up a running emulation session.
42 function int_func()
43 {
44         tset
45         echo "$0: Interrupt."
46         exit 1
47 }
48 trap int_func INT
49
50
51 function colorprint()
52 {
53         echo -en "\033[1m\033[3$1m"
54         shift
55         echo "$@"
56         echo -en "\033[0m"
57 }
58 trap int_func INT
59
60
61
62 # Download any packages we don't have yet
63 function download_installers()
64 {
65         colorprint 3 "Downloading missing components..."
66
67         mkdir -p "$INSTALLERS"
68
69         for n in $(cat installer_urls)
70         do
71                 LHANAME=${n##*/}
72                 TXTNAME=${LHANAME%.lha}.readme
73
74                 if [ ! -e "$INSTALLERS/$LHANAME" ]
75                 then
76                         echo -e "\033[1m\033[34mDownloading\033[0m $LHANAME ..."
77                         $CURL "$INSTALLERS/$LHANAME" "$n"
78                 fi
79
80                 if [ ! -e "$INSTALLERS/$TXTNAME" ]
81                 then
82                         echo -e "\033[1m\033[34mDownloading\033[0m $TXTNAME ..."
83                         $CURL "$INSTALLERS/$TXTNAME" "${n%.lha}.readme"
84                 fi
85         done
86
87         colorprint 2 "...done"
88         echo
89 }
90
91
92
93 # Checksum all files we get from Aminet
94 function verify_installers()
95 {
96         colorprint 3 "Checking integrity..."
97
98         if ! sha256sum --strict --quiet --check sha256sums
99         then
100                 echo
101                 echo -e "\033[1m\033[31mERROR:\033[0m"
102                 echo "Integrity check failed."
103                 echo "Try removing the broken file and re-downloading it."
104                 echo "If you just downloaded these files, then maybe Aminet is currently having problems serving those files?"
105                 echo
106                 exit 1
107         fi
108
109         colorprint 2 "...done"
110         echo
111 }
112
113
114
115 # This prepares a folder to be a virtual partition,
116 # with an Amiga system ready to run and scan a directory.
117 function populate_dh0()
118 {
119         mkdir -p "$TD/$DHDIR"
120
121
122         # Programs
123         mkdir -p "$TD/$DHDIR/C"
124         lha xqiw="$TD/$DHDIR/C" "$INSTALLERS"/CheckX.lha CheckX/CheckX
125         lha xqiw="$TD/$DHDIR/C" "$INSTALLERS"/UAEquit.lha UAEquit
126
127
128         # Libraries
129         mkdir -p "$TD/$DHDIR/Libs"
130
131         mkdir -p "$TD/$DHDIR/Libs/xad"
132         lha xqiw="$TD/$DHDIR/Libs" "$INSTALLERS"/xadmaster000.lha xad/Libs/xadmaster.library
133         lha xqiw="$TD/$DHDIR/Libs/xad" "$INSTALLERS"/xadmaster000.lha xad/Libs/xad/*
134
135         mkdir -p "$TD/$DHDIR/Libs/xfd"
136         lha xqiw="$TD/$DHDIR/Libs" "$INSTALLERS"/xfdmaster.lha xfd_User/Libs/xfdmaster.library
137         lha xqiw="$TD/$DHDIR/Libs/xfd" "$INSTALLERS"/xfdmaster.lha xfd_User/Libs/xfd/*
138
139         lha xqiw="$TD/$DHDIR/Libs" "$INSTALLERS"/xvslibrary.lha xvs/libs/xvs.library
140
141
142         # Startup-sequence, config, registration keys
143         mkdir -p "$TD/$DHDIR/S"
144         lha xqiw="$TD/$DHDIR/S" "$INSTALLERS"/xadmaster-key.lha xadmaster.key
145
146         cat > "$TD/$DHDIR/S/startup-sequence" <<-EOF
147                 ;CheckX ALL FROM DF1: LOG SYS:checkx-scandir.log
148                 CheckX ALL FROM SYS:scandir LOG SYS:checkx-scandir.log
149                 UAEquit
150         EOF
151 }
152
153
154
155 function write_uae_config()
156 {
157         # Write main UAE config
158         cat > "$TD/amiga-virus-scan.fs-uae" <<-EOF
159                 [fs-uae]
160                 amiga_model = A4000
161                 zorro_iii_memory = 1048576
162                 automatic_input_grab = 0
163                 end_config = 1
164                 expect_version = 2.8.0
165                 floppies_dir = ./
166                 #floppy_drive_1 = ./df1.adf
167                 fullscreen = 0
168                 governor_warning = 0
169                 hard_drive_0 = ./$DHDIR
170                 initial_input_grab = 0
171                 jit_compiler = 1
172                 joystick_port_0 = Mouse
173                 joystick_port_0_mode = mouse
174                 joystick_port_1 = none
175                 joystick_port_1_mode = nothing
176                 joystick_port_2 = none
177                 joystick_port_2_mode = none
178                 joystick_port_3 = none
179                 joystick_port_3_mode = none
180                 keep_aspect = 1
181                 maximized = 0
182                 save_disk = 0
183                 uae_sound_output = none
184                 video_sync = 1
185                 window_hidden = 0
186                 zoom = full
187         EOF
188
189
190         # Prevent FS-UAE from printing audio errors
191         cat > "$TD"/.alsoftrc <<-EOF
192                 [general]
193                 drivers = null
194         EOF
195 }
196
197
198
199
200 #
201 #
202 # Main script
203 #
204
205 colorprint 7 " *******************************************"
206 colorprint 7 "   Amiga virus scanner wrapper starting up"
207 colorprint 7 " *******************************************"
208 echo
209
210
211 # Get external Amiga software
212 download_installers
213 verify_installers
214
215
216 # Prepare emulation environment
217 colorprint 3 "Preparing emulation environment..."
218
219 TD="$(mktemp --directory)"
220 populate_dh0
221 write_uae_config
222
223 # Copy files to scan
224 colorprint 7 "Scan target: $1 (will be copied to emulation first)"
225
226 cp -r "$1" "$TD/$DHDIR/scandir"
227 chmod -R u+rwX "$TD/$DHDIR/scandir"
228
229 colorprint 2 "...done"
230 echo
231
232
233 # Run emulator
234 colorprint 3 "Running emulator..."
235 cd "$TD"
236 export HOME="$TD"
237 fs-uae amiga-virus-scan.fs-uae > /dev/null
238
239 colorprint 2 "...done"
240 echo
241
242
243 # Print results
244 echo
245 echo
246 colorprint 2 "Scan results:"
247 echo
248 cat ./dh0/checkx-scandir.log
249
250
251 # Clean up
252 cd ..
253 rm -rf "$TD"
254
255 echo