Last active
December 27, 2023 05:39
-
-
Save theptrk/ddd12460aaf5a2896e2d1a501f03ac4f to your computer and use it in GitHub Desktop.
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
Excerpt From | |
Deployment from Scratch | |
Josef Strzibny | |
This material may be protected by copyright. |
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 | |
USER=root | |
SERVER=$SERVER | |
PORT=22 | |
SSH_KEY=$SSH_KEY | |
SSH_OPTIONS="-i $SSH_KEY -o StrictHostKeyChecking=no" | |
SSH_ARGS="$USER@$SERVER -p $PORT $SSH_OPTIONS" | |
fail () { | |
echo $1 | |
exit 1 | |
} | |
# Check if SERVER is set | |
if [ -z "$SERVER" ]; then | |
fail "SERVER key is not set. Aborting script." | |
fi | |
# Check if SSH_KEY is set | |
if [ -z "$SSH_KEY" ]; then | |
fail "SSH key is not set. Aborting script." | |
fi | |
ssh $SSH_ARGS 'bash -s' <<-STDIN || fail "installation failed" | |
set -euo pipefail | |
apt-get install -y nginx | |
STDIN | |
DIR=`dirname "$(readlink -f "$0")"` | |
if [ -e $DIR/index.html ]; then | |
scp $SCP_ARGS $DIR/index.html \ | |
$USER@$SERVER:/var/www/html/index.html || \ | |
fail "scp failed" | |
else | |
echo "index.html does not exist!" | |
exit 1 | |
fi | |
ssh $SSH_ARGS 'bash -s' <<-STDIN || fail "restart nginx failed" | |
set -euo pipefail | |
systemctl restart nginx.service | |
STDIN |
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
USER=root | |
SERVER=$SERVER | |
PORT=22 | |
SSH_KEY=$SSH_KEY | |
SSH_OPTIONS="-i $SSH_KEY -o StrictHostKeyChecking=no" | |
SSH_ARGS="$USER@$SERVER -p $PORT $SSH_OPTIONS" | |
ssh $SSH_ARGS 'bash -s' <<-STDIN | |
apt-get install -y nginx | |
cat /etc/nginx/sites-available/default | grep root | |
> /var/www/html/index.html | |
cat <<-TEXT | tee /var/www/html/index.html | |
<h1>Tiger</h1> | |
<p> | |
Hey hey, my name is Tiger. | |
</p> | |
TEXT | |
systemctl restart nginx.service | |
STDIN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment