pastafari2/scripts/system/updates.py

74 lines
2.3 KiB
Python

#!/usr/bin/python3 -u
# A script for install pzoo user
from subprocess import call
from time import sleep
import distro
import os
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' or linux_distro=='ubuntu':
if call('sudo DEBIAN_FRONTEND="noninteractive" apt-get -y update', shell=True) > 0:
print('Error, cannot upgrade server...')
exit(1)
# Update command
update_command='sudo DEBIAN_FRONTEND="noninteractive" apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade'
if call(update_command, shell=True) > 0:
print('Error, cannot upgrade server...')
exit(1)
elif linux_distro=='rocky' or linux_distro=='fedora' or linux_distro=='alma' or linux_distro=='centos':
if call("sudo dnf upgrade -y", shell=True) > 0:
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 Composer...')
if call("sudo /usr/local/bin/composer self-update", shell=True) > 0:
print('Error, cannot upgrade composer...')
exit(1)
print('Upgrading Pastafari utils...')
if not os.path.isdir('./leviathanutils'):
if call("git clone https://git.cuchulu.com/phangoapp/leviathanutils.git && composer install --working-dir=./leviathanutils", shell=True) > 0:
print('Error, cannot install leviathanutils...')
exit(1)
else:
if call("cd ./leviathanutils && git pull && composer update", shell=True) > 0:
print('Error, cannot upgrade Leviathanutils...')
exit(1)
user=os.getlogin()
if call("/home/{}/pythonenv/bin/pip install --upgrade git+https://git.cuchulu.com/paramecio/pastafariutils.git".format(user), shell=True) > 0:
print('Error, cannot upgrade pastafariutils...')
exit(1)