Added users support to pastafari

This commit is contained in:
Antonio de la Rosa 2025-11-01 01:02:26 +01:00
parent ba7fd8dcc9
commit 646f0bb721
5 changed files with 263 additions and 16 deletions

View file

@ -0,0 +1,53 @@
#!/usr/bin/python3 -u
import sys
import argparse
import os
#from pastafariutils.unix import add_user, del_user, change_password
from pathlib import Path
from subprocess import call, DEVNULL
import json
import time
import shutil
import pwd
import distro
import subprocess
from pastafariutils import linux
parser=argparse.ArgumentParser(prog='add_user.py', description='A user to the linux system')
parser.add_argument('--user', help='The unix user', required=True)
parser.add_argument('--home', help='The home of the unix user')
parser.add_argument('--shell', help='The home of the unix user')
args=parser.parse_args()
if not linux.shell_command('sudo useradd -m -d {} -s {} {}'.format(args.home, args.shell, args.user)):
linux.json_log('Sorry, cannot create the new user, please check permissions and the users not exists', error=1, status=1, progress=100, no_progress=0, return_message=0, result=None)
exit(1)
"""
if args.password:
password_user=args.password
ret_pass=change_password(args.user, password_user)
if not ret_pass[0]:
print('Error, cannot change password for %s' % args.user+"\n"+ret_pass[1]+"\n")
exit(1)
else:
print('Changed password succesfully...\n')
"""
"""
if args.ssh_pub_key_file:
if call("sudo su - %s -s /bin/bash -c 'mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch ~/.ssh/authorized_keys' && sudo cat %s >> /home/%s/.ssh/authorized_keys && sudo usermod --shell /bin/bash %s" % (args.user, args.ssh_pub_key_file, args.user, args.user), shell=True) > 0:
print('Error, cannot add ssh pub key to user %s' % args.user )
exit(1)
else:
print('Added ssh key successfully...\n')
"""