#!/bin/sh -ex
# A ship template script
die() { [ "$1" ] && echo "$0: $*" >&2; exit 1; }
[ "$1" ] || die 'host argument missing'
[ -f /etc/alpine-release ] || die 'not on alpinelinux system'
[ "$USER" = root ] || exec doas "$0" "$@"
: Step 1: install dependencies
apk add nginx
: Step 2: Configure
mkdir -p "/var/www/$1/html"
cat <<- EOF > "/var/www/$1/html/index.html"
Server block
Success! The Nginx server block is running!
EOF
chown -R nginx: "/var/www/$1"
cat <<- EOF > "/etc/nginx/http.d/$1.conf"
server {
listen 80;
listen [::]:80;
server_name $1;
root /var/www/$1/html;
access_log /var/log/nginx/$1.access.log;
error_log /var/log/nginx/$1.error.log;
}
EOF
: Step 3: Enable and start
service nginx restart
: Step 4: Test
netstat -tulpn | grep :80