taler-unified-setup.sh (30451B)
1 #!/usr/bin/env bash 2 # 3 # This file is part of TALER 4 # Copyright (C) 2023, 2024 Taler Systems SA 5 # 6 # TALER is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as 8 # published by the Free Software Foundation; either version 3, or 9 # (at your option) any later version. 10 # 11 # TALER is distributed in the hope that it will be useful, but 12 # WITHOUT ANY WARRANTY; without even the implied warranty of 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 # GNU General Public License for more details. 15 # 16 # You should have received a copy of the GNU General Public 17 # License along with TALER; see the file COPYING. If not, see 18 # <http://www.gnu.org/licenses/> 19 # 20 # Author: Christian Grothoff 21 # 22 # This script configures and launches various GNU Taler services. 23 # Which ones depend on command-line options. Use "-h" to find out. 24 # Prints "<<READY>>" on a separate line once all requested services 25 # are running. Close STDIN (or input 'NEWLINE') to stop all started 26 # services again. 27 # 28 # shellcheck disable=SC2317 29 30 set -eu 31 32 # These break TALER_HOME control via TALER_TEST_HOME... 33 unset XDG_DATA_HOME 34 unset XDG_CONFIG_HOME 35 unset XDG_CACHE_HOME 36 37 EXIT_STATUS=2 38 39 # Exit, with status code "skip" (no 'real' failure) 40 function exit_skip() { 41 echo " SKIP: " "$@" >&2 42 EXIT_STATUS=77 43 exit "$EXIT_STATUS" 44 } 45 46 # Exit, with error message (hard failure) 47 function exit_fail() { 48 echo " FAIL: " "$@" >&2 49 EXIT_STATUS=1 50 exit "$EXIT_STATUS" 51 } 52 53 # Cleanup to run whenever we exit 54 function cleanup() 55 { 56 echo "Taler unified setup terminating at $STAGE!" >&2 57 58 for n in $(jobs -p) 59 do 60 kill "$n" 2> /dev/null || true 61 done 62 wait 63 rm -f libeufin-nexus.pid libeufin-sandbox.pid 64 exit "$EXIT_STATUS" 65 } 66 67 STAGE="boot" 68 69 # Install cleanup handler (except for kill -9) 70 trap cleanup EXIT 71 72 WAIT_FOR_SIGNAL=0 73 START_AUDITOR=0 74 START_BACKUP=0 75 START_EXCHANGE=0 76 START_FAKEBANK=0 77 START_DONAU=0 78 START_CHALLENGER=0 79 START_AGGREGATOR=0 80 START_MERCHANT=0 81 START_NEXUS=0 82 START_BANK=0 83 START_TRANSFER=0 84 START_WIREWATCH=0 85 START_DEPOSITCHECK=0 86 START_MERCHANT_EXCHANGE=0 87 START_MERCHANT_WIREWATCH=0 88 START_MERCHANT_DONAUKEYUPDATE=0 89 USE_ACCOUNT="exchange-account-1" 90 USE_VALGRIND="" 91 WIRE_DOMAIN="x-taler-bank" 92 CONF_ORIG="$HOME/.config/taler.conf" 93 LOGLEVEL="DEBUG" 94 DEFAULT_SLEEP="0.5" 95 96 # Parse command-line options 97 while getopts ':abc:d:DeEfghkL:mMnr:stu:vwWzZ' OPTION; do 98 case "$OPTION" in 99 a) 100 START_AUDITOR="1" 101 ;; 102 b) 103 START_BANK="1" 104 ;; 105 c) 106 CONF_ORIG="$OPTARG" 107 ;; 108 d) 109 WIRE_DOMAIN="$OPTARG" 110 ;; 111 D) 112 START_DONAU="1" 113 ;; 114 e) 115 START_EXCHANGE="1" 116 ;; 117 E) 118 START_MERCHANT_EXCHANGE="1" 119 ;; 120 f) 121 START_FAKEBANK="1" 122 ;; 123 h) 124 echo 'Supported options:' 125 echo ' -a -- start auditor' 126 echo ' -b -- start bank' 127 # shellcheck disable=SC2016 128 echo ' -c $CONF -- set configuration' 129 # shellcheck disable=SC2016 130 echo ' -d $METHOD -- use wire method (default: x-taler-bank)' 131 echo ' -D -- start donau' 132 echo ' -e -- start exchange' 133 echo ' -E -- start taler-merchant-exchange' 134 echo ' -f -- start fakebank' 135 echo ' -g -- start taler-exchange-aggregator' 136 echo ' -h -- print this help' 137 echo ' -k -- start challenger (KYC service)' 138 # shellcheck disable=SC2016 139 echo ' -L $LOGLEVEL -- set log level' 140 echo ' -m -- start taler-merchant' 141 echo ' -M -- start taler-merchant-depositcheck' 142 echo ' -n -- start nexus' 143 # shellcheck disable=SC2016 144 echo ' -r $MEX -- which exchange to use at the merchant (optional)' 145 echo ' -s -- start backup/sync' 146 echo ' -S $SLEEP -- set default sleep time between retries' 147 echo ' -t -- start taler-exchange-transfer' 148 # shellcheck disable=SC2016 149 echo ' -u $SECTION -- exchange account to use' 150 echo ' -v -- use valgrind' 151 echo ' -w -- start taler-exchange-wirewatch' 152 echo ' -W -- wait for signal' 153 echo ' -z -- start taler-merchant-wirewatch' 154 echo ' -Z -- start taler-merchant-donaukeyupdate' 155 exit 0 156 ;; 157 g) 158 START_AGGREGATOR="1" 159 ;; 160 k) 161 START_CHALLENGER="1" 162 ;; 163 L) 164 LOGLEVEL="$OPTARG" 165 ;; 166 m) 167 START_MERCHANT="1" 168 ;; 169 M) 170 START_DEPOSITCHECK="1" 171 ;; 172 n) 173 START_NEXUS="1" 174 ;; 175 r) 176 USE_MERCHANT_EXCHANGE="$OPTARG" 177 ;; 178 s) 179 START_BACKUP="1" 180 ;; 181 S) 182 DEFAULT_SLEEP="$OPTARG" 183 ;; 184 t) 185 START_TRANSFER="1" 186 ;; 187 u) 188 USE_ACCOUNT="$OPTARG" 189 ;; 190 v) 191 USE_VALGRIND="valgrind --leak-check=yes" 192 DEFAULT_SLEEP="2" 193 ;; 194 w) 195 START_WIREWATCH="1" 196 ;; 197 W) 198 WAIT_FOR_SIGNAL="1" 199 ;; 200 z) 201 START_MERCHANT_WIREWATCH="1" 202 ;; 203 Z) 204 START_MERCHANT_DONAUKEYUPDATE="1" 205 ;; 206 ?) 207 exit_fail "Unrecognized command line option" 208 ;; 209 esac 210 done 211 212 STAGE="init" 213 214 echo "Starting with configuration file at: $CONF_ORIG" 215 CONF="$CONF_ORIG.edited" 216 cp "${CONF_ORIG}" "${CONF}" 217 218 STAGE="checks" 219 220 echo -n "Testing for jq" 221 jq -h > /dev/null || exit_skip " jq required" 222 echo " FOUND" 223 224 echo -n "Testing for wget" 225 wget --help > /dev/null || exit_skip " wget required" 226 echo " FOUND" 227 228 if [ "1" = "$START_EXCHANGE" ] 229 then 230 echo -n "Testing for Taler exchange" 231 taler-exchange-httpd -h > /dev/null || exit_skip " taler-exchange-httpd required" 232 echo " FOUND" 233 fi 234 235 if [ "1" = "$START_DONAU" ] 236 then 237 echo -n "Testing for Donau" 238 donau-httpd -h > /dev/null || exit_skip " donau-httpd required" 239 echo " FOUND" 240 fi 241 242 if [ "1" = "$START_MERCHANT" ] 243 then 244 echo -n "Testing for Taler merchant" 245 taler-merchant-httpd -h > /dev/null || exit_skip " taler-merchant-httpd required" 246 echo " FOUND" 247 fi 248 249 if [ "1" = "$START_CHALLENGER" ] 250 then 251 echo -n "Testing for Taler challenger" 252 challenger-httpd -h > /dev/null || exit_skip " challenger-httpd required" 253 echo " FOUND" 254 fi 255 256 if [ "1" = "$START_BACKUP" ] 257 then 258 echo -n "Testing for sync-httpd" 259 sync-httpd -h > /dev/null || exit_skip " sync-httpd required" 260 echo " FOUND" 261 fi 262 263 if [ "1" = "$START_NEXUS" ] 264 then 265 echo -n "Testing for libeufin-nexus" 266 libeufin-nexus --help >/dev/null </dev/null || exit_skip " MISSING" 267 echo " FOUND" 268 fi 269 270 if [ "1" = "$START_BANK" ] 271 then 272 echo -n "Testing for libeufin-bank" 273 libeufin-bank --help >/dev/null </dev/null || exit_skip " MISSING" 274 echo " FOUND" 275 fi 276 277 STAGE="config" 278 279 if [ "1" = "$START_EXCHANGE" ] 280 then 281 CURRENCY=$(taler-exchange-config -c "$CONF" -s "EXCHANGE" -o "CURRENCY") 282 else 283 if [ "1" = "$START_DONAU" ] 284 then 285 CURRENCY=$(donau-config -c "$CONF" -s "DONAU" -o "CURRENCY") 286 else 287 if [ "1" = "$START_BANK" ] 288 then 289 # Note: would be nice to have libeufin-config in the future... 290 CURRENCY=$(taler-exchange-config -c "$CONF" -s "libeufin-bank" -o "CURRENCY") 291 else 292 CURRENCY="UNKNOWN" 293 fi 294 fi 295 fi 296 297 echo "Setting up for $CURRENCY" 298 299 register_bank_account() { 300 wget \ 301 --http-user="$AUSER" \ 302 --http-password="$APASS" \ 303 --method=DELETE \ 304 -o /dev/null \ 305 -O /dev/null \ 306 -a wget-delete-account.log \ 307 "http://localhost:${BANK_PORT}/accounts/$1" \ 308 || true # deletion may fail, that's OK! 309 if [ "$1" = "exchange" ] || [ "$1" = "Exchange" ] 310 then 311 IS_EXCHANGE="true" 312 else 313 IS_EXCHANGE="false" 314 fi 315 MAYBE_IBAN="${4:-}" 316 if [ -n "$MAYBE_IBAN" ] 317 then 318 # shellcheck disable=SC2001 319 ENAME=$(echo "$3" | sed -e "s/ /+/g") 320 if [ "$WIRE_DOMAIN" = "x-taler-bank" ] 321 then 322 # hostname 323 OPERATOR="localhost" 324 MAYBE_IBAN="$1" 325 else 326 # BIC 327 OPERATOR="SANDBOXX" 328 fi 329 PAYTO="payto://${WIRE_DOMAIN}/${OPERATOR}/${MAYBE_IBAN}?receiver-name=$ENAME" 330 BODY='{"username":"'"$1"'","password":"'"$2"'","is_taler_exchange":'"$IS_EXCHANGE"',"name":"'"$3"'","payto_uri":"'"$PAYTO"'"}' 331 else 332 BODY='{"username":"'"$1"'","password":"'"$2"'","is_taler_exchange":'"$IS_EXCHANGE"',"name":"'"$3"'"}' 333 fi 334 wget \ 335 --http-user="$AUSER" \ 336 --http-password="$APASS" \ 337 --method=POST \ 338 --header='Content-type: application/json' \ 339 --body-data="${BODY}" \ 340 -o /dev/null \ 341 -O /dev/null \ 342 -a wget-register-account.log \ 343 "http://localhost:${BANK_PORT}/accounts" 344 } 345 346 register_fakebank_account() { 347 if [ "$1" = "exchange" ] || [ "$1" = "Exchange" ] 348 then 349 IS_EXCHANGE="true" 350 else 351 IS_EXCHANGE="false" 352 fi 353 BODY='{"username":"'"$1"'","password":"'"$2"'","name":"'"$1"'","is_taler_exchange":'"$IS_EXCHANGE"'}' 354 wget \ 355 --post-data="$BODY" \ 356 --header='Content-type: application/json' \ 357 --tries=3 \ 358 --waitretry=1 \ 359 --timeout=30 \ 360 "http://localhost:$BANK_PORT/accounts" \ 361 -a wget-register-account.log \ 362 -o /dev/null \ 363 -O /dev/null \ 364 >/dev/null 365 } 366 367 368 if [[ "1" = "$START_BANK" ]] 369 then 370 BANK_PORT=$(taler-exchange-config -c "$CONF" -s "libeufin-bank" -o "PORT") 371 BANK_URL="http://localhost:${BANK_PORT}/" 372 fi 373 374 if [[ "1" = "$START_FAKEBANK" ]] 375 then 376 BANK_PORT=$(taler-exchange-config -c "$CONF" -s "BANK" -o "HTTP_PORT") 377 BANK_URL="http://localhost:${BANK_PORT}/" 378 fi 379 380 STAGE="bank" 381 382 if [ "1" = "$START_BANK" ] 383 then 384 echo -n "Setting up bank database ... " 385 libeufin-bank dbinit \ 386 -r \ 387 -c "$CONF" \ 388 -L "$LOGLEVEL" \ 389 &> libeufin-bank-reset.log 390 echo "DONE" 391 echo -n "Launching bank ... " 392 libeufin-bank serve \ 393 -c "$CONF" \ 394 -L "$LOGLEVEL" \ 395 > libeufin-bank-stdout.log \ 396 2> libeufin-bank-stderr.log & 397 echo $! > libeufin-bank.pid 398 echo "DONE" 399 echo -n "Waiting for Bank ..." 400 OK="0" 401 for n in $(seq 1 100); do 402 echo -n "." 403 sleep "$DEFAULT_SLEEP" 404 wget --timeout=1 \ 405 --tries=3 \ 406 --waitretry=0 \ 407 -a wget-bank-check.log \ 408 -o /dev/null \ 409 -O /dev/null \ 410 "${BANK_URL}config" || continue 411 OK="1" 412 break 413 done 414 if [ "1" != "$OK" ] 415 then 416 exit_skip "Failed to launch services (bank)" 417 fi 418 echo "OK" 419 echo -n "Set admin password..." 420 AUSER="admin" 421 APASS="secret-password" 422 libeufin-bank \ 423 passwd \ 424 -c "$CONF" \ 425 -L "$LOGLEVEL" \ 426 "$AUSER" "$APASS" \ 427 &> libeufin-bank-passwd.log 428 libeufin-bank \ 429 edit-account \ 430 -c "$CONF" \ 431 -L "$LOGLEVEL" \ 432 --debit_threshold="$CURRENCY:1000000" \ 433 "$AUSER" \ 434 &> libeufin-bank-debit-threshold.log 435 echo " OK" 436 fi 437 438 if [ "1" = "$START_NEXUS" ] 439 then 440 echo "Nexus currently not supported ..." 441 fi 442 443 if [ "1" = "$START_FAKEBANK" ] 444 then 445 echo -n "Setting up fakebank ..." 446 $USE_VALGRIND taler-fakebank-run \ 447 -c "$CONF" \ 448 -L "$LOGLEVEL" \ 449 -n 4 \ 450 2> taler-fakebank-run.log & 451 echo " OK" 452 fi 453 454 if [[ "1" = "$START_BANK" || "1" = "$START_FAKEBANK" ]] 455 then 456 echo -n "Waiting for the bank" 457 # Wait for bank to be available (usually the slowest) 458 OK="0" 459 for n in $(seq 1 300) 460 do 461 echo -n "." 462 sleep "$DEFAULT_SLEEP" 463 # bank 464 wget --tries=1 \ 465 --waitretry=0 \ 466 --timeout=1 \ 467 --user admin \ 468 --password secret \ 469 -a wget-bank-check.log \ 470 -o /dev/null \ 471 -O /dev/null \ 472 "http://localhost:${BANK_PORT}/" || continue 473 OK="1" 474 break 475 done 476 if [ "1" != "$OK" ] 477 then 478 exit_skip "Failed to launch services (bank)" 479 fi 480 echo " OK" 481 fi 482 483 STAGE="accounts" 484 485 if [ "1" = "$START_FAKEBANK" ] 486 then 487 echo -n "Register Fakebank users ..." 488 register_fakebank_account fortytwo password 489 register_fakebank_account fortythree password 490 register_fakebank_account exchange password 491 register_fakebank_account tor password 492 register_fakebank_account gnunet password 493 register_fakebank_account tutorial password 494 register_fakebank_account survey password 495 echo " DONE" 496 fi 497 498 if [ "1" = "$START_BANK" ] 499 then 500 echo -n "Register bank users ..." 501 # The specified IBAN and name must match the ones hard-coded into 502 # the C helper for the add-incoming call. Without this value, 503 # libeufin-bank won't find the target account to debit along a /add-incoming 504 # call. 505 register_bank_account fortytwo password "User42" FR7630006000011234567890189 506 register_bank_account fortythree password "Forty Three" 507 register_bank_account exchange password "Exchange Company" DE989651 508 register_bank_account tor password "Tor Project" 509 register_bank_account gnunet password "GNUnet" 510 register_bank_account tutorial password "Tutorial" 511 register_bank_account survey password "Survey" 512 echo " DONE" 513 fi 514 515 STAGE="exchange" 516 517 if [ "1" = "$START_EXCHANGE" ] 518 then 519 echo -n "Starting exchange ..." 520 EXCHANGE_PORT=$(taler-exchange-config -c "$CONF" -s EXCHANGE -o PORT) 521 SERVE=$(taler-exchange-config -c "$CONF" -s EXCHANGE -o SERVE) 522 if [ "${SERVE}" = "unix" ] 523 then 524 EXCHANGE_URL=$(taler-exchange-config -c "$CONF" -s EXCHANGE -o BASE_URL) 525 else 526 EXCHANGE_URL="http://localhost:${EXCHANGE_PORT}/" 527 fi 528 MASTER_PRIV_FILE=$(taler-exchange-config -f -c "${CONF}" -s "EXCHANGE-OFFLINE" -o "MASTER_PRIV_FILE") 529 MASTER_PRIV_DIR=$(dirname "$MASTER_PRIV_FILE") 530 mkdir -p "${MASTER_PRIV_DIR}" 531 if [ ! -e "$MASTER_PRIV_FILE" ] 532 then 533 gnunet-ecc -g1 "$MASTER_PRIV_FILE" > /dev/null 2> /dev/null 534 echo -n "." 535 fi 536 MASTER_PUB=$(gnunet-ecc -p "${MASTER_PRIV_FILE}") 537 MPUB=$(taler-exchange-config -c "$CONF" -s exchange -o MASTER_PUBLIC_KEY) 538 if [ "$MPUB" != "$MASTER_PUB" ] 539 then 540 echo -n " patching master_pub ($MASTER_PUB)..." 541 taler-exchange-config -c "$CONF" -s exchange -o MASTER_PUBLIC_KEY -V "$MASTER_PUB" 542 fi 543 taler-exchange-dbinit \ 544 -c "$CONF" \ 545 --reset 546 $USE_VALGRIND taler-exchange-secmod-eddsa \ 547 -c "$CONF" \ 548 -L "$LOGLEVEL" \ 549 2> taler-exchange-secmod-eddsa.log & 550 $USE_VALGRIND taler-exchange-secmod-rsa \ 551 -c "$CONF" \ 552 -L "$LOGLEVEL" \ 553 2> taler-exchange-secmod-rsa.log & 554 $USE_VALGRIND taler-exchange-secmod-cs \ 555 -c "$CONF" \ 556 -L "$LOGLEVEL" \ 557 2> taler-exchange-secmod-cs.log & 558 $USE_VALGRIND taler-exchange-httpd \ 559 -c "$CONF" \ 560 -L "$LOGLEVEL" 2> taler-exchange-httpd.log & 561 echo " DONE" 562 fi 563 564 STAGE="donau" 565 566 if [ "1" = "$START_DONAU" ] 567 then 568 echo -n "Starting Donau ..." 569 DONAU_PORT=$(donau-config -c "$CONF" -s DONAU -o PORT) 570 SERVE=$(donau-config -c "$CONF" -s DONAU -o SERVE) 571 if [ "${SERVE}" = "unix" ] 572 then 573 DONAU_URL=$(donau-config -c "$CONF" -s DONAU -o BASE_URL) 574 else 575 DONAU_URL="http://localhost:${DONAU_PORT}/" 576 fi 577 donau-dbinit -c "$CONF" --reset 578 $USE_VALGRIND donau-secmod-eddsa -c "$CONF" -L "$LOGLEVEL" 2> donau-secmod-eddsa.log & 579 $USE_VALGRIND donau-secmod-rsa -c "$CONF" -L "$LOGLEVEL" 2> donau-secmod-rsa.log & 580 $USE_VALGRIND donau-secmod-cs -c "$CONF" -L "$LOGLEVEL" 2> donau-secmod-cs.log & 581 $USE_VALGRIND donau-httpd -c "$CONF" -L "$LOGLEVEL" 2> donau-httpd.log & 582 echo " DONE" 583 fi 584 585 STAGE="wirewatch" 586 587 if [ "1" = "$START_WIREWATCH" ] 588 then 589 echo -n "Starting wirewatch ..." 590 $USE_VALGRIND taler-exchange-wirewatch \ 591 --account="$USE_ACCOUNT" \ 592 -c "$CONF" \ 593 -L "$LOGLEVEL" \ 594 --longpoll-timeout="60 s" \ 595 2> taler-exchange-wirewatch.log & 596 echo " DONE" 597 fi 598 599 STAGE="aggregator" 600 601 if [ "1" = "$START_AGGREGATOR" ] 602 then 603 echo -n "Starting aggregator ..." 604 $USE_VALGRIND taler-exchange-aggregator \ 605 -c "$CONF" \ 606 -L "$LOGLEVEL" \ 607 2> taler-exchange-aggregator.log & 608 echo " DONE" 609 fi 610 611 STAGE="transfer" 612 613 if [ "1" = "$START_TRANSFER" ] 614 then 615 echo -n "Starting transfer ..." 616 $USE_VALGRIND taler-exchange-transfer \ 617 -c "$CONF" \ 618 -L "$LOGLEVEL" \ 619 2> taler-exchange-transfer.log & 620 echo " DONE" 621 fi 622 623 STAGE="merchant" 624 625 if [ -n "${USE_MERCHANT_EXCHANGE+x}" ] 626 then 627 MEPUB=$(taler-merchant-config -c "$CONF" -s "${USE_MERCHANT_EXCHANGE}" -o MASTER_KEY) 628 MXPUB=${MASTER_PUB:-$(taler-exchange-config -c "$CONF" -s exchange -o MASTER_PUBLIC_KEY)} 629 if [ "$MEPUB" != "$MXPUB" ] 630 then 631 echo -n " patching master_pub ($MXPUB)..." 632 taler-merchant-config -c "$CONF" -s "${USE_MERCHANT_EXCHANGE}" -o MASTER_KEY -V "$MXPUB" 633 else 634 echo -n " with exchange $MXPUB ..." 635 fi 636 fi 637 638 if [ "1" = "$START_MERCHANT" ] 639 then 640 echo -n "Starting merchant ..." 641 MERCHANT_TYPE=$(taler-merchant-config -c "$CONF" -s MERCHANT -o SERVE) 642 if [ "unix" = "$MERCHANT_TYPE" ] 643 then 644 MERCHANT_URL="$(taler-merchant-config -c "$CONF" -s MERCHANT -o BASE_URL)" 645 else 646 MERCHANT_PORT="$(taler-merchant-config -c "$CONF" -s MERCHANT -o PORT)" 647 MERCHANT_URL="http://localhost:${MERCHANT_PORT}/" 648 fi 649 taler-merchant-dbinit \ 650 -c "$CONF" \ 651 --reset &> taler-merchant-dbinit.log 652 $USE_VALGRIND taler-merchant-exchangekeyupdate \ 653 -c "$CONF" \ 654 -L "$LOGLEVEL" 2> taler-merchant-exchangekeyupdate.log & 655 $USE_VALGRIND taler-merchant-kyccheck \ 656 -c "$CONF" \ 657 -L "$LOGLEVEL" 2> taler-merchant-kyccheck.log & 658 $USE_VALGRIND taler-merchant-httpd \ 659 -c "$CONF" \ 660 -L "$LOGLEVEL" 2> taler-merchant-httpd.log & 661 $USE_VALGRIND taler-merchant-webhook \ 662 -c "$CONF" \ 663 -L "$LOGLEVEL" 2> taler-merchant-webhook.log & 664 echo " DONE" 665 if [ "1" = "$START_MERCHANT_WIREWATCH" ] 666 then 667 echo -n "Starting taler-merchant-wirewatch ..." 668 $USE_VALGRIND taler-merchant-wirewatch \ 669 -c "$CONF" \ 670 -L "$LOGLEVEL" \ 671 --persist \ 672 2> taler-merchant-wirewatch.log & 673 echo " DONE" 674 fi 675 if [ "1" = "$START_MERCHANT_EXCHANGE" ] 676 then 677 echo -n "Starting taler-merchant-exchange ..." 678 $USE_VALGRIND taler-merchant-exchange \ 679 -c "$CONF" \ 680 -L "$LOGLEVEL" 2> taler-merchant-exchange.log & 681 echo " DONE" 682 fi 683 if [ "1" = "$START_DEPOSITCHECK" ] 684 then 685 echo -n "Starting taler-merchant-depositcheck ..." 686 $USE_VALGRIND taler-merchant-depositcheck \ 687 -c "$CONF" \ 688 -L "$LOGLEVEL" 2> taler-merchant-depositcheck.log & 689 echo " DONE" 690 fi 691 if [ "1" = "$START_MERCHANT_DONAUKEYUPDATE" ] 692 then 693 echo -n "Starting taler-merchant-donaukeyupdate..." 694 $USE_VALGRIND taler-merchant-donaukeyupdate \ 695 -c "$CONF" \ 696 -L "$LOGLEVEL" 2> taler-merchant-donaukeyupdate.log & 697 echo " DONE" 698 fi 699 fi 700 701 STAGE="sync" 702 703 if [ "1" = "$START_BACKUP" ] 704 then 705 echo -n "Starting sync ..." 706 SYNC_PORT=$(sync-config -c "$CONF" -s SYNC -o PORT) 707 SERVE=$(sync-config -c "$CONF" -s SYNC -o SERVE) 708 if [ "${SERVE}" = "unix" ] 709 then 710 SYNC_URL=$(sync-config -c "$CONF" -s SYNC -o BASE_URL) 711 else 712 SYNC_URL="http://localhost:${SYNC_PORT}/" 713 fi 714 sync-dbinit -c "$CONF" --reset 715 $USE_VALGRIND sync-httpd \ 716 -c "$CONF" \ 717 -L "$LOGLEVEL" \ 718 2> sync-httpd.log & 719 echo " DONE" 720 fi 721 722 STAGE="challenger" 723 724 if [ "1" = "$START_CHALLENGER" ] 725 then 726 echo -n "Starting challenger ..." 727 CHALLENGER_PORT=$(challenger-config -c "$CONF" -s CHALLENGER -o PORT) 728 SERVE=$(challenger-config -c "$CONF" -s CHALLENGER -o SERVE) 729 if [ "${SERVE}" = "unix" ] 730 then 731 CHALLENGER_URL=$(challenger-config -c "$CONF" -s CHALLENGER -o BASE_URL) 732 else 733 CHALLENGER_URL="http://localhost:${CHALLENGER_PORT}/" 734 fi 735 challenger-dbinit \ 736 -c "$CONF" \ 737 --reset 738 $USE_VALGRIND challenger-httpd \ 739 -c "$CONF" \ 740 -L "$LOGLEVEL" \ 741 2> challenger-httpd.log & 742 echo " DONE" 743 for SECTION in $(taler-exchange-config -c "$CONF" -S | grep kyc-provider) 744 do 745 LOGIC=$(taler-exchange-config -c "$CONF" -s "$SECTION" -o "LOGIC") 746 if [ "${LOGIC}" = "oauth2" ] 747 then 748 INFO=$(taler-exchange-config -c "$CONF" -s "$SECTION" -o "KYC_OAUTH2_INFO_URL") 749 if [ "${CHALLENGER_URL}info" = "$INFO" ] 750 then 751 echo -n "Enabling Challenger client for $SECTION" 752 CLIENT_SECRET=$(taler-exchange-config -c "$CONF" -s "$SECTION" -o "KYC_OAUTH2_CLIENT_SECRET") 753 RFC_8959_PREFIX="secret-token:" 754 if ! echo "${CLIENT_SECRET}" | grep ^${RFC_8959_PREFIX} > /dev/null 755 then 756 exit_fail "Client secret does not begin with '${RFC_8959_PREFIX}'" 757 fi 758 REDIRECT_URI="${EXCHANGE_URL}kyc-proof/kyc-provider-example-challeger" 759 CLIENT_ID=$(challenger-admin --add="${CLIENT_SECRET}" --quiet "${REDIRECT_URI}") 760 taler-exchange-config -c "$CONF" -s "$SECTION" -o KYC_OAUTH2_CLIENT_ID -V "$CLIENT_ID" 761 echo " DONE" 762 fi 763 fi 764 done 765 fi 766 767 STAGE="auditor" 768 769 if [ "1" = "$START_AUDITOR" ] 770 then 771 echo -n "Starting auditor ..." 772 773 export TALER_AUDITOR_SALT=$(taler-auditor-config -c "$CONF" -s AUDITOR -o TALER_AUDITOR_SALT) 774 775 AUDITOR_URL=$(taler-auditor-config -c "$CONF" -s AUDITOR -o BASE_URL) 776 AUDITOR_PRIV_FILE=$(taler-auditor-config -f -c "$CONF" -s AUDITOR -o AUDITOR_PRIV_FILE) 777 AUDITOR_PRIV_DIR=$(dirname "$AUDITOR_PRIV_FILE") 778 mkdir -p "$AUDITOR_PRIV_DIR" 779 if [ ! -e "$AUDITOR_PRIV_FILE" ] 780 then 781 gnunet-ecc -g1 "$AUDITOR_PRIV_FILE" > /dev/null 2> /dev/null 782 echo -n "." 783 fi 784 AUDITOR_PUB=$(gnunet-ecc -p "${AUDITOR_PRIV_FILE}") 785 APUB=$(taler-exchange-config -c "$CONF" -s auditor -o PUBLIC_KEY) 786 if [ "$APUB" != "$AUDITOR_PUB" ] 787 then 788 echo -n " patching auditor public key ..." 789 # Using taler-exchange-config is correct here, we don't want to 790 # suddenly use the auditor-defaults while editing... 791 taler-exchange-config -c "$CONF" -s auditor -o PUBLIC_KEY -V "$AUDITOR_PUB" 792 fi 793 794 taler-auditor-dbinit \ 795 -c "$CONF" \ 796 --reset 797 echo "Launching auditor using $CONF" > taler-auditor-httpd.log 798 echo "Launching auditor using $AUDITOR_PUB from $AUDITOR_PRIV_FILE" \ 799 >> taler-auditor-httpd.log 800 $USE_VALGRIND taler-auditor-httpd \ 801 -L "$LOGLEVEL" \ 802 -c "$CONF" 2>> taler-auditor-httpd.log & 803 echo " DONE" 804 fi 805 806 STAGE="wait" 807 808 echo -n "Waiting for Taler services ..." 809 # Wait for all other taler services to be available 810 E_DONE=0 811 D_DONE=0 812 M_DONE=0 813 S_DONE=0 814 K_DONE=0 815 A_DONE=0 816 for n in $(seq 1 30) 817 do 818 sleep "$DEFAULT_SLEEP" 819 OK="0" 820 if [ "0" = "$E_DONE" ] && [ "1" = "$START_EXCHANGE" ] 821 then 822 echo -n "E" 823 wget \ 824 --tries=1 \ 825 --timeout=1 \ 826 "${EXCHANGE_URL}config" \ 827 -o /dev/null \ 828 -O /dev/null >/dev/null || continue 829 E_DONE=1 830 fi 831 if [ "0" = "$D_DONE" ] && [ "1" = "$START_DONAU" ] 832 then 833 echo -n "D" 834 wget \ 835 --tries=1 \ 836 --timeout=1 \ 837 "${DONAU_URL}config" \ 838 -o /dev/null \ 839 -O /dev/null >/dev/null || continue 840 D_DONE=1 841 fi 842 if [ "0" = "$M_DONE" ] && [ "1" = "$START_MERCHANT" ] 843 then 844 echo -n "M" 845 wget \ 846 --tries=1 \ 847 --timeout=1 \ 848 "${MERCHANT_URL}config" \ 849 -o /dev/null \ 850 -O /dev/null >/dev/null || continue 851 M_DONE=1 852 fi 853 if [ "0" = "$S_DONE" ] && [ "1" = "$START_BACKUP" ] 854 then 855 echo -n "S" 856 wget \ 857 --tries=1 \ 858 --timeout=1 \ 859 "${SYNC_URL}config" \ 860 -o /dev/null \ 861 -O /dev/null >/dev/null || continue 862 S_DONE=1 863 fi 864 if [ "0" = "$K_DONE" ] && [ "1" = "$START_CHALLENGER" ] 865 then 866 echo -n "K" 867 wget \ 868 --tries=1 \ 869 --timeout=1 \ 870 "${CHALLENGER_URL}config" \ 871 -o /dev/null \ 872 -O /dev/null >/dev/null || continue 873 K_DONE=1 874 fi 875 if [ "0" = "$A_DONE" ] && [ "1" = "$START_AUDITOR" ] 876 then 877 echo -n "A" 878 wget \ 879 --tries=1 \ 880 --timeout=1 \ 881 "${AUDITOR_URL}config" \ 882 -o /dev/null \ 883 -O /dev/null >/dev/null || continue 884 A_DONE=1 885 fi 886 OK="1" 887 break 888 done 889 if [ 1 != "$OK" ] 890 then 891 exit_skip "Failed to launch (some) Taler services (E: $E_DONE, M: $M_DONE, S: $S_DONE, K: $K_DONE, A: $A_DONE, D: $D_DONE)" 892 fi 893 echo " OK" 894 895 if [ "1" = "$START_EXCHANGE" ] 896 then 897 echo -n "Wait for exchange /management/keys to be ready " 898 OK="0" 899 LAST_RESPONSE=$(mktemp tmp-last-response.XXXXXXXX) 900 for n in $(seq 1 10) 901 do 902 echo -n "." 903 sleep "$DEFAULT_SLEEP" 904 # exchange 905 wget \ 906 --tries=3 \ 907 --waitretry=0 \ 908 --timeout=30 \ 909 "${EXCHANGE_URL}management/keys"\ 910 -o /dev/null \ 911 -O "$LAST_RESPONSE" \ 912 >/dev/null || continue 913 OK="1" 914 break; 915 done 916 if [ "1" != "$OK" ] 917 then 918 cat "$LAST_RESPONSE" 919 exit_fail "Failed to setup exchange keys, check secmod logs" 920 fi 921 rm "$LAST_RESPONSE" 922 echo " OK" 923 924 echo -n "Setting up exchange keys ..." 925 rm -f test_exchange_api_home/.local/share/taler-exchange/offline/secm_tofus.pub 926 NEXT_YEAR=$(expr 1 + $(date +%Y)) 927 taler-exchange-offline -c "$CONF" \ 928 download \ 929 sign \ 930 wire-fee now "$WIRE_DOMAIN" "$CURRENCY:0.01" "$CURRENCY:0.01" \ 931 wire-fee "$NEXT_YEAR" "$WIRE_DOMAIN" "$CURRENCY:0.01" "$CURRENCY:0.01" \ 932 global-fee now "$CURRENCY:0.01" "$CURRENCY:0.01" "$CURRENCY:0.0" 1h 1year 5 \ 933 global-fee "$NEXT_YEAR" "$CURRENCY:0.01" "$CURRENCY:0.01" "$CURRENCY:0.0" 1h 1year 5 \ 934 upload &> taler-exchange-offline.log 935 echo "OK" 936 ENABLED=$(taler-exchange-config -c "$CONF" -s "$USE_ACCOUNT" -o "ENABLE_CREDIT") 937 if [ "YES" = "$ENABLED" ] 938 then 939 echo -n "Configuring bank account $USE_ACCOUNT ..." 940 EXCHANGE_PAYTO_URI=$(taler-exchange-config -c "$CONF" -s "$USE_ACCOUNT" -o "PAYTO_URI") 941 taler-exchange-offline -c "$CONF" \ 942 enable-account "$EXCHANGE_PAYTO_URI" \ 943 upload &> "taler-exchange-offline-account.log" 944 echo " OK" 945 else 946 echo "WARNING: Account ${USE_ACCOUNT} not enabled (set to: '$ENABLED')" 947 fi 948 if [ "1" = "$START_AUDITOR" ] 949 then 950 echo -n "Enabling auditor ..." 951 taler-exchange-offline -c "$CONF" \ 952 enable-auditor "$AUDITOR_PUB" "$AUDITOR_URL" "$CURRENCY Auditor" \ 953 upload &> taler-exchange-offline-auditor.log 954 echo "OK" 955 fi 956 957 echo -n "Checking /keys " 958 OK="0" 959 LAST_RESPONSE=$(mktemp tmp-last-response.XXXXXXXX) 960 for n in $(seq 1 10) 961 do 962 echo -n "." 963 sleep "$DEFAULT_SLEEP" 964 wget \ 965 --tries=1 \ 966 --timeout=5 \ 967 "${EXCHANGE_URL}keys" \ 968 -a wget-keys-check.log \ 969 -o /dev/null \ 970 -O "$LAST_RESPONSE" \ 971 >/dev/null || continue 972 OK="1" 973 break 974 done 975 if [ "1" != "$OK" ] 976 then 977 cat "$LAST_RESPONSE" 978 exit_fail " Failed to fetch ${EXCHANGE_URL}keys" 979 fi 980 rm "$LAST_RESPONSE" 981 echo " OK" 982 fi 983 984 if [ "1" = "$START_AUDITOR" ] 985 then 986 echo -n "Setting up auditor signatures ..." 987 timeout 15 taler-auditor-offline -c "$CONF" \ 988 download \ 989 sign \ 990 upload &> taler-auditor-offline.log 991 echo " OK" 992 993 echo -n "Starting helpers " 994 995 $USE_VALGRIND taler-helper-auditor-coins \ 996 -L "$LOGLEVEL" \ 997 -c "$CONF" 2> taler-helper-auditor.log & 998 echo -n "." 999 1000 $USE_VALGRIND taler-helper-auditor-reserves \ 1001 -L "$LOGLEVEL" \ 1002 -c "$CONF" 2> taler-helper-auditor.log & 1003 echo -n "." 1004 1005 $USE_VALGRIND taler-helper-auditor-purses \ 1006 -L "$LOGLEVEL" \ 1007 -c "$CONF" 2> taler-helper-auditor.log & 1008 echo -n "." 1009 1010 $USE_VALGRIND taler-helper-auditor-aggregation \ 1011 -L "$LOGLEVEL" \ 1012 -c "$CONF" 2> taler-helper-auditor.log & 1013 echo -n "." 1014 1015 $USE_VALGRIND taler-helper-auditor-deposits \ 1016 -L "$LOGLEVEL" \ 1017 -c "$CONF" 2> taler-helper-auditor.log & 1018 echo -n "." 1019 1020 echo " OK" 1021 1022 fi 1023 1024 STAGE="ready" 1025 1026 # Signal caller that we are ready. 1027 echo "<<READY>>" 1028 1029 if [ "1" = "$WAIT_FOR_SIGNAL" ] 1030 then 1031 while true 1032 do 1033 sleep 0.1 1034 done 1035 else 1036 # Wait until caller stops us. 1037 # shellcheck disable=SC2162 1038 read 1039 fi 1040 1041 1042 1043 STAGE="exiting" 1044 1045 echo "Taler unified setup terminating!" >&2 1046 EXIT_STATUS=0 1047 exit "$EXIT_STATUS"