GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — bashbox/bashbox at master · bashbox/bashbox Expand file tree/ Copy pathbashboxMore file actions executable file ·1635 lines (1624 loc) · 64.5 KB / Copy pathbashboxFile metadata and controlsexecutable file ·1635 lines (1624 loc) · 64.5 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 #!/usr/bin/env bash main@bashbox%bashbox () { if test "${BASH_VERSINFO[0]}${BASH_VERSINFO[1]}" -lt 43; then { printf '[!!!] \033[1;31m%s\033[0m[%s]: %s\n' ERROR 1 "At least bash 4.3 is required to run this." "Please upgrade bash or use the correct interpreter." "If you're on MacOS, you can install latest bash using brew or nix." 1>&2; exit 1 }; fi; function process::self::exit () { local _r=$?; ( kill -USR1 "$___self_PID" 2> /dev/null || : ) & exit $_r }; function process::self::forcekill () { kill -9 "$___self_PID" 2> /dev/null }; function log::error () { local _retcode="${2:-$?}"; local _exception_line="$1"; local _source="${BB_ERR_SOURCE:-"${BASH_SOURCE[-1]}"}"; function ___errmsg () { printf '[!!!] \033[1;31m%s\033[0m[%s]: %s\n' ERROR "$_retcode" "$@" 1>&2 }; if [[ ! "$_exception_line" == \(*\) ]]; then { ___errmsg "${_source##*/}[${BASH_LINENO[0]}]: ${BB_ERR_MSG:-"$_exception_line"}"; if test -v BB_ERR_MSG; then { printf "STACK TRACE: (TOKEN: %s)\n" "$_exception_line" 1>&2; local -i _frame=0; local _treestack='|-'; local _line _caller _source; while read -r _line _caller _source < <(caller "$_frame"); do { printf '%s >> %s\n' "$_treestack ${_caller}" "${_source##*/}:${_line}" 1>&2; _frame+=1; _treestack+='-' }; done }; fi }; else { ___errmsg "${_source##*/}[${BASH_LINENO[0]}]: SUBSHELL EXITED WITH NON-ZERO STATUS" }; fi; return "$_retcode" }; \command unalias -a || true; set -eEuT -o pipefail; shopt -sq inherit_errexit expand_aliases nullglob; trap 'exit' USR1; trap 'BB_ERR_MSG="UNCAUGHT EXCEPTION" log::error "$BASH_COMMAND" || process::self::exit' ERR; ___self="$0"; ___self_PID="$$"; ___self_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"; ___MAIN_FUNCNAME='main@bashbox%bashbox'; ___self_NAME="BashBox"; ___self_CODENAME="bashbox"; ___self_AUTHORS=("AXON <[email protected]>"); ___self_VERSION="0.4.1"; ___self_DEPENDENCIES=(https://github.com/bashbox/std.git::15dc26b argbash::0.1.1); ___self_REPOSITORY="https://github.com/bashbox/bashbox"; ___self_BASHBOX_COMPAT="0.3.9~"; function bashbox::build::after () { cp "$_target_workfile" "$_arg_path/$CODENAME"; chmod +x "$_arg_path/$CODENAME" }; function pkgfun () { ( echo "$@" ) }; function bb_bootstrap_header () { if test "${BASH_VERSINFO[0]}${BASH_VERSINFO[1]}" -lt 43; then { printf '[!!!] \033[1;31m%s\033[0m[%s]: %s\n' ERROR 1 "At least bash 4.3 is required to run this." "Please upgrade bash or use the correct interpreter." "If you're on MacOS, you can install latest bash using brew or nix." 1>&2; exit 1 }; fi; function process::self::exit () { local _r=$?; ( kill -USR1 "$___self_PID" 2> /dev/null || : ) & exit $_r }; function process::self::forcekill () { kill -9 "$___self_PID" 2> /dev/null }; function log::error () { local _retcode="${2:-$?}"; local _exception_line="$1"; local _source="${BB_ERR_SOURCE:-"${BASH_SOURCE[-1]}"}"; function ___errmsg () { printf '[!!!] \033[1;31m%s\033[0m[%s]: %s\n' ERROR "$_retcode" "$@" 1>&2 }; if [[ ! "$_exception_line" == \(*\) ]]; then { ___errmsg "${_source##*/}[${BASH_LINENO[0]}]: ${BB_ERR_MSG:-"$_exception_line"}"; if test -v BB_ERR_MSG; then { printf "STACK TRACE: (TOKEN: %s)\n" "$_exception_line" 1>&2; local -i _frame=0; local _treestack='|-'; local _line _caller _source; while read -r _line _caller _source < <(caller "$_frame"); do { printf '%s >> %s\n' "$_treestack ${_caller}" "${_source##*/}:${_line}" 1>&2; _frame+=1; _treestack+='-' }; done }; fi }; else { ___errmsg "${_source##*/}[${BASH_LINENO[0]}]: SUBSHELL EXITED WITH NON-ZERO STATUS" }; fi; return "$_retcode" }; \command unalias -a || true; set -eEuT -o pipefail; shopt -sq inherit_errexit expand_aliases nullglob; trap 'exit' USR1; trap 'BB_ERR_MSG="UNCAUGHT EXCEPTION" log::error "$BASH_COMMAND" || process::self::exit' ERR }; unset -f bashbox::build::before bashbox::build::after bashbox::run::before bashbox::run::after; readonly _bashbox_meta_name="Bashbox.sh"; readonly _src_dir_name="src"; readonly _bashbox_home="${HOME:-"${0%/*}"}/.bashbox" && mkdir -p "$_bashbox_home"; readonly _bashbox_registrydir="$_bashbox_home/registry" && mkdir -p "$_bashbox_registrydir"; readonly _bashbox_bindir="$_bashbox_home/bin" && mkdir -p "$_bashbox_bindir"; readonly _bashbox_posix_envfile="$_bashbox_home/env"; readonly _bashbox_fish_envfile="$_bashbox_home/env.fish"; readonly _bashbox_compat_var_name="BASHBOX_COMPAT"; readonly SUBCOMMANDS_DESC=("" "Create a new bashbox project" "Compile a bashbox project" "Cleanup target/ directories" "Install a bashbox project from repo" "Install bashbox into PATH"); _var_exports=(_bashbox_registrydir); for _var in "${_var_exports[@]}"; do { export "$_var" }; done; ( for _envfile in "$_bashbox_posix_envfile" "$_bashbox_fish_envfile"; do { if test ! -e "$_envfile"; then { case "$_envfile" in "$_bashbox_posix_envfile") echo "export PATH=\"$_bashbox_bindir:\$PATH\"" > "$_envfile" ;; "$_bashbox_fish_envfile") echo "set PATH \"$_bashbox_bindir\" \"\$PATH\" && export PATH" > "$_envfile" ;; esac }; fi }; done ) & function log::info () { echo -e "[%%%] \033[1;37minfo\033[0m: $@" }; function log::warn () { echo -e "[***] \033[1;37mwarn\033[0m: $@" }; function println::helpgen () { _positionals=(); _arg_helpname=; _arg_short_desc=; _arg_usage=; _arg_options_desc=; _arg_subcommands=; _arg_examples=; _arg_footer_msg=; function print_help () { printf '%s\n' "<The general help message of my script>"; printf 'Usage: %s [--short-desc <arg>] [--usage <arg>] [--options-desc <arg>] [--subcommands <arg>] [--examples <arg>] [--footer-msg <arg>] [-h|--help] <helpname>\n' "$0"; printf '\t%s\n' "-h, --help: Prints help" }; function parse_commandline () { _positionals_count=0; while test $# -gt 0; do _key="$1"; case "$_key" in --short-desc) test $# -lt 2 && println::error "Missing value for the optional argument '$_key'." 1; _arg_short_desc="$2"; shift ;; --short-desc=*) _arg_short_desc="${_key##--short-desc=}" ;; --usage) test $# -lt 2 && println::error "Missing value for the optional argument '$_key'." 1; _arg_usage="$2"; shift ;; --usage=*) _arg_usage="${_key##--usage=}" ;; --options-desc) test $# -lt 2 && println::error "Missing value for the optional argument '$_key'." 1; _arg_options_desc="$2"; shift ;; --options-desc=*) _arg_options_desc="${_key##--options-desc=}" ;; --subcommands) test $# -lt 2 && println::error "Missing value for the optional argument '$_key'." 1; _arg_subcommands="$2"; shift ;; --subcommands=*) _arg_subcommands="${_key##--subcommands=}" ;; --examples) test $# -lt 2 && println::error "Missing value for the optional argument '$_key'." 1; _arg_examples="$2"; shift ;; --examples=*) _arg_examples="${_key##--examples=}" ;; --footer-msg) test $# -lt 2 && println::error "Missing value for the optional argument '$_key'." 1; _arg_footer_msg="$2"; shift ;; --footer-msg=*) _arg_footer_msg="${_key##--footer-msg=}" ;; -h | --help) print_help; exit 0 ;; -h*) print_help; exit 0 ;; *) _last_positional="$1"; _positionals+=("$_last_positional"); _positionals_count=$((_positionals_count + 1)) ;; esac; shift; done }; function handle_passed_args_count () { local _required_args_string="'helpname'"; test "${_positionals_count}" -ge 1 || _PRINT_HELP=yes println::error "FATAL ERROR: Not enough positional arguments - we require exactly 1 (namely: $_required_args_string), but got only ${_positionals_count}." 1; test "${_positionals_count}" -le 1 || _PRINT_HELP=yes println::error "FATAL ERROR: There were spurious positional arguments --- we expect exactly 1 (namely: $_required_args_string), but got ${_positionals_count} (the last one was: '${_last_positional}')." 1 }; function assign_positional_args () { local _positional_name _shift_for=$1; _positional_names="_arg_helpname "; shift "$_shift_for"; for _positional_name in ${_positional_names}; do test $# -gt 0 || break; eval "$_positional_name=\${1}" || println::error "Error during argument parsing." 1; shift; done }; parse_commandline "$@"; handle_passed_args_count; assign_positional_args 1 "${_positionals[@]}"; echo -e "${_arg_helpname}\c"; if test -n "$_arg_short_desc"; then echo -e " - $_arg_short_desc\n"; else echo; fi; if test -n "$_arg_usage"; then echo -e "USAGE:"; while read -r line; do echo -e " $line"; done < <(echo "$_arg_usage"); echo; fi; for child in "$_arg_options_desc" "$_arg_subcommands"; do if test -n "$child"; then local _startString _endString gapVar; _startString="$(sed 's|<^>.*||g' <<<"${child}")"; _endString="$(sed 's|.*<^>||g' <<<"${child}")"; mapfile -t _startString < <(echo "$_startString"); mapfile -t _endString < <(echo "$_endString"); local i=0; local firstChild=false; ! "$firstChild" && echo -e "OPTIONS:" || echo -e 'SUBCOMMANDS:' && firstChild=true; for line in "${_startString[@]}"; do gapVar="$( for t in $(seq $((30 - ${#line}))); do echo -n " " done )"; echo -e " $line${gapVar}${_endString[$i]}"; i=$((i+1)); done; echo; fi; done; if test -n "$_arg_examples"; then echo -e "EXAMPLES:"; while read -r line; do echo -e " $line"; done < <(echo "$_arg_examples"); echo; fi; if test -n "$_arg_footer_msg"; then echo -e "$_arg_footer_msg\n"; fi }; readonly RC='\033[0m' RED='\033[0;31m' BRED='\033[1;31m' GRAY='\033[1;30m'; readonly BLUE='\033[0;34m' BBLUE='\033[1;34m' CYAN='\033[0;34m' BCYAN='\033[1;34m'; readonly WHITE='\033[1;37m' GREEN='\033[0;32m' BGREEN='\033[1;32m' YELLOW='\033[1;33m'; readonly PURPLE='\033[0;35m' BPURPLE='\033[1;35m' ORANGE='\033[0;33m'; function io::file::check_newline () { local _input="$1"; if ! [[ $(tail -c1 "$_input" | wc -l) -gt 0 ]]; then { echo >> "$_input" }; fi }; function get_temp::file () { if test -w /tmp; then { printf '/tmp/%s\n' ".$$_$((RANDOM * RANDOM))" }; else if res="$(mktemp -u)"; then { printf '%s\n' "$res" && unset res }; else { return 1 }; fi; fi }; function get_temp::dir () { if test -w /tmp; then { printf '%s\n' '/tmp' }; else if res="$(mktemp -u)"; then { printf '%s\n' "${res%/*}" && unset res }; else { return 1 }; fi; fi }; function trap::stack_name () { local sig=${1//[^a-zA-Z0-9]/_}; printf '__trap_stack_%s\n' "$sig" }; function trap::extract () { printf '%s\n' "${3:-}" }; function trap::get () { eval "trap::extract $(trap -p "$1")" }; function trap::push () { local new_trap="$1" && shift; local sig; for sig in $*; do local stack_name="$(trap::stack_name "$sig")"; local old_trap=$(trap::get "$sig"); if test ! -v "$stack_name"; then { eval "${stack_name}=()" }; fi; eval "${stack_name}"'[${#'"${stack_name}"'[@]}]=${old_trap:-}'; trap "${new_trap}" "$sig"; done }; function trap::append () { local new_trap="$1" && shift; local sig; for sig in $*; do if [[ -z "$(trap::get "$sig")" ]]; then trap::push "$new_trap" "$sig"; else trap::push "$(trap::get $sig) ; $new_trap" "$sig"; fi; done }; function lockfile () { local name="$1"; local lock_file; lock_file="$(get_temp::dir)/.${name}.lock"; if test -e "$lock_file"; then { if ! { kill -0 "$(< "$lock_file")" }; then { rm "$lock_file" 2> /dev/null || : }; fi; log::info "Awaiting for another ${name} job to finish" }; fi; for _ in {1..5}; do { while { kill -0 "$(< "$lock_file")" }; do { sleep 0.5 }; done }; done; until ( set -o noclobber && printf '%s\n' "$$" > "$lock_file" ); do { sleep 0.5 }; done; trap::append "rm -f '$lock_file' 2>/dev/null" ${SIGNALS:-EXIT} } 2> /dev/null; function sleep () { [[ -n "${_snore_fd:-}" ]] || { exec {_snore_fd}<> <(:) } 2> /dev/null || { local fifo; fifo=$(mktemp -u); mkfifo -m 700 "$fifo"; exec {_snore_fd}<> "$fifo"; rm "$fifo" }; IFS='' read ${1:+-t "$1"} -u $_snore_fd || : }; function begins_with_short_option () { local first_option all_short_options='h'; first_option="${1:0:1}"; test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0 }; function subcommand::new () { _positionals=(); _arg_path=; _arg_codename=; function print_help () { println::helpgen "${_self_name^^}-${_subcommand_argv^^}" --short-desc "${SUBCOMMANDS_DESC[1]}" --usage "${_self_name} ${_subcommand_argv} [OPTIONAL-OPTIONS] <path>" --options-desc "-c, --codename<^>Avoid directory-as-codename -h, --help<^>Prints this help information" --examples "### The basic way: ${YELLOW}${_self_name} ${_subcommand_argv} awesome_project${RC} ### Pre-setting project codename, avoiding directory-path as codename: ${YELLOW}${_self_name} ${_subcommand_argv} --codename cake awesome_project${RC}" }; function parse_commandline () { _positionals_count=0; while test $# -gt 0; do _key="$1"; case "$_key" in --codename | -c) test $# -lt 2 && log::error "Missing value for the optional argument '$_key'." 1 || exit; _arg_codename="$2"; shift ;; --codename=*) _arg_codename="${_key##--codename=}" ;; -h | --help) print_help; exit 0 ;; -h*) print_help; exit 0 ;; *) _last_positional="$1"; _positionals+=("$_last_positional"); _positionals_count=$((_positionals_count + 1)) ;; esac; shift; done }; function handle_passed_args_count () { local _required_args_string="'path'"; test "${_positionals_count}" -ge 1 || log::error "Not enough positional arguments - we require exactly 1 (namely: $_required_args_string), but got only ${_positionals_count}." 1 || exit; test "${_positionals_count}" -le 1 || log::error "There were spurious positional arguments --- we expect exactly 1 (namely: $_required_args_string), but got ${_positionals_count} (the last one was: '${_last_positional}')." 1 || exit }; function assign_positional_args () { local _positional_name _shift_for=$1; _positional_names="_arg_path "; shift "$_shift_for"; for _positional_name in ${_positional_names}; do test $# -gt 0 || break; eval "$_positional_name=\${1}" || log::error "Error during argument parsing." 1 || exit; shift; done }; parse_commandline "$@"; handle_passed_args_count; assign_positional_args 1 "${_positionals[@]}"; _path_codename="${_arg_path##*/}"; : "${_arg_codename:="$_path_codename"}"; _arg_codename="$(tr -d '[:space:]' <<<"${_arg_codename,,}")"; if test -e "$_arg_path"; then log::error "Destination \`$_arg_path\` already exists.\n\t You may either remove that project dir or use a different path for setup." 1 || exit; fi; log::info "Setting up project at \`$_arg_path\`"; mkdir -p "$_arg_path" || log::error "Failed to initialize the project directory" 1 || exit; mkdir -p "$_arg_path/$_src_dir_name"; cat <<'EOF' > "$_arg_path/$_src_dir_name/main.sh" function main() { echo "Hello world"; } EOF cat <<EOF > "$_arg_path/$_bashbox_meta_name" NAME="$_path_codename" CODENAME="$_arg_codename" AUTHORS=("AXON <[email protected]>") VERSION="1.0" DEPENDENCIES=() REPOSITORY="" BASHBOX_COMPAT="${___self_VERSION}~" EOF log::info "Initializing git version control for your project"; if command -v git > /dev/null; then git init "$_arg_path" > /dev/null || { _r=$?; rm -r "$_arg_path"; log::error "Failed to initialize git at \`$_arg_path\`" $_r || exit }; echo -e '/target' > "$_arg_path/.gitignore"; else rm -r "$_arg_path"; log::error "git does not seem to be available, please install it" 1 || exit; fi }; function subcommand::install () { function trim_leading_trailing () { local _stream="${1:-}"; local _stdin; if test -z "${_stream}"; then { read -r _stdin; _stream="$_stdin" }; fi; _stream="${_stream#"${_stream%%[![:space:]]*}"}"; _stream="${_stream%"${_stream##*[![:space:]]}"}"; printf '%s\n' "$_stream" }; function trim_string () { : "${1#"${1%%[![:space:]]*}"}"; : "${_%"${_##*[![:space:]]}"}"; printf '%s\n' "$_" }; function trim_all () { set -f; set -- $*; printf '%s\n' "$*"; set +f }; function trim_quotes () { : "${1//\'}"; printf '%s\n' "${_//\"}" }; function string::matches () { local _string _match _arg; local _print=false; for _arg in "${@}"; do { case "$_arg" in --print | -p) shift; _print=true ;; esac }; done; if [[ $1 =~ $2 ]]; then { if [ "$_print" == "true" ]; then { echo "${BASH_REMATCH[@]}" }; fi; return 0 }; else { return 1 }; fi }; lockfile "install"; local _arg_force=off; local _arg_syncmeta=off; local _arg_eval; for _arg_eval in "force" "syncmeta"; do { case "$@" in *${_arg_eval}*) eval "_arg_${_arg_eval}=on" ;; esac }; done; unset _arg_eval; local _github_api_root _registry_meta_file; readonly _registry_meta_file="${_bashbox_home}/registry.meta" && touch "$_registry_meta_file"; readonly _github_api_root="https://api.github.com"; function box::syncmeta () { local _registry_meta_url _registry_lastsync_file; readonly _registry_meta_url="https://raw.githubusercontent.com/bashbox/registry/main/registry.meta"; readonly _registry_lastsync_file="${_bashbox_home}/.registry.lastsync" && touch "$_registry_lastsync_file"; local _user_repo _check_file _branch; readonly _user_repo="bashbox/registry"; readonly _check_file="registry.meta"; readonly _branch="main"; local _lock_file="$_bashbox_home/.registry.lastdate"; local _date && _date="$(date '+%d-%m')"; if test "$_arg_offline" == "off"; then { touch "$_lock_file"; if [ "$_arg_syncmeta" == "on" ] || [ "$(< "$_lock_file")" != "$_date" ]; then { echo "$_date" > "$_lock_file"; log::info "Syncing repository metadata"; local _local_sha _remote_sha; _local_sha="$(< "$_registry_lastsync_file")"; _remote_sha="$(curl --silent "${_github_api_root}/repos/${_user_repo}/contents/${_check_file}?ref=${_branch}" | head -n4 | grep -I '"sha":' | sed -E 's/.*"([^"]+)".*/\1/')" || return 0; readonly _local_sha _remote_sha; if test "$_arg_syncmeta" == "on" || test "$_local_sha" != "$_remote_sha"; then { log::info "Updating registry.meta"; curl --silent -o "$_registry_meta_file" -L "$_registry_meta_url"; echo "$_remote_sha" > "$_registry_lastsync_file" }; fi }; fi }; fi }; function box::parsemeta () { local _input="$1"; local _box_dir _box_name; local _repo_source _repo_url _tag_name; IFS='|' read -r _repo_source _tag_name <<< "${_input//::/|}"; : "${_tag_name:="HEAD"}"; if string::matches "$_repo_source" '^file://.*'; then { _box_dir="$_repo_source"; if test ! -e "$_box_dir"; then { log::error "$_box_dir does not exist" 1 || exit }; fi; _arg_force=off; _repo_url=; _box_name="${_box_dir##*/}" }; else if string::matches "$_repo_source" '^.*://.*'; then { local _repo_user _repo_name; _repo_source="${_repo_source%.git}"; _repo_url="${_repo_source}"; IFS='|' read -r _repo_user _repo_name < <( _user="${_repo_source%/*}" && _user="${_user##*/}"; echo -e "${_user}|${_repo_source##*/}"; ); _box_dir="$_bashbox_registrydir/${_repo_user}_${_repo_name}-${_tag_name}"; _box_name="${_repo_name}" }; else if string::matches "$_repo_source" "[a-zA-Z0-9_]"; then { _repo_url="$(grep ".*/${_repo_source}$" "$_registry_meta_file")" || log::error "No such box as $_repo_source was found in the registry" 1 || exit; _box_dir="$_bashbox_registrydir/${_repo_source}-${_tag_name}"; _box_name="${_repo_source##*/}" }; fi; fi; fi; echo "${_box_name}|${_box_dir}|${_repo_url}|${_tag_name}" }; box::syncmeta; local _box _box_dir _gitmod_file; local _path _url _install_path _install_executable _built_executable; for _box in "${@}"; do { if [[ "$_box" =~ ^-- ]]; then { continue }; fi; local _box_name _box_dir _repo_url _tag_name; IFS='|' read -r _box_name _box_dir _repo_url _tag_name <<< "$(box::parsemeta "$_box")"; if test "${EXPORT_USEMOL:-}" == "true"; then { export "_usemol_${_box_name}=${_box_dir}" }; fi; if test -e "$_box_dir"; then { if [ "$_arg_force" == "off" ] && [ -e "$_box_dir/$_bashbox_meta_name" ]; then { if test ! -v EXPORT_USEMOL; then { log::warn "$_box_name already exists" }; fi; continue }; else { rm -rf "$_box_dir" }; fi }; fi; mkdir -p "$_box_dir"; log::info "Downloading box $_box_name $_tag_name"; curl --silent -L "${_repo_url}/archive/${_tag_name}.tar.gz" | tar --strip-components=1 -C "$_box_dir" -xpzf -; _gitmod_file="$_box_dir/.gitmodules"; if test -e "$_gitmod_file"; then { log::info "Resolving git submodules"; while read -r _line; do { _line="${_line%%:*}"; _path="$(sed "${_line}q;d" "$_gitmod_file" | cut -d '=' -f2 | trim_leading_trailing)"; _url="$(sed "$(( _line + 1 ))q;d" "$_gitmod_file" | cut -d '=' -f2 | trim_leading_trailing)"; _install_path="${_box_dir}/${_path}"; log::info "Downloading git submodule: $_path"; mkdir -p "$_install_path"; curl --silent -L "${_url}/archive/${_tag_name}.tar.gz" | tar --strip-components=1 -C "$_install_path" -xpzf - }; done < <(grep -n 'path.*=' "$_gitmod_file") }; fi; if test -e "$_box_dir/$_src_dir_name/main.sh" && test ! -v "EXPORT_USEMOL"; then { log::info "Compiling $_box in release mode"; ( main -C "$_box_dir" build --release ) || { log::error "Errors were found while compiling $_box, operation failed" 1 || exit }; source "$_box_dir/$_bashbox_meta_name"; _built_executable="$_box_dir/target/release/$CODENAME"; _install_executable="$_bashbox_bindir/$CODENAME"; chmod +x "$_built_executable"; ln -srf "$_built_executable" "$_install_executable"; chmod +x "$_install_executable"; log::info "$_box was successfully installed as $CODENAME" }; else { log::info "$_box was installed as a library" }; fi }; done }; function subcommand::build () { lockfile "build"; function print_help () { println::helpgen ${_self_name^^}-${_subcommand_argv^^} --short-desc "${SUBCOMMANDS_DESC[3]}" --usage "${_self_name} ${_subcommand_argv} [OPTIONAL-OPTIONS] <path>" --options-desc "--release<^>Build in release mode --debug<^>Build in debug mode(default) --run<^>Auto-run the executable after build --<^>Pass arguments to your compiled program -h, --help<^>Prints this help information" --examples "### The basic way: # Buld the project in your current directory hierarchy in release-mode ${YELLOW}${_self_name} ${_subcommand_argv} --release${RC} ### Build project from a specified directory: ${YELLOW}${_self_name} ${_subcommand_argv} --release /home/me/awesome_project${RC} ### Pass arguments to the compiled executable and auto-run it after build ${YELLOW}${_self_name} ${_subcommand_argv} --release --run -- arg1 arg2 \"string arg\" and-so-on${RC} " }; clap "$@"; local _orig_PWD="$PWD"; function Resolve::Colons () { local result="$1"; if [[ "$result" =~ (use\ )?([^[:space:]]+)\;$ ]]; then { result="${BASH_REMATCH[2]//::/\/}"; result="${result/box\//}"; result="${result//\/\*/}" }; fi; printf '%s\n' "$result" }; function perform_task () { local _task="bashbox::$1"; if declare -F "$_task" > /dev/null; then { "$_task" }; fi }; function Resolve::UseSymbols () { local _input="$1"; local _parsed_input; _parsed_input="$(Resolve::Colons "$_input")"; local _parsed_input_name="${_parsed_input##*/}" && { local _modname="${_parsed_input_name}"; _parsed_input="${_parsed_input/${_parsed_input_name}/${_parsed_input_name#_}}"; unset _parsed_input_name }; local _ref="_usemol_${_parsed_input%%/*}"; local _src && { if [[ "$_input" =~ use\ box:: ]]; then { _src="${PWD%%/src*}/src" }; else if test -v "$_ref"; then { local _reg_mod_path="${!_ref}"; local _reg_mod_target="${_local_build_registrydir}/${_reg_mod_path##*/}"; if test ! -e "$_reg_mod_target"; then { cp -r "$_reg_mod_path" "$_reg_mod_target" }; fi; _src="$_reg_mod_target/src"; _parsed_input="${_parsed_input#*/}" }; else { _src="$PWD" }; fi; fi; _parsed_input="$_src/$_parsed_input" }; if test "${_modname::1}" == "_" || [[ "$_input" =~ ^[[:space:]]+use ]] || ! [[ "$(< "${_used_symbols_statfile}")" =~ "${_parsed_input}.sh" ]]; then { if test "$_arg_verbose" == "off"; then { echo -e " ${BGREEN}Compiling${RC} $_modname" }; else { echo -e "---------- $_modname" }; fi; if test ! -e "${_parsed_input}.sh" && test ! -e "${_parsed_input}"; then { log::error "$_input is missing" 5 || exit }; fi; if [[ "$_input" =~ \*\;$ ]]; then { printf '\n' > "$_compiled_mod_bundle.sh"; for _modFile in "$_parsed_input/"*; do { printf '%s\n' "$(< "$modFile")" >> "$_compiled_mod_bundle" }; done; _parsed_input="$_compiled_mod_bundle" }; else if test ! -e "${_parsed_input}.sh" && test -d "$_parsed_input"; then { _parsed_input="$_parsed_input/mod" }; fi; fi; cd "$(dirname "$_parsed_input")"; if test "$_arg_verbose" == "on"; then { echo -e "${RED}PWD${RC}: $PWD"; echo -e "${CYAN}File${RC}: ${_parsed_input}.sh" }; fi; mapfile -t _use_symbols < <(grep -w -I -x -E '^\s+use .*;$|^use .*;$' "${_parsed_input}.sh" || true); : ${_last_parsed_input:="${_parsed_input}"}; if test "$_arg_verbose" == "on"; then { echo -e "${PURPLE}Caller${RC}: $_last_parsed_input\n" }; fi; for _symbol in "${_use_symbols[@]}"; do ( _last_parsed_input="${_parsed_input}"; Resolve::UseSymbols "$_symbol" ) || exit 1; done; if test "${_parsed_input}.sh" != "${_last_parsed_input}.sh"; then { bash -n "${_parsed_input}.sh" || log::error "Syntax errors were found" || exit 1; local _insert_stream _input_stream; _insert_stream=$(< "${_parsed_input}.sh"); _input_stream=$(< "${_last_parsed_input}.sh"); printf '%s\n' "${_input_stream/$_input/$_insert_stream}" > "${_last_parsed_input}.sh"; unset _insert_stream _input_stream; printf '%s\n' "${_parsed_input}.sh" >> "$_used_symbols_statfile" }; fi; if test "$_arg_verbose" == "on"; then { echo "$_parsed_input.sh ++ ${_last_parsed_input}.sh($_input)" }; fi }; else { local _input_stream; _input_stream=$(< "${_last_parsed_input}.sh"); printf '%s\n' "${_input_stream/$_input/}" > "${_last_parsed_input}.sh"; unset _input_stream }; fi }; if test -e "$_arg_path/build.sh"; then { source "$_arg_path/build.sh" }; fi; perform_task "build::before"; cd "$_target_workdir"; Resolve::UseSymbols "main"; local _bb_bootstrap; _bb_bootstrap=$(declare -f bb_bootstrap_header) && { _bb_bootstrap="${_bb_bootstrap#*{}"; _bb_bootstrap="${_bb_bootstrap%\}}" }; local _ran="$RANDOM"; local _main_funcname="main@bashbox%${CODENAME}"; local _tmp_target_workfile="$_target_workdir/.${NAME}.$_ran"; if test -e /usr/bin/env; then { |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |