updated domain script

This commit is contained in:
2026-03-27 19:06:23 -05:00
parent 18e9ccf85e
commit f1149f3465

View File

@@ -22,17 +22,17 @@ let
confirmDomain = name: ''
while true; do
echo ""
echo -e " ''${YELLOW}You entered:''${NC}"
echo -e " Domain: ''${CYAN}$DOMAIN''${NC}"
printf "%b%s%b\n" "$YELLOW" " You entered:" "$NC"
printf "%b%s%b\n" "$CYAN" " Domain: $DOMAIN" "$NC"
if [ -n "''${DDNS_DISPLAY:-}" ]; then
echo -e " DDNS URL: ''${CYAN}$DDNS_DISPLAY''${NC}"
printf "%b%s%b\n" "$CYAN" " DDNS URL: $DDNS_DISPLAY" "$NC"
fi
echo ""
read -p " Is this correct? (y/n): " CONFIRM
case "$CONFIRM" in
[yY])
echo "$DOMAIN" > "/var/lib/domains/${name}"
echo -e " ''${GREEN}Saved.''${NC}"
printf "%b%s%b\n" "$GREEN" " Saved." "$NC"
break
;;
[nN])
@@ -53,11 +53,11 @@ let
REDO=false
DDNS_DISPLAY=""
echo ""
echo -e "''${GREEN} ${d.label} ''${NC}"
printf "%b%s%b\n" "$GREEN" " ${d.label} " "$NC"
EXISTING=""
if [ -f "/var/lib/domains/${d.name}" ]; then
EXISTING=$(cat "/var/lib/domains/${d.name}")
echo -e " Current: ''${CYAN}$EXISTING''${NC}"
printf "%b%s%b\n" "$CYAN" " Current: $EXISTING" "$NC"
fi
read -p " Subdomain (e.g. ${d.example}) or Enter to keep current: " DOMAIN_INPUT
DOMAIN="''${DOMAIN_INPUT:-$EXISTING}"
@@ -91,7 +91,7 @@ $PENDING_NJALLA"
REDO=false
DDNS_DISPLAY=""
echo ""
echo -e "''${GREEN} ${d.label} (NEW) ''${NC}"
printf "%b%s%b\n" "$GREEN" " ${d.label} (NEW) " "$NC"
read -p " Subdomain (e.g. ${d.example}): " DOMAIN
if [ -n "$DOMAIN" ]; then
@@ -118,7 +118,7 @@ $PENDING_NJALLA"
domainSummary = lib.concatMapStringsSep "\n" (d: ''
if [ -f "/var/lib/domains/${d.name}" ]; then
echo " ${d.label}: $(cat /var/lib/domains/${d.name})"
printf "%b%s%b\n" "$NC" " ${d.label}: $(cat /var/lib/domains/${d.name})" "$NC"
fi
'') domains;
@@ -132,18 +132,18 @@ $PENDING_NJALLA"
DOLLAR='$'
echo ""
echo -e "''${CYAN}''${NC}"
echo -e "''${CYAN} Sovran_SystemsOS Domain & DDNS Setup''${NC}"
echo -e "''${CYAN}''${NC}"
printf "%b%s%b\n" "$CYAN" "" "$NC"
printf "%b%s%b\n" "$CYAN" " Sovran_SystemsOS Domain & DDNS Setup" "$NC"
printf "%b%s%b\n" "$CYAN" "" "$NC"
echo ""
echo -e "''${YELLOW}Before running this, you need:''${NC}"
printf "%b%s%b\n" "$YELLOW" "Before running this, you need:" "$NC"
echo ""
echo " 1. Domains/subdomains purchased on https://njal.la"
echo " 2. For each subdomain, add a Dynamic record in"
echo " your Njal.la dashboard."
echo " 3. Njal.la will give you a curl command like:"
echo ""
echo -e " ''${CYAN}curl \"https://njal.la/update/?h=sub.domain.com&k=abc123&auto\"''${NC}"
printf "%b%s%b\n" "$CYAN" " curl \"https://njal.la/update/?h=sub.domain.com&k=abc123&auto\"" "$NC"
echo ""
echo " Have those curl commands ready."
echo ""
@@ -161,26 +161,26 @@ $PENDING_NJALLA"
while [ "$REDO" = true ]; do
REDO=false
echo ""
echo -e "''${GREEN} SSL Certificate Email ''${NC}"
printf "%b%s%b\n" "$GREEN" " SSL Certificate Email " "$NC"
echo "Let's Encrypt needs an email for certificate notifications."
EXISTING_EMAIL=""
if [ -f "/var/lib/domains/sslemail" ]; then
EXISTING_EMAIL=$(cat /var/lib/domains/sslemail)
echo -e " Current: ''${CYAN}$EXISTING_EMAIL''${NC}"
printf "%b%s%b\n" "$CYAN" " Current: $EXISTING_EMAIL" "$NC"
fi
read -p " Email address (or Enter to keep current): " EMAIL_INPUT
SSL_EMAIL="''${EMAIL_INPUT:-$EXISTING_EMAIL}"
if [ -n "$SSL_EMAIL" ]; then
while true; do
echo ""
echo -e " ''${YELLOW}You entered:''${NC}"
echo -e " Email: ''${CYAN}$SSL_EMAIL''${NC}"
printf "%b%s%b\n" "$YELLOW" " You entered:" "$NC"
printf "%b%s%b\n" "$CYAN" " Email: $SSL_EMAIL" "$NC"
echo ""
read -p " Is this correct? (y/n): " CONFIRM
case "$CONFIRM" in
[yY])
echo "$SSL_EMAIL" > /var/lib/domains/sslemail
echo -e " ''${GREEN}Saved.''${NC}"
printf "%b%s%b\n" "$GREEN" " Saved." "$NC"
break
;;
[nN])
@@ -201,9 +201,9 @@ $PENDING_NJALLA"
# Final review
echo ""
echo -e "''${CYAN}''${NC}"
echo -e "''${CYAN} Review All Entries''${NC}"
echo -e "''${CYAN}''${NC}"
printf "%b%s%b\n" "$CYAN" "" "$NC"
printf "%b%s%b\n" "$CYAN" " Review All Entries" "$NC"
printf "%b%s%b\n" "$CYAN" "" "$NC"
echo ""
echo " Configured domains:"
${domainSummary}
@@ -218,14 +218,14 @@ $PENDING_NJALLA"
read -p " Does everything look correct? (y/n): " FINAL_CONFIRM
if [ "$FINAL_CONFIRM" != "y" ] && [ "$FINAL_CONFIRM" != "Y" ]; then
echo ""
echo -e " ''${YELLOW}Setup cancelled. Run 'sudo sovran-setup-domains' to start over.''${NC}"
printf "%b%s%b\n" "$YELLOW" " Setup cancelled. Run 'sudo sovran-setup-domains' to start over." "$NC"
echo ""
exit 1
fi
# Write njalla.sh
echo ""
echo -e "''${GREEN} Generating DDNS script ''${NC}"
printf "%b%s%b\n" "$GREEN" " Generating DDNS script " "$NC"
cat > /var/lib/njalla/njalla.sh <<SCRIPT
#!/usr/bin/env bash
@@ -244,20 +244,20 @@ SCRIPT
echo " DNS records updated."
fi
# Mark setup complete
# Mark setup complete <EFBFBD><EFBFBD>
touch /var/lib/domains/.setup-complete
# Summary
echo ""
echo -e "''${CYAN}''${NC}"
echo -e "''${CYAN} Setup Complete!''${NC}"
echo -e "''${CYAN}''${NC}"
printf "%b%s%b\n" "$CYAN" "" "$NC"
printf "%b%s%b\n" "$CYAN" " Setup Complete!" "$NC"
printf "%b%s%b\n" "$CYAN" "" "$NC"
echo ""
echo " Domain files: /var/lib/domains/"
echo " DDNS script: /var/lib/njalla/njalla.sh"
echo " DDNS cron: Every 15 minutes (already configured)"
echo ""
echo -e "''${YELLOW} Rebuilding to activate services with new domains...''${NC}"
printf "%b%s%b\n" "$YELLOW" " Rebuilding to activate services with new domains..." "$NC"
echo ""
nixos-rebuild switch --flake /etc/nixos#nixos
'';
@@ -276,9 +276,9 @@ SCRIPT
PENDING_NJALLA=""
echo ""
echo -e "''${CYAN}''${NC}"
echo -e "''${CYAN} Sovran_SystemsOS New Feature Domains''${NC}"
echo -e "''${CYAN}''${NC}"
printf "%b%s%b\n" "$CYAN" "" "$NC"
printf "%b%s%b\n" "$CYAN" " Sovran_SystemsOS New Feature Domains" "$NC"
printf "%b%s%b\n" "$CYAN" "" "$NC"
echo ""
echo " Checking for newly enabled features that need domains..."
@@ -289,16 +289,16 @@ SCRIPT
if [ "$MISSING" = false ]; then
echo ""
echo -e "''${GREEN} All domains are already configured. Nothing to do.''${NC}"
printf "%b%s%b\n" "$GREEN" " All domains are already configured. Nothing to do." "$NC"
echo ""
exit 0
fi
# Final review
echo ""
echo -e "''${CYAN}''${NC}"
echo -e "''${CYAN} Review New Entries''${NC}"
echo -e "''${CYAN}''${NC}"
printf "%b%s%b\n" "$CYAN" "" "$NC"
printf "%b%s%b\n" "$CYAN" " Review New Entries" "$NC"
printf "%b%s%b\n" "$CYAN" "" "$NC"
echo ""
echo " All configured domains:"
${domainSummary}
@@ -313,7 +313,7 @@ SCRIPT
read -p " Does everything look correct? (y/n): " FINAL_CONFIRM
if [ "$FINAL_CONFIRM" != "y" ] && [ "$FINAL_CONFIRM" != "Y" ]; then
echo ""
echo -e " ''${YELLOW}Setup cancelled. Run 'sudo sovran-add-domains' to start over.''${NC}"
printf "%b%s%b\n" "$YELLOW" " Setup cancelled. Run 'sudo sovran-add-domains' to start over." "$NC"
echo ""
exit 1
fi
@@ -321,7 +321,7 @@ SCRIPT
# Append new entries to njalla.sh
if [ -n "$NEW_NJALLA_ENTRIES" ]; then
echo ""
echo -e "''${GREEN} Updating DDNS script ''${NC}"
printf "%b%s%b\n" "$GREEN" " Updating DDNS script " "$NC"
if [ -f /var/lib/njalla/njalla.sh ]; then
echo "$NEW_NJALLA_ENTRIES" >> /var/lib/njalla/njalla.sh
@@ -346,16 +346,16 @@ SCRIPT
# Summary
echo ""
echo -e "''${CYAN}<EFBFBD><EFBFBD>''${NC}"
echo -e "''${CYAN} New Domains Added!''${NC}"
echo -e "''${CYAN}''${NC}"
printf "%b%s%b\n" "$CYAN" "" "$NC"
printf "%b%s%b\n" "$CYAN" " New Domains Added!" "$NC"
printf "%b%s%b\n" "$CYAN" "" "$NC"
echo ""
echo " All configured domains:"
${domainSummary}
echo ""
echo -e "''${YELLOW} Rebuilding to activate services with new domains...''${NC}"
printf "%b%s%b\n" "$YELLOW" " Rebuilding to activate services with new domains..." "$NC"
echo ""
nixos-rebuild switch --flake /etc/nixos#nixos
nixos-rebuild switch --impure
'';
needsSetup = pkgs.writeShellScriptBin "sovran-domains-need-setup" ''