Joey Armstrong | 3691f4f | 2024-04-16 09:30:06 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | ## ----------------------------------------------------------------------- |
| 3 | ## Intent: Construct gerrit server queries and URLs based on arguments |
| 4 | ## ----------------------------------------------------------------------- |
| 5 | |
| 6 | { # loader |
| 7 | declare pgm='' |
| 8 | pgm="$(realpath --canonicalize-existing "$0")" |
| 9 | readonly pgm |
| 10 | |
| 11 | declare libdir="${pgm%/*}" |
| 12 | libdir="${libdir%/*}/jenkins" |
| 13 | readonly libdir |
| 14 | |
| 15 | declare root='' |
| 16 | root="${pgm%%/jenkins/bin/jenkins.sh}" |
| 17 | source "$root/lf/onf-common/common.sh" '--common-args-begin--' |
| 18 | } |
| 19 | |
| 20 | ##-------------------## |
| 21 | ##---] GLOBALS [---## |
| 22 | ##-------------------## |
| 23 | declare -x -g BROWSER="${BROWSER:-/usr/local/bin/firefox}" |
| 24 | |
| 25 | declare -a comps=() |
| 26 | declare -a search=() |
| 27 | declare -a servs=() |
| 28 | |
| 29 | ##--------------------## |
| 30 | ##---] INCLUDES [---## |
| 31 | ##--------------------## |
| 32 | |
| 33 | function usage() |
| 34 | { |
| 35 | cat <<EOH |
| 36 | Usage: $0 |
| 37 | --computer View jenkins node UI |
| 38 | --serv(er) {cord} |
| 39 | |
| 40 | EOH |
| 41 | } |
| 42 | |
| 43 | ##----------------## |
| 44 | ##---] MAIN [---## |
| 45 | ##----------------## |
| 46 | [[ $# -eq 0 ]] && { set -- '--help'; } |
| 47 | |
| 48 | declare -a urls=() |
| 49 | while [ $# -ne 0 ]; do |
| 50 | arg="$1"; shift |
| 51 | case "$arg" in |
| 52 | --help) usage; exit 0 ;; |
| 53 | |
| 54 | ## Modes |
| 55 | --debug) |
| 56 | # shellcheck disable=SC2034 |
| 57 | declare -g -i argv_debug=1 |
| 58 | declare -g -i debug=1 |
| 59 | ;; |
| 60 | |
| 61 | --comp*) |
| 62 | arg="$1"; shift |
| 63 | comps+=("$arg") |
| 64 | |
| 65 | declare -g -i argv_comp=1 |
| 66 | ;; |
| 67 | |
| 68 | --set*) set -x ;; |
| 69 | --serv*) |
| 70 | arg="$1"; shift |
| 71 | case "$arg" in |
| 72 | *cord*) servs+=('jenkins.opencord.org') ;; |
| 73 | *) error "Detected invalid server name [$arg]" ;; |
| 74 | esac |
| 75 | ;; |
| 76 | |
Joey Armstrong | 49d2dce | 2024-04-25 11:22:09 -0400 | [diff] [blame] | 77 | -*) |
| 78 | shopt -s extglob # ON |
| 79 | arg="${arg##+(-)}" # remove switch prefix |
| 80 | shopt -u extglob # OFF |
Joey Armstrong | 3691f4f | 2024-04-16 09:30:06 -0400 | [diff] [blame] | 81 | search+=("$arg") |
| 82 | declare -g -i argv_search=1 |
| 83 | ;; |
Joey Armstrong | 49d2dce | 2024-04-25 11:22:09 -0400 | [diff] [blame] | 84 | |
| 85 | *) error "Detected invalid argument [$arg]" ;; |
Joey Armstrong | 3691f4f | 2024-04-16 09:30:06 -0400 | [diff] [blame] | 86 | esac |
| 87 | done |
| 88 | |
| 89 | [[ ${#urls[@]} -eq 0 ]] && { servs+=('jenkins.opencord.org'); } |
| 90 | |
| 91 | if [[ -v argv_comp ]]; then |
| 92 | urls+=("https://${serv}/computer") |
| 93 | for serv in "${servs[@]}"; |
| 94 | do |
| 95 | for comp in "${comps[@]}"; |
| 96 | do |
| 97 | urls+=("https://${serv}/computer/$comp") |
| 98 | done |
| 99 | done |
| 100 | fi |
| 101 | |
| 102 | if [[ -v argv_search ]]; then |
| 103 | base='https://jenkins.opencord.org/view/bbsim/search' |
| 104 | for search in "${search[@]}"; |
| 105 | do |
| 106 | urls+=("${base}?q=${search}") |
| 107 | done |
| 108 | # https://jenkins.opencord.org/view/bbsim/search/?q=bbs&Jenkins-Crumb=2368d5a9f8f7999b720d0bf0dc605ef2230dce1a77baad6ab1dd1d8b2f4799ea |
| 109 | fi |
| 110 | |
| 111 | if [[ ! -v argv_comp ]] && [[ ! -v argv_search ]]; then |
| 112 | urls+=("https://jenkins.opencord.org") |
| 113 | fi |
| 114 | |
| 115 | [[ ${#urls[@]} -gt 0 ]] && { "$BROWSER" "${urls[@]}" & } |
| 116 | |
| 117 | # [EOF] |