gitlab.azmi.pl/azmi-open-source/helm@v3.0.0-beta.3+incompatible/scripts/sync-repo.sh (about)

     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
    19  set -euo pipefail
    20  IFS=$'\n\t'
    21  
    22  # Helper Functions -------------------------------------------------------------
    23  
    24  # Display error message and exit
    25  error_exit() {
    26    echo "error: ${1:-"unknown error"}" 1>&2
    27    exit 1
    28  }
    29  
    30  # Checks if a command exists.  Returns 1 or 0
    31  command_exists() {
    32    hash "${1}" 2>/dev/null
    33  }
    34  
    35  # Program Functions ------------------------------------------------------------
    36  
    37  verify_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  
    46  confirm() {
    47    case $response in
    48      [yY][eE][sS]|[yY])
    49        true
    50        ;;
    51      *)
    52        false
    53        ;;
    54    esac
    55  }
    56  
    57  # Main -------------------------------------------------------------------------
    58  
    59  main() {
    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  
    82  main "${@:-}"