blob: 47f7b492cb329e6e71e676ade694315fda25b014 [file] [log] [blame]
#!/bin/bash
## -----------------------------------------------------------------------
## Intent: Construct gerrit server queries and URLs based on arguments
## -----------------------------------------------------------------------
{ # loader
declare pgm=''
pgm="$(realpath --canonicalize-existing "$0")"
readonly pgm
declare libdir="${pgm%/*}"
libdir="${libdir%/*}/jenkins"
readonly libdir
declare root=''
root="${pgm%%/jenkins/bin/jenkins.sh}"
source "$root/lf/onf-common/common.sh" '--common-args-begin--'
}
##-------------------##
##---] GLOBALS [---##
##-------------------##
declare -x -g BROWSER="${BROWSER:-/usr/local/bin/firefox}"
declare -a comps=()
declare -a search=()
declare -a servs=()
##--------------------##
##---] INCLUDES [---##
##--------------------##
function usage()
{
cat <<EOH
Usage: $0
--computer View jenkins node UI
--serv(er) {cord}
EOH
}
##----------------##
##---] MAIN [---##
##----------------##
[[ $# -eq 0 ]] && { set -- '--help'; }
declare -a urls=()
while [ $# -ne 0 ]; do
arg="$1"; shift
case "$arg" in
--help) usage; exit 0 ;;
## Modes
--debug)
# shellcheck disable=SC2034
declare -g -i argv_debug=1
declare -g -i debug=1
;;
--comp*)
arg="$1"; shift
comps+=("$arg")
declare -g -i argv_comp=1
;;
--set*) set -x ;;
--serv*)
arg="$1"; shift
case "$arg" in
*cord*) servs+=('jenkins.opencord.org') ;;
*) error "Detected invalid server name [$arg]" ;;
esac
;;
-*)
shopt -s extglob # ON
arg="${arg##+(-)}" # remove switch prefix
shopt -u extglob # OFF
search+=("$arg")
declare -g -i argv_search=1
;;
*) error "Detected invalid argument [$arg]" ;;
esac
done
[[ ${#urls[@]} -eq 0 ]] && { servs+=('jenkins.opencord.org'); }
if [[ -v argv_comp ]]; then
urls+=("https://${serv}/computer")
for serv in "${servs[@]}";
do
for comp in "${comps[@]}";
do
urls+=("https://${serv}/computer/$comp")
done
done
fi
if [[ -v argv_search ]]; then
base='https://jenkins.opencord.org/view/bbsim/search'
for search in "${search[@]}";
do
urls+=("${base}?q=${search}")
done
# https://jenkins.opencord.org/view/bbsim/search/?q=bbs&Jenkins-Crumb=2368d5a9f8f7999b720d0bf0dc605ef2230dce1a77baad6ab1dd1d8b2f4799ea
fi
if [[ ! -v argv_comp ]] && [[ ! -v argv_search ]]; then
urls+=("https://jenkins.opencord.org")
fi
[[ ${#urls[@]} -gt 0 ]] && { "$BROWSER" "${urls[@]}" & }
# [EOF]