2024-01-18 13:31:47 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-01-26 18:47:19 +00:00
|
|
|
hacks_db_setup() {
|
2024-01-18 13:31:47 +00:00
|
|
|
crc32_cmd="python3 /app/libexec/crc32.py"
|
|
|
|
|
|
|
|
# "hacks" is the general name which includes ROM Hacks, Homebrew and Ports
|
|
|
|
hacks_db_path="$HOME/.var/app/net.retrodeck.retrodeck/data/hacks_metadata.db"
|
|
|
|
|
2024-01-27 14:32:42 +00:00
|
|
|
# Set up hacks database
|
2024-01-18 13:31:47 +00:00
|
|
|
declare -g hacks_db_cmd="sqlite3 $hacks_db_path"
|
2024-01-27 14:32:42 +00:00
|
|
|
$hacks_db_cmd < <(curl -sL "https://raw.githubusercontent.com/Libretto7/best-romhacks/main/db_setup.sql")
|
|
|
|
$hacks_db_cmd "ALTER TABLE bases ADD COLUMN local_path;"
|
2024-01-18 13:31:47 +00:00
|
|
|
}
|
|
|
|
|
2024-01-26 23:37:01 +00:00
|
|
|
db_sanitize() {
|
|
|
|
echo "$(echo "$1" | sed -e "s/'/''/g")"
|
|
|
|
}
|
|
|
|
|
2024-01-26 18:47:19 +00:00
|
|
|
check_romhacks_compatibility() {
|
2024-01-26 23:37:01 +00:00
|
|
|
# Add paths of locally available base roms to db
|
2024-01-18 13:31:47 +00:00
|
|
|
|
2024-01-26 18:47:19 +00:00
|
|
|
for rom_path in ${roms_folder}/*/*; do
|
|
|
|
if [[ "$(basename "$rom_path")" != "systeminfo.txt" ]]; then
|
2024-01-18 13:31:47 +00:00
|
|
|
|
2024-01-26 18:47:19 +00:00
|
|
|
crc32="$($crc32_cmd "$rom_path")"
|
2024-01-18 13:31:47 +00:00
|
|
|
|
2024-01-26 23:37:01 +00:00
|
|
|
$hacks_db_cmd < <(echo "UPDATE bases SET local_path = '""$(db_sanitize "$rom_path")""' WHERE crc32 = '""$crc32""'")
|
2024-01-18 13:31:47 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2024-01-26 23:37:01 +00:00
|
|
|
install_romhack() {
|
|
|
|
# $1: name of romhack
|
|
|
|
|
|
|
|
hack_name="$1"
|
|
|
|
infos=$($hacks_db_cmd "SELECT bases.system,bases.name,bases.local_path \
|
|
|
|
FROM bases JOIN rhacks ON bases.crc32 = rhacks.base_crc32 \
|
|
|
|
WHERE rhacks.name = '""$(db_sanitize "$1")""'")
|
|
|
|
|
|
|
|
IFS='|' read -r system base_name base_local_path <<< $infos
|
|
|
|
|
2024-01-27 14:32:42 +00:00
|
|
|
# Download patchfile
|
|
|
|
wget -q "https://github.com/Libretto7/best-romhacks/raw/main/rhacks/$system/$base_name/$hack_name/patch.tar.xz" \
|
|
|
|
-O "/tmp/patch.tar.xz"
|
2024-01-26 23:37:01 +00:00
|
|
|
|
2024-01-27 14:32:42 +00:00
|
|
|
# Extract patchfile
|
2024-01-26 23:37:01 +00:00
|
|
|
patchfile_name=$(tar -xvf "/tmp/patch.tar.xz" --directory="$roms_folder/$system")
|
2024-01-27 14:32:42 +00:00
|
|
|
|
|
|
|
# Create the hack
|
|
|
|
base_name="$(basename "$base_local_path")"
|
|
|
|
ext="$(echo "${base_name##*.}")"
|
2024-01-27 22:37:30 +00:00
|
|
|
flips --apply "$roms_folder/$system/$patchfile_name" "$base_local_path" "$roms_folder/$system/$hack_name.$ext" >/dev/null
|
2024-01-27 14:32:42 +00:00
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
rm "$roms_folder/$system/$patchfile_name"
|
2024-01-26 23:37:01 +00:00
|
|
|
}
|