Add credentials.sh and heroku.sh to Rails Tutorial Sample App
Last active
May 24, 2021 21:06
-
-
Save jhsu802701/690066b5fed9924e519be6ae4ee8c418 to your computer and use it in GitHub Desktop.
Scripts to add to Rails Tutorial Sample app
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 | |
# Output: | |
# First argument if it is not blank | |
# Second argument if first argument is blank | |
anti_blank () { | |
if [ -z "$1" ]; then | |
echo "$2" | |
else | |
echo "$1" | |
fi | |
} | |
# Setting Git email if necessary | |
GIT_EMAIL="$(git config user.email)" | |
if [ -z "$GIT_EMAIL" ]; then | |
EMAIL_DEF='you@example.com' | |
echo | |
echo "Default email address: ${EMAIL_DEF}" | |
echo | |
echo 'Enter your Git email address:' | |
read EMAIL_SEL | |
EMAIL=$(anti_blank $EMAIL_SEL $EMAIL_DEF) | |
echo | |
echo | |
echo '------------------------------' | |
echo "git config --global user.email" | |
echo "$EMAIL" | |
git config --global user.email "$EMAIL" | |
fi | |
# Setting Git name if necessary | |
GIT_NAME="$(git config user.name)" | |
if [ -z "$GIT_NAME" ]; then | |
NAME_DEF='Your Name' | |
echo | |
echo "Default name: ${NAME_DEF}" | |
echo | |
echo 'Enter your Git name:' | |
read NAME_SEL | |
# NOTE: The double quotes are needed to avoid truncating the string | |
# at the space. | |
NAME=$(anti_blank "$NAME_SEL" "$NAME_DEF") | |
echo | |
echo '-----------------------------' | |
echo "git config --global user.name" | |
echo "$NAME" | |
git config --global user.name "$NAME" | |
echo | |
fi | |
echo '--------------------------' | |
echo 'heroku login --interactive' | |
heroku login --interactive | |
echo '---------------' | |
echo 'heroku keys:add' | |
heroku keys:add |
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 | |
PATH_HEROKU_NAME='config/heroku_name.txt' | |
HEROKU_NAME='' | |
if [ -e $PATH_HEROKU_NAME ] | |
then | |
HEROKU_NAME=$(cat $PATH_HEROKU_NAME) | |
else | |
echo 'If you have not already done so, you must create this app on Heroku.' | |
echo '' | |
echo 'Once you have done this, you are ready to move on.' | |
echo '' | |
echo 'Enter the name of your app:' | |
read HEROKU_NAME | |
echo $HEROKU_NAME > $PATH_HEROKU_NAME | |
echo '' | |
fi | |
echo '-----------------------------' | |
echo "Heroku app name: $HEROKU_NAME" | |
echo "(stored at $PATH_HEROKU_NAME)" | |
echo '' | |
echo 'If you need to change the name of this Heroku app you wish to deploy to,' | |
echo "you must change the name stored in $PATH_HEROKU_NAME." | |
echo '' | |
echo '--------------------' | |
echo 'git remote rm heroku' | |
git remote rm heroku | |
echo '-----------------------------------------------------' | |
echo "git remote add heroku git@heroku.com:$HEROKU_NAME.git" | |
git remote add heroku git@heroku.com:$HEROKU_NAME.git | |
echo '-------------' | |
echo 'git remote -v' | |
git remote -v | |
echo '----------------------' | |
echo 'git push heroku master' | |
git push heroku master | |
echo '---------------------------' | |
echo 'heroku run rails db:migrate' | |
heroku run rails db:migrate | |
echo '-------------' | |
echo 'git remote -v' | |
git remote -v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment