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