-
Notifications
You must be signed in to change notification settings - Fork 3
/
saturn-us-bios-installer.sh
133 lines (111 loc) · 5 KB
/
saturn-us-bios-installer.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
#!/bin/sh
version=1.4
# ===
bios="faa8ea183a6d7bbe5d4e03bb1332519800d3fbc3"
region="USA"
biosversion="1.01a"
name=us
# ===
biospath=""
corename="Saturn"
self="$(readlink -f "$0")"
conf="${self%.*}.ini"
[ -f "$conf" ] && . "$conf"
trap "result" 0 1 3 15
result(){
case "$?" in
# 0) echo -e "last version: Github says, last commit on $gitversion"
# echo -e "core version: ${corefile##*/}\n";;
99) echo "self: updated self";;
100) echo "error: cannot reach url";;
101) echo "error: cannot write to sdcard";;
102) echo "error: download failed";;
103) echo "error: checksum failed";;
104) echo "error: json parsing failed";;
105) echo "error: unzip failed";;
esac
}
makedir(){ [ -d "$1" ] || { mkdir -p "$1" || exit 101;};}
download(){ wget --no-cache -q "$2" -O "$1" || { rm "$1";exit 102;};}
urlcat(){ wget --no-cache -q "$1" -O - || exit 100;}
checksum(){ md5sum "$1"|grep -q "$2" || { rm "$1";exit 103;};}
unpack(){ unzip -j -o "$1" -d "$2" >/dev/null 2>&1 || exit 105;}
selfurl="https://raw.githubusercontent.com/SwedishGojira/MiSTer-scripts/main/saturn-${name}-bios-installer.sh"
selfurl_version="$(urlcat "$selfurl"|sed -n 's,^version=,,;2p')"
[ "$selfurl_version" = "$version" ] || {
tempfile="$(mktemp -u)"; download "$tempfile" "$selfurl"
mv "$tempfile" "$self";chmod +x "$self";exec "$self"; exit 99
}
echo ""
echo -e "█▀▀ █▀▀█ ▀▀█▀▀ █\e[34m░░\e[39m█ █▀▀█ █▀▀▄ █▀▀▄ ▀█▀ █▀▀█ █▀▀ "
echo -e "▀▀█ █▄▄█ \e[34m░░\e[39m█\e[34m░░\e[39m █\e[34m░░\e[39m█ █▄▄▀ █\e[34m░░\e[39m█ █▀▀▄ \e[34m░\e[39m█\e[34m░\e[39m █\e[34m░░\e[39m█ ▀▀█ "
echo -e "▀▀▀ ▀\e[34m░░\e[39m▀ \e[34m░░\e[39m▀\e[34m░░\e[39m \e[34m░\e[39m▀▀▀ ▀\e[34m░\e[39m▀▀ ▀\e[34m░░\e[39m▀ ▀▀▀\e[34m░\e[39m ▀▀▀ ▀▀▀▀ ▀▀▀ "
echo ""
echo -e "█▀▀▄ █▀▀█ █\e[34m░░░\e[39m█ █▀▀▄ █\e[34m░░\e[39m █▀▀█ █▀▀█ █▀▀▄ █▀▀ █▀▀█"
echo -e "█\e[34m░░\e[39m█ █\e[34m░░\e[39m█ █▄█▄█ █\e[34m░░\e[39m█ █\e[34m░░\e[39m █\e[34m░░\e[39m█ █▄▄█ █\e[34m░░\e[39m█ █▀▀ █▄▄▀ \e[1m\e[34mversion $version\e[0m"
echo -e "▀▀▀\e[34m░\e[39m ▀▀▀▀ \e[34m░\e[39m▀\e[34m░\e[39m▀\e[34m░\e[39m ▀\e[34m░░\e[39m▀ ▀▀▀ ▀▀▀▀ ▀\e[34m░░\e[39m▀ ▀▀▀\e[34m░\e[39m ▀▀▀ ▀\e[34m░\e[39m▀▀ \e[34m░░░░░░░ ░░░\e[39m"
echo ""
# Path Priority (https://mister-devel.github.io/MkDocs_MiSTer/cores/paths/#path-priority)
# There is a priority order of core paths. When you plug in a USB drive and it has a folder /games/Saturn on it (mounted locally as /media/usb<0..5>/games/Saturn when plugged in),
# then the MiSTer Saturn core will look to that folder on the USB drive instead of the local one on the MicroSD at /media/fat/games/Saturn.
# Here is the priority list from Main_MiSTer's file_io.cpp in order of highest priority to lowest:
echo "Detecting $corename file path for bios installation..."
declare -a paths=("/media/fat"
"/media/fat/games"
"/media/usb0"
"/media/usb1"
"/media/usb2"
"/media/usb3"
"/media/usb4"
"/media/usb5"
"/media/usb0/games"
"/media/usb1/games"
"/media/usb2/games"
"/media/usb3/games"
"/media/usb4/games"
"/media/usb5/games"
"/media/fat/cifs"
"/media/fat/cifs/games"
)
# You can access them using echo "${paths[0]}", "${paths[1]}" also
## now loop through the above array
for path in "${paths[@]}"; do
if [ -d "$path/$corename" ]; then
echo "[X] $path/$corename"
biospath="$path/$corename"
else
echo "[ ] $path/$corename"
fi
done
if [ "$biospath" = "" ]; then
biospath="/media/fat/games/$corename"
echo ""
echo "No existing $corename folder found!"
echo "A $corename folder will be created at $biospath"
mkdir -p "$biospath"
fi
echo ""
biosurl="https://archive.org/download/segasaturnbios/Sega%20Saturn%20BIOS.zip"
bioshash="a8cd8951d07cd9ecdc175e9f0462cfb8"
biosfile="/media/fat/Scripts/saturnbios.zip"
biospack="/media/fat/Scripts/.saturn-bios"
if [ ! -d "$biospack" ]; then
mkdir -p "$biospack"
echo "Downloading Saturn bios pack..."
download "$biosfile" "$biosurl"
[ -n "$bioshash" ] && checksum "$biosfile" "$bioshash"
unpack "$biosfile" "$biospack"
rm "$biosfile"
cd "$biospack"
for i in *.bin; do
sum=$(sha1sum "$i" | cut -f 1 -d ' ')
mv "$i" "$sum"
done
fi
echo "Installing $corename bios into $biospath..."
if [ -f "$biospath/boot.bin" ]; then
rm "$biospath/boot.bin"
fi
cp "$biospack/${bios}" "$biospath/boot.rom"
echo "Finished installing Saturn bios ${biosversion} ${region} version in $biospath"
echo ""