Add jenkins.sh script
Change-Id: I39774f17a646e146a5d8b9807b221473ca7a1ea7
diff --git a/jenkins/bin/jenkins.sh b/jenkins/bin/jenkins.sh
new file mode 100755
index 0000000..29c8f51
--- /dev/null
+++ b/jenkins/bin/jenkins.sh
@@ -0,0 +1,113 @@
+#!/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
+ ;;
+
+ *)
+ arg="$1"; shift
+ search+=("$arg")
+ declare -g -i argv_search=1
+ ;;
+ 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]