From 7a3fe536a81df3050b085f730f4f302994b22cc2 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Fri, 11 Feb 2022 00:12:11 +0100 Subject: [PATCH] Fixes in updates --- admin/dashboard.py | 2 +- scripts/system/install_git.py | 24 ++++++++++++++++++++++++ scripts/system/install_psutil.sh | 6 ++---- scripts/system/install_python.sh | 25 +++++++++++++++++++++++-- scripts/system/updates.py | 28 ++++++++++++++++++++++++++++ tasks/system/task.py | 4 ++-- tasks/system/updates.py | 14 ++++++++++++++ 7 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 scripts/system/install_git.py create mode 100644 scripts/system/updates.py create mode 100644 tasks/system/updates.py diff --git a/admin/dashboard.py b/admin/dashboard.py index 321655a..ab670f4 100644 --- a/admin/dashboard.py +++ b/admin/dashboard.py @@ -451,7 +451,7 @@ def pastafari2_update_task(): task_id=0 - path_task='modules.pastafari2.tasks.system.ping' + path_task='modules.pastafari2.tasks.system.updates' data={} diff --git a/scripts/system/install_git.py b/scripts/system/install_git.py new file mode 100644 index 0000000..eecbaa8 --- /dev/null +++ b/scripts/system/install_git.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 -u + +# A script for install pzoo user + +from subprocess import call +from time import sleep +import distro + +linux_distro=distro.id() + +print('{"error": 0, "status": 0, "progress": 0, "no_progress":0, "message": "Installing git..."}') + +sleep(1) + +if linux_distro=='arch': + + if call("sudo pacman -S --noconfirm git", shell=True) > 0: + print('Error, cannot install git...') + exit(1) +elif linux_distro=='debian': + + if call('sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y git', shell=True) > 0: + print('Error, cannot install git...') + exit(1) diff --git a/scripts/system/install_psutil.sh b/scripts/system/install_psutil.sh index 3b2dadf..5742b32 100644 --- a/scripts/system/install_psutil.sh +++ b/scripts/system/install_psutil.sh @@ -6,10 +6,8 @@ sleep 1 echo '{"error": 0, "status": 0, "progress": 100, "no_progress":0, "message": "Installing python3-psutil..."}' -sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y python3-pip - -#sudo pip3 install psutil -sudo apt-get install -y python3-psutil +sudo pip3 install psutil +#sudo apt-get install -y python3-psutil #echo "Installed python3-psutil sucessfully if not error..." diff --git a/scripts/system/install_python.sh b/scripts/system/install_python.sh index 005f24a..01f06c1 100644 --- a/scripts/system/install_python.sh +++ b/scripts/system/install_python.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash sleep 1 @@ -16,7 +16,7 @@ if [[ $DISTRO =~ ^Debian ]]; then elif [[ $DISTRO =~ ^NAME=\"Arch ]]; then - sudo pacman -S python python-pip + sudo pacman -S --noconfirm python python-pip else @@ -40,5 +40,26 @@ else fi +echo '{"error": 0, "status": 0, "progress": 0, "no_progress":0, "message": "Installing distro package for python and detect distribution..."}' + +sleep 1 + +sudo pip3 install distro + +if [ $? -eq 0 ]; then + + #echo "Installed python3 sucessfully if not error..." + echo '{"error": 0, "status": 0, "progress": 100, "no_progress":0, "message": "Installed distro python package sucessfully..."}' + + sleep 1 + +else + + echo "Sorry, cannot install distro python package..." + + exit 1; + +fi + sleep 1 diff --git a/scripts/system/updates.py b/scripts/system/updates.py new file mode 100644 index 0000000..8306bcd --- /dev/null +++ b/scripts/system/updates.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 -u + +# A script for install pzoo user + +from subprocess import call +from time import sleep +import distro + +linux_distro=distro.id() + +print('{"error": 0, "status": 0, "progress": 0, "no_progress":0, "message": "Upgrading server..."}') + +sleep(1) + +if linux_distro=='arch': + + if call("sudo pacman -Syu --noconfirm", shell=True) > 0: + print('Error, cannot upgrade server...') + exit(1) +elif linux_distro=='debian': + + if call('sudo DEBIAN_FRONTEND="noninteractive" apt-get -y update', shell=True) > 0: + print('Error, cannot upgrade server...') + exit(1) + + if call('sudo DEBIAN_FRONTEND="noninteractive" apt-get -y upgrade', shell=True) > 0: + print('Error, cannot upgrade server...') + exit(1) diff --git a/tasks/system/task.py b/tasks/system/task.py index d351dc5..00078ee 100644 --- a/tasks/system/task.py +++ b/tasks/system/task.py @@ -12,7 +12,7 @@ class ServerTask(Task): self.files=[['modules/pastafari2/scripts/system/install_pzoo_stats.py', 0o755]] self.files.append(['modules/pastafari2/scripts/system/install_python.sh', 0o755]) self.files.append(['modules/pastafari2/scripts/system/install_psutil.sh', 0o755]) - self.files.append(['modules/pastafari2/scripts/system/install_git.sh', 0o755]) + self.files.append(['modules/pastafari2/scripts/system/install_git.py', 0o755]) self.files.append(['modules/pastafari2/scripts/system/sudoers.d/spanel', 0o640]) self.files.append([self.data['pub_key'], 0o600]) @@ -20,8 +20,8 @@ class ServerTask(Task): self.commands_to_execute=[] #self.commands_to_execute.append(['modules/pastafari2/scripts/system/alive.sh', '']) - self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_git.sh', '']) self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_python.sh', '']) + self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_git.py', '']) self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_psutil.sh', '']) self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_pzoo_stats.py', '--user='+self.data['ssh_user']+' --pub_key='+self.data['pub_key']+' --url_stats='+self.data['url_stats']+' --group='+self.data['group_name']]) diff --git a/tasks/system/updates.py b/tasks/system/updates.py new file mode 100644 index 0000000..4250d0c --- /dev/null +++ b/tasks/system/updates.py @@ -0,0 +1,14 @@ +from modules.pastafari2.libraries.task import Task +from modules.pastafari2.models.pastafari2 import ServerDbTask + +class ServerTask(Task): + + def __init__(self, server, conn, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data={}): + + super().__init__(server, conn, remote_user, remote_password, private_key, password_key, remote_path, task_id, data) + + self.files=[['modules/pastafari2/scripts/system/updates.py', 0o755]] + + self.commands_to_execute=[] + + self.commands_to_execute.append(['modules/pastafari2/scripts/system/updates.py', ''])