init.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2022 The MMGen Project <mmgen@tuta.io>
  5. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen-node-tools
  9. # https://gitlab.com/mmgen/mmgen-node-tools
  10. RED="\e[31;1m" GREEN="\e[32;1m" YELLOW="\e[33;1m" BLUE="\e[34;1m" RESET="\e[0m"
  11. set -o errtrace
  12. set -o functrace
  13. trap 'echo -e "${GREEN}Exiting at user request$RESET"; exit' INT
  14. trap 'echo -e "${RED}Node Tools test suite initialization exited with error (line $BASH_LINENO) $RESET"' ERR
  15. umask 0022
  16. PROGNAME=$(basename $0)
  17. while getopts h OPT
  18. do
  19. case "$OPT" in
  20. h) printf " %-16s Initialize the MMGen Node Tools test suite\n" "${PROGNAME}:"
  21. echo " USAGE: $PROGNAME"
  22. echo " OPTIONS: '-h' Print this help message"
  23. exit ;;
  24. *) exit ;;
  25. esac
  26. done
  27. shift $((OPTIND-1))
  28. mm_repo='../mmgen'
  29. die() { echo -e ${YELLOW}ERROR: $1$RESET; false; }
  30. becho() { echo -e $BLUE$1$RESET; }
  31. check_mmgen_repo() {
  32. ( cd $mm_repo; python3 ./setup.py --url | grep -iq 'mmgen' )
  33. }
  34. build_mmgen_extmod() {
  35. ( cd $mm_repo; python3 ./setup.py build_ext --inplace )
  36. }
  37. create_dir_links() {
  38. for target in 'mmgen' 'scripts'; do
  39. src="$mm_repo/$target"
  40. if [ -e $target ]; then
  41. [ $(realpath --relative-to=. $target) == $src ] || die "'$target' does not point to '$src'"
  42. else
  43. echo "Creating symlink: $target"
  44. ln -s $src
  45. fi
  46. done
  47. }
  48. create_test_links() {
  49. sources='
  50. test/include
  51. test/overlay/__init__.py
  52. test/overlay/fakemods/mmgen
  53. test/__init__.py
  54. test/test.py
  55. test/unit_tests.py
  56. test/test-release.sh
  57. test/test_py_d/common.py
  58. test/test_py_d/ts_base.py
  59. cmds/mmgen-regtest
  60. '
  61. for src in $sources; do
  62. pfx=$(echo $src | sed -r 's/[^/]//g' | sed 's/\//..\//g')
  63. if [ ! -e $src ]; then
  64. echo "Creating symlink: $src"
  65. ( cd "$(dirname $src)" && ln -s "$pfx$mm_repo/$src" )
  66. fi
  67. done
  68. }
  69. set -e
  70. becho 'Initializing MMGen Node Tools Test Suite'
  71. check_mmgen_repo || die "MMGen repository not found at $mm_repo!"
  72. build_mmgen_extmod
  73. create_dir_links
  74. create_test_links
  75. becho 'OK'