Deployment scripts for my website.
https://fwdekker.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.4 KiB
43 lines
1.4 KiB
#!/usr/local/bin/bash |
|
# Usage: `deploy-nginx $target` |
|
# |
|
# Copies nginx configuration files from the repository in the current directory to `$target`, and then reloads nginx. |
|
# |
|
# This script is specifically for https://git.fwdekker.com/fwdekker.com/nginx-config. |
|
|
|
|
|
repo_dir="$(pwd)" |
|
repo_name="$(basename -s .git "$repo_dir")" |
|
dst_dir="$1" |
|
tmp_dir="$HOME/tmp/git/$repo_name-$(date +%s)" |
|
|
|
echo "[[ Deploy ]] nginx($repo_name)" |
|
echo "[[ Deploy ]] src: '$repo_dir'" |
|
echo "[[ Deploy ]] dst: '$dst_dir'" |
|
echo "[[ Deploy ]] tmp: '$tmp_dir'" |
|
|
|
|
|
if test -e "$tmp_dir"; then |
|
echo "[[ Deploy ]] Directory '$tmp_dir' already exists, stopping deployment." |
|
exit |
|
fi |
|
|
|
|
|
echo "[[ Deploy ]] Creating directories '$dst_dir' and '$tmp_dir'." |
|
mkdir -p "$dst_dir" "$tmp_dir" |
|
|
|
echo "[[ Deploy ]] Cloning repository at '$repo_dir' into '$tmp_dir'." |
|
git clone "$repo_dir" "$tmp_dir" |
|
|
|
echo "[[ Deploy ]] Removing directories '$dst_dir/sites-available', '$dst_dir/sites-enabled', and '$dst_dir/snippets', and file '$dst_dir/nginx.conf'." |
|
rm -rf "$dst_dir/sites-available" "$dst_dir/sites-enabled" "$dst_dir/snippets" "$dst_dir/nginx.conf" |
|
|
|
echo "[[ Deploy ]] Copying files from '$tmp_dir' to '$dst_dir'." |
|
chmod -R g+w "$tmp_dir" |
|
cp -RP "$tmp_dir/sites-available" "$tmp_dir/sites-enabled" "$tmp_dir/snippets" "$tmp_dir/nginx.conf" "$dst_dir" |
|
|
|
echo "[[ Deploy ]] Reloading nginx configurations" |
|
sudo service nginx reload |
|
|
|
echo "[[ Deploy ]] Deleting '$tmp_dir'." |
|
rm -rf "$tmp_dir"
|
|
|