...
1#!/usr/bin/env bash
2
3# Copyright The Helm Authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Bash 'Strict Mode'
18# http://redsymbol.net/articles/unofficial-bash-strict-mode
19set -euo pipefail
20IFS=$'\n\t'
21
22# Helper Functions -------------------------------------------------------------
23
24# Display error message and exit
25error_exit() {
26 echo "error: ${1:-"unknown error"}" 1>&2
27 exit 1
28}
29
30# Checks if a command exists. Returns 1 or 0
31command_exists() {
32 hash "${1}" 2>/dev/null
33}
34
35# Program Functions ------------------------------------------------------------
36
37verify_prereqs() {
38 echo "Verifying Prerequisites...."
39 if command_exists gsutil; then
40 echo "Thumbs up! Looks like you have gsutil. Let's continue."
41 else
42 error_exit "Couldn't find gsutil. Bailing out."
43 fi
44}
45
46confirm() {
47 case $response in
48 [yY][eE][sS]|[yY])
49 true
50 ;;
51 *)
52 false
53 ;;
54 esac
55}
56
57# Main -------------------------------------------------------------------------
58
59main() {
60 if [ "$#" -ne 2 ]; then
61 error_exit "Illegal number of parameters. You must pass in local directory path and a GCS bucket name"
62 fi
63
64 echo "Getting ready to sync your local directory ($1) to a remote repository at gs://$2"
65
66 verify_prereqs
67
68 # dry run of the command
69 gsutil rsync -d -n $1 gs://$2
70
71 read -p "Are you sure you would like to continue with these changes? [y/N]} " confirm
72 if [[ $confirm =~ [yY](es)* ]]; then
73 gsutil rsync -d $1 gs://$2
74 else
75 error_exit "Discontinuing sync process."
76 fi
77
78 echo "Your remote chart repository now matches the contents of the $1 directory!"
79
80}
81
82main "${@:-}"
View as plain text