123 lines
No EOL
4.7 KiB
Bash
Executable file
123 lines
No EOL
4.7 KiB
Bash
Executable file
#!/bin/bash
|
|
source .config
|
|
|
|
workdir=${WORKDIR:-/tmp/wacca}
|
|
version=${VERSION:-3.07.01}
|
|
|
|
check_prereqs () {
|
|
tools=("vhdimount" "umu-run" "fsdecrypt" "xdelta3" "aria2c")
|
|
echo "Checking for required tools..."
|
|
echo "=============================="
|
|
|
|
all_installed=true
|
|
|
|
for tool in "${tools[@]}"; do
|
|
if command -v "$tool" &> /dev/null; then
|
|
echo -e "\033[0;32m✓\033[0m $tool is installed"
|
|
else
|
|
echo -e "\033[0;31m✗\033[0m $tool is NOT installed"
|
|
all_installed=false
|
|
fi
|
|
done
|
|
|
|
echo "=============================="
|
|
if [ "$all_installed" != true ]; then
|
|
echo "Some tools are missing :("
|
|
if [ "$ignore_prereqs" = true ]; then
|
|
echo "Ignoring prerequisites"
|
|
else
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
# GET NEEDED APPS FROM $VERSION
|
|
get_required_app () {
|
|
apps=""
|
|
while IFS=',' read -r version url prettyname; do
|
|
apps+="$url,"
|
|
if [[ "$version" == "$VERSION" ]]; then
|
|
break
|
|
fi
|
|
done < <(grep "$(echo "^$VERSION" | cut -c1-4)" imagestore/index.csv)
|
|
}
|
|
|
|
extract_apps () {
|
|
mkdir -p imagestore/vhd
|
|
for url in ${apps//,/ }; do
|
|
file=$(basename "$url")
|
|
local vhd=$(basename "$url" | sed -E "s/.app/.vhd/")
|
|
if [ -f imagestore/app/$file ]; then
|
|
echo "Found $file"
|
|
if [ -f imagestore/vhd/$vhd ]; then
|
|
echo "Found $vhd"
|
|
else
|
|
echo "Decrypting $file"
|
|
fsdecrypt imagestore/app/$file
|
|
mv imagestore/app/$vhd imagestore/vhd/
|
|
fi
|
|
else
|
|
if [ ! -f imagestore/vhd/$vhd ]; then
|
|
echo "Downloading $file"
|
|
aria2c -x 8 -j 8 -o imagestore/app/$file $url
|
|
|
|
echo "Decrypting $file"
|
|
fsdecrypt imagestore/app/$file
|
|
mv imagestore/app/$vhd imagestore/vhd/
|
|
fi
|
|
fi
|
|
done
|
|
}
|
|
|
|
patchbin () {
|
|
# local targetvhd="$1"
|
|
# local tmp=$(mktemp -u)
|
|
# dd if=$targetvhd of=$tmp bs=1 count=576
|
|
# dd if=TEST.vhd of=$tmp bs=1 skip=575 seek=576 count=80
|
|
# dd if=$tmp of=$targetvhd bs=1 conv=notrunc
|
|
# echo -n $(basename $1) | iconv -f UTF-8 -t UTF-16BE | dd of=test
|
|
|
|
for url in ${apps//,/ }; do
|
|
local file=$(basename $url)
|
|
IFS='_' read gameid version date vhdpos parentversion <<< "${file%.app}"
|
|
if [[ "$vhdpos" != "0" ]]; then
|
|
local vhd=$(basename "$url" | sed -E "s/.app/.vhd/")
|
|
input=$(vhdiinfo imagestore/vhd/$vhd)
|
|
|
|
identifier=$(echo "$input" | grep -i "Identifier" | head -1 | awk '{print $NF}')
|
|
parent_identifier=$(echo "$input" | grep -i "Parent identifier" | awk '{print $NF}')
|
|
parent_filename=$(echo "$input" | grep -i "Parent filename" | awk -F': ' '{print $2}')
|
|
echo "Checking $vhd parent"
|
|
if [[ ! "$parent_filename" =~ ^\\SDFE ]]; then
|
|
echo "$vhd Parent filename incorrect"
|
|
new_parent_filename=$(grep "^$parentversion" imagestore/index.csv | cut -d',' -f2 | xargs basename | sed -E "s/.app/.vhd/")
|
|
new_parent_filename="\\$new_parent_filename"
|
|
local len=${#new_parent_filename}
|
|
result=$(((len * 2)))
|
|
echo "Writing parent filename $new_parent_filename to $vhd"
|
|
echo $new_parent_filename | iconv -f UTF-8 -t UTF-16BE | dd of=imagestore/vhd/$vhd seek=576 bs=1 conv=notrunc
|
|
echo $new_parent_filename | iconv -f UTF-8 -t UTF-16BE | dd of=imagestore/vhd/$vhd seek=4096 bs=1 conv=notrunc
|
|
if [ $result -lt 80 ]; then
|
|
remainder=$((80 - result))
|
|
dd if=/dev/zero of=imagestore/vhd/$vhd seek=$((576 + result)) bs=1 count=$remainder conv=notrunc
|
|
dd if=/dev/zero of=imagestore/vhd/$vhd seek=$((4096 + result)) bs=1 count=$remainder conv=notrunc
|
|
fi # echo $parent_filename
|
|
fi
|
|
fi
|
|
done
|
|
}
|
|
|
|
mount () {
|
|
vhdpath=$(grep "^$version" imagestore/index.csv | cut -d',' -f2 | xargs basename | sed -E "s/.app/.vhd/")
|
|
|
|
mkdir -p $workdir/$version/{dev,lower,upper,game,work}
|
|
vhdimount imagestore/vhd/$vhdpath $workdir/$version/dev
|
|
# sudo mount -t ntfs -o offset=$((2048*512)),uid=$(id -u),gid=$(id -g) $(sudo find /tmp/wacca/$profile/dev -maxdepth 1 -type f | sort -V | tail -1) /tmp/wacca/$profile/lower
|
|
# sudo mount overlay -t overlay -o lowerdir=/tmp/wacca/$profile/lower,upperdir=/tmp/wacca/$profile/upper,workdir=/tmp/wacca/$profile/work /tmp/wacca/$profile/game
|
|
}
|
|
|
|
check_prereqs
|
|
get_required_app
|
|
extract_apps
|
|
patchbin
|
|
mount
|
|
# patchbin "images/vhd/SDFE_2.53.00_20210607052915_3_2.52.00.vhd.old" |