Installer client-setup script: download pgo client binary
This update will download the `pgo` (Linux) or `pgo-mac` (Darwin) binary from
github based on the operating system. The binary will be downloaded to
`~/.pgo/<operator-namespace>` and should be added to the users `PATH`.
# This script should be run after the operator has been deployed
export PGO_OPERATOR_NAMESPACE="${PGO_OPERATOR_NAMESPACE:-pgo}"
PGO_USER_ADMIN="${PGO_USER_ADMIN:-pgouser-admin}"
+PGO_CLIENT_VERSION="${PGO_CLIENT_VERSION:-v4.3.0}"
+PGO_CLIENT_URL="https://github.com/CrunchyData/postgres-operator/releases/download/${PGO_CLIENT_VERSION}"
+
+# Checks operating system and determines which binary to download
+UNAME_RESULT=$(uname)
+if [[ "${UNAME_RESULT}" == "Linux" ]]
+then
+ BIN_NAME="pgo"
+elif [[ "${UNAME_RESULT}" == "Darwin" ]]
+then
+ BIN_NAME="pgo-mac"
+else
+ echo "${UNAME_RESULT} is not supported, valid operating systems are: Linux, Darwin"
+ echo "Exiting..."
+ exit 1
+fi
+
+# Creates the output directory for files
+OUTPUT_DIR="${HOME}/.pgo/${PGO_OPERATOR_NAMESPACE}"
+mkdir -p "${OUTPUT_DIR}"
+# lock down the directory to just this user
+chmod a-rwx,u+rwx "${OUTPUT_DIR}"
+
+echo "Operating System found is ${UNAME_RESULT}. Downloading ${BIN_NAME} client binary..."
+
+FULL_PATH="${PGO_CLIENT_URL}/${BIN_NAME}"
+curl -L "${FULL_PATH}" -o "${OUTPUT_DIR}/${BIN_NAME}"
+chmod +x "${OUTPUT_DIR}/${BIN_NAME}"
+
# Check that the pgouser-admin secret exists
if [ -z "$(kubectl get secret -n ${PGO_OPERATOR_NAMESPACE} ${PGO_USER_ADMIN})" ]
@@ -33,13 +62,6 @@ then
exit 1
fi
-
-# Creates the output directory for files
-OUTPUT_DIR="${HOME}/.pgo/${PGO_OPERATOR_NAMESPACE}"
-mkdir -p "${OUTPUT_DIR}"
-# lock down the directory to just this user
-chmod a-rwx,u+rwx "${OUTPUT_DIR}"
-
# Use the pgouser-admin secret to generate pgouser file
kubectl get secret -n "${PGO_OPERATOR_NAMESPACE}" "${PGO_USER_ADMIN}" -o 'go-template={{.data.username | base64decode }}:{{.data.password | base64decode}}' > $OUTPUT_DIR/pgouser
# ensure this file is locked down to the specific user running this
@@ -54,6 +76,7 @@ chmod a-rwx,u+rw "${OUTPUT_DIR}/client.crt" "${OUTPUT_DIR}/client.key"
echo "pgo client files have been generated, please add the following to your bashrc"
+echo "export PATH=${OUTPUT_DIR}/${BIN_NAME}:\$PATH"
echo "export PGOUSER=${OUTPUT_DIR}/pgouser"
echo "export PGO_CA_CERT=${OUTPUT_DIR}/client.crt"
echo "export PGO_CLIENT_CERT=${OUTPUT_DIR}/client.crt"
