From b745154c300fe9d7ce01b212f8f9f7244603dba3 Mon Sep 17 00:00:00 2001 From: Christopher Roy Bratusek Date: Fri, 5 Aug 2016 21:22:15 +0200 Subject: [PATCH] mkwiimm_karts.sh: fixes and code review --- script.d/mkwii/mkwiimm_karts.sh | 58 ++++++++++++++++----------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/script.d/mkwii/mkwiimm_karts.sh b/script.d/mkwii/mkwiimm_karts.sh index 7b41072..83d0028 100644 --- a/script.d/mkwii/mkwiimm_karts.sh +++ b/script.d/mkwii/mkwiimm_karts.sh @@ -22,12 +22,12 @@ check_input_image_special () { ask_input_image_mkwiimm echo -e "type ALL or RMC???.wbfs:\n" - read ID + read -r ID if [[ -f ${PWD}/${ID} ]]; then - GAMEDIR=${PWD} + GAMEDIR="${PWD}" elif [[ -f ${PATCHIMAGE_WBFS_DIR}/${ID} ]]; then - GAMEDIR=${PATCHIMAGE_WBFS_DIR} + GAMEDIR="${PATCHIMAGE_WBFS_DIR}" else echo "invalid user input." exit 75 fi @@ -37,14 +37,14 @@ check_input_image_special () { ask_slot () { echo -e "\nFirst choose a vehicle to be replaced\n" - gawk -F \: '{print $1 "\t\t" $2}' < ${PATCHIMAGE_DATABASE_DIR}/mkwiimm_vehicles.db + gawk -F : '{print $1 "\t\t" $2}' < "${PATCHIMAGE_DATABASE_DIR}"/mkwiimm_vehicles.db echo -e "\ntype in ??_??? as in first column\n" - read VEHICLE + read -r VEHICLE echo -e "\nNow choose a character to be replaced\n" - gawk -F \: '{print $1 "\t\t" $2}' < ${PATCHIMAGE_DATABASE_DIR}/mkwiimm_characters.db + gawk -F : '{print $1 "\t\t" $2}' < "${PATCHIMAGE_DATABASE_DIR}"/mkwiimm_characters.db echo -e "\ntype in -?? as in first column\n" - read CHARACTER + read -r CHARACTER choosenkarts=( ${choosenkarts[@]} ${kart}:${VEHICLE}${CHARACTER} ) @@ -55,22 +55,20 @@ download_wiimm () { if [[ -f ${HOME}/.patchimage.choice ]]; then echo "Your choices from last time can be re-used." echo "y (yes) or n (no)" - read choice + read -r choice if [[ ${choice} == y ]]; then - source ${HOME}/.patchimage.choice + source "${HOME}"/.patchimage.choice fi fi if [[ ${choosenkarts[@]} == "" ]]; then echo -e "Choose a character to add to the game\n" - - gawk -F \: '{print $1 "\t\t" $2}' < ${PATCHIMAGE_DATABASE_DIR}/mkwiimm_karts.db - + gawk -F : '{print $1 "\t\t" $2}' < "${PATCHIMAGE_DATABASE_DIR}"/mkwiimm_karts.db echo -e "\ntype ???.szs (multiple possible, space separated)" - read KART + read -r KART - for kart in ${KART[@]}; do + for kart in "${KART[@]}"; do if [[ ! -f ${PATCHIMAGE_DATA_DIR}/mkwiimm_karts/${kart} ]]; then echo "unknown Kart ${kart}" exit 75 @@ -78,8 +76,8 @@ download_wiimm () { done ask_slot - echo ${choosenkarts[@]} - echo "choosenkarts=( ${choosenkarts[@]} )" > ${HOME}/.patchimage.choice + echo "${choosenkarts[@]}" + echo "choosenkarts=( ${choosenkarts[*]} )" > "${HOME}"/.patchimage.choice fi } @@ -88,36 +86,36 @@ build_mkwiimm () { rm -rf workdir echo "*** 5) extracting image" - ${WIT} extract ${IMAGE%/*}/${ID} workdir -q || exit 51 + "${WIT}" extract "${GAMEDIR}"/"${ID}" workdir -q || exit 51 if [[ ! -d "${PATCHIMAGE_RIIVOLUTION_DIR}"/${ID/.*}_SZS ]]; then echo "*** 6) this is the first run, so backing up original files (in ${PATCHIMAGE_RIIVOLUTION_DIR}) for future customizations" - mkdir "${PATCHIMAGE_RIIVOLUTION_DIR}"/${ID/.*}_SZS + mkdir "${PATCHIMAGE_RIIVOLUTION_DIR}"/"${ID/.*}"_SZS cp workdir/files/Race/Kart/* \ - "${PATCHIMAGE_RIIVOLUTION_DIR}"/${ID/.*}_SZS + "${PATCHIMAGE_RIIVOLUTION_DIR}"/"${ID/.*}"_SZS else echo "*** 6) restoring original files" - cp "${PATCHIMAGE_RIIVOLUTION_DIR}"/${ID/.*}_SZS/* \ + cp "${PATCHIMAGE_RIIVOLUTION_DIR}"/"${ID/.*}"_SZS/* \ workdir/files/Race/Kart/ fi echo "*** 7) replacing kart(s)" - for kart in ${choosenkarts[@]}; do - source=${kart/*:} - dest=${kart/:*} + for kart in "${choosenkarts[@]}"; do + source="${kart/*:}" + dest="${kart/:*}" echo " old: ${dest}.szs new: ${source}" - cp "${PATCHIMAGE_DATA_DIR}"/mkwiimm_karts/${source} \ - workdir/files/Race/Kart/${dest}.szs - cp "${PATCHIMAGE_DATA_DIR}"/mkwiimm_karts/${source} \ - workdir/files/Race/Kart/${dest}_2.szs - cp "${PATCHIMAGE_DATA_DIR}"/mkwiimm_karts/${source} \ - workdir/files/Race/Kart/${dest}_4.szs + cp "${PATCHIMAGE_DATA_DIR}"/mkwiimm_karts/"${source}" \ + workdir/files/Race/Kart/"${dest}".szs + cp "${PATCHIMAGE_DATA_DIR}"/mkwiimm_karts/"${source}" \ + workdir/files/Race/Kart/"${dest}"_2.szs + cp "${PATCHIMAGE_DATA_DIR}"/mkwiimm_karts/"${source}" \ + workdir/files/Race/Kart/"${dest}"_4.szs done echo "*** 8) rebuilding game" echo " (storing game in ${PATCHIMAGE_GAME_DIR}/${ID})" - ${WIT} cp -o -q -B workdir ${PATCHIMAGE_GAME_DIR}/${ID} || exit 51 + "${WIT}" cp -o -q -B workdir "${PATCHIMAGE_GAME_DIR}"/"${ID}" || exit 51 rm -rf workdir