mkwiimm.sh: fixes and code review

This commit is contained in:
Christopher Roy Bratusek 2016-08-06 20:30:18 +02:00
parent 8d2f0a260f
commit 6628ecce58

View File

@ -25,20 +25,20 @@ download_wiimm () {
echo "Choose a Mario Kart Wiimm Distribution echo "Choose a Mario Kart Wiimm Distribution
ALL Build all distributions." ALL Build all distributions."
gawk -F \: 'NR>1 {print $1 "\t" $2}' < ${PATCHIMAGE_DATABASE_DIR}/mkwiimm.db gawk -F : 'NR>1 {print $1 "\t" $2}' < "${PATCHIMAGE_DATABASE_DIR}"/mkwiimm.db
echo " echo "
type in ALL or an ID (multiple separated by space)" type in ALL or an ID (multiple separated by space)"
read ID read -r ID
} }
wiimmfi () { wiimmfi () {
mkdir -p "${HOME}/.patchimage/tools/" mkdir -p "${HOME}/.patchimage/tools/"
cd ${HOME}/.patchimage/tools cd "${HOME}"/.patchimage/tools
rm -rf wiimmfi-patcher/ *.7z* rm -rf wiimmfi-patcher/ ./*.7z*
wget "${DOWNLOAD_LINK}" &>/dev/null || ( echo "something went wrong downloading ${DOWNLOAD_LINK}" && exit 57 ) wget "${DOWNLOAD_LINK}" &>/dev/null || ( echo "something went wrong downloading ${DOWNLOAD_LINK}" && exit 57 )
${UNP} mkw-wiimmfi-patcher.7z >/dev/null || ( echo "something went wrong extracting files" && exit 63 ) "${UNP}" mkw-wiimmfi-patcher.7z >/dev/null || ( echo "something went wrong extracting files" && exit 63 )
mv mkw-wiimmfi-patcher*/ wiimmfi-patcher mv mkw-wiimmfi-patcher*/ wiimmfi-patcher
chmod +x wiimmfi-patcher/*.sh chmod +x wiimmfi-patcher/*.sh
cd wiimmfi-patcher/ cd wiimmfi-patcher/
@ -46,9 +46,9 @@ wiimmfi () {
ln -s "${1}" . ln -s "${1}" .
./patch-wiimmfi.sh >/dev/null || exit 51 ./patch-wiimmfi.sh >/dev/null || exit 51
echo "*** 8) storing game in ${PATCHIMAGE_GAME_DIR}/${1##*/}" echo "*** 8) storing game in ${PATCHIMAGE_GAME_DIR}/${1##*/}"
mv ./wiimmfi-images/${1##*/} "${PATCHIMAGE_GAME_DIR}"/ mv ./wiimmfi-images/"${1##*/}" "${PATCHIMAGE_GAME_DIR}"/
rm -rf ${HOME}/.patchimage/tools/* rm -rf "${HOME}"/.patchimage/tools/*
} }
@ -56,17 +56,17 @@ mkwiimm_distfiles () {
if [[ -f ${PATCHIMAGE_RIIVOLUTION_DIR}/${FILENAME} ]]; then if [[ -f ${PATCHIMAGE_RIIVOLUTION_DIR}/${FILENAME} ]]; then
echo "*** 5) extracting mkwiimm files" echo "*** 5) extracting mkwiimm files"
${UNP} ${PATCHIMAGE_RIIVOLUTION_DIR}/${FILENAME} >/dev/null || \ "${UNP}" "${PATCHIMAGE_RIIVOLUTION_DIR}"/"${FILENAME}" >/dev/null || \
( echo "something went wrong extracting files" && exit 63 ) ( echo "something went wrong extracting files" && exit 63 )
elif [[ -f ${PWD}/${FILENAME} ]]; then elif [[ -f ${PWD}/${FILENAME} ]]; then
echo "*** 5) extracting mkwiimm files" echo "*** 5) extracting mkwiimm files"
${UNP} ${PWD}/${FILENAME} >/dev/null || \ "${UNP}" "${PWD}"/"${FILENAME}" >/dev/null || \
( echo "something went wrong extracting files" && exit 63 ) ( echo "something went wrong extracting files" && exit 63 )
else else
echo "*** 5) downloading and extracting mkwiimm files" echo "*** 5) downloading and extracting mkwiimm files"
wget -O ${PATCHIMAGE_RIIVOLUTION_DIR}/${FILENAME} ${DOWNLOAD} >/dev/null || \ wget -O "${PATCHIMAGE_RIIVOLUTION_DIR}"/"${FILENAME}" "${DOWNLOAD}" >/dev/null || \
( echo "something went wrong downloading ${DOWNLOAD}" && exit 57 ) ( echo "something went wrong downloading ${DOWNLOAD}" && exit 57 )
${UNP} ${PATCHIMAGE_RIIVOLUTION_DIR}/${FILENAME} >/dev/null || \ "${UNP}" "${PATCHIMAGE_RIIVOLUTION_DIR}"/"${FILENAME}" >/dev/null || \
( echo "something went wrong extracting files" && exit 63 ) ( echo "something went wrong extracting files" && exit 63 )
fi fi
@ -79,12 +79,12 @@ mkwiimm_build_olddist () {
MSGLANG=${MKWIIMM_MSG_LANG} MSGLANG=${MKWIIMM_MSG_LANG}
ISOMODE=wbfs ISOMODE=wbfs
SPLITISO= SPLITISO=
PRIV_SAVEGAME=${MKWIIMM_OWN_SAVE}" > ${PWD}/config.def PRIV_SAVEGAME=${MKWIIMM_OWN_SAVE}" > "${PWD}"/config.def
echo "*** 6) creating >${DIST}< (can take some time)" echo "*** 6) creating >${DIST}< (can take some time)"
./create-image.sh -a --dest=${XD}/RMC${REG}${MY_ID}.wbfs >/dev/null || exit 51 ./create-image.sh -a --dest="${XD}/RMC${REG}${MY_ID}".wbfs >/dev/null || exit 51
else else
echo "*** 6) creating >${DIST}< (can take some time)" echo "*** 6) creating >${DIST}< (can take some time)"
./create-image.sh --dest=${XD}/RMC${REG}${MY_ID}.wbfs || exit 51 ./create-image.sh --dest="${XD}/RMC${REG}${MY_ID}".wbfs || exit 51
fi fi
} }
@ -100,89 +100,89 @@ CTRENAME=${MKWIIMM_CTRENAME}
REORDER=${MKWIIMM_CTREORDER} REORDER=${MKWIIMM_CTREORDER}
ISOMODE=wbfs ISOMODE=wbfs
SPLITISO= SPLITISO=
PRIV_SAVEGAME=${MKWIIMM_OWN_SAVE}" > ${PWD}/config.def PRIV_SAVEGAME=${MKWIIMM_OWN_SAVE}" > "${PWD}"/config.def
echo "*** 6) creating >${DIST}< (can take some time)" echo "*** 6) creating >${DIST}< (can take some time)"
./create-image.sh -a --dest=${XD}/RMC${REG}${MY_ID}.wbfs >/dev/null || exit 51 ./create-image.sh -a --dest="${XD}/RMC${REG}${MY_ID}".wbfs >/dev/null || exit 51
else else
echo "*** 6) creating >${DIST}< (can take some time)" echo "*** 6) creating >${DIST}< (can take some time)"
./create-image.sh --dest=${XD}/RMC${REG}${MY_ID}.wbfs || exit 51 ./create-image.sh --dest="${XD}/RMC${REG}${MY_ID}".wbfs || exit 51
fi fi
} }
build_mkwiimm () { build_mkwiimm () {
MY_ID=${1} MY_ID=${1}
DIST=$(gawk -F \: "/^${MY_ID}/"'{print $2}' < ${PATCHIMAGE_DATABASE_DIR}/mkwiimm.db) DIST=$(gawk -F : "/^${MY_ID}/"'{print $2}' < "${PATCHIMAGE_DATABASE_DIR}"/mkwiimm.db)
DOWNLOAD=$(gawk -F \: "/^${MY_ID}/"'{print $3}' < ${PATCHIMAGE_DATABASE_DIR}/mkwiimm.db) DOWNLOAD=$(gawk -F : "/^${MY_ID}/"'{print $3}' < "${PATCHIMAGE_DATABASE_DIR}"/mkwiimm.db)
FILENAME=$(gawk -F \: "/^${MY_ID}/"'{split($3, a, "/") ; print a[3]}' < ${PATCHIMAGE_DATABASE_DIR}/mkwiimm.db) FILENAME=$(gawk -F : "/^${MY_ID}/"'{split($3, a, "/") ; print a[3]}' < "${PATCHIMAGE_DATABASE_DIR}"/mkwiimm.db)
if [[ ${FILENAME} != mkw* ]]; then if [[ ${FILENAME} != mkw* ]]; then
echo "wrong ID passed from user-input, exiting." echo "wrong ID passed from user-input, exiting."
exit 75 exit 75
fi fi
rm -rf ${FILENAME/.7z} rm -rf "${FILENAME/.7z}"
mkwiimm_distfiles mkwiimm_distfiles
cd ${FILENAME/.7z} cd "${FILENAME/.7z}"
REG=$(gawk '/^RMC/{print $3}' <(${WIT} ll ${IMAGE})) REG=$(gawk '/^RMC/{print $3}' <("${WIT}" ll "${IMAGE}"))
case $REG in case $REG in
PAL) REG=P ;; PAL) REG=P ;;
NTSC-J) REG=J ;; NTSC-J) REG=J ;;
NTSC-U) REG=E ;; NTSC-U) REG=E ;;
esac esac
ln -s "${IMAGE}" . ln -s "${IMAGE}" .
chmod +x *.sh chmod +x ./*.sh
if [[ ${MKWIIMM_OVERRIDE_SZS} == "TRUE" ]] && cp -r ${PATCHIMAGE_OVERRIDE_DIR}/* ${PWD}/bin/ [[ ${MKWIIMM_OVERRIDE_SZS} == "TRUE" ]] && cp -r "${PATCHIMAGE_OVERRIDE_DIR}"/* "${PWD}"/bin/
if [[ ${MY_ID} -lt 27 ]]; then if [[ ${MY_ID} -lt 27 ]]; then
mkwiimm_olddist mkwiimm_olddist
else mkwiimm_newdist else mkwiimm_newdist
fi fi
if [[ ${MY_ID} -lt 23 ]]; then if [[ ${MY_ID} -lt 23 ]]; then
echo "*** 7) patching >${DIST}< to use custom server" echo "*** 7) patching >${DIST}< to use custom server"
wiimmfi ${XD}/RMC${REG}${MY_ID}.wbfs || (echo "something went wrong wiimmfi-ing ${XD}/RMC${REG}${MY_ID}.wbfs" && exit 69) wiimmfi "${XD}/RMC${REG}${MY_ID}".wbfs || (echo "something went wrong wiimmfi-ing ${XD}/RMC${REG}${MY_ID}.wbfs" && exit 69)
echo "*** 8) storing game" echo "*** 8) storing game"
else echo "*** 7) storing game" else echo "*** 7) storing game"
fi fi
cd ${XD} cd "${XD}"
echo " ${DIST} saved as ${PATCHIMAGE_GAME_DIR}/RMC${REG}${MY_ID}.wbfs" echo " ${DIST} saved as ${PATCHIMAGE_GAME_DIR}/RMC${REG}${MY_ID}.wbfs"
mv RMC${REG}${MY_ID}.wbfs \ mv "RMC${REG}${MY_ID}".wbfs \
${PATCHIMAGE_GAME_DIR}/RMC${REG}${MY_ID}.wbfs || exit 51 "${PATCHIMAGE_GAME_DIR}/RMC${REG}${MY_ID}".wbfs || exit 51
if [[ ${MY_ID} -lt 23 ]]; then if [[ ${MY_ID} -lt 23 ]]; then
echo "*** 9) cleaning up workdir" echo "*** 9) cleaning up workdir"
else else
echo "*** 8) cleaning up workdir" echo "*** 8) cleaning up workdir"
fi fi
rm -rf ${FILENAME/.7z} rm -rf "${FILENAME/.7z}"
if [[ ${PATCHIMAGE_COVER_DOWNLOAD} == TRUE ]]; then if [[ ${PATCHIMAGE_COVER_DOWNLOAD} == TRUE ]]; then
echo -e "*** Z) download_covers\n" echo -e "*** Z) download_covers\n"
download_covers RMC${REG}${MY_ID} download_covers "RMC${REG}${MY_ID}"
fi fi
} }
patch_wiimm () { patch_wiimm () {
XD=${PWD} XD="${PWD}"
if [[ ${ID} == ALL ]]; then if [[ ${ID} == ALL ]]; then
for ID in {06..31}; do for ID in {06..31}; do
build_mkwiimm ${ID} build_mkwiimm "${ID}"
done done
else else
for game in ${ID[@]}; do for game in "${ID[@]}"; do
build_mkwiimm ${game} build_mkwiimm "${game}"
done done
fi fi
} }