diff --git a/scripts/system/install_composer.sh b/scripts/system/install_composer.sh new file mode 100644 index 0000000..deea22b --- /dev/null +++ b/scripts/system/install_composer.sh @@ -0,0 +1,32 @@ +#!/bin/bash + + +echo "Installing composer..." + +EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" +php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" + +if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ] +then + >&2 echo 'ERROR: Invalid installer checksum' + rm composer-setup.php + exit 1 +fi + +php composer-setup.php --quiet +RESULT=$? +rm composer-setup.php + +sudo mv composer.phar /usr/local/bin/composer + +if [ $RESULT -eq 0 ]; then + + echo '{"error": 0, "status": 0, "progress": 100, "no_progress":0, "message": "Composer installed sucessfully..."}' + +else + echo '{"error": 1, "status": 1, "progress": 100, "no_progress":0, "message": "Error: cannot install composer!"}' + + exit 1 + +fi diff --git a/scripts/system/install_leviathanutils.py b/scripts/system/install_leviathanutils.py new file mode 100644 index 0000000..00e7a6f --- /dev/null +++ b/scripts/system/install_leviathanutils.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 -u + +import sys, os +import subprocess +import argparse +import platform +import shutil +import pathlib +import distro +import pwd +import getpass +import re +import platform + +#import pymysql.cursors +#pymysql.install_as_MySQLdb + +pyv=platform.python_version_tuple() + +if pyv[0]!='3': + print('Need python 3 for execute this script') + sys.exit(1) + +parser=argparse.ArgumentParser(prog='install_leviathanutils.py', description='Add leviathanutils for a system user') + +parser.add_argument('--user', help='The user used for install leviathanutils', required=True) + +args=parser.parse_args() + +user=args.user + +if subprocess.call("cd /home/{} && git clone https://git.cuchulu.com/phangoapp/leviathanutils.git && COMPOSER_ALLOW_SUPERUSER=1 composer install --working-dir=/home/{}/leviathanutils && chown -R {}:{} /home/{}/leviathanutils".format(user, user, user, user, user), shell=True) > 0: + print('Error, cannot install leviathanutils...') + exit(1) + +print("Leviathanutils installed...") diff --git a/scripts/system/install_python.sh b/scripts/system/install_python.sh index e455e96..8ceaf65 100644 --- a/scripts/system/install_python.sh +++ b/scripts/system/install_python.sh @@ -14,7 +14,7 @@ if [[ $DISTRO =~ ^Debian ]] || [[ $DISTRO =~ ^Ubuntu ]]; then apt-get update apt-get install sudo - sudo apt-get -y install python3 python3-full python3-pip python3-venv libaugeas0 + sudo apt-get -y install python3 python3-full python3-pip python3-venv libaugeas0 python3-distro elif [[ $DISTRO =~ ^NAME=\"Arch ]]; then diff --git a/scripts/system/updates.py b/scripts/system/updates.py index c78f9ac..fa31882 100644 --- a/scripts/system/updates.py +++ b/scripts/system/updates.py @@ -36,3 +36,20 @@ elif linux_distro=='rocky' or linux_distro=='fedora' or linux_distro=='alma' or print('Error, cannot upgrade server...') exit(1) +# Need update certbot and leviathanutils. + +print('Upgrading certbot...') + +#/opt/certbot/bin/pip install --upgrade certbot + +if call("sudo /opt/certbot/bin/pip install --upgrade certbot", shell=True) > 0: + print('Error, cannot upgrade certbot...') + exit(1) + +print('Upgrading Pastafari utils...') + +print('Upgrading Composer...') + +if call("sudo /usr/local/bin/composer self-update", shell=True) > 0: + print('Error, cannot upgrade composer...') + exit(1) diff --git a/tasks/system/task.py b/tasks/system/task.py index 0fdbed2..134ecda 100644 --- a/tasks/system/task.py +++ b/tasks/system/task.py @@ -14,8 +14,10 @@ class ServerTask(Task): #self.files.append(['modules/pastafari2/scripts/system/install_psutil.sh', 0o755]) self.files.append(['modules/pastafari2/scripts/system/install_git.py', 0o755]) self.files.append(['modules/pastafari2/scripts/system/install_php.py', 0o755]) + self.files.append(['modules/pastafari2/scripts/system/install_composer.sh', 0o755]) #self.files.append(['modules/pastafari2/scripts/system/install_unixutils.sh', 0o755]) self.files.append(['modules/pastafari2/scripts/system/sudoers.d/spanel', 0o640]) + self.files.append(['modules/pastafari2/scripts/system/install_leviathanutils.py', 0o755]) self.files.append([self.data['pub_key'], 0o600]) @@ -25,12 +27,11 @@ class ServerTask(Task): 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_php.py', '']) - #self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_unixutils.sh', '']) - #self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_psutil.sh', '']) - - #' --url_stats='+self.data['url_stats']+ + self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_composer.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']+' --group="'+self.data['group_name']+'" --path='+remote_path]) + + self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_leviathanutils.py', '--user='+self.data['ssh_user']]) def post_task(self):