blob: 29c8f510b461a50d4605f086359b0e8e806cd0cf [file] [log] [blame]
Joey Armstrong3691f4f2024-04-16 09:30:06 -04001#!/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##-------------------##
23declare -x -g BROWSER="${BROWSER:-/usr/local/bin/firefox}"
24
25declare -a comps=()
26declare -a search=()
27declare -a servs=()
28
29##--------------------##
30##---] INCLUDES [---##
31##--------------------##
32
33function usage()
34{
35 cat <<EOH
36Usage: $0
37 --computer View jenkins node UI
38 --serv(er) {cord}
39
40EOH
41}
42
43##----------------##
44##---] MAIN [---##
45##----------------##
46[[ $# -eq 0 ]] && { set -- '--help'; }
47
48declare -a urls=()
49while [ $# -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
77 *)
78 arg="$1"; shift
79 search+=("$arg")
80 declare -g -i argv_search=1
81 ;;
82 esac
83done
84
85[[ ${#urls[@]} -eq 0 ]] && { servs+=('jenkins.opencord.org'); }
86
87if [[ -v argv_comp ]]; then
88 urls+=("https://${serv}/computer")
89 for serv in "${servs[@]}";
90 do
91 for comp in "${comps[@]}";
92 do
93 urls+=("https://${serv}/computer/$comp")
94 done
95 done
96fi
97
98if [[ -v argv_search ]]; then
99 base='https://jenkins.opencord.org/view/bbsim/search'
100 for search in "${search[@]}";
101 do
102 urls+=("${base}?q=${search}")
103 done
104 # https://jenkins.opencord.org/view/bbsim/search/?q=bbs&Jenkins-Crumb=2368d5a9f8f7999b720d0bf0dc605ef2230dce1a77baad6ab1dd1d8b2f4799ea
105fi
106
107if [[ ! -v argv_comp ]] && [[ ! -v argv_search ]]; then
108 urls+=("https://jenkins.opencord.org")
109fi
110
111[[ ${#urls[@]} -gt 0 ]] && { "$BROWSER" "${urls[@]}" & }
112
113# [EOF]