From 39311099dfc9e8d01f544facccb5acf28fc82933 Mon Sep 17 00:00:00 2001 From: sadnub Date: Fri, 21 Jan 2022 18:11:27 -0500 Subject: [PATCH] community-script rework --- api/tacticalrmm/scripts/models.py | 10 ++-------- api/tacticalrmm/tacticalrmm/settings.py | 2 +- docker/containers/tactical/dockerfile | 9 +++++++-- docker/containers/tactical/entrypoint.sh | 2 +- install.sh | 7 +++++++ restore.sh | 7 +++++++ update.sh | 20 ++++++++++++++++++++ 7 files changed, 45 insertions(+), 12 deletions(-) diff --git a/api/tacticalrmm/scripts/models.py b/api/tacticalrmm/scripts/models.py index 979b8894..89605c11 100644 --- a/api/tacticalrmm/scripts/models.py +++ b/api/tacticalrmm/scripts/models.py @@ -93,15 +93,9 @@ class Script(BaseAuditModel): # load community uploaded scripts into the database # skip ones that already exist, only updating name / desc in case it changes # for install script - if not settings.DOCKER_BUILD: - scripts_dir = os.path.join(Path(settings.BASE_DIR).parents[1], "scripts") - # for docker - else: - scripts_dir = settings.SCRIPTS_DIR + scripts_dir = os.path.join(settings.SCRIPTS_DIR, "scripts") - with open( - os.path.join(settings.BASE_DIR, "scripts/community_scripts.json") - ) as f: + with open(os.path.join(settings.SCRIPTS_DIR, "community_scripts.json")) as f: info = json.load(f) # used to remove scripts from DB that are removed from the json file and file system diff --git a/api/tacticalrmm/tacticalrmm/settings.py b/api/tacticalrmm/tacticalrmm/settings.py index 09a9ed9f..c4247f3d 100644 --- a/api/tacticalrmm/tacticalrmm/settings.py +++ b/api/tacticalrmm/tacticalrmm/settings.py @@ -4,7 +4,7 @@ from pathlib import Path BASE_DIR = Path(__file__).resolve().parent.parent -SCRIPTS_DIR = "/srv/salt/scripts" +SCRIPTS_DIR = "/community-scripts" DOCKER_BUILD = False diff --git a/docker/containers/tactical/dockerfile b/docker/containers/tactical/dockerfile index 035f6476..6c7e872c 100644 --- a/docker/containers/tactical/dockerfile +++ b/docker/containers/tactical/dockerfile @@ -16,11 +16,16 @@ COPY api/tacticalrmm/requirements.txt ${TACTICAL_TMP_DIR}/api/requirements.txt RUN apt-get update && \ apt-get install -y --no-install-recommends gcc libc6-dev && \ - rm -rf /var/lib/apt/lists/* && \ pip install --upgrade pip && \ pip install --no-cache-dir setuptools wheel && \ pip install --no-cache-dir -r ${TACTICAL_TMP_DIR}/api/requirements.txt +# pulls community scripts from git repo +FROM python:3.9.9-slim AS GET_SCRIPTS_STAGE + +RUN apt-get update && \ + apt-get install -y --no-install-recommends git && \ + git clone https://github.com/amidaware/community-scripts.git / # runtime image FROM python:3.9.9-slim @@ -35,7 +40,7 @@ ENV PATH "${VIRTUAL_ENV}/bin:$PATH" # copy files from repo COPY api/tacticalrmm ${TACTICAL_TMP_DIR}/api -COPY scripts ${TACTICAL_TMP_DIR}/scripts +COPY --from=GET_SCRIPTS_STAGE /community-scripts ${TACTICAL_TMP_DIR}/community-scripts # copy go install from build stage COPY --from=CREATE_VENV_STAGE ${VIRTUAL_ENV} ${VIRTUAL_ENV} diff --git a/docker/containers/tactical/entrypoint.sh b/docker/containers/tactical/entrypoint.sh index 1f3dd578..797c8117 100644 --- a/docker/containers/tactical/entrypoint.sh +++ b/docker/containers/tactical/entrypoint.sh @@ -70,7 +70,7 @@ KEY_FILE = '${CERT_PRIV_PATH}' EXE_DIR = '/opt/tactical/api/tacticalrmm/private/exe' LOG_DIR = '/opt/tactical/api/tacticalrmm/private/log' -SCRIPTS_DIR = '/opt/tactical/scripts' +SCRIPTS_DIR = '/opt/tactical/community-scripts' ALLOWED_HOSTS = ['${API_HOST}', 'tactical-backend'] diff --git a/install.sh b/install.sh index 6acce06f..23229c0d 100644 --- a/install.sh +++ b/install.sh @@ -243,6 +243,13 @@ git config user.email "admin@example.com" git config user.name "Bob" git checkout master +sudo mkdir /community-scripts +sudo chown ${USER}:${USER} /community-scripts +git clone https://github.com/wh1te909/tacticalrmm.git /community-scripts/ +cd /community-scripts +git config user.email "admin@example.com" +git config user.name "Bob" + print_green 'Downloading NATS' NATS_SERVER_VER=$(grep "^NATS_SERVER_VER" /rmm/api/tacticalrmm/tacticalrmm/settings.py | awk -F'[= "]' '{print $5}') diff --git a/restore.sh b/restore.sh index b02c9d80..1c024b36 100755 --- a/restore.sh +++ b/restore.sh @@ -218,6 +218,13 @@ git config user.email "admin@example.com" git config user.name "Bob" git checkout master +sudo mkdir /community-scripts +sudo chown ${USER}:${USER} /community-scripts +git clone https://github.com/wh1te909/tacticalrmm.git /community-scripts/ +cd /community-scripts +git config user.email "admin@example.com" +git config user.name "Bob" + print_green 'Restoring NATS' NATS_SERVER_VER=$(grep "^NATS_SERVER_VER" /rmm/api/tacticalrmm/tacticalrmm/settings.py | awk -F'[= "]' '{print $5}') diff --git a/update.sh b/update.sh index ba17279a..48998c6a 100644 --- a/update.sh +++ b/update.sh @@ -226,6 +226,7 @@ fi sudo npm install -g npm +# update from main repo cd /rmm git config user.email "admin@example.com" git config user.name "Bob" @@ -235,11 +236,30 @@ git reset --hard FETCH_HEAD git clean -df git pull +# update from community-scripts repo +if [[ ! -d /community-scripts ]]; then + sudo mkdir /community-scripts + sudo chown ${USER}:${USER} /community-scripts + git clone https://github.com/wh1te909/tacticalrmm.git /community-scripts/ + cd /community-scripts + git config user.email "admin@example.com" + git config user.name "Bob" +else + cd /community-scripts + git config user.email "admin@example.com" + git config user.name "Bob" + git fetch + git reset --hard FETCH_HEAD + git clean -df + git pull +fi + SETUPTOOLS_VER=$(grep "^SETUPTOOLS_VER" "$SETTINGS_FILE" | awk -F'[= "]' '{print $5}') WHEEL_VER=$(grep "^WHEEL_VER" "$SETTINGS_FILE" | awk -F'[= "]' '{print $5}') sudo chown ${USER}:${USER} -R /rmm +sudo chown ${USER}:${USER} -R /community-scripts sudo chown ${USER}:${USER} /var/log/celery sudo chown ${USER}:${USER} -R /etc/conf.d/ sudo chown -R $USER:$GROUP /home/${USER}/.npm