diff --git a/createuserpkg b/createuserpkg index 2beefc9..f7a5e0f 100755 --- a/createuserpkg +++ b/createuserpkg @@ -27,6 +27,7 @@ from locallibs import kcpassword from locallibs import shadowhash from locallibs import userplist from locallibs import userpkg +from locallibs import jpegphoto def main(): @@ -62,6 +63,9 @@ def main(): optional_user_options.add_option( '--hint', help='User password hint. Optional.') + optional_user_options.add_option( + '--jpegphoto', help='Path to JPEG photo that contains a profile picture. Image should be square and recommended 512px x 512px and JPEG (RGB). Optional.') + optional_user_options.add_option( '--home', '-H', help='Path to user home directory. Optional.') optional_user_options.add_option( @@ -107,6 +111,7 @@ def main(): print >> sys.stderr, "Password mismatch!" exit(-1) + # make user plist user_data = {'name': options.name, 'uid': options.uid, @@ -126,6 +131,11 @@ def main(): if options.hint: user_data['hint'] = options.hint + if options.jpegphoto: + jpeg_data=jpegphoto.jpeg_photo_from_file(options.jpegphoto) + if (len(jpeg_data)>0): + user_data['image_data'] = jpeg_data + user_plist = userplist.generate(user_data) diff --git a/locallibs/jpegphoto.py b/locallibs/jpegphoto.py new file mode 100644 index 0000000..8afae24 --- /dev/null +++ b/locallibs/jpegphoto.py @@ -0,0 +1,28 @@ +# Copyright 2019 Timothy Perfitt. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +'''Functions for generating JPEGPhoto''' + + +import os + +def jpeg_photo_from_file(file_path): + '''Read in a file and return binary data''' + + photo_data=buffer("") + if os.path.exists(file_path): + with open(file_path,'rb') as photo_file: + photo_data=buffer(photo_file.read()) + + return photo_data