{"id":315,"date":"2025-07-16T10:53:20","date_gmt":"2025-07-16T17:53:20","guid":{"rendered":"https:\/\/www.cmsws.com\/blog\/?p=315"},"modified":"2025-07-16T10:53:20","modified_gmt":"2025-07-16T17:53:20","slug":"create-tinydns-hook-script-for-use-with-acme-sh","status":"publish","type":"post","link":"https:\/\/www.cmsws.com\/blog\/create-tinydns-hook-script-for-use-with-acme-sh\/","title":{"rendered":"Create TinyDNS &#8220;hook&#8221; script for use with acme.sh"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Add_%E2%80%9Chook%E2%80%9D_processing_file_for_acmesh\"><\/span>Add &#8220;hook&#8221; processing file for acme.sh<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_the_file_acmeshdns_tinydnssh\"><\/span>Create the file ~\/.acme.sh\/dns_tinydns.sh<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Add the following to this file:<\/p><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-right counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.cmsws.com\/blog\/create-tinydns-hook-script-for-use-with-acme-sh\/#Add_%E2%80%9Chook%E2%80%9D_processing_file_for_acmesh\" >Add &#8220;hook&#8221; processing file for acme.sh<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.cmsws.com\/blog\/create-tinydns-hook-script-for-use-with-acme-sh\/#Create_the_file_acmeshdns_tinydnssh\" >Create the file ~\/.acme.sh\/dns_tinydns.sh<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.cmsws.com\/blog\/create-tinydns-hook-script-for-use-with-acme-sh\/#Set_file_as_executable\" >Set file as executable<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.cmsws.com\/blog\/create-tinydns-hook-script-for-use-with-acme-sh\/#Create_tinydns_update_script_%E2%80%98usrlocalbinupdate_tinydns_txtsh\" >Create tinydns update script &#8216;\/usr\/local\/bin\/update_tinydns_txt.sh&#8217;<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.cmsws.com\/blog\/create-tinydns-hook-script-for-use-with-acme-sh\/#Set_file_as_executable-2\" >Set file as executable<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# acme.sh custom DNS API hook for TinyDNS\n\n# Path to your update script\nTINYSCRIPT=\"\/usr\/local\/bin\/update_tinydns_txt.sh\"\n\ndns_tinydns_add() {\n    fulldomain=\"$1\" # e.g. _acme-challenge.example.com\n    txtvalue=\"$2\" # e.g. the ACME challenge token\n\n    _debug \"dns_tinydns_add: $fulldomain = $txtvalue\"\n\n    \"$TINYSCRIPT\" \"$txtvalue\" \"$fulldomain\" || return 1\n\n    return 0\n}\n\ndns_tinydns_rm() {\n    fulldomain=\"$1\"\n    txtvalue=\"$2\"\n\n    _debug \"dns_tinydns_rm: $fulldomain (value $txtvalue)\"\n\n    # Optional: implement record removal here\n    return 0\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Set_file_as_executable\"><\/span>Set file as executable<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod +x ~\/.acme.sh\/dns_tinydns.sh<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_tinydns_update_script_%E2%80%98usrlocalbinupdate_tinydns_txtsh\"><\/span>Create tinydns update script &#8216;\/usr\/local\/bin\/update_tinydns_txt.sh&#8217;<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Add the following to this file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# Must be run as root\nif &#91;&#91; $EUID -ne 0 ]]; then\n    echo \"This script must be run as root.\"\n    exit 1\nfi\n\n# Check arguments\nif &#91;&#91; -z \"$1\" || -z \"$2\" ]]; then\n    echo \"Usage: $0 \\\"txt-value\\\" \\\"record-name\\\"\"\n    exit 1\nfi\n\n# Input parameters\nTXT_VALUE=\"$1\"\nRECORD_NAME=\"$2\"\n\n# Paths and settings\nTINYDNS_ROOT=\"\/var\/tinydns\/root\"\nDATA_FILE=\"$TINYDNS_ROOT\/data\"\nBACKUP_DIR=\"$TINYDNS_ROOT\/backups\"\nDNSCACHE_SERVICE_NAME=\"dnscached\"\n\n# Ensure backup directory exists\nmkdir -p \"$BACKUP_DIR\"\necho \"Updating TXT record for $RECORD_NAME\"\n\n# Backup current data file\nTIMESTAMP=$(date +%Y%m%d_%H%M%S)\ncp \"$DATA_FILE\" \"$BACKUP_DIR\/data_$TIMESTAMP.bak\" || {\n    echo \"Failed to back up data file.\"\n    exit 1\n}\n\n# Backup in-place\ncp \"$DATA_FILE\" \"$DATA_FILE.bak\"\n\n# Check if record exists\nif grep -q \"^'${RECORD_NAME}:\" \"$DATA_FILE\"; then\n    # Update existing TXT record\n    sed -i -E \"s|^('${RECORD_NAME}):.*|\\1:${TXT_VALUE}:30|\" \"$DATA_FILE\"\nelse\n    # Append new TXT record\n    echo \"'${RECORD_NAME}:${TXT_VALUE}\" &gt;&gt; \"$DATA_FILE\"\nfi\n\n# Rebuild data.cdb\ncd \"$TINYDNS_ROOT\" &amp;&amp; make || {\n    echo \"make failed. Restoring original data file.\"\n    mv \"$DATA_FILE.bak\" \"$DATA_FILE\"\n    make\n    exit 1\n}\n\n# Restart dnscached service\nservice \"$DNSCACHE_SERVICE_NAME\" restart || {\n    echo \"Failed to restart $DNSCACHE_SERVICE_NAME service.\"\n    exit 1\n}\n\necho \"Successfully updated TXT record for $RECORD_NAME\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Set_file_as_executable-2\"><\/span>Set file as executable<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod +x \/usr\/local\/bin\/update_tinydns_txt.sh<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Add &#8220;hook&#8221; processing file for acme.sh Create the file ~\/.acme.sh\/dns_tinydns.sh Add the following to this file: Set file as executable Create tinydns update script &#8216;\/usr\/local\/bin\/update_tinydns_txt.sh&#8217; Add the following to this file: Set file as executable<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-315","post","type-post","status-publish","format-standard","hentry","category-misc"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/posts\/315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/comments?post=315"}],"version-history":[{"count":0,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/posts\/315\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/media?parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/categories?post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/tags?post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}