Created
December 10, 2016 19:40
-
-
Save pradeepkumargali/70322dd0270e386f98686674fdbb10af to your computer and use it in GitHub Desktop.
Prepare Redirect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Requirements | |
# Install and setup Java We assume $JAVA_HOME is set | |
# Install openssl either through your linux package manager or macOS package manager (we like brew) | |
# Update to keystore folders for debug and release | |
set -o errtrace | |
set -o pipefail | |
package_name="com.jda.internal.mytestapp" | |
#java_bin="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/jre/bin" | |
#keytool=$java_bin/keytool | |
keytool=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/jre/bin/keytool | |
debug_key_store=$HOME/.android/debug.keystore | |
release_alias="xxxxxx" | |
release_key_store=$HOME/keystore/android.jks | |
release_password="xxxxxx" | |
android_key_store= | |
usage() { | |
echo "" | |
echo " This tool generates a ReplyURL you'll need to enter in to your Azure Portal" | |
echo " to allow for your app to use the Microsoft Accounts broker app. This will" | |
echo " allow your app to particiapte in SSO and do Certificate based authentication" | |
echo " among other good things./n" | |
echo "" | |
echo "Usage:"; | |
echo " -d | --debug genrates a replyURL using your debug keystore in Android Studio" | |
echo " -r | --release generates a replyURL using your production keystore in Android Studio" | |
echo " -c | --package the package name of your application" | |
echo " -p | --password your keystore password (default for debug keychain is android)" | |
echo " -a | --alias your keystore alias (default for debug keychain is androiddebugkey)" | |
echo "" | |
} | |
if [ $# -gt 0 ]; then | |
while [ "$1" != "" ]; do | |
case $1 in | |
-d | --debug) debug=1 | |
;; | |
-r | --release ) release=1 | |
;; | |
-c | --package ) shift | |
package_name=$1 | |
;; | |
-p | --password ) shift | |
release_password=$1 | |
;; | |
-a | --alias ) shift | |
release_alias=$1 | |
;; | |
-h | --help ) usage | |
exit | |
;; | |
* ) usage | |
exit 1 | |
esac | |
shift | |
done | |
else | |
usage | |
fi | |
#--------------------------------- | |
# Simple func() to encode a URL. Wrote it so we don't have an external dependency | |
# | |
rawurlencode() { | |
local string="${1}" | |
local strlen=${#string} | |
local encoded="" | |
local pos c o | |
for (( pos=0 ; pos<strlen ; pos++ )); do | |
c=${string:$pos:1} | |
case "$c" in | |
[-_.~a-zA-Z0-9] ) o="${c}" ;; | |
* ) echo -v o '%%%02x' "'$c" | |
esac | |
encoded+="${o}" | |
done | |
echo "${encoded}" # You can either set a return variable (FASTER) | |
REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p | |
} | |
#--------------------------------- | |
#--------------------------------- | |
# Simple Func() to generate the hash from the certificate provided by the android keystore. | |
makeTag() { | |
tag=`$keytool -storepass $release_password -exportcert -alias $release_alias -keystore $android_key_store | openssl sha1 -binary | openssl base64` | |
#tag="RQqo1o5+gbZ0kOFHlrKoZs+on9Q=" | |
} | |
#--------------------------------- | |
#--------------------------------- | |
makeReplyURL() { | |
printf "msauth://%s/%s\n" $package_name_encoded $tag | |
} | |
#--------------------------------- | |
# Simple Func() to do release | |
makerelease() { | |
if [ -f "$release_key_store" ]; then | |
android_key_store=$release_key_store | |
echo "We are using the following values" | |
printf "Package Name: %s\n" $package_name | |
printf "Keystore alias: %s\n" $release_alias | |
printf "Keystore password: %s\n" $release_password | |
printf "Keystore: %s\n" $android_key_store | |
makeTag | |
echo "Release Redirect URI is:" | |
makeReplyURL | |
else | |
printf "ERROR: The Release Android Key Store location %s was not found. Have you set up Android Studio for Google Play?\n" $android_key_store | |
fi | |
} | |
#--------------------------------- | |
# Simple Func() to do debug | |
makedebug() { | |
if [ -f "$debug_key_store" ]; then | |
android_key_store=$debug_key_store | |
echo "We are using the following values" | |
printf "Package Name: %s\n" $package_name | |
printf "Keystore alias: %s\n" $release_alias | |
printf "Keystore password: %s\n" $release_password | |
printf "Keystore: %s\n" $android_key_store | |
makeTag | |
echo "Debug Redirect URI is:" | |
makeReplyURL | |
else | |
printf "ERROR: The Debug Android Key Store location %s was not found. Try deploying your app in debug mode first to generate keys.\n" $android_key_store | |
fi | |
} | |
#--------------------------------- | |
# main | |
# Encoding the package name | |
package_name_encoded=`rawurlencode "$package_name"` | |
if [ "$debug" = "1" ]; then | |
makedebug | |
fi | |
if [ "$release" = "1" ]; then | |
makerelease | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment