From 2cbbcd2c3fc97a9fad14f305b5156ce7c09d5b9e Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Tue, 21 Jun 2022 09:34:12 -0700 Subject: [PATCH] add private provision scripts - beaded: updates - ns1.cad: add install_sentry - move tnpi scripts into ./tnpi/ - tnpi: add ns3.art, ns3.cad, wp_sim, sigels - beaded: enable promotion - move whmcs to tnpi - tnpi/*: remove dialog4ports, chmod +x - tinydns: refactor djb installers into include/djb - update ns1.theartfarm to use include/djb --- provision/dovecot.sh | 2 +- tnpi/beaded-api.sh | 49 ++++++++ tnpi/isaac.sh | 35 ++++++ tnpi/mike.sh | 34 ++++++ tnpi/ns1.cadillac.net.sh | 77 +++++++++++++ tnpi/ns1.theartfarm.com.sh | 83 ++++++++++++++ tnpi/ns2.cadillac.net.sh | 83 ++++++++++++++ tnpi/ns2.theartfarm.com.sh | 77 +++++++++++++ tnpi/ns3.cadillac.net.sh | 86 ++++++++++++++ tnpi/ns3.theartfarm.com.sh | 202 +++++++++++++++++++++++++++++++++ tnpi/sigels.sh | 119 ++++++++++++++++++++ {provision => tnpi}/whmcs.sh | 0 tnpi/wordpress_simerson.sh | 209 +++++++++++++++++++++++++++++++++++ 13 files changed, 1055 insertions(+), 1 deletion(-) create mode 100755 tnpi/beaded-api.sh create mode 100755 tnpi/isaac.sh create mode 100755 tnpi/mike.sh create mode 100755 tnpi/ns1.cadillac.net.sh create mode 100755 tnpi/ns1.theartfarm.com.sh create mode 100755 tnpi/ns2.cadillac.net.sh create mode 100755 tnpi/ns2.theartfarm.com.sh create mode 100755 tnpi/ns3.cadillac.net.sh create mode 100755 tnpi/ns3.theartfarm.com.sh create mode 100755 tnpi/sigels.sh rename {provision => tnpi}/whmcs.sh (100%) create mode 100755 tnpi/wordpress_simerson.sh diff --git a/provision/dovecot.sh b/provision/dovecot.sh index 0b78916d..e546b90d 100755 --- a/provision/dovecot.sh +++ b/provision/dovecot.sh @@ -597,7 +597,7 @@ base_snapshot_exists || exit create_staged_fs dovecot mkdir -p "$STAGE_MNT/usr/local/vpopmail" start_staged_jail dovecot -allow_sysvipc_stage +#allow_sysvipc_stage install_dovecot configure_dovecot stage_resolv_conf diff --git a/tnpi/beaded-api.sh b/tnpi/beaded-api.sh new file mode 100755 index 00000000..9c95b8d2 --- /dev/null +++ b/tnpi/beaded-api.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# shellcheck disable=1091 +. mail-toaster.sh || exit + +mt6-include user + +install_beaded_api() +{ + tell_status "installing beadedstream API" + stage_pkg_install npm-node16 git-lite mongodb44 mongodb-tools ssmtp + stage_exec bash -c "cd /data/db && npm install" + stage_exec bash -c "cd /data/db/api && npm install" + stage_exec npm install -g pm2 +} + +configure_beaded_api() +{ + tell_status "configuring beaded_api" + + preserve_passdb beaded_api + preserve_ssh_host_keys beaded_api + + cp /data/beaded_api/rc.d/pm2_beaded "$STAGE_MNT/usr/local/etc/rc.d/" + stage_sysrc pm2_beaded_enable="YES" + stage_sysrc sshd_enable="YES" +} + +start_beaded_api() +{ + tell_status "configuring beaded_api" + stage_exec service pm2_beaded start +} + +test_beaded_api() +{ + tell_status "testing beaded_api" + stage_listening 3000 + echo "it works" +} + +base_snapshot_exists || exit +create_staged_fs beaded_api +start_staged_jail beaded_api +install_beaded_api +configure_beaded_api +start_beaded_api +test_beaded_api +promote_staged_jail beaded_api diff --git a/tnpi/isaac.sh b/tnpi/isaac.sh new file mode 100755 index 00000000..a9b3c3e6 --- /dev/null +++ b/tnpi/isaac.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +# shellcheck disable=1091 +. mail-toaster.sh || exit + +install_isaac() +{ + tell_status "installing Isaac" + stage_pkg_install python37 +} + +configure_isaac() +{ + tell_status "configuring isaac" + echo "WARN: manually copy passwd & group files over" +} + +start_isaac() +{ + tell_status "configuring isaac" +} + +test_isaac() +{ + tell_status "testing isaac" +} + +base_snapshot_exists || exit +create_staged_fs isaac +start_staged_jail isaac +install_isaac +configure_isaac +start_isaac +test_isaac +promote_staged_jail isaac diff --git a/tnpi/mike.sh b/tnpi/mike.sh new file mode 100755 index 00000000..e649fa7a --- /dev/null +++ b/tnpi/mike.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +# shellcheck disable=1091 +. mail-toaster.sh || exit + +install_mike() +{ + tell_status "installing Mike" + stage_pkg_install mtr-nox11 +} + +configure_mike() +{ + tell_status "configuring mike" +} + +start_mike() +{ + tell_status "configuring mike" +} + +test_mike() +{ + tell_status "testing mike" +} + +base_snapshot_exists || exit +create_staged_fs mike +start_staged_jail mike +install_mike +configure_mike +start_mike +test_mike +promote_staged_jail mike diff --git a/tnpi/ns1.cadillac.net.sh b/tnpi/ns1.cadillac.net.sh new file mode 100755 index 00000000..c8c34d88 --- /dev/null +++ b/tnpi/ns1.cadillac.net.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +# shellcheck disable=1091 +. mail-toaster.sh || exit + +export JAIL_START_EXTRA="" +export JAIL_CONF_EXTRA="" + +mt6-include user + +install_knot() +{ + tell_status "installing Knot DNS 3" + stage_pkg_install knot3 rsync || exit + + if [ ! -d "$STAGE_MNT/data/home" ]; then + mkdir -p "$STAGE_MNT/data/home" || exit + fi + + install_nrpe + install_sentry +} + + +install_nrpe() +{ + if [ -z "$TOASTER_NRPE" ]; then + echo "TOASTER_NRPE unset, skipping nrpe plugin" + return + fi + + tell_status "installing nrpe plugin" + stage_pkg_install nrpe3 + stage_sysrc nrpe3_enable=YES + stage_sysrc nrpe3_configfile="/data/etc/nrpe.cfg" +} + +configure_knot() +{ + stage_sysrc sshd_enable=YES + stage_sysrc knot_enable=YES + stage_sysrc knot_config=/data/etc/knot.conf + + preserve_passdb ns1.cadillac.net + stage_exec pw user mod knot -d /data/home/knot -s /bin/sh + stage_exec pw user mod root -d /data/home/root -s /usr/local/bin/bash +} + +start_knot() +{ + tell_status "starting knot daemon" + stage_exec service knot start || exit +} + +test_knot() +{ + tell_status "testing knot" + stage_test_running knot + + stage_listening 53 8 + echo "it worked." + + tell_status "testing UDP DNS query" + drill ns1.cadillac.net @"$(get_jail_ip stage)" || exit + + tell_status "testing TCP DNS query" + drill -t ns1.cadillac.net @"$(get_jail_ip stage)" || exit +} + +base_snapshot_exists || exit +create_staged_fs ns1.cadillac.net +start_staged_jail ns1.cadillac.net +install_knot +configure_knot +start_knot +test_knot +promote_staged_jail ns1.cadillac.net diff --git a/tnpi/ns1.theartfarm.com.sh b/tnpi/ns1.theartfarm.com.sh new file mode 100755 index 00000000..baa6d8e5 --- /dev/null +++ b/tnpi/ns1.theartfarm.com.sh @@ -0,0 +1,83 @@ +#!/bin/sh + +set -e + +. mail-toaster.sh +. include/djb.sh + +export JAIL_START_EXTRA="" +export JAIL_CONF_EXTRA="" +export JAIL_FSTAB="" + +configure_tinydns() +{ + configure_svscan + configure_tinydns4 + configure_tinydns_data + configure_tinydns6 + stage_sysrc sshd_enable="YES" +} + +configure_tinydns_data() +{ + _data_root="$ZFS_DATA_MNT/ns1.theartfarm.com/root" + if [ -d "$_data_root" ]; then + tell_status "tinydns data already configured" + return + fi + + tell_status "configuring tinydns data" + mv "$STAGE_MNT/var/service/tinydns/root" "$_data_root" + tee -a "$_data_root/data" <&1 + +# logging disabled +exec 1>/dev/null 2>&1 + +exec envuidgid tinydns envdir ./env softlimit -d300000 /usr/local/bin/tinydns +EO_TINYDNS_RUN + + echo "/data/root" > "$STAGE_MNT/var/service/tinydns/env/ROOT" || exit +} + +configure_tinydns6() +{ + tell_status "creating tinydns IPv6 server" + stage_exec tinydns-conf tinydns bin /var/service/tinydns-v6 "$(get_jail_ip6 stage)" + tee "$STAGE_MNT/var/service/tinydns-v6/run" <&1 + +# logging disabled +exec 1>/dev/null 2>&1 + +exec envuidgid tinydns envdir ./env softlimit -d300000 /usr/local/bin/tinydns +EO_TINYDNS_RUN + + echo "/data/root" > "$STAGE_MNT/var/service/tinydns-v6/env/ROOT" || exit +} + +configure_tinydns() +{ + configure_svscan + configure_tinydns4 + configure_tinydns_data + stage_sysrc hostname="ns3.theartfarm.com" + #configure_tinydns6 +} + +configure_tinydns_data() +{ + if [ -d "$ZFS_DATA_MNT/tinydns/root" ]; then + tell_status "tinydns data already configured" + return + fi + + tell_status "configuring tinydns data" + mv "$STAGE_MNT/var/service/tinydns/root" "$ZFS_DATA_MNT/tinydns/root" + tee -a "$ZFS_DATA_MNT/tinydns/root/data" <&1 + +# logging disabled +exec 1>/dev/null 2>&1 + +exec envdir ./env sh -c ' + exec envuidgid tinydns softlimit -d300000 tcpserver -vDRHl0 -x tcp.cdb -- "$IP" 53 /usr/local/bin/axfrdns +' +EO_AXFRDNS_RUN + + tee "$STAGE_MNT/var/service/axfrdns/tcp" <&1 + +# logging disabled +exec 1>/dev/null 2>&1 + +exec envdir ./env sh -c ' + exec envuidgid tinydns softlimit -d300000 tcpserver -vDRHl0 -x tcp.cdb -- "$IP" 53 /usr/local/bin/axfrdns +' +EO_AXFRDNS_RUN + + tee "$STAGE_MNT/var/service/axfrdns-v6/tcp" < "$STAGE_MNT/data/etc/opendkim.conf" +} + +configure_postfix() +{ + stage_sysrc postfix_enable=YES + stage_exec postconf -e "myhostname = sigels.com" + stage_exec postconf -e 'smtp_use_tls=yes' + stage_exec postconf -e 'smtp_tls_security_level = may' + stage_exec postconf -e "mynetworks = ${JAIL_NET_PREFIX}.0${JAIL_NET_MASK}" + + if [ -f "$ZFS_DATA_MNT/etc/sasl_passwd" ]; then + stage_exec postmap /data/etc/sasl_passwd + stage_exec postconf -e 'smtp_sasl_auth_enable = yes' + stage_exec postconf -e 'smtp_sasl_password_maps = hash:/data/etc/sasl_passwd' + fi + + if [ -n "$TOASTER_NRPE" ]; then + stage_sysrc nrpe3_enable=YES + stage_sysrc nrpe3_configfile="/data/etc/nrpe.cfg" + fi + + for _f in master main + do + if [ -f "$ZFS_DATA_MNT/sigels/etc/$_f.cf" ]; then + cp "$ZFS_DATA_MNT/sigels/etc/$_f.cf" "$STAGE_MNT/usr/local/etc/postfix/" + fi + done + + if [ -f "$ZFS_JAIL_MNT/sigels/etc/aliases" ]; then + tell_status "preserving /etc/aliases" + cp "$ZFS_JAIL_MNT/sigels/etc/aliases" "$STAGE_MNT/etc/aliases" + stage_exec newaliases + fi + + if [ ! -f "$ZFS_JAIL_MNT/usr/local/etc/mail/mailer.conf" ]; then + if [ ! -d "$ZFS_JAIL_MNT/usr/local/etc/mail" ]; then + mkdir "$ZFS_JAIL_MNT/usr/local/etc/mail" + fi + stage_exec install -m 0644 /usr/local/share/postfix/mailer.conf.postfix /usr/local/etc/mail/mailer.conf + fi + + configure_opendkim +} + +start_postfix() +{ + tell_status "starting postfix" + if [ -n "$_has_dkim" ]; then + stage_exec service milter-opendkim start + fi + stage_exec service postfix start || exit +} + +test_postfix() +{ + if [ -n "$_has_dkim" ]; then + tell_status "testing opendkim" + stage_test_running opendkim + stage_listening 2016 + fi + + tell_status "testing postfix" + stage_test_running master + stage_listening 25 + echo "it worked." +} + +base_snapshot_exists || exit +create_staged_fs sigels +start_staged_jail sigels +install_postfix +configure_postfix +start_postfix +test_postfix +promote_staged_jail sigels diff --git a/provision/whmcs.sh b/tnpi/whmcs.sh similarity index 100% rename from provision/whmcs.sh rename to tnpi/whmcs.sh diff --git a/tnpi/wordpress_simerson.sh b/tnpi/wordpress_simerson.sh new file mode 100755 index 00000000..6c220784 --- /dev/null +++ b/tnpi/wordpress_simerson.sh @@ -0,0 +1,209 @@ +#!/bin/sh + +# shellcheck disable=1091 +. mail-toaster.sh || exit + +export JAIL_START_EXTRA="" +export JAIL_CONF_EXTRA="" + +mt6-include php +mt6-include nginx + +install_wordpress() +{ + assure_jail mysql + + install_nginx + install_php 74 "ctype curl ftp gd hash json mysqli session tokenizer xml zip zlib" + + # stage_pkg_install wordpress + stage_port_install www/wordpress || exit +} + +configure_nginx_standalone() +{ + if [ -f "$STAGE_MNT/data/etc/nginx-locations.conf" ]; then + tell_status "preserving /data/etc/nginx-locations.conf" + return + fi + + tee "$STAGE_MNT/data/etc/nginx-locations.conf" <<'EO_WP_NGINX' + + server_name wordpress; + index index.php; + root /usr/local/www; + + location = /favicon.ico { + log_not_found off; + access_log off; + } + + location = /robots.txt { + allow all; + log_not_found off; + access_log off; + } + + location / { + # include "?$args" so non-default permalinks don't break + try_files $uri $uri/ /index.php?$args; + } + + location ~ \.php$ { + include /usr/local/etc/nginx/fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_intercept_errors on; + fastcgi_pass php; + } + + location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ { + expires max; + log_not_found off; + } + +EO_WP_NGINX + +} + +configure_nginx_with_path() +{ + if [ -f "$STAGE_MNT/data/etc/nginx-locations.conf" ]; then + tell_status "preserving /data/etc/nginx-locations.conf" + return + fi + + local _uri_path="$1" + if [ -z "$_uri_path" ]; then + tell_status "using /wpn (wordpress network) for WP url path" + _uri_path="/wpn" + fi + + tee "$STAGE_MNT/data/etc/nginx-locations.conf" <<'EO_WP_NGINX' + + server_name wordpress; + index index.php; + root /usr/local/www/wordpress; + + # all PHP scripts, optionally within /wpn/ + location ~ ^/(?:wpn/)?(?