|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# autocompletion list |
| 4 | +if [ "${1}" = "shortlist" ] |
| 5 | +then |
| 6 | + if [ -z "${2}" ] |
| 7 | + then |
| 8 | + echo "setup version help" |
| 9 | + fi |
| 10 | + exit |
| 11 | +fi |
| 12 | + |
| 13 | +# shellcheck source=scripts/functions |
| 14 | +source "$(dirname "${0}")"/../functions |
| 15 | +GCLOUD_HOME="${DEVON_IDE_HOME}/software/gcloud" |
| 16 | +TOOL_VERSION_COMMAND="${GCLOUD_HOME}/bin/gcloud --version" |
| 17 | +# shellcheck source=scripts/commandlet-cli |
| 18 | +source "$(dirname "${0}")"/../commandlet-cli |
| 19 | + |
| 20 | +function doConfig() { |
| 21 | + local gcloud_config_files="${DEVON_IDE_HOME}/conf/.gcloud" |
| 22 | + local gcloud_config_export="export CLOUDSDK_CONFIG=${gcloud_config_files}" |
| 23 | + if ! grep -q "${gcloud_config_export}" "${DEVON_IDE_HOME}/conf/devon.properties" |
| 24 | + then |
| 25 | + doRunCommand "${gcloud_config_export}" |
| 26 | + echo -e "\n${gcloud_config_export}" >> "${DEVON_IDE_HOME}/conf/devon.properties" |
| 27 | + doEcho "Location of GClouds's configuration files is set to ${gcloud_config_files}" |
| 28 | + fi |
| 29 | +} |
| 30 | + |
| 31 | +# the path of gcloud modules must be added to python's sys.path via .pth file |
| 32 | +function doSetPth() { |
| 33 | + local lib_path="${GCLOUD_HOME}/lib" |
| 34 | + local win_path |
| 35 | + local pth_file="${DEVON_IDE_HOME}/software/python/ext_modules.pth" |
| 36 | + if doIsWindows |
| 37 | + then |
| 38 | + win_path="$(cygpath -w "${lib_path}")" |
| 39 | + if ! grep -Fq "${win_path}" "${pth_file}" &> /dev/null |
| 40 | + then |
| 41 | + echo -e "\n${win_path}" >> "${pth_file}" |
| 42 | + fi |
| 43 | + fi |
| 44 | +} |
| 45 | + |
| 46 | +function doRun() { |
| 47 | + doSetup silent |
| 48 | + doRunCommand "${GCLOUD_HOME}/bin/gcloud ${*}" |
| 49 | +} |
| 50 | + |
| 51 | +function doSetup() { |
| 52 | + doDevonCommand python setup silent |
| 53 | + doSetPth |
| 54 | + doConfig |
| 55 | + if doIsWindows |
| 56 | + then |
| 57 | + doInstall "gcloud" "${GCLOUD_VERSION}" "${1}" "" "${GCLOUD_HOME}" |
| 58 | + else |
| 59 | + doEchoAttention "GCloud is currently not supported for your operation system." |
| 60 | + fi |
| 61 | +} |
| 62 | + |
| 63 | +# CLI |
| 64 | +case ${1} in |
| 65 | +"help" | "-h") |
| 66 | + echo "Setup or run GCloud CLI (command-line interface for Google Cloud Service)." |
| 67 | + echo |
| 68 | + echo "Arguments:" |
| 69 | + echo " setup install gcloud on your machine." |
| 70 | + echo " «args» call gcloud with the specified arguments. Call gcloud --help for details or use gcloud directly as preferred." |
| 71 | + echo |
| 72 | +;; |
| 73 | +"setup" | "s" | "") |
| 74 | + doSetup "${2}" |
| 75 | +;; |
| 76 | +*) |
| 77 | + doRun "${@}" |
| 78 | +;; |
| 79 | +esac |
0 commit comments