Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two options --createhome and --key #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion createuserpkg
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def main():
'--password', '-p',
help='User password. If this is not provided, interactively prompt for '
'password.')
optional_user_options.add_option(
'--key', '-k', default=False,
help='User ssh public key. If provided stored in ~/.ssh/authorized_keys '
'implies --createhome and therefore works only when installing to "/". Optional.')
optional_user_options.add_option(
'--fullname', '-f', help='User full name. Optional.')
optional_user_options.add_option('--gid', '-g', help='User gid. Optional.')
Expand All @@ -64,6 +68,10 @@ def main():

optional_user_options.add_option(
'--home', '-H', help='Path to user home directory. Optional.')
optional_user_options.add_option(
'--createhome', '-c', default=False,
action='store_true', help='Create the user home directory. '
'Works only when installing to "/". Optional.')
optional_user_options.add_option(
'--shell', '-s', help='User shell path. Optional.')
optional_user_options.add_option(
Expand Down Expand Up @@ -133,7 +141,9 @@ def main():
pkg_data = {'version': options.version,
'pkgid': options.identifier,
'destination_path': filename,
'user_plist': user_plist}
'user_plist': user_plist,
'createhome': options.createhome,
'key': options.key}
if options.autologin:
pkg_data['kcpassword'] = kcpassword.generate(password)
if options.admin:
Expand Down
6 changes: 5 additions & 1 deletion locallibs/userpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ def make_config_file(scripts_path, pkg_info):
uuid = user_plist[u'generateduid'][0]
user_is_admin = pkg_info.get('is_admin', False)
enable_autologin = (pkg_info.get('kcpassword') != None)
createhome = pkg_info.get('createhome', False)
key = pkg_info.get('key', False)
config_content = """
USERNAME="%s"
UUID=%s
USER_IS_ADMIN=%s
ENABLE_AUTOLOGIN=%s
""" % (username, uuid, user_is_admin, enable_autologin)
CREATEHOME=%s
KEY="%s"
""" % (username, uuid, user_is_admin, enable_autologin, createhome, key)
config_path = os.path.join(scripts_path, "config")
try:
fileref = open(config_path, 'w')
Expand Down
12 changes: 12 additions & 0 deletions pkg_scripts/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ if [ "$3" == "/" ]; then
# set AutoLogin preference, working around path issue with 'defaults'
/usr/bin/defaults write "/Library/Preferences/com.apple.loginwindow" autoLoginUser "$USERNAME"
fi
if [[ "$CREATEHOME" == "True" || "$KEY" != "False" ]]; then
# create home directory
/usr/sbin/createhomedir -c -u $USERNAME

if [[ "$KEY" != "False" ]]; then
# create authorized_keys file and populate...do this as the user to pick up home and gid
/usr/bin/sudo -u $USERNAME -H -s eval '/bin/mkdir -p ~/.ssh'
/usr/bin/sudo -u $USERNAME -H -s eval '/bin/chmod 700 ~/.ssh'
/usr/bin/sudo -u $USERNAME -H -s eval "/bin/echo '${KEY}' >> ~/.ssh/authorized_keys"
/usr/bin/sudo -u $USERNAME -H -s eval '/bin/chmod 600 ~/.ssh/authorized_keys'
fi
fi
else
# we're installing to non-boot volume; probably from Recovery-like or
# AutoDMG environment - so we can just copy the user plist into place
Expand Down