/
AO486_PRE_RELEASE_Update_Top300_updater.sh
274 lines (233 loc) · 7.61 KB
/
AO486_PRE_RELEASE_Update_Top300_updater.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
#!/bin/bash
set -e
ver="v.2.0.0"
# ========= CODE STARTS HERE =========
# Ansi color code variables
red="\e[0;91m"
blue="\e[0;94m"
expand_bg="\e[K"
blue_bg="\e[0;104m${expand_bg}"
red_bg="\e[0;101m${expand_bg}"
green_bg="\e[0;102m${expand_bg}"
green="\e[0;92m"
white="\e[0;97m"
bold="\e[1m"
uline="\e[4m"
reset="\e[0m"
function pause(){
echo -en "\ec"
echo -e "${red_bg}${reset}"
echo -e "This script updates the ${green}(flynnsbit AO486 - Top 300 DOS Games pack)${reset} VHD to the ${red}PRE RELEASE Version ${reset} of the Top 300 pack. This script directly mounts and modifies the VHD in one step. If the script fails to find your VHD you will need to edit the script and change the User options at the top to fit your setup and re-run."
echo -e ""
echo -e "${red}BACKING UP YOUR EXISTING VHD IS RECOMMENDED BEFORE RUNNING THIS UPDATER.${reset}"
echo -e ""
echo -e "${green}Script version ${ver}${reset}"
read -s -n 1 -p "Press any key to continue . . ."
echo ""
}
# ======== BEGIN USER OPTIONS ========
# Specifies the Games/Programs subdirectory where core specific directories will be placed.
# AO486TOP300DIR="" for letting the script choose between /media/fat and /media/fat/games when it exists,
# otherwise the subdir you prefer (i.e. AO486TOP300DIR="/Programs").
AO486TOP300DIR=""
# Base directory for all script’s tasks, "/media/fat" for SD root, "/media/usb0" for USB drive root.
BASE_PATH="/media/fat"
# Overwrite user variables with values from optional ini file
source_ini()
{
original_script_path="$0"
if [ $original_script_path == "bash" ]
then
original_script_path=$(ps | grep "^ *$PPID " | grep -o "[^ ]*$")
fi
ini_path=${original_script_path%.*}.ini
if [[ -f "${ini_path}" ]] ; then
tmp=$(mktemp)
dos2unix < "${ini_path}" 2> /dev/null | grep -v "^exit" > ${tmp} || true
set +u
source ${tmp}
set -u
rm -f ${tmp}
fi
}
source_ini
# ========= END USER OPTIONS =========
github_repo="flynnsbit/Top300_updates"
fastdoom_repo="viti95/FastDoom"
primary_disk_image="IDE 0-0 BOOT-DOS98.vhd"
secondary_disk_image="IDE 0-1 Top 300 DOS Games.vhd"
mount_dir=/tmp/dos_vhds
extract_dir=/tmp/dos_extract
fastdoom_dir=/tmp/fastdoom
# Ansi color code variables
red="\e[0;91m"
blue="\e[0;94m"
expand_bg="\e[K"
blue_bg="\e[0;104m${expand_bg}"
red_bg="\e[0;101m${expand_bg}"
green_bg="\e[0;102m${expand_bg}"
green="\e[0;92m"
white="\e[0;97m"
bold="\e[1m"
uline="\e[4m"
reset="\e[0m"
# Arg $1: GitHub repo name, e.g. "username/repo"
# Can we grab the file names and insert them into a variable ex. FastDoom_0.7.zip so it is not hard coded in the execution part below
get_latest_release()
{
local api_url="https://api.github.com/repos/${1}/releases/latest"
local download_url
read -r tag_name download_url < <(echo $(curl -k -s "${api_url}" | jq -r ".tag_name, .assets[0].browser_download_url"))
echo Downloading "${tag_name}"...
cd /tmp && { curl -k -L "${download_url}" -O ; cd -; }
}
get_pre_release()
{
local api_url="https://api.github.com/repos/${1}/releases"
local download_url
read -r tag_name download_url < <(echo $(curl -k -s "${api_url}" | jq -r ".[0].tag_name, .[0].assets[0].browser_download_url"))
echo Downloading "${tag_name}"...
cd /tmp && { curl -k -L "${download_url}" -O ; cd -; }
}
# Arg $1: Path to image
# Arg $2: Partition number
# Arg $3: Mount point
mount_simage()
{
# Get next free loop device
loop_dev_s=$(losetup -f)
# Associate next free loop device with image
losetup -f "${1}"
# Mount the partition
mount "${loop_dev_s}p${2}" "${3}"
}
mount_pimage()
{
# Get next free loop device
loop_dev_p=$(losetup -f)
# Associate next free loop device with image
losetup -f "${1}"
# Mount the partition
mount "${loop_dev_p}p${2}" "${3}"
}
# Arg $1: Secondary Mount point
unmount_simage()
{
loop_dev_s=$(losetup -a | awk -F: -v IMG="${1}" '{gsub(/^[\t ]+[0-9]+[\t ]+/,"",$2); if($2 == IMG) { print $1; }}')
# Unmount partition
sync
umount "${2}"
# Disassociate loop device
if [ ! -z "$loop_dev_s" -a "$loop_dev_s" != " " ]; then
losetup -d "${loop_dev_s}"
fi
}
# Arg $1: Primary Mount point
unmount_pimage()
{
loop_dev_p=$(losetup -a | awk -F: -v IMG="${1}" '{gsub(/^[\t ]+[0-9]+[\t ]+/,"",$2); if($2 == IMG) { print $1; }}')
# Unmount partition
sync
umount "${2}"
# Disassociate loop device
if [ ! -z "$loop_dev_p" -a "$loop_dev_p" != " " ]; then
losetup -d "${loop_dev_p}"
fi
}
find_secondary_disk_image()
{
# Similar logic to MiSTer update.sh script
ao486_dir="${AO486TOP300DIR}/AO486"
if [ "${AO486TOP300DIR}" == "" ]; then
if [ "$(find ${BASE_PATH}/games -type f -print -quit 2> /dev/null)" == "" ] && [ "$(find ${BASE_PATH}/AO486 -type f -print -quit 2> /dev/null)" != "" ]; then
ao486_dir="${BASE_PATH}/AO486"
else
ao486_dir="${BASE_PATH}/games/AO486"
fi
fi
secondary_disk_image="${ao486_dir}/${secondary_disk_image}"
if [ ! -f "${secondary_disk_image}" ]; then
echo "Couldn't find disk image: \" ${secondary_disk_image}\"."
exit 1
fi
}
find_primary_disk_image()
{
# Similar logic to MiSTer update.sh script
ao486_dir="${AO486TOP300DIR}/AO486"
if [ "${AO486TOP300DIR}" == "" ]; then
if [ "$(find ${BASE_PATH}/games -type f -print -quit 2> /dev/null)" == "" ] && [ "$(find ${BASE_PATH}/AO486 -type f -print -quit 2> /dev/null)" != "" ]; then
ao486_dir="${BASE_PATH}/AO486"
else
ao486_dir="${BASE_PATH}/games/AO486"
fi
fi
primary_disk_image="${ao486_dir}/${primary_disk_image}"
if [ ! -f "${primary_disk_image}" ]; then
echo "Couldn't find disk image: \"${primary_disk_image}\"."
exit 1
fi
}
# Look for disk image in user's games directory
find_secondary_disk_image
echo ""
echo -e "${white}Disk image found at \"${secondary_disk_image}\".${reset}"
echo ""
find_primary_disk_image
echo ""
echo -e "${white}Disk image found at \"${primary_disk_image}\".${reset}"
echo ""
#Cleaning up any bad updates or failed updates before running again
echo -en "\ec"
echo ""
echo -e "${blue}Cleaning up any previous failed updates, ignore any errors...${reset}"
echo ""
#get rid of this hacky cleanup or dont show users the error when the command could not complete
set +e
rm /tmp/update.zip 2>/dev/null
unmount_simage "${secondary_disk_image}" "${mount_dir}/E" 2>/dev/null
unmount_pimage "${primary_disk_image}" "${mount_dir}/C" 2>/dev/null
rm -r "${mount_dir}" 2>/dev/null
rm -r "${extract_dir}" 2>/dev/null
set -e
pause
# Download latest release zip
echo ""
echo "Downloading the latest FastDoom"
echo ""
get_latest_release "${fastdoom_repo}"
echo ""
echo "Downloading the Pre-Release Top 300 with MyMenu update"
echo ""
get_pre_release "${github_repo}"
# Mount partition 2 for secondary and 1 for primary in the disk image for C and E
mkdir "${mount_dir}"
mkdir "${extract_dir}"
mkdir "${mount_dir}/E"
mkdir "${mount_dir}/C"
echo "${secondary_disk_image}"
echo "${primary_disk_image}"
mount_simage "${secondary_disk_image}" 2 "${mount_dir}/E"
mount_pimage "${primary_disk_image}" 1 "${mount_dir}/C"
echo ""
# Extract updates from repos, rsync files to both vhds
unzip -o /tmp/update.zip -d "${extract_dir}/"
unzip -o "/tmp/FastDoom*.zip" -d "${fastdoom_dir}/"
#Fast doom copy
rsync '/tmp/fastdoom/' /tmp/dos_vhds/E/games/DOOM1993/DOOM/ -r -I -v
rsync '/tmp/fastdoom/' /tmp/dos_vhds/E/games/DOOMII-H/DOOMII/ -r -I -v
rsync '/tmp/fastdoom/' /tmp/dos_vhds/E/games/THEULTIM/UltDoom -r -I -v
#Rsync all the updates to the VHDs that are mounted
rsync -crv "${extract_dir}"/ "${mount_dir}"/
echo ""
# Clean up everything
rm /tmp/update.zip
rm /tmp/FastDoom*.zip
sync
unmount_simage "${secondary_disk_image}" "${mount_dir}/E"
unmount_pimage "${primary_disk_image}" "${mount_dir}/C"
rm -r "${mount_dir}"
rm -r "${extract_dir}"
rm -r "${fastdoom_dir}"
echo ""
echo -e "${green}Successfully updated to ${tag_name}!${reset}"