Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typo correction and small enhancements before going my own way. #3

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ This scripts copy the specified LetsEncrypt certificate issue by your pfSense in

How to get started:
```bash
bash install_letsencrypt_cert_from_pfsense.sh -s LETSENCRYPT_SHARE -n CERTIFICATE_NAME -p PFSENSE_SSH_PORT -u PFSENSE_USERNAME -h PFSENSE_HOSTNAME
bash copy_letsencrypt_cert_from_pfsense.sh -s LETSENCRYPT_SHARE -n CERTIFICATE_NAME -p PFSENSE_SSH_PORT -u PFSENSE_USERNAME -h PFSENSE_HOSTNAME

# Arguments:
# -s LETSENCRYPT_SHARE Full share path to download the LetsEncrypt certificates into (e.g. /volume1/LetsEncrypt)
Expand Down
46 changes: 41 additions & 5 deletions synology/install_letsencrypt_cert_from_pfsense.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,39 @@ do
case "${flag}" in
s) LETSENCRYPT_SHARE=${OPTARG};;
n) CERTIFICATE_NAME=${OPTARG};;
f) CERTIFICATE_PATH=${OPTARG};;
esac
done

[ -z "${LETSENCRYPT_SHARE}" ] && echo "Set Let's Encrypt share path through -s (e.g. -s /volume1/LetsEncrypt)" && exit 1
[ -z "${CERTIFICATE_NAME}" ] && echo "Set Certificate name as displayed (case sensitive) on pfSense UI -n (e.g. -n Synology)" && exit 1
display_help=0
if [[ -z "${CERTIFICATE_PATH}" ]]; then
[[ -z "${LETSENCRYPT_SHARE}" ]] && display_help=1
[[ -z "${CERTIFICATE_NAME}" ]] && display_help=1
[[ -n "${CERTIFICATE_PATH}" ]] && echo "-f should not be used with -s -n" && display_help=1
else
[[ ! -f "${CERTIFICATE_PATH}" ]] && echo "${CERTIFICATE_PATH} : File not found" && display_help=1
[[ -n "${LETSENCRYPT_SHARE}" || -n "${CERTIFICATE_NAME}" ]] && echo "-f should not be used with -s -n" && display_help=1
fi

if [[ "${display_help}" ]]; then
echo << __EO_HELP__
This script updates the Synology CRT with a renewed one then restarts services if needed.

You may use it in 2 ways:

1) With a share and a certificate name:
-s crt_share : Set Let's Encrypt share path (e.g. -s /volume1/LetsEncrypt)
-n crt_name : Set Certificate name as displayed (case sensitive) on pfSense UI (e.g. -n Synology)

2) With the CRT full path:
-f crt_path : Set Let's Encrypt crt path (e.g. -f /volume1/docker/swag/etc/letsencrypt/live/my.domain.com/priv-fullchain-bundle.pem)

__EO_HELP__

exit

# Existing certificates are replaced below
DSM_MAJOR_VERSION=$([[ $(grep majorversion /etc/VERSION) =~ [0-9] ]] && echo ${BASH_REMATCH[0]})
DEFAULT_CERT_ROOT_DIR="/usr/syno/etc/certificate"
DEFAULT_ARCHIVE_CERT_DIR="${DEFAULT_CERT_ROOT_DIR}/_archive"
DEFAULT_ARCHIVE_CERT_NAME=${DEFAULT_ARCHIVE_CERT_DIR}/$(cat ${DEFAULT_ARCHIVE_CERT_DIR}/DEFAULT)
Expand All @@ -30,6 +56,16 @@ for _dir in ${EXISTING_CERT_FOLDERS} ${DEFAULT_ARCHIVE_CERT_NAME}; do
done

# Restart web server
synoservice --restart nginx
synoservice --restart nmbd
synoservice --restart avahi
if [[ ${DSM_MAJOR_VERSION} == 6]]; then
synoservice --restart nginx
synoservice --restart nmbd
synoservice --restart smbd
synoservice --restart avahi
synoservice --restart pkgctl-WebStation.service
else
systemctl restart nginx
systemctl restart pkg-synosamba-nmbd.service
systemctl restart pkg-synosamba-smbd.service
systemctl restart avahi
systemctl restart pkgctl-WebStation.service
fi