Jump to content

Recommended Posts

Posted

Pour ceux qui ont un certificat Let's Encrypt sur leur Synology, voici un script pour le transformer automatique en fichier P12 pour être utilisé par EMBY

#!/bin/sh

# CONFIGURATION

#script_folder=/volume2/Emby backup/Certificats à conserver
script_folder=/volume2/video
# p12 file
p12_file_path=$script_folder/certificate_auto.pfx
# Synology's Default Let's encrypt folder
letsencrypt_cert_folder=/usr/syno/etc/certificate/system/default
# renew timestamp
renew_timestamp=renew_emby_timestamp.txt
# p12 password
p12cert_password=EMBY


# DO NOT CHANGE BELOW UNLESS YOU'RE A WIZARD

generate_p12=false
current_date=`date +"%s"`
current_certificate_date=`openssl x509 -enddate -noout -in $letsencrypt_cert_folder/RSA-cert.pem | cut -d'=' -f2`
current_certificate_timestamp=`date -d "$current_certificate_date" +"%s"`

# check if the renew_timestamp file exists
if [ ! -f $script_folder/$renew_timestamp ]; then
  echo "Generate timestamp for the current renew date... "
  echo $current_certificate_timestamp > $script_folder/$renew_timestamp
  chmod +rw $script_folder/$renew_timestamp
  chown admin:users $script_folder/$renew_timestamp

  # generate the first p12 file
  generate_p12=true
else
  renew_date=`cat $script_folder/$renew_timestamp`
  # check if it is necessary to renew the certificate or not
  if expr "$current_date" ">" "$renew_date" > /dev/null; then
    # generate a new p12 file
    echo "Renewing certificate..."
    generate_p12=true

    # update timestamp in the file
    echo $current_certificate_timestamp > $script_folder/$renew_timestamp
  else
    echo "It is not necessary to renew the certificate, abort."
    exit 0
  fi
fi

# generate a new certificate file if necessary, and restart EMBY Server
if expr "$generate_p12" "=" "true" > /dev/null; then
  echo "Generating the p12 certificate file..."
  openssl pkcs12 -export -in $letsencrypt_cert_folder/RSA-fullchain.pem -inkey $letsencrypt_cert_folder/RSA-privkey.pem -out $p12_file_path -password pass:$p12cert_password
  chmod +r $p12_file_path
  chown admin:users $p12_file_path
  echo "Restarting EMBY Server..."
  synopkg restart EmbyServer
  echo "Done."
fi

 

 

A lancer en "Root" quotidiennement

 

  • Thanks 1
massilliaman
Posted

Salut, dommage ca manque un peu d'information sur la partie # CONFIGURATION pour les gens comme moi, qui sont un peu juste en informatique 😛

Posted

# CONFIGURATION

#script_folder endroit où tu veux mettre ton certificat pour EMBY
script_folder=/volume2/video
# p12 file Nom du certificat pour EMBY
p12_file_path=$script_folder/certificate_auto.pfx
# Synology's Default Let's encrypt folder
letsencrypt_cert_folder=/usr/syno/etc/certificate/system/default
# renew timestamp
renew_timestamp=renew_emby_timestamp.txt
# p12 password Mot de passe du certificat pour EMBY
p12cert_password=EMBY

  • 2 months later...
yohan_g
Posted (edited)

Merci pour le script, cependant pour moi il ne fonctionnait pas. J'ai réussi à appliquer une correction qui fonctionne avec l'aide de Copilot 🙂

Pour les détails:

- J'ai créé un répertoire partagé dédié: /volume1/Emby-certs

- J'y ai créé en SSH (avec le compte root) le script corrigé "Emby_certs_from_dsm.sh" et copié/collé le script ( vi /volume1/Emby-certs/Emby_certs_from_dsm.sh )=> cela évite des erreurs due au format du fichier lorsque créé depuis un ordinateur et déposé dans le répertoire partagé

- (optionnel) Vérifié en SSH (avec le compte root) le bon fonctionnement du script, en tapant simplement /bin/bash /volume1/Emby-certs/Emby_certs_from_dsm.sh

- Créé une tâche planifiée exécutée avec le compte root, avec la commande: /bin/bash /volume1/Emby-certs/Emby_certs_from_dsm.sh

- Lancé une fois la tâche et vérifié dans le répertoire partagé que le certificat apparait

- Configuré Emby pour récupérer le certificat généré (mot de passe du certificat configuré dans le script: "EMBY")

 

Le script corrigé (vous pouvez ne modifier que l'emplacement du répertoire où se trouve le script, pour le reste, inutile de modifier):

#!/bin/sh

# CONFIGURATION
script_folder="/volume1/Emby-certs"
p12_file_path="$script_folder/certificate_auto.pfx"
letsencrypt_cert_folder="/usr/syno/etc/certificate/system/default"
renew_timestamp="renew_emby_timestamp.txt"
p12cert_password="EMBY"

# DO NOT CHANGE BELOW UNLESS YOU'RE A WIZARD
generate_p12=false
current_date=$(date +"%s")
current_certificate_date=$(openssl x509 -enddate -noout -in "$letsencrypt_cert_folder/RSA-cert.pem" | cut -d'=' -f2)
current_certificate_timestamp=$(date -d "$current_certificate_date" +"%s")

# Vérifier si le fichier renew_timestamp existe
if [ ! -f "$script_folder/$renew_timestamp" ]; then
  echo "Generate timestamp for the current renew date... "
  echo "$current_certificate_timestamp" > "$script_folder/$renew_timestamp"
  chmod +rw "$script_folder/$renew_timestamp"
  chown admin:users "$script_folder/$renew_timestamp"

  # Generate the first p12 file
  generate_p12=true
else
  renew_date=$(cat "$script_folder/$renew_timestamp")

  # Check if it is necessary to renew the certificate
  if [ "$current_date" -ge "$renew_date" ]; then
    echo "Renewing certificate..."
    generate_p12=true
    echo "$current_certificate_timestamp" > "$script_folder/$renew_timestamp"
  else
    echo "It is not necessary to renew the certificate, abort."
    exit 0
  fi
fi

# Generate a new certificate file if necessary and restart EMBY Server
if [ "$generate_p12" = "true" ]; then
  echo "Generating the p12 certificate file..."
  openssl pkcs12 -export -in "$letsencrypt_cert_folder/RSA-fullchain.pem" -inkey "$letsencrypt_cert_folder/RSA-privkey.pem" -out "$p12_file_path" -password pass:"$p12cert_password"
  chmod +r "$p12_file_path"
  chown admin:users "$p12_file_path"
  echo "Restarting EMBY Server..."
  synopkg restart EmbyServer
  echo "Done."
fi

 

Edited by yohan_g
  • Like 1
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...