Joey Armstrong | 4048c1f | 2022-12-17 22:24:42 -0500 | [diff] [blame] | 1 | #!/bin/bash |
Joey Armstrong | 6f63edf | 2024-01-12 11:30:08 -0500 | [diff] [blame] | 2 | # Copyright 2017-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Matt Jeanneret | c7b437c | 2019-05-13 12:33:08 -0400 | [diff] [blame] | 3 | # |
| 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 Armstrong | a9deb69 | 2023-06-30 18:13:01 -0400 | [diff] [blame] | 16 | ##-------------------## |
| 17 | ##---] GLOBALS [---## |
| 18 | ##-------------------## |
| 19 | # set -euo pipefail |
| 20 | umask 022 |
| 21 | declare -g HERE; HERE="$(pwd)" |
| 22 | |
| 23 | ## ----------------------------------------------------------------------- |
| 24 | ## Intent: Display an error mesage then exit with shell exit status |
| 25 | ## ----------------------------------------------------------------------- |
| 26 | function error() |
| 27 | { |
| 28 | echo "${BASH_SOURCE[0]} ERROR: $*" |
| 29 | exit 1 |
| 30 | } |
| 31 | |
| 32 | ## ----------------------------------------------------------------------- |
| 33 | ## Intent: Verify required environment variables are set |
| 34 | ## ----------------------------------------------------------------------- |
| 35 | function 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 | |
| 46 | init |
| 47 | |
| 48 | readarray -t OARS < <(find "$DOWNLOAD_ROOT" -name '*.oar') |
| 49 | for 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 Jeanneret | c7b437c | 2019-05-13 12:33:08 -0400 | [diff] [blame] | 55 | echo "Installing application '$oar'" |
Joey Armstrong | a9deb69 | 2023-06-30 18:13:01 -0400 | [diff] [blame] | 56 | 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 Jeanneret | c7b437c | 2019-05-13 12:33:08 -0400 | [diff] [blame] | 76 | done |
Joey Armstrong | a9deb69 | 2023-06-30 18:13:01 -0400 | [diff] [blame] | 77 | |
| 78 | # [EOF] |