#!/bin/sh set -e out="/etc/nginx/sites-available/autogen" if ! [ -w "$out" ]; then echo "Must have write access to $out." exit 1 fi cp "$out" "$out.bak" output="$(m4 -P -I ../conf/nginx nginx.m4)" echo "$output" \ | sed '/^\s*$/d' \ | tee "$out" >/dev/null if ! sudo nginx -t; then cp "$out" "../nginx-error.conf" echo "Reverting to backup file." echo "Bad file saved to nginx-error.conf." mv "$out.bak" "$out" else echo "Press enter to restart nginx." read _ echo "Restarting..." systemctl restart nginx fi