Revert "Revert "oran-shell-release: release image for F""
[pti/rtp.git] / meta-starlingx / meta-stx-virt / recipes-containers / kubernetes / files / helm-upload
1 #!/bin/bash
2
3 #
4 # Copyright (c) 2018 Wind River Systems, Inc.
5 #
6 # SPDX-License-Identifier: Apache-2.0
7 #
8
9 # This script takes the names of packaged helm charts as arguments.
10 # It installs them in the on-node helm chart repository and regenerates
11 # the repository index.
12
13
14 # We want to run as the "www" user and scripts can't be setuid.  The
15 # sudoers permissions are set up to allow wrsroot to run this script
16 # as the "www" user without a password.
17 if [ $USER != "www" ]; then
18     exec sudo -u www $0 $@
19 fi
20
21
22 RETVAL=0
23 REINDEX=0
24
25 REPO_BASE='/www/pages/helm_charts'
26
27 # First argument is always the repo where the charts need to be placed
28 if [ $# -lt 2 ]; then
29     echo "Usage: helm-upload <repo name> <chart 1> .. <chart N>"
30     exit 1
31 fi
32
33 # Make sure the repo directory exists
34 REPO_DIR="${REPO_BASE}/$1"
35 if [ ! -e $REPO_DIR ]; then
36     echo "$REPO_DIR doesn't exist."
37     exit 1
38 fi
39
40 shift 1
41
42 for FILE in "$@"; do
43     if [ -r $FILE ]; then
44         # QUESTION:  should we disallow overwriting an existing file?
45         # The versions are embedded in the filename, so it shouldn't
46         # cause problems.
47         cp $FILE $REPO_DIR
48         if [ $? -ne 0 ]; then
49             echo Problem adding $FILE to helm chart registry.
50             RETVAL=1
51         else
52             REINDEX=1
53         fi
54     else
55         echo Cannot read file ${FILE}.
56         RETVAL=1
57     fi
58 done
59
60
61 # Now re-index the helm repository if we successfully copied in
62 # any new charts.
63 if [ $REINDEX -eq 1 ]; then
64     /usr/sbin/helm repo index $REPO_DIR
65 fi
66
67 exit $RETVAL