47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
#!/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 json
|
|
|
|
#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_pastafariutils.py', description='Add pastafariutils for a system user')
|
|
|
|
parser.add_argument('--user', help='The user used for install pastafariutils', required=True)
|
|
|
|
args=parser.parse_args()
|
|
|
|
user=args.user
|
|
|
|
# https://git.cuchulu.com/paramecio/pastafariutils.git
|
|
# python3 -m venv /home/{}/pythonenv/ && source /home/{}/pythonenv/bin/activate && pip3 install git+https://git.cuchulu.com/paramecio/pastafariutils.git
|
|
|
|
if subprocess.call("sudo su - {} -s /bin/bash -c 'cd /home/{} && python3 -m venv /home/{}/pythonenv/ && . /home/{}/pythonenv/bin/activate && pip3 install git+https://git.cuchulu.com/paramecio/pastafariutils.git && pip3 install distro'".format(user, user, user, user), shell=True) > 0:
|
|
print('Error, cannot install pastafariutils...')
|
|
exit(1)
|
|
|
|
print("pastafariutils installed...")
|
|
|
|
# #{'result': 1, 'message': {'username': 'hosting', 'uid': 1002, 'gid': 1002, 'home': '/srv/sites'}, 'error': 0, 'progress': 100, 'task_id': 483, 'server': '192.168.122.55'}
|
|
#json_code['message']=json.dumps(json_code['message'])
|
|
|
|
print(json.dumps({'error': 0, 'status': 1, 'progress': 100, 'no_progress':0, 'message': '{"distro": "'+distro.id()+'"}', 'result': 1}))
|
|
|
|
#print('{"error": 0, "status": 1, "progress": 100, "no_progress":0, "message": "{\\"distro\\": \\"'+distro.id()+'\\"}", "result": 1}')
|