status-react/scripts/generate-keystore.sh
Jakub Sokołowski de53581ef4
nix: don't generate keystore inside of Nix build
changes:
- Stops scripts/generate-keystore.sh runnig for every new TARGET=android shell
- Moves running scripts/generate-keystore.sh to keystore Makefile target
- Makes generate-keystore.sh accept STATUS_RELEASE_STORE_FILE as env variable
- Fixes error about missing lsof from start-react-native.sh
- Fixes error about unknown -keystore command in scripts/generate-keystore.sh
- Fixes getting OS_NAME without calling Nix shell
- Fixes getting TMP_BUILD_NUMBER without calling Nix shell
- Adds lsof used in start-react-native.sh to Android release Nix derivation
- Simplified how nix/scripts/build.sh appends the --keep flag
- Made use of colors.sh in more scripts

Signed-off-by: Jakub Sokołowski <jakub@status.im>
2020-03-05 10:56:54 +01:00

50 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euf pipefail
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
source "${GIT_ROOT}/scripts/colors.sh"
function property() {
grep "${2}" "${1}" | cut -d'=' -f2
}
function property_gradle() {
property ${GIT_ROOT}/android/gradle.properties ${1}
}
KEYSTORE_PASSWORD=$(property_gradle 'KEYSTORE_PASSWORD')
KEYSTORE_ALIAS=$(property_gradle 'KEYSTORE_ALIAS')
KEYSTORE_KEY_PASSWORD=$(property_gradle 'KEYSTORE_KEY_PASSWORD')
# Allow Makefile modify Keystore path if necessary
if [[ -z ${KEYSTORE_PATH} ]]; then
KEYSTORE_PATH=$(property_gradle 'KEYSTORE_FILE')
fi
# Replace ~ with proper absolute path
KEYSTORE_PATH=${KEYSTORE_FILE/#\~/$HOME}
if [[ -e "${KEYSTORE_PATH}" ]]; then
echo -e "${YLW}Keystore file already exists:${RST} ${KEYSTORE_PATH}" > /dev/stderr
echo "${KEYSTORE_PATH}"
exit 0
fi
KEYSTORE_DIR=$(dirname "${S/TATUS_RELEASE_STORE_FILE}")
[[ -d $KEYSTORE_DIR ]] || mkdir -p $KEYSTORE_DIR
echo -e "${GRN}Generating keystore...${RST}" > /dev/stderr
keytool -genkey -v \
-keyalg RSA \
-keysize 2048 \
-validity 10000 \
-dname "CN=, OU=, O=, L=, S=, C=" \
-keystore "${KEYSTORE_PATH}" \
-alias "${KEYSTORE_ALIAS}" \
-storepass "${KEYSTORE_PASSWORD}" \
-keypass "${KEYSTORE_KEY_PASSWORD}" \
> /dev/stderr
echo "${KEYSTORE_PATH}"