blob: 59b102aa8f1c9c06c72d850666abd56f86b2ac36 [file] [log] [blame]
Joey Armstrong4048c1f2022-12-17 22:24:42 -05001#!/bin/bash
Joey Armstrong6f63edf2024-01-12 11:30:08 -05002# Copyright 2017-2024 Open Networking Foundation (ONF) and the ONF Contributors
Matt Jeanneretc7b437c2019-05-13 12:33:08 -04003#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
Joey Armstronga9deb692023-06-30 18:13:01 -040016##-------------------##
17##---] GLOBALS [---##
18##-------------------##
19# set -euo pipefail
20umask 022
Joey Armstronga9deb692023-06-30 18:13:01 -040021
22## -----------------------------------------------------------------------
23## Intent: Display an error mesage then exit with shell exit status
24## -----------------------------------------------------------------------
25function error()
26{
27 echo "${BASH_SOURCE[0]} ERROR: $*"
28 exit 1
29}
30
31## -----------------------------------------------------------------------
32## Intent: Verify required environment variables are set
33## -----------------------------------------------------------------------
Joey Armstrong62d454f2024-02-08 12:29:47 -050034## TODO: Covert into command line args
35## -----------------------------------------------------------------------
36# shellcheck disable=SC2120
Joey Armstronga9deb692023-06-30 18:13:01 -040037function init()
38{
Joey Armstrong62d454f2024-02-08 12:29:47 -050039 declare -a vars=()
40 vars+=('APP_INSTALL_ROOT')
41 vars+=('APPS_ROOT')
42 vars+=('DOWNLOAD_ROOT')
43 vars+=('KARAF_M2')
44
45 local var
46 for var in "${vars[@]}";
47 do
48 [[ ! -v "$var" ]] && { error "EnvVar ${var}= is required"; }
49 done
50
51 cat <<EOM
52
53** -----------------------------------------------------------------------
54** Running: $0 $@
55** -----------------------------------------------------------------------
56** $(declare -p APP_INSTALL_ROOT)
57** $(declare -p APPS_ROOT)
58** $(declare -p DOWNLOAD_ROOT)
59** -----------------------------------------------------------------------
60EOM
61
62 return
63}
64
65## -----------------------------------------------------------------------
66## Intent: Gather artifact *.oar files to unpack
67## -----------------------------------------------------------------------
68## GIVEN
69## ref An indirect array variable to return values through.
70## dir Directory to glob *.oar files from
71## -----------------------------------------------------------------------
72function get_oar_files()
73{
74 local -n ref=$1 ; shift
75 local dir="$1" ; shift
76
77 readarray -t oars < <(find "$dir" -name '*.oar' -type f -print)
78 [[ ${#oars[@]} -eq 0 ]] && { error "No \*.oar files detected in $dir"; }
79
80 # shellcheck disable=SC2034
81 ref=("${oars[@]}")
Joey Armstronga9deb692023-06-30 18:13:01 -040082 return
83}
84
85##----------------##
86##---] MAIN [---##
87##----------------##
88
Joey Armstrong62d454f2024-02-08 12:29:47 -050089declare arg
90while [[ $# -gt 0 ]]; do
91 arg="$1"; shift
92 case "$arg" in
93 '--debug') declare -g -i debug=1 ;;
94 *) echo "[SKIP] Unknown argument [$arg]" ;;
95 esac
96done
97
Joey Armstronga9deb692023-06-30 18:13:01 -040098init
99
Joey Armstrong62d454f2024-02-08 12:29:47 -0500100declare -a oars
101get_oar_files oars "$DOWNLOAD_ROOT"
102
103for oar in "${oars[@]}"; do
Joey Armstronga9deb692023-06-30 18:13:01 -0400104
105 app_xml="$APP_INSTALL_ROOT/app.xml"
106 oar_basename="${oar##*/}" # bash builtin
107
Joey Armstrong62d454f2024-02-08 12:29:47 -0500108 cat <<EOF
109
110** -----------------------------------------------------------------------
111** Artifact: ${oar##*/}
112** -----------------------------------------------------------------------
113EOF
114
115 echo "Installing application '${oar##*/}'"
Joey Armstronga9deb692023-06-30 18:13:01 -0400116 rm -rf "$APP_INSTALL_ROOT"
117 mkdir -p "$APP_INSTALL_ROOT"
Joey Armstronga9deb692023-06-30 18:13:01 -0400118
Joey Armstrong62d454f2024-02-08 12:29:47 -0500119 ## pushd()/popd(): cd $here && cd $root w/error checking
120 pushd "$APP_INSTALL_ROOT" >/dev/null \
121 || { error "pushd failed: $APP_INSTALL_ROOT"; }
122
123 [[ -v debug ]] && { echo "** Installing: $oar"; }
124
125 set -x
126 rsync --checksum "$oar" "$APP_INSTALL_ROOT/."
127 unzip -oq -d . "$APP_INSTALL_ROOT/${oar_basename}"
128 set +x
129
130 # ------------------------------------------------------------
131 # [IN] <app name="org.opencord.kafka" origin="ONF" version="2.13.2"
132 # [OUT] declare -a names=([0]="org.opencord.kafka")
133 # ------------------------------------------------------------
134 readarray -t names < <(grep 'name=' "$app_xml" \
135 | sed 's/<app name="//g;s/".*//g')
136
137 [[ ${#names[@]} -gt 0 ]] \
138 || { error "Detected invalid name gathering"; }
139
140 printf '** %s\n' "$(declare -p names)"
141 name="${names[0]}"
Joey Armstronga9deb692023-06-30 18:13:01 -0400142 apps_name="$APPS_ROOT/$name"
143
144 mkdir -p "$apps_name"
Joey Armstrong62d454f2024-02-08 12:29:47 -0500145 rsync -v --checksum "$app_xml" "${apps_name}/app.xml"
146
147 touch "${apps_name}/active" # what is this used for (?)
148
149 declare app_png="$APP_INSTALL_ROOT/app.png"
150 [ -f "$app_png" ] && { rsync -v --checksum "$app_png" "${apps_name}/."; }
Joey Armstronga9deb692023-06-30 18:13:01 -0400151 cp "${APP_INSTALL_ROOT}/${oar_basename}" "${apps_name}/${name}.oar"
Joey Armstrong62d454f2024-02-08 12:29:47 -0500152
153 rsync -rv --checksum "${APP_INSTALL_ROOT}/m2/." "$KARAF_M2/."
Joey Armstronga9deb692023-06-30 18:13:01 -0400154 rm -rf "$APP_INSTALL_ROOT"
Joey Armstrong62d454f2024-02-08 12:29:47 -0500155
156 popd >/dev/null || { error "popd failed: $APP_INSTALL_ROOT"; }
157
Matt Jeanneretc7b437c2019-05-13 12:33:08 -0400158done
Joey Armstronga9deb692023-06-30 18:13:01 -0400159
160# [EOF]