Files
linux-scripts/zola-deploy.sh
2026-01-18 10:18:49 +01:00

63 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
set -e
dev_server=""
prod_server=""
websites=("")
active_website=""
path_match=0
not_git(){
echo "You are not in a git repository!"
exit 1
}
get_git_branch(){
gitBranch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null) || not_git
}
check_path_match(){
for website in "${websites[@]}"; do
if [[ $cwd == *$website* ]]; then
path_match=1
active_website=$website
break
fi
done
}
zola_deploy(){
cwd=$(pwd)
check_path_match
if [[ $path_match == 1 ]]; then
if [[ $gitBranch == "main" ]]; then
cd "$(git rev-parse --show-toplevel)"
production_deploy_alert
zola build
rsync -r --delete --chown=www-data:www-data ./public/ $prod_server:/srv/http/$active_website
elif [[ $gitBranch == "dev" ]]; then
cd "$(git rev-parse --show-toplevel)"
zola --config config.dev.toml build --drafts
rsync -r --delete ./public/ $dev_server:/var/www/dev.$active_website
else
echo "Not on a correct branch (must be either dev or main)!"
fi
else
echo "Not a known website!"
exit 1
fi
}
production_deploy_alert(){
read -p "Deploying to production! Are you sure? (y/N):" -s -n 1 -r
echo
case $REPLY in
[Yy]) echo "Okay! Here we go!";;
*) echo "See ya!"; exit 1;;
esac
}
get_git_branch
zola_deploy