change example

This commit is contained in:
quackerd 2021-02-19 18:41:39 -05:00
parent da45cf4f5a
commit 6a0c42f86b
Signed by: d
GPG Key ID: F73412644EDE357A

View File

@ -19,8 +19,10 @@ def main():
if (len(elements) != 2): if (len(elements) != 2):
print("Skipping invalid group config string \"" + group + "\"") print("Skipping invalid group config string \"" + group + "\"")
continue continue
subprocess.check_call(shlex.join(["addgroup", "-g", elements[1], elements[0]]), shell=True) gid = elements[1]
print("Added group " + elements[0] + " with gid " + elements[1]) gname = elements[0]
subprocess.check_call("addgroup -g" + shlex.quote(gid) + " " + shlex.quote(gname), shell=True)
print("Added group " + gname + " with gid " + gid)
# username,uid,password,[group] # username,uid,password,[group]
@ -29,13 +31,17 @@ def main():
if (len(elements) != 3 and len(elements) != 4): if (len(elements) != 3 and len(elements) != 4):
print("Skipping invalid user config string \"" + user + "\"") print("Skipping invalid user config string \"" + user + "\"")
continue continue
subprocess.check_call(shlex.join(["adduser", "-D", "-H", "-u", elements[1], elements[0]]), shell=True) uname = elements[0]
print("Added user " + elements[0] + " with uid " + elements[1]) uid = elements[1]
passwd = elements[2]
subprocess.check_call("adduser -D -H -u ", shlex.quote(uid), shlex.quote(uname), shell=True)
print("Added user " + uname + " with uid " + uid)
if (len(elements) == 4): if (len(elements) == 4):
subprocess.check_call(shlex.join(["addgroup", elements[0], elements[3]]), shell=True) gname = elements[3]
print("Added user " + elements[0] + " to group " + elements[3]) subprocess.check_call("addgroup " + shlex.quote(uname) + " " + shlex.quote(gname), shell=True)
print("Added user " + uname + " to group " + gname)
# set passwd # set passwd
subprocess.check_call(shlex.join(["echo", "-ne", "\"" + elements[2] + "\n" + elements[2] + "\n\""]) + " | " + shlex.join(["smbpasswd", "-a", "-U", elements[0]]), shell=True) subprocess.check_call("echo -ne " + shlex.quote("\n" + passwd + "\n" + passwd + "\n") + " | smbpasswd -a -U " + shlex.quote(uname), shell=True)
print("Set user " + elements[0] + " password to " + elements[2]) print("Set user " + uname + " password to " + passwd)
main() main()