From b5157fcaf18bfae6d3981700089738182b7b7dd7 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sun, 4 Apr 2021 01:13:27 +0000 Subject: [PATCH] update bash scripts for channels --- backup.sh | 5 ++++- install.sh | 31 +++++++------------------------ restore.sh | 4 ++-- update.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 61 insertions(+), 30 deletions(-) diff --git a/backup.sh b/backup.sh index f8696460..07ec4605 100755 --- a/backup.sh +++ b/backup.sh @@ -1,6 +1,6 @@ #!/bin/bash -SCRIPT_VERSION="11" +SCRIPT_VERSION="12" SCRIPT_URL='https://raw.githubusercontent.com/wh1te909/tacticalrmm/master/backup.sh' GREEN='\033[0;32m' @@ -73,6 +73,9 @@ sudo tar -czvf ${tmp_dir}/nginx/etc-nginx.tar.gz -C /etc/nginx . 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 ${tmp_dir}/systemd/ +if [ -f "${sysd}/daphne.service" ]; then + sudo cp ${sysd}/daphne.service ${tmp_dir}/systemd/ +fi cat /rmm/api/tacticalrmm/tacticalrmm/private/log/debug.log | gzip -9 > ${tmp_dir}/rmm/debug.log.gz cp /rmm/api/tacticalrmm/tacticalrmm/local_settings.py /rmm/api/tacticalrmm/app.ini ${tmp_dir}/rmm/ diff --git a/install.sh b/install.sh index 6747bba1..0a0a3105 100644 --- a/install.sh +++ b/install.sh @@ -1,6 +1,6 @@ #!/bin/bash -SCRIPT_VERSION="44" +SCRIPT_VERSION="45" SCRIPT_URL='https://raw.githubusercontent.com/wh1te909/tacticalrmm/master/install.sh' sudo apt install -y curl wget dirmngr gnupg lsb-release @@ -132,31 +132,14 @@ CHECK_HOSTS=$(grep 127.0.1.1 /etc/hosts | grep "$rmmdomain" | grep "$meshdomain" HAS_11=$(grep 127.0.1.1 /etc/hosts) if ! [[ $CHECK_HOSTS ]]; then - echo -ne "${GREEN}We need to append your 3 subdomains to the line starting with 127.0.1.1 in your hosts file.${NC}\n" - until [[ $edithosts =~ (y|n) ]]; do - echo -ne "${GREEN}Would you like me to do this for you? [y/n]${NC}: " - read edithosts - done - - if [[ $edithosts == "y" ]]; then - if [[ $HAS_11 ]]; then - sudo sed -i "/127.0.1.1/s/$/ ${rmmdomain} $frontenddomain $meshdomain/" /etc/hosts - else - echo "127.0.1.1 ${rmmdomain} $frontenddomain $meshdomain" | sudo tee --append /etc/hosts > /dev/null - fi - else - if [[ $HAS_11 ]]; then - echo -ne "${GREEN}Please manually edit your /etc/hosts file to match the line below and re-run this script.${NC}\n" - sed "/127.0.1.1/s/$/ ${rmmdomain} $frontenddomain $meshdomain/" /etc/hosts | grep 127.0.1.1 - else - echo -ne "\n${GREEN}Append the following line to your /etc/hosts file${NC}\n" - echo "127.0.1.1 ${rmmdomain} $frontenddomain $meshdomain" - fi - exit 1 - fi + print_green 'Adding subdomains to hosts file' + if [[ $HAS_11 ]]; then + sudo sed -i "/127.0.1.1/s/$/ ${rmmdomain} ${frontenddomain} ${meshdomain}/" /etc/hosts + else + echo "127.0.1.1 ${rmmdomain} ${frontenddomain} ${meshdomain}" | sudo tee --append /etc/hosts > /dev/null + fi fi - BEHIND_NAT=false IPV4=$(ip -4 addr | sed -ne 's|^.* inet \([^/]*\)/.* scope global.*$|\1|p' | head -1) if echo "$IPV4" | grep -qE '^(10\.|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.|192\.168)'; then diff --git a/restore.sh b/restore.sh index 239d0754..b74df4a0 100755 --- a/restore.sh +++ b/restore.sh @@ -1,6 +1,6 @@ #!/bin/bash -SCRIPT_VERSION="22" +SCRIPT_VERSION="23" SCRIPT_URL='https://raw.githubusercontent.com/wh1te909/tacticalrmm/master/restore.sh' sudo apt update @@ -323,7 +323,7 @@ sudo chown -R $USER:$GROUP /home/${USER}/.cache print_green 'Enabling Services' sudo systemctl daemon-reload -for i in celery.service celerybeat.service rmm.service nginx +for i in celery.service celerybeat.service rmm.service daphne.service nginx do sudo systemctl enable ${i} sudo systemctl stop ${i} diff --git a/update.sh b/update.sh index 4764199a..9cc5be6b 100644 --- a/update.sh +++ b/update.sh @@ -1,6 +1,6 @@ #!/bin/bash -SCRIPT_VERSION="116" +SCRIPT_VERSION="117" SCRIPT_URL='https://raw.githubusercontent.com/wh1te909/tacticalrmm/master/update.sh' LATEST_SETTINGS_URL='https://raw.githubusercontent.com/wh1te909/tacticalrmm/master/api/tacticalrmm/tacticalrmm/settings.py' YELLOW='\033[1;33m' @@ -75,7 +75,52 @@ if [ -f /etc/systemd/system/natsapi.service ]; then sudo systemctl daemon-reload fi -for i in nginx nats rmm celery celerybeat +cls() { + printf "\033c" +} + +CHECK_HAS_DAPHNE=$(grep daphne.sock /etc/nginx/sites-available/rmm.conf) +if ! [[ $CHECK_HAS_DAPHNE ]]; then + cls + echo -ne "${GREEN}Nginx config changes required before continuing.${NC}\n" + echo -ne "${GREEN}Please check the v0.5.0 release notes on github for instructions, then re-run this script.${NC}\n" + echo -ne "${GREEN}Aborting...${NC}\n" + exit 1 +fi + +if ! sudo nginx -t > /dev/null 2>&1; then + sudo nginx -t + echo -ne "\n" + echo -ne "${RED}You have syntax errors in your nginx configs. See errors above. Please fix them and re-run this script.${NC}\n" + echo -ne "${RED}Aborting...${NC}\n" + exit 1 +fi + +if [ -f /etc/systemd/system/daphne.service ]; then +daphneservice="$(cat << EOF +[Unit] +Description=django channels daemon +After=network.target + +[Service] +User=${USER} +Group=www-data +WorkingDirectory=/rmm/api/tacticalrmm +Environment="PATH=/rmm/api/env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" +ExecStart=/rmm/api/env/bin/daphne -u /rmm/daphne.sock tacticalrmm.asgi:application +Restart=always +RestartSec=3s + +[Install] +WantedBy=multi-user.target +EOF +)" +echo "${daphneservice}" | sudo tee /etc/systemd/system/daphne.service > /dev/null +sudo systemctl daemon-reload +sudo systemctl enable daphne.service +fi + +for i in nginx nats rmm daphne celery celerybeat do printf >&2 "${GREEN}Stopping ${i} service...${NC}\n" sudo systemctl stop ${i} @@ -240,7 +285,7 @@ sudo rm -rf /var/www/rmm/dist sudo cp -pr /rmm/web/dist /var/www/rmm/ sudo chown www-data:www-data -R /var/www/rmm/dist -for i in rmm celery celerybeat nginx nats +for i in rmm daphne celery celerybeat nginx nats do printf >&2 "${GREEN}Starting ${i} service${NC}\n" sudo systemctl start ${i}