This script automates the process of issuing, renewing, and deploying SSL certificates using acme.sh with Cloudflare DNS verification and deployment to Synology DSM.
Before running the script, ensure that:
- You have
curlinstalled. - You have a Cloudflare API token with DNS editing permissions.
- Your Synology DSM is set up to accept certificate updates.
- You have the required environment variables set.
Before running the script, make sure you have the following variables:
export DOMAIN="yourdomain.com"
export CF_Token="your-cloudflare-api-token"
export ACME_EMAIL="your-email@example.com"To deploy the certificate to Synology DSM, you must set either:
SYNO_USE_TEMP_ADMIN=true(for temporary admin mode), or- Both
SYNO_USERNAMEandSYNO_PASSWORD(for permanent admin authentication). - If you change ports/hostname/scheme, you can also set
SYNO_SCHEME,SYNO_HOSTNAME,SYNO_PORT. see https://github.com/acmesh-official/acme.sh/blob/master/deploy/synology_dsm.sh - If variables has special characters, you can escape them with
\.
Example:
export SYNO_USE_TEMP_ADMIN=true
# OR
export SYNO_USERNAME="your-synology-admin"
export SYNO_PASSWORD="your-synology-password"Clone the repository and run the script:
mkdir acme_synology.sh
wget https://raw.githubusercontent.com/ibesty/acme_synology.sh/refs/heads/main/acme_synology.sh -O acme_synology.sh/acme_synology.shThis will:
- Check for required environment variables.
- Install
acme.shfrom GitHub (if not already installed). - Register an ACME account if necessary.
- Issue a wildcard SSL certificate for the domain using Cloudflare DNS.
- Deploy the certificate to Synology DSM.
- Automatically renew and deploy the certificate when needed.
If you have trouble accessing GitHub, use the --use-gitee flag to install acme.sh from Gitee:
mkdir acme_synology.sh
wget https://gitee.com/best1e/acme_synology.sh/raw/main/acme_synology.sh -O acme_synology.sh/acme_synology.shThis will install acme.sh from:
https://gitee.com/best1e/acme.sh.git
instead of GitHub.
After downloading the script, follow these steps to set up automatic execution in Synology DSM:
-
Open Synology DSM Control Panel
-
Navigate to
Control Panel > Task Scheduler -
Click
Createand selectScheduled Task > User-defined Script -
Enter Task Name (e.g.,
Auto SSL Renewal) -
Set User Account
- Choose any administrator account.
-
Set Schedule
- Configure the task to run weekly or at your preferred interval.
-
Define the User Script
- Add the following environment variables in the script:
export CF_Token="your-cloudflare-api-token" export ACME_EMAIL="your-email@example.com" export SYNO_USERNAME="your-synology-admin" export SYNO_PASSWORD="your-synology-password" bash /path/to/your/acme_synology.sh/acme_synology.sh --use-gitee
-
Save and Confirm
-
Manually Run the Task Once
- Click the
Runbutton in the menu bar.
- Click the
-
Check Execution Results
- Click
Action > View Resultsto confirm successful deployment.
Certificates are stored in:
/path/to/script/acme/certs
You can configure the path by modifying the CERT_DIR variable in the script.
- The script uses the
--deploy-hook synology_dsmoption to automatically deploy certificates to Synology DSM. - Ensure your DSM allows certificate updates via
acme.sh. - If you encounter issues, check
acme.shlogs for details.