init.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. wallet_repo='../mmgen-wallet'
  29. die() { echo -e ${YELLOW}ERROR: $1$RESET; false; }
  30. becho() { echo -e $BLUE$1$RESET; }
  31. check_mmgen_repo() {
  32. ( cd $wallet_repo; python3 ./setup.py --url | grep -iq 'mmgen' )
  33. }
  34. build_mmgen_extmod() {
  35. ( cd $wallet_repo; python3 ./setup.py build_ext --inplace )
  36. }
  37. create_dir_links() {
  38. for link_name in 'mmgen' 'scripts'; do
  39. target="$wallet_repo/$link_name"
  40. if [ -L $link_name ]; then
  41. [ "$(realpath --relative-to=. $link_name 2>/dev/null)" == $target ] || {
  42. echo "Removing broken symlink '$link_name'"
  43. rm $link_name
  44. }
  45. elif [ -e $link_name ]; then
  46. die "'$link_name' is not a symbolic link. Please remove or relocate it and re-run this script"
  47. fi
  48. if [ ! -e $link_name ]; then
  49. echo "Creating symlink: $link_name"
  50. ln -s $target
  51. fi
  52. done
  53. }
  54. create_test_links() {
  55. paths='
  56. test/include symbolic
  57. test/overlay/__init__.py symbolic
  58. test/overlay/fakemods/mmgen symbolic
  59. test/__init__.py symbolic
  60. test/cmdtest.py hard
  61. test/unit_tests.py hard
  62. test/test-release.sh symbolic
  63. test/cmdtest_py_d/common.py symbolic
  64. test/cmdtest_py_d/ct_base.py symbolic
  65. cmds/mmgen-regtest symbolic
  66. '
  67. while read path type; do
  68. [ "$path" ] || continue
  69. pfx=$(echo $path | sed -r 's/[^/]//g' | sed 's/\//..\//g')
  70. symlink_arg=$(if [ $type == 'symbolic' ]; then echo --symbolic; fi)
  71. target="$wallet_repo/$path"
  72. if [ ! -e "$target" ]; then
  73. echo "Target path $target is missing! Cannot proceed"
  74. exit 1
  75. fi
  76. fs="%-8s %-16s %s -> %s\n"
  77. if [ $type == 'hard' ]; then
  78. if [ -L $path ]; then
  79. printf "$fs" "Deleting" "symbolic link:" $path $target
  80. rm -rf $path
  81. elif [ -e $path ]; then
  82. if [ "$(stat --printf=%i $path)" -ne "$(stat --printf=%i $target)" ]; then
  83. printf "$fs" "Deleting" "stale hard link:" $path "?"
  84. rm -rf $path
  85. fi
  86. fi
  87. fi
  88. if [ ! -e $path ]; then # link is either absent or a broken symlink
  89. printf "$fs" "Creating" "$type link:" $path $target
  90. ( cd "$(dirname $path)" && ln -f $symlink_arg $pfx$target )
  91. fi
  92. done <<<$paths
  93. }
  94. set -e
  95. becho 'Initializing MMGen Node Tools Test Suite'
  96. check_mmgen_repo || die "MMGen Wallet repository not found at $wallet_repo!"
  97. build_mmgen_extmod
  98. create_dir_links
  99. create_test_links
  100. becho 'OK'