From fa19538c9dd189a4dbd7704c311f1fe28ce87f98 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sun, 30 Jul 2023 07:14:44 +0000 Subject: [PATCH] handle custom certs in backup/restore --- backup.sh | 18 +++++++++++++++--- restore.sh | 24 +++++++++++++++++++----- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/backup.sh b/backup.sh index 9f399f59..147ccc46 100755 --- a/backup.sh +++ b/backup.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -SCRIPT_VERSION="27" +SCRIPT_VERSION="28" GREEN='\033[0;32m' YELLOW='\033[1;33m' @@ -89,7 +89,19 @@ fi tar -czvf ${tmp_dir}/meshcentral/mesh.tar.gz --exclude=/meshcentral/node_modules /meshcentral -sudo tar -czvf ${tmp_dir}/certs/etc-letsencrypt.tar.gz -C /etc/letsencrypt . +if [ -d /etc/letsencrypt ]; then + sudo tar -czvf ${tmp_dir}/certs/etc-letsencrypt.tar.gz -C /etc/letsencrypt . +fi + +local_settings='/rmm/api/tacticalrmm/tacticalrmm/local_settings.py' + +if grep -q CERT_FILE "$local_settings"; then + mkdir -p ${tmp_dir}/certs/custom + CERT_FILE=$(grep "^CERT_FILE" "$local_settings" | awk -F'[= "]' '{print $5}') + KEY_FILE=$(grep "^KEY_FILE" "$local_settings" | awk -F'[= "]' '{print $5}') + cp -p $CERT_FILE ${tmp_dir}/certs/custom/cert + cp -p $KEY_FILE ${tmp_dir}/certs/custom/key +fi for i in rmm frontend meshcentral; do sudo cp /etc/nginx/sites-available/${i}.conf ${tmp_dir}/nginx/ @@ -99,7 +111,7 @@ sudo tar -czvf ${tmp_dir}/confd/etc-confd.tar.gz -C /etc/conf.d . sudo cp ${sysd}/rmm.service ${sysd}/celery.service ${sysd}/celerybeat.service ${sysd}/meshcentral.service ${sysd}/nats.service ${sysd}/daphne.service ${sysd}/nats-api.service ${tmp_dir}/systemd/ -cp /rmm/api/tacticalrmm/tacticalrmm/local_settings.py ${tmp_dir}/rmm/ +cp $local_settings ${tmp_dir}/rmm/ if [[ $* == *--auto* ]]; then diff --git a/restore.sh b/restore.sh index ecd7de9d..bd138029 100755 --- a/restore.sh +++ b/restore.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -SCRIPT_VERSION="49" +SCRIPT_VERSION="50" SCRIPT_URL='https://raw.githubusercontent.com/amidaware/tacticalrmm/master/restore.sh' sudo apt update @@ -193,10 +193,24 @@ sudo apt install -y certbot openssl print_green 'Restoring certs' -sudo rm -rf /etc/letsencrypt -sudo mkdir /etc/letsencrypt -sudo tar -xzf $tmp_dir/certs/etc-letsencrypt.tar.gz -C /etc/letsencrypt -sudo chown ${USER}:${USER} -R /etc/letsencrypt +if [ -f "$tmp_dir/certs/etc-letsencrypt.tar.gz" ]; then + sudo rm -rf /etc/letsencrypt + sudo mkdir /etc/letsencrypt + sudo tar -xzf $tmp_dir/certs/etc-letsencrypt.tar.gz -C /etc/letsencrypt + sudo chown ${USER}:${USER} -R /etc/letsencrypt +fi + +if [ -d "${tmp_dir}/certs/custom" ]; then + CERT_FILE=$(grep "^CERT_FILE" "$tmp_dir/rmm/local_settings.py" | awk -F'[= "]' '{print $5}') + KEY_FILE=$(grep "^KEY_FILE" "$tmp_dir/rmm/local_settings.py" | awk -F'[= "]' '{print $5}') + + sudo mkdir -p $(dirname $CERT_FILE) $(dirname $KEY_FILE) + sudo chown ${USER}:${USER} $(dirname $CERT_FILE) $(dirname $KEY_FILE) + + cp -p ${tmp_dir}/certs/custom/cert $CERT_FILE + cp -p ${tmp_dir}/certs/custom/key $KEY_FILE + +fi print_green 'Restoring celery configs'