Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #######################################################################
- #
- # linux patcher for ever17
- # tested on xubuntu and alpine linux
- # license for this script: http://www.wtfpl.net/
- #
- #######################################################################
- # abort if something goes bad
- set -e
- # fancy status messages
- function out() { printf " $@\n"; }
- function msg() { printf "\033[0;33m[*]\033[0m $@\n" "$@"; }
- function inf() { printf "\n\033[1;32m[+]\033[0m $@\n" "$@"; }
- function err() { printf "\n\033[1;31m[-]\033[0m $@\n" "$@"; }
- function ask() { printf "\n\033[1;37m[>]\033[0m "; read -u1 -r; echo; }
- # say hi
- inf "Ever17 PSP English Patch Beta 2 (linux patcher v1)"
- msg "checking that all dependencies are installed"
- function have()
- {
- which "$1" >/dev/null 2>/dev/null ||
- {
- err "the program '$1' is not installed"
- out "please install $2"
- echo
- exit 1
- }
- }
- have mkisofs "'cdrtools' or 'cdrkit'"
- have isoinfo "'cdrtools' or 'cdrkit'"
- have xdelta3 it
- msg "checking that your xdelta3 works"
- function xdelta3unusable()
- {
- strings "$(which xdelta3)" |
- grep LZMA |
- grep -iq unavailable
- }
- xdelta3unusable &&
- {
- err "your xdelta3 is probably unusable:"
- out "the translation patch uses LZMA compression,"
- out "your xdelta3 seems to have LZMA disabled."
- inf "that said, this MIGHT work after all... wanna try?"
- echo
- out "CTRL-C to abort"
- out "ENTER to continue"
- ask
- }
- msg "checking that your mkisofs works"
- strings "$(which mkisofs)" | grep -qE 'xorriso %d.%d' &&
- {
- err "wrong version of mkisofs"
- echo
- out "you have xorriso installed,"
- out "this conflicts with the real mkisofs from cdrkit."
- out "please temporarily uninstall xorriso/libburn"
- out "(usually pulled in by alpine-sdk)"
- out "then reinstall cdrkit"
- echo
- exit 1
- }
- # need to make sure we are in the correct directory
- # (same directory as this script is in)
- self="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
- oldpwd="$(pwd)"
- cd "$self"
- newpwd="$(pwd)"
- [[ "x$oldpwd" == "x$newpwd" ]] ||
- msg "changing directory to $newpwd"
- msg "checking that you have enough disk space"
- free=$(
- df -PBM . | tail -n 1 |
- awk '{sub(/M$/, "", $4); print $4}' ||
- echo 99999999
- )
- needed=3206
- needed=$((needed+128))
- [[ $free -lt $needed ]] &&
- {
- err "not enough disk space"
- err "in the folder where this script is located:"
- out "you have $free MB free"
- out " we need $needed MB free"
- echo
- msg "move the patch folder and try again"
- exit 1
- }
- # read the iso filename
- arg="$1"
- [[ "x$arg" == "x" ]] &&
- {
- err 'need mandatory argument 1:'
- out 'path to the ever17 iso file'
- echo
- out "example: $0 ~/games/ever17.iso"
- echo
- exit 1
- }
- msg "checking that the iso exists"
- iso="$arg"
- [[ -s "$iso" ]] ||
- # maybe it was a relative path
- iso="$oldpwd/$arg"
- [[ -s "$iso" ]] ||
- {
- err 'could not read the iso file:'
- out "$arg"
- echo
- exit 1
- }
- # all tests ok
- inf "unpacking iso"
- rm -rf ISO 2>/dev/null || true
- # get a list of all the files in the iso
- isoinfo -i "$iso" -f |
- # normalize the output, just in case some
- # versions of isoinfo should appear different
- sed -r 's@^/@@;s@^@ISO/@' |
- while read path
- do
- dir="${path%/*}"
- file="${path##*/}"
- # don't care about directories
- [[ "$file" =~ \. ]] ||
- continue
- msg "extracting $dir/$file"
- mkdir -p "$dir"
- # remove ISO from the start of the string
- isoinfo -i "$iso" -x "${path:3}" > "$path"
- [[ -s "$path" ]] ||
- # this version of isoinfo expects no leading slash
- isoinfo -i "$iso" -x "${path:4}" > "$path"
- [[ -s "$path" ]] ||
- {
- err "failed to extract file from iso:"
- out "$path"
- echo
- exit 1
- }
- done
- inf "patching files using xdelta3"
- mv ISO/PSP_GAME/USRDIR/mac.afs ISO/PSP_GAME/USRDIR/mac.old
- mv ISO/PSP_GAME/USRDIR/init.bin ISO/PSP_GAME/USRDIR/init.old
- msg "patching USRDIR/mac.afs"
- xdelta3 -d -s \
- ISO/PSP_GAME/USRDIR/mac.old \
- patch/mac.delta \
- ISO/PSP_GAME/USRDIR/mac.afs ||
- {
- err "failed to patch file"
- xdelta3unusable &&
- out "you definitely need a better version of xdelta3 :(" ||
- out "and i have no idea why... :("
- echo
- exit 1
- }
- msg "patching USRDIR/init.afs"
- xdelta3 -d -s \
- ISO/PSP_GAME/USRDIR/init.old \
- patch/init.delta \
- ISO/PSP_GAME/USRDIR/init.bin
- msg "cleanup"
- rm ISO/PSP_GAME/USRDIR/mac.old
- rm ISO/PSP_GAME/USRDIR/init.old
- msg "copying SYSDIR/EBOOT.BIN"
- cp patch/EBOOT.BIN ISO/PSP_GAME/SYSDIR/EBOOT.BIN
- inf "creating new iso"
- outfile="ever17EN_Beta2.iso"
- rm "$outfile" 2>/dev/null || true
- mkisofs -sort patch/filelist.txt \
- -iso-level 4 -xa -A "PSP GAME" -V "Ever17" \
- -sysid "PSP GAME" -volset "Ever17" \
- -p "" -publisher "" -o "$outfile" ISO/ 2>&1 |
- # make mkisofs output less verbose
- # by keeping all the progress stuff on one line
- sed -r "s/(.*% done.*)/$(printf '\033[A\\1\033[K')/"
- #inf "done! disk space used: $(du -sBM)"
- inf "done!"
- msg "this is your new iso:"
- out "$outfile"
- echo
- rm -rf ISO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement