Skip to content

Instantly share code, notes, and snippets.

@renelink
Last active August 26, 2024 15:35
Show Gist options
  • Save renelink/6a12336b5282c94a69a598deddf295ab to your computer and use it in GitHub Desktop.
Save renelink/6a12336b5282c94a69a598deddf295ab to your computer and use it in GitHub Desktop.
Bash utilities for Gradle
#!/usr/bin/env bash
#
# You can import this script in your current bash using the following command
# source <(curl -s https://gist.githubusercontent.com/renelink/6a12336b5282c94a69a598deddf295ab/raw/bash-gradle-utils.sh)
#
# You can also put these lines in your .bashrc or .bash_profile to automatically install the utils if they do not exist
#
# -----------------------------
# BASH_GRADLE_UTILS_FILE="${HOME}/.bash-gradle-utils.sh"
#
# if ! [ -f "${BASH_GRADLE_UTILS_FILE}" ]; then
# curl -o "$BASH_GRADLE_UTILS_FILE" https://gist.githubusercontent.com/renelink/6a12336b5282c94a69a598deddf295ab/raw/bash-gradle-utils.sh
# fi
#
# . "$BASH_GRADLE_UTILS_FILE"
# -----------------------------
#
# To update the git-utils you can then just execute
# $ rm ~/.bash-gradle-utils.sh
# and reopen the shell
# Asks for the signing key and signing key password and stores them in environment
# variables named after the first and second argument passed to this function.
#
function exportSigning(){
local signingKeyName="$1"
local signingPasswordName="$2"
if [ -z "${signingKeyName}" ] || [ -z "${signingPasswordName}" ]; then
>&2 echo "Usage: exportSigning SIGNING_KEY_ENV_VAR_NAME SIGNING_PASSWORD_ENV_VAR_NAME"
return
fi
>&2 echo "Enter the signing key. and finish with CTRL-D. Abort with CTRL-C."
IFS='' read -s -r -d '' ${signingKeyName} < <(cat)
if [ -z ${!signingKeyName+x} ]; then
>&2 echo "Aborted due to empty signing key."
return
fi
>&2 echo "Enter the signing key password. It will not be printed to the terminal."
IFS='' read -s -r -d '' ${signingPasswordName} < <(cat)
if [ -z ${!signingPasswordName+x} ]; then
>&2 echo "Aborted due to empty signing key password."
unset ${signingKeyName}
return
fi
export ${signingKeyName}
export ${signingPasswordName}
}
# Asks for the signing key and signing key password and stores them in the
# environment variables:
# - ORG_GRADLE_PROJECT_signingKey
# - ORG_GRADLE_PROJECT_signingPassword
#
# So that they can be accessed as Gradle project properties.
# For details take a look at: https://docs.gradle.org/current/userguide/signing_plugin.html#sec:in-memory-keys
#
function exportGradleSigning(){
exportSigning ORG_GRADLE_PROJECT_signingKey ORG_GRADLE_PROJECT_signingPassword
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment