From aad766297a915143c1ec1c1f85f639880b873c21 Mon Sep 17 00:00:00 2001 From: tperfitt Date: Sat, 5 Oct 2019 23:40:55 -0500 Subject: [PATCH 1/4] added option for jpegphoto --- createuserpkg | 10 ++++++++++ 1 file changed, 10 insertions(+) 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) From 179f9223cea6d28755dd248573392abe193760af Mon Sep 17 00:00:00 2001 From: tperfitt Date: Sat, 5 Oct 2019 23:42:58 -0500 Subject: [PATCH 2/4] added library --- locallibs/jpegphoto.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 locallibs/jpegphoto.py diff --git a/locallibs/jpegphoto.py b/locallibs/jpegphoto.py new file mode 100644 index 0000000..9e26eba --- /dev/null +++ b/locallibs/jpegphoto.py @@ -0,0 +1,29 @@ +# 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 binascii +import os + +def jpeg_photo_from_file(file_path): + '''Read in a file and return binary data as ascii formatted for plist (groups of 4 bytes)''' + + 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 From 023697ed0007a17c145372d76b40c25da04adc9e Mon Sep 17 00:00:00 2001 From: tperfitt Date: Sat, 5 Oct 2019 23:43:36 -0500 Subject: [PATCH 3/4] updated comments to reflect reality --- locallibs/jpegphoto.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locallibs/jpegphoto.py b/locallibs/jpegphoto.py index 9e26eba..06014a4 100644 --- a/locallibs/jpegphoto.py +++ b/locallibs/jpegphoto.py @@ -19,7 +19,7 @@ import os def jpeg_photo_from_file(file_path): - '''Read in a file and return binary data as ascii formatted for plist (groups of 4 bytes)''' + '''Read in a file and return binary data''' photo_data=buffer("") if os.path.exists(file_path): From 46cb574e22910a30a66de66a5a26ee332be260d7 Mon Sep 17 00:00:00 2001 From: tperfitt Date: Sat, 5 Oct 2019 23:45:15 -0500 Subject: [PATCH 4/4] removed unneeded import --- locallibs/jpegphoto.py | 1 - 1 file changed, 1 deletion(-) diff --git a/locallibs/jpegphoto.py b/locallibs/jpegphoto.py index 06014a4..8afae24 100644 --- a/locallibs/jpegphoto.py +++ b/locallibs/jpegphoto.py @@ -15,7 +15,6 @@ '''Functions for generating JPEGPhoto''' -import binascii import os def jpeg_photo_from_file(file_path):