init.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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
  52. test/__init__.py
  53. test/test.py
  54. test/unit_tests.py
  55. test/test-release.sh
  56. test/test_py_d/common.py
  57. test/test_py_d/ts_base.py
  58. cmds/mmgen-regtest
  59. '
  60. for src in $sources; do
  61. pfx=$(echo $src | sed -r 's/[^/]//g' | sed 's/\//..\//g')
  62. if [ ! -e $src ]; then
  63. echo "Creating symlink: $src"
  64. ( cd "$(dirname $src)" && ln -s "$pfx$mm_repo/$src" )
  65. fi
  66. done
  67. }
  68. set -e
  69. becho 'Initializing MMGen Node Tools Test Suite'
  70. check_mmgen_repo || die "MMGen repository not found at $mm_repo!"
  71. build_mmgen_extmod
  72. create_dir_links
  73. create_test_links
  74. becho 'OK'