Compare commits

..

No commits in common. "1639c613ab272350a1defc8ba39eb0434fdde674" and "56b9ede990413e244c24811d56a24dda07cc3575" have entirely different histories.

4 changed files with 12 additions and 195 deletions

View file

@ -1,98 +0,0 @@
#!/usr/bin/epython3
import os
import distro
from subprocess import call, DEVNULL
import re
import json
def shell_command(command):
if call(command, shell=True) > 0:
print('Error: cannot execute command')
return False
def check_distro(arr_command):
distro_id=distro.id()
if not distro_id in arr_command:
print("Sorry, you don't have a patch for this distro\n\n")
return False
else:
return distro_id
def install_package(package):
distro_id=distro.id()
if distro_id=='debian' or distro_id=='ubuntu':
return shell_command('sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y {}'.format(package[distro]))
elif distro_id=='fedora' or distro_id=='almalinux' or distro_id=='rocky':
return shell_command('sudo dnf install -y {}'.format(package[distro]))
elif distro_id=='arch':
return shell_command('sudo pacman -S --noconfirm {}'.format(package[distro]))
def patch_file(original_file, patch_file):
distro_id=check_distro(original_file)
if not distro_id:
return False
return shell_command("sudo patch {} < {}".format(original_file[distro], patch_file[distro]))
def systemd_service(action, service):
distro_id=check_distro(service)
if not distro_id:
return False
return shell_command('sudo systemctl {} {}'.format(action, service[distro]))
def exec(command):
distro_id=check_distro(command)
if not distro_id:
return False
return shell_command(command[distro])
def sed(arr_sed):
distro_id=check_distro(arr_sed)
if not distro_id:
return False
return shell_command("sudo sed -i s/{}/{}/g".format(arr_sed[distro][0], arr_sed[distro][1]))
def json_log(message, error=0, status=0, progress=0, no_progress=0, return_message=0):
log={'error': error, 'status': status, 'progress': progress, 'no_progress': no_progress, 'message': message}
if not return_message:
print(json.dumps(log))
else:
return json.dumps(log)

View file

@ -1,73 +0,0 @@
#!/usr/bin/env python3
import os
import distro
from subprocess import call, DEVNULL
import re
def install_package(package: dict, extra_configurations={}):
"""A function for install packages for different distros. Now support, debian, ubuntu, rocky, almalinux, fedora, archlinux.
Args:
package (dict): A dict with all packages names for every distro.
Returns:
result_package_manager (bool): return false if install fail, if install is finished, return true.
"""
linux_distro=distro.id()
if not linux_distro in package:
print('Sorry, not package in {}'.format(linux_distro))
return False
if linux_distro=='debian' or linux_distro=='ubuntu':
if call('sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y {}'.format(package[linux_distro]), shell=True) > 0:
print('Error, cannot install {}...'.format(package[linux_distro]))
return False
elif linux_distro=='rocky' or linux_distro=='fedora' or linux_distro=='almalinux':
if call("sudo dnf install -y {}".format(package[linux_distro]), shell=True) > 0:
print('Error, cannot install {}...'.format(package[linux_distro]))
return False
if linux_distro=='arch':
if call("sudo pacman -S --noconfirm {}".format(package[linux_distro]), shell=True) > 0:
print('Error, cannot install {}...'.format(package[linux_distro]))
return False
# Method for patch files using patch utility
def apply_patch(original_file: dict, patch_file: dict):
linux_distro=distro.id()
# patch originalAmigo.sh < parche.patch
if not linux_distro in original_file or not linux_distro in patch_file):
print('Error, not exists original file and patch files for this distro'))
return False
if call("sudo patch {} < {}".format(original_file[linux_distro], patch_file[linux_distro]), shell=True) > 0:
print('Error, cannot patch {}...'.format(original_file[linux_distro]))
return False
# A simple function for fill an array for every distros with the same package name.
def fill_all_distros_str(name):
fill_str={}
for distro in ['debian', 'ubuntu', 'rocky', 'almalinux', 'fedora', 'arch']:
fill_str[distro]=name
return fill_str
# A simple function for get a json return value
def return_json_value():
return {}

View file

@ -13,7 +13,7 @@ from subprocess import call, DEVNULL
def add_user(user, password='', group='', user_directory='', shell='/usr/sbin/nologin'):
if user_directory=='':
user_directory='/home/'+user
user_directory=user
try:
user_pwd=pwd.getpwnam(user)
@ -32,8 +32,6 @@ def add_user(user, password='', group='', user_directory='', shell='/usr/sbin/no
if group!='':
# Buggy, need fix.
stat_group=os.stat('/home/%s' % user_directory)
gid=stat_group.st_gid
@ -45,12 +43,10 @@ def add_user(user, password='', group='', user_directory='', shell='/usr/sbin/no
if call(func_user, shell=True, stdout=DEVNULL) > 0:
return (False, 'Error executing useradd command')
else:
return (True, '')
else:
return (False, 'Error executing useradd command')
def change_password(user, new_password):
@ -58,13 +54,9 @@ def change_password(user, new_password):
try:
user_pwd=pwd.getpwnam(user)
if call("sudo echo \"%s:%s\" | sudo chpasswd" % (user, new_password), shell=True, stdout=DEVNULL) > 0:
if call("sudo echo \"%s:%s\" | chpasswd" % (user, new_password), shell=True, stdout=DEVNULL) > 0:
return (False, 'I cannot change password, permissions?')
else:
return (True, 'Change password successfully')
except KeyError:
@ -73,14 +65,10 @@ def change_password(user, new_password):
def del_user(user):
if call("sudo userdel -r %s" % user, shell=True, stdout=DEVNULL, stderr=DEVNULL) > 0:
return (False, '')
else:
return (True, 'Deleted user successfully')
def mkdir_sh(directory):
return (True, 'Deleted user successfully')
if call("sudo mkdir -p %s" % directory, shell=True) > 0:
return (False, '')
else:
return (True, 'Created directory successfully %s' % directory)
return (False, '')

View file

@ -5,15 +5,15 @@ import os
from setuptools import setup, find_packages
if sys.version_info < (3, 6):
raise NotImplementedError("Sorry, you need at least Python 3.6 for use pastafariutils.")
if sys.version_info < (3, 3):
raise NotImplementedError("Sorry, you need at least Python 3.3 for use pastafariutils.")
#import paramecio
# Pillow should be installed after if you need ImageField
# If you install passlib and bcrypt, the password system will use bcrypt by default, if not, will use native crypt libc
setup(name='pastafariutils',
version='0.6.3',
setup(name='paramecio',
version='0.5.0',
description='Utils for make *nix scripts.',
long_description='Utils for make *nix scripts.',
author='Antonio de la Rosa Caballero',