clarify variables in rename script
parent
0d8b370b5d
commit
7da85faeed
|
@ -1,12 +1,14 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""This script wraps the usermod command to allow user account renames via sudoers."""
|
"""This script wraps the usermod command to allow user account renames via
|
||||||
|
sudoers."""
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
def rename_user(username, new_username):
|
def rename_user(old_username, new_username):
|
||||||
# usermod -l new_username -m -d /home/{new_username} username
|
"""Given an old and a new username, renames user on disk with usermod.
|
||||||
|
Raises if the usermod call fails."""
|
||||||
args = [
|
args = [
|
||||||
'usermod',
|
'usermod',
|
||||||
'-l',
|
'-l',
|
||||||
|
@ -14,7 +16,7 @@ def rename_user(username, new_username):
|
||||||
'-m',
|
'-m',
|
||||||
'-d',
|
'-d',
|
||||||
os.path.join('/home', new_username),
|
os.path.join('/home', new_username),
|
||||||
username
|
old_username
|
||||||
]
|
]
|
||||||
subprocess.run(args, check=True)
|
subprocess.run(args, check=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue