setup.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #! /usr/bin/env bash
  2. # This script is a derivative work based on Wiimmfi Patcher and WIT
  3. # Copyright 2022 MH3SP Patcher Project
  4. # SPDX-License-Identifier: GPL-2.0-or-later
  5. export MH_PATCHER_NAME="MH3SP Patcher v2022-12"
  6. export MH_PATCHER_HEADER="** $MH_PATCHER_NAME based on **"
  7. export PATCHER_NAME="Wiimmfi Patcher v7.5"
  8. export DATE=2021-03-13
  9. export COPYRIGHT="(c) wiimm (at) wiimm.de -- $DATE"
  10. export PATCHER_HEADER="** $PATCHER_NAME - $DATE **"
  11. export DESTDIR="./mh3sp-images"
  12. export WORKDIR="./patch-dir"
  13. export LOGDIR="./_log"
  14. export LC_ALL=C
  15. export COL_ERROR="\033[41;37;1m"
  16. export COL_HEAD="\033[44;37;1m"
  17. export COL_INFO="\033[42;37;1m"
  18. export COL0="\033[0m"
  19. script="${0##*/}"
  20. #
  21. #------------------------------------------------------------------------------
  22. # print title
  23. function print_title
  24. {
  25. local h1=${#MH_PATCHER_HEADER}
  26. local h2=${#PATCHER_HEADER}
  27. local title_length=$(($h1 > $h2 ? $h1 : $h2))
  28. local stars="************************************************"
  29. printf -v stars "${COL_HEAD}%.*s${COL0}" ${title_length} "$stars$stars"
  30. printf "\n${stars}\n"
  31. printf "${COL_HEAD}${MH_PATCHER_HEADER}${COL0}\n"
  32. printf "${COL_HEAD}${PATCHER_HEADER}${COL0}\n"
  33. printf "${stars}\n\n"
  34. }
  35. ((PRINT_TITLE>0)) && print_title
  36. #
  37. #------------------------------------------------------------------------------
  38. # system and bin path
  39. #--- BASEDIR
  40. if [[ ${BASH_SOURCE:0:1} == / ]]
  41. then
  42. BASEDIR="${BASH_SOURCE%/*}"
  43. [[ $BASEDIR = "" ]] && BASEDIR=/
  44. else
  45. BASEDIR="$PWD/$BASH_SOURCE"
  46. BASEDIR="${BASEDIR%/*}"
  47. fi
  48. export BASEDIR
  49. #--- predefine BINDIR & PATH for Cygwin
  50. export ORIGPATH="$PATH"
  51. export BINDIR="$BASEDIR/cygwin"
  52. [[ -d $BINDIR ]] && export PATH="$BINDIR:$ORIGPATH"
  53. #--- find system
  54. export SYSTEM="$( uname -s | tr '[A-Z]' '[a-z]' )"
  55. export MACHINE="$( uname -m | tr '[A-Z]' '[a-z]' )"
  56. export HOST
  57. case "$SYSTEM-$MACHINE" in
  58. darwin-*) HOST=mac ;;
  59. linux-x86_64) HOST=linux64 ;;
  60. linux-*) HOST=linux32 ;;
  61. cygwin*-x86_64) HOST=cygwin64 ;;
  62. cygwin*) HOST=cygwin32 ;;
  63. *) HOST=- ;;
  64. esac
  65. #--- setup BINDIR and PATH
  66. BINDIR="$BASEDIR/$HOST"
  67. ((VERBOSE>0)) && echo "BINDIR = $BINDIR"
  68. if [[ -d $BINDIR ]]
  69. then
  70. chmod u+x "$BINDIR"/* 2>/dev/null || true
  71. export PATH="$BINDIR:$ORIGPATH"
  72. fi
  73. export WIT="$BINDIR/wit"
  74. #
  75. #------------------------------------------------------------------------------
  76. # check existence of tools
  77. needed_tools="awk bash chmod cp mkdir mv rm sed sort tr uname uniq which wit"
  78. err=
  79. for tool in $needed_tools
  80. do
  81. if ! which $tool >/dev/null 2>&1
  82. then
  83. err+=" $tool"
  84. fi
  85. done
  86. if [[ $err != "" ]]
  87. then
  88. printf "\n\033[31;1m!!! Missing tools:$err => abort!\033[0m\n\n" >&2
  89. printf "\033[36mPATH:\n " >&2
  90. sed 's/:/\n /g' <<< "$PATH" >&2
  91. printf "\033[0m\n" >&2
  92. exit 1
  93. fi
  94. printf '\e[0;30;47m HOST: %s \e[m\n' "$HOST"