init.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 -e
  12. set -o errtrace
  13. set -o functrace
  14. trap 'echo -e "${GREEN}Exiting at user request$RESET"; exit' INT
  15. trap 'echo -e "${RED}Node Tools test suite initialization exited with error (line $BASH_LINENO) $RESET"' ERR
  16. umask 0022
  17. STDOUT_DEVNULL='>/dev/null'
  18. STDERR_DEVNULL='2>/dev/null'
  19. PROGNAME=$(basename $0)
  20. while getopts hv OPT
  21. do
  22. case "$OPT" in
  23. h) printf " %-16s Initialize the MMGen Node Tools test suite\n" "${PROGNAME}:"
  24. echo " USAGE: $PROGNAME"
  25. echo " OPTIONS: '-h' Print this help message"
  26. echo " -v Be more verbose"
  27. exit ;;
  28. v) VERBOSE=1 STDOUT_DEVNULL='' STDERR_DEVNULL='' ;;
  29. *) exit ;;
  30. esac
  31. done
  32. shift $((OPTIND-1))
  33. wallet_repo='../mmgen-wallet'
  34. die() { echo -e ${YELLOW}ERROR: $1$RESET; false; }
  35. becho() { echo -e $BLUE$1$RESET; }
  36. check_mmgen_repo() {
  37. ( cd $wallet_repo; python3 ./setup.py --url | grep -iq 'mmgen' )
  38. }
  39. build_mmgen_extmod() {
  40. (
  41. cd $wallet_repo
  42. eval "python3 ./setup.py build_ext --inplace $STDOUT_DEVNULL $STDERR_DEVNULL"
  43. )
  44. }
  45. create_dir_links() {
  46. for link_name in 'mmgen' 'scripts'; do
  47. target="$wallet_repo/$link_name"
  48. if [ -L $link_name ]; then
  49. [ "$(realpath --relative-to=. $link_name 2>/dev/null)" == $target ] || {
  50. [ "$VERBOSE" ] && echo "Removing broken symlink '$link_name'"
  51. rm $link_name
  52. }
  53. elif [ -e $link_name ]; then
  54. die "'$link_name' is not a symbolic link. Please remove or relocate it and re-run this script"
  55. fi
  56. if [ ! -e $link_name ]; then
  57. [ "$VERBOSE" ] && echo "Creating symlink: $link_name"
  58. ln -s $target
  59. fi
  60. done
  61. }
  62. create_test_links() {
  63. paths='
  64. test/include symbolic
  65. test/overlay/__init__.py symbolic
  66. test/overlay/fakemods/mmgen symbolic
  67. test/__init__.py symbolic
  68. test/cmdtest.py hard
  69. test/unit_tests.py hard
  70. test/test-release.sh symbolic
  71. test/cmdtest_py_d/common.py symbolic
  72. test/cmdtest_py_d/ct_base.py symbolic
  73. cmds/mmgen-regtest symbolic
  74. '
  75. while read path type; do
  76. [ "$path" ] || continue
  77. pfx=$(echo $path | sed -r 's/[^/]//g' | sed 's/\//..\//g')
  78. symlink_arg=$(if [ $type == 'symbolic' ]; then echo --symbolic; fi)
  79. target="$wallet_repo/$path"
  80. if [ ! -e "$target" ]; then
  81. echo "Target path $target is missing! Cannot proceed"
  82. exit 1
  83. fi
  84. fs="%-8s %-16s %s -> %s\n"
  85. if [ $type == 'hard' ]; then
  86. if [ -L $path ]; then
  87. [ "$VERBOSE" ] && printf "$fs" "Deleting" "symbolic link:" $path $target
  88. rm -rf $path
  89. elif [ -e $path ]; then
  90. if [ "$(stat --printf=%i $path)" -ne "$(stat --printf=%i $target)" ]; then
  91. [ "$VERBOSE" ] && printf "$fs" "Deleting" "stale hard link:" $path "?"
  92. rm -rf $path
  93. fi
  94. fi
  95. fi
  96. if [ ! -e $path ]; then # link is either absent or a broken symlink
  97. [ "$VERBOSE" ] && printf "$fs" "Creating" "$type link:" $path $target
  98. ( cd "$(dirname $path)" && ln -f $symlink_arg $pfx$target )
  99. fi
  100. done <<<$paths
  101. }
  102. becho 'Initializing MMGen Node Tools Test Suite'
  103. check_mmgen_repo || die "MMGen Wallet repository not found at $wallet_repo!"
  104. build_mmgen_extmod
  105. [ "$VERBOSE" ] && becho 'Creating links to mmgen-wallet repo'
  106. create_dir_links
  107. create_test_links
  108. [ "$VERBOSE" ] && becho 'OK'
  109. true