-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Deploy to plex #6395
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
Open
fergbrain
wants to merge
15
commits into
acmesh-official:dev
Choose a base branch
from
fergbrain:deploy_to_plex
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Deploy to plex #6395
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bfaacd6
Create plex.sh
fergbrain db49858
Check/assign variables before printing debug2
fergbrain b2be1eb
Update to align with SC2181 (style): Check exit code directly with e.…
fergbrain 238cd4b
Check for shfmt -w -i 2 plex.sh
fergbrain 718774a
Disable SC2154. There seems to be a bug in version 0.7 of shellcheck.…
fergbrain 660d8bc
Update generation of PKCS12 cert to use modern encryption so that Ple…
fergbrain fad63bd
Merge branch 'acmesh-official:master' into deploy_to_plex
fergbrain 2c950d6
Create plex_synology.sh
fergbrain 9bce5bc
Merge branch 'acmesh-official:master' into deploy_to_plex
fergbrain fa44e09
Merge branch 'acmesh-official:master' into deploy_to_plex
fergbrain f802fb7
Fix formatting
fergbrain 948c41c
support PLEX_RELOAD environment variable to override the Plex restart…
fergbrain cd89c68
Merge branch 'dev' into deploy_to_plex
fergbrain 757958e
Remove disable=SC2154
fergbrain 8b9ebe5
Merge branch 'deploy_to_plex' of github.com:fergbrain/acme.sh into de…
fergbrain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Here is a script to deploy cert to local Plex Media Server on Debian. | ||
|
||
# The following environment variables must be set: | ||
# | ||
# PLEX_PKCS12_Password - Password used for the PKCS12 certificate | ||
|
||
#returns 0 means success, otherwise error. | ||
|
||
# Settings for Plex Media Server: | ||
# | ||
# PLEX_PKCS12_password -- Password for the PKCS file. Required by plex | ||
# PLEX_PKCS12_file -- Full PKCS file location, otherwise defaults to placing with the other certs in that domain with a pfx extension | ||
# PLEX_sudo_required -- 1 = True, 0 = False. You may need to add "plex ALL=(ALL) NOPASSWD:/bin/systemctl restart plexmediaserver.service" to your sudo'ers file | ||
# PLEX_RELOAD -- Optional custom command to restart Plex. If not set, the script will try | ||
# to restart the service via systemctl when Plex is detected as active. | ||
|
||
######## Public functions ##################### | ||
|
||
#domain keyfile certfile cafile fullchain | ||
plex_deploy() { | ||
_cdomain="$1" | ||
_ckey="$2" | ||
_ccert="$3" | ||
_cca="$4" | ||
_cfullchain="$5" | ||
|
||
_debug _cdomain "$_cdomain" | ||
_debug _ckey "$_ckey" | ||
_debug _ccert "$_ccert" | ||
_debug _cca "$_cca" | ||
_debug _cfullchain "$_cfullchain" | ||
|
||
_getdeployconf PLEX_PKCS12_password | ||
_getdeployconf PLEX_PKCS12_file | ||
_getdeployconf PLEX_sudo_required | ||
_getdeployconf PLEX_RELOAD | ||
|
||
#_DEPLOY_PLEX_WIKI="https://github.com/acmesh-official/acme.sh/wiki/deploy-to-plex" | ||
|
||
_plex_to_pkcs() { | ||
# The existing _toPkcs command doesn't have an option to specify cipher, so copied here | ||
# to force using a modern cipher, as required by PMS: | ||
# https://forums.plex.tv/t/ssl-became-broken-after-latest-pms-update/837416/4 | ||
_cpfx="$1" | ||
_ckey="$2" | ||
_ccert="$3" | ||
_cca="$4" | ||
pfxPassword="$5" | ||
|
||
${ACME_OPENSSL_BIN:-openssl} pkcs12 -export -out "$_cpfx" -certpbe AES-256-CBC -keypbe AES-256-CBC -macalg SHA256 -inkey "$_ckey" -in "$_ccert" -certfile "$_cca" -password "pass:$pfxPassword" | ||
} | ||
|
||
if [ -z "$PLEX_PKCS12_password" ]; then | ||
_err "The PLEX_PKCS12_password variable is not defined. Plex requires a password for the certificate." | ||
#_err "See: $_DEPLOY_PLEX_WIKI" | ||
return 1 | ||
fi | ||
_debug2 PLEX_PKCS12_password "$PLEX_PKCS12_password" | ||
|
||
if [ -z "$PLEX_PKCS12_file" ]; then | ||
PLEX_PKCS12_file="$DOMAIN_PATH/$_cdomain.pfx" | ||
_debug2 "Setting PLEX_PKCS12_file to default" | ||
fi | ||
_debug2 PLEX_PKCS12_file "$PLEX_PKCS12_file" | ||
|
||
if [ -z "$PLEX_sudo_required" ]; then | ||
PLEX_sudo_required=0 | ||
_debug2 "Setting PLEX_PKCS12_file to default (0/False)" | ||
fi | ||
|
||
_debug2 PLEX_sudo_required "$PLEX_sudo_required" | ||
_debug2 PLEX_RELOAD "$PLEX_RELOAD" | ||
|
||
_reload_cmd="$PLEX_RELOAD" | ||
|
||
_debug "Generate import pkcs12" | ||
|
||
if ! _plex_to_pkcs "$PLEX_PKCS12_file" "$_ckey" "$_ccert" "$_cca" "$PLEX_PKCS12_password"; then | ||
_err "Error generating pkcs12. Please re-run with --debug and report a bug." | ||
return 1 | ||
fi | ||
|
||
if [ -z "$_reload_cmd" ]; then | ||
if systemctl -q is-active plexmediaserver; then | ||
_debug2 "Plex is active. Restarting..." | ||
if [ "$PLEX_sudo_required" = "1" ]; then | ||
_reload_cmd="sudo systemctl restart plexmediaserver.service" | ||
else | ||
_reload_cmd="systemctl restart plexmediaserver.service" | ||
fi | ||
fi | ||
fi | ||
if [ -z "$_reload_cmd" ]; then | ||
_info "Plex server is not active. Certificates installed, but skipping restart." | ||
else | ||
if eval "$_reload_cmd"; then | ||
_info "Reload success!" | ||
else | ||
_err "Reload error" | ||
return 1 | ||
fi | ||
fi | ||
|
||
_services_updated="${_services_updated} plexmediaserver" | ||
_info "Install Plex Media Server certificate success!" | ||
|
||
# Successful, so save all (non-default) config: | ||
_savedeployconf PLEX_PKCS12_password "$PLEX_PKCS12_password" | ||
_savedeployconf PLEX_PKCS12_file "$PLEX_PKCS12_file" | ||
_savedeployconf PLEX_sudo_required "$PLEX_sudo_required" | ||
_savedeployconf PLEX_RELOAD "$PLEX_RELOAD" | ||
|
||
return 0 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/usr/bin/bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shebang |
||
|
||
# Here is a script to deploy cert to local Plex Media Server on Synology. | ||
# Based on https://www.snbforums.com/threads/issue-lets-encrypt-certificate-with-acme-sh-use-it-with-synology-dsm-and-plex.70395/ | ||
|
||
# The following environment variables must be set: | ||
# | ||
# PLEX_PKCS12_Password - Password used for the PKCS12 certificate | ||
|
||
#returns 0 means success, otherwise error. | ||
|
||
# Settings for Plex Media Server: | ||
# | ||
# PLEX_PKCS12_password -- Password for the PKCS file. Required by plex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Plex 1.41.5 (on Synology DSM 7.2.2) accepts empty/blank passwords. |
||
# PLEX_PKCS12_file -- Full PKCS file location, otherwise defaults to placing with the other certs in that domain with a pfx extension | ||
# PLEX_sudo_required -- 1 = True, 0 = False. You may need to add "plex ALL=(ALL) NOPASSWD:/bin/systemctl restart plexmediaserver.service" to your sudo'ers file | ||
|
||
# Set Plex certificate location to /usr/local/share/Plex/plex_cert.pfx | ||
|
||
######## Public functions ##################### | ||
|
||
#domain keyfile certfile cafile fullchain | ||
plex_synology_deploy() { | ||
_cdomain="$1" | ||
_ckey="$2" | ||
_ccert="$3" | ||
_cca="$4" | ||
_cfullchain="$5" | ||
|
||
_debug _cdomain "$_cdomain" | ||
_debug _ckey "$_ckey" | ||
_debug _ccert "$_ccert" | ||
_debug _cca "$_cca" | ||
_debug _cfullchain "$_cfullchain" | ||
|
||
_getdeployconf PLEX_PKCS12_password | ||
_getdeployconf PLEX_PKCS12_file | ||
_getdeployconf PLEX_sudo_required | ||
|
||
#_DEPLOY_PLEX_WIKI="https://github.com/acmesh-official/acme.sh/wiki/deploy-to-plex" | ||
|
||
_plex_to_pkcs() { | ||
# The existing _toPkcs command doesn't have an option to specify cipher, so copied here | ||
# to force using a modern cipher, as required by PMS: | ||
# https://forums.plex.tv/t/ssl-became-broken-after-latest-pms-update/837416/4 | ||
_cpfx="$1" | ||
_ckey="$2" | ||
_ccert="$3" | ||
_cca="$4" | ||
pfxPassword="$5" | ||
|
||
${ACME_OPENSSL_BIN:-openssl} pkcs12 -export -out "$_cpfx" -certpbe AES-256-CBC -keypbe AES-256-CBC -macalg SHA256 -inkey "$_ckey" -in "$_ccert" -certfile "$_cca" -password "pass:$pfxPassword" | ||
} | ||
|
||
if [ -z "$PLEX_PKCS12_password" ]; then | ||
_err "The PLEX_PKCS12_password variable is not defined. Plex requires a password for the certificate." | ||
#_err "See: $_DEPLOY_PLEX_WIKI" | ||
return 1 | ||
fi | ||
_debug2 PLEX_PKCS12_password "$PLEX_PKCS12_password" | ||
|
||
if [ -z "$PLEX_PKCS12_file" ]; then | ||
PLEX_PKCS12_file="/usr/local/share/Plex/plex_cert.pfx" | ||
_debug2 "Setting PLEX_PKCS12_file to default" | ||
fi | ||
_debug2 PLEX_PKCS12_file "$PLEX_PKCS12_file" | ||
|
||
if [ -z "$PLEX_sudo_required" ]; then | ||
PLEX_sudo_required=0 | ||
_debug2 "Setting PLEX_PKCS12_file to default (0/False)" | ||
fi | ||
|
||
_debug2 PLEX_sudo_required "$PLEX_sudo_required" | ||
|
||
_reload_cmd="" | ||
|
||
_debug "Generate import pkcs12" | ||
|
||
if ! _plex_to_pkcs "$PLEX_PKCS12_file" "$_ckey" "$_ccert" "$_cca" "$PLEX_PKCS12_password"; then | ||
_err "Error generating pkcs12. Please re-run with --debug and report a bug." | ||
return 1 | ||
fi | ||
|
||
if systemctl -q is-active pkgctl-PlexMediaServer.service; then | ||
_debug2 "Plex is active. Restarting..." | ||
_reload_cmd="/usr/syno/bin/synopkg restart PlexMediaServer" | ||
fi | ||
if [ -z "$_reload_cmd" ]; then | ||
_info "Plex server is not active. Certificates installed, but skipping restart." | ||
else | ||
if eval "$_reload_cmd"; then | ||
_info "Reload success!" | ||
else | ||
_err "Reload error" | ||
return 1 | ||
fi | ||
fi | ||
|
||
_services_updated="${_services_updated} plexmediaserver" | ||
_info "Install Plex Media Server certificate success!" | ||
|
||
# Successful, so save all (non-default) config: | ||
_savedeployconf PLEX_PKCS12_password "$PLEX_PKCS12_password" | ||
_savedeployconf PLEX_PKCS12_file "$PLEX_PKCS12_file" | ||
_savedeployconf PLEX_sudo_required "$PLEX_sudo_required" | ||
|
||
return 0 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't copy.
modify the _toPkcs function to use a cipher