Created
December 28, 2018 18:52
-
-
Save alaxalves/8214651f4e8c18836eb6ce392d7905f8 to your computer and use it in GitHub Desktop.
Script to push to Heroku
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 | |
# Download and install Heroku CLI | |
# curl https://cli-assets.heroku.com/install-ubuntu.sh | sh | |
# Insert here your Heroku app name | |
HEROKU_APP_NAME="MY-AWESOME-APP" | |
install_heroku() { | |
{ | |
set -e | |
SUDO='' | |
if [ "$(id -u)" != "0" ]; then | |
SUDO='sudo' | |
echo "This script requires superuser access to install apt packages." | |
echo "You will be prompted for your password by sudo." | |
# clear any previous sudo permission | |
sudo -k | |
fi | |
# run inside sudo | |
$SUDO sh <<SCRIPT | |
set -ex | |
# if apt-transport-https is not installed, clear out old sources, update, then install apt-transport-https | |
dpkg -s apt-transport-https 1>/dev/null 2>/dev/null || \ | |
(echo "" > /etc/apt/sources.list.d/heroku.list \ | |
&& apt-get update \ | |
&& apt-get install -y apt-transport-https) | |
# add heroku repository to apt | |
echo "deb https://cli-assets.heroku.com/apt ./" > /etc/apt/sources.list.d/heroku.list | |
# remove toolbelt | |
(dpkg -s heroku-toolbelt 1>/dev/null 2>/dev/null && (apt-get remove -y heroku-toolbelt heroku || true)) || true | |
# install heroku's release key for package verification | |
curl https://cli-assets.heroku.com/apt/release.key | apt-key add - | |
# update your sources | |
apt-get update | |
# install the toolbelt | |
apt-get install -y heroku | |
SCRIPT | |
# test the CLI | |
LOCATION=$(which heroku) | |
echo "Heroku installed to $LOCATION" | |
heroku version | |
} | |
} | |
verify_valid_cmd() | |
{ | |
if [[ $? -eq 0 ]]; then | |
echo -e $1; | |
else | |
echo -e $2; | |
if [[ "$2" == "Heroku installation needed!" ]]; then | |
install_heroku | |
fi; | |
fi; | |
} | |
dpkg -s heroku > /dev/null | |
verify_valid_cmd "You already have Heroku installed!" "Heroku installation needed!" | |
git remote add production https://git.heroku.com/$HEROKU_APP_NAME.git &> /dev/null | |
verify_valid_cmd "Production remote successfully added!" "Production remote already exists!\nContinuing..." | |
git remote update | |
heroku login | |
git push -f production master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Give it executable permissions, such as
chmod +x deploy.sh
and later just./deploy.sh
.