blob: b783565517a28733812af368e59dd7f1d54dba1a [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
21declare -g HERE; HERE="$(pwd)"
22
23## -----------------------------------------------------------------------
24## Intent: Display an error mesage then exit with shell exit status
25## -----------------------------------------------------------------------
26function error()
27{
28 echo "${BASH_SOURCE[0]} ERROR: $*"
29 exit 1
30}
31
32## -----------------------------------------------------------------------
33## Intent: Verify required environment variables are set
34## -----------------------------------------------------------------------
35function init()
36{
37 [[ ! -v APP_INSTALL_ROOT ]] && error "Var APP_INSTALL_ROOT= is required"
38 [[ ! -v DOWNLOAD_ROOT ]] && error "Var DOWNLOAD_ROOT= is required"
39 return
40}
41
42##----------------##
43##---] MAIN [---##
44##----------------##
45
46init
47
48readarray -t OARS < <(find "$DOWNLOAD_ROOT" -name '*.oar')
49for oar in "${OARS[@]}"; do
50
51 app_xml="$APP_INSTALL_ROOT/app.xml"
52 oar_basename="${oar##*/}" # bash builtin
53
54 cd "$HERE" || error "cd $HERE failed"
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040055 echo "Installing application '$oar'"
Joey Armstronga9deb692023-06-30 18:13:01 -040056 rm -rf "$APP_INSTALL_ROOT"
57 mkdir -p "$APP_INSTALL_ROOT"
58 cd "$APP_INSTALL_ROOT" || error "cd $APP_INSTALL_ROOT failed"
59 cp -v "$oar" "$APP_INSTALL_ROOT"
60 unzip -oq -d . "$APP_INSTALL_ROOT/${oar_basename}"
61
62 readarray -t names < <(grep "name=" "$app_xml" \
63 | sed 's/<app name="//g;s/".*//g')
64 [[ ${#names[@]} -gt 0 ]] || error "Detected invalid name gathering"
65 name="${names[1]}"
66 apps_name="$APPS_ROOT/$name"
67
68 mkdir -p "$apps_name"
69 cp "$app_xml" "${apps_name}/app.xml"
70 touch "${apps_name}/active"
71 [ -f "$APP_INSTALL_ROOT/app.png" ] \
72 && cp "$APP_INSTALL_ROOT/app.png" "${apps_name}/app.png"
73 cp "${APP_INSTALL_ROOT}/${oar_basename}" "${apps_name}/${name}.oar"
74 cp -rf "$APP_INSTALL_ROOT/m2/"* "$KARAF_M2"
75 rm -rf "$APP_INSTALL_ROOT"
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040076done
Joey Armstronga9deb692023-06-30 18:13:01 -040077
78# [EOF]