blob: 47f7b492cb329e6e71e676ade694315fda25b014 [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
Joey Armstrong49d2dce2024-04-25 11:22:09 -040077 -*)
78 shopt -s extglob # ON
79 arg="${arg##+(-)}" # remove switch prefix
80 shopt -u extglob # OFF
Joey Armstrong3691f4f2024-04-16 09:30:06 -040081 search+=("$arg")
82 declare -g -i argv_search=1
83 ;;
Joey Armstrong49d2dce2024-04-25 11:22:09 -040084
85 *) error "Detected invalid argument [$arg]" ;;
Joey Armstrong3691f4f2024-04-16 09:30:06 -040086 esac
87done
88
89[[ ${#urls[@]} -eq 0 ]] && { servs+=('jenkins.opencord.org'); }
90
91if [[ -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
100fi
101
102if [[ -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
109fi
110
111if [[ ! -v argv_comp ]] && [[ ! -v argv_search ]]; then
112 urls+=("https://jenkins.opencord.org")
113fi
114
115[[ ${#urls[@]} -gt 0 ]] && { "$BROWSER" "${urls[@]}" & }
116
117# [EOF]