MagerValp / CreateUserPkg

This project has been archived and is no longer maintained
262 stars 43 forks source link

Auto login #10

Closed cgerke closed 12 years ago

cgerke commented 12 years ago

Would be really nice if the CreateUserPkg had an option to allow auto login. My current workflow (and I suspect others out there do the same) is for the newly imaged machine to boot and run first boot scripts and provide my helpdesk guys a GUI for running localisation. I have a custom PKG that autologs in the first time as my admin user. I have some sample code if you want it.

MagerValp commented 12 years ago

Beta release of 1.2 with support for automatic login added to the downloads, please test.

cgerke commented 12 years ago

Tested on 10.7.3 Creates the user. Creates the kcpassword file. Doesn't write the autoLoginUser string key to /Library/Preferences/com.apple.loginwindow

I tested on a second machine running 10.7.3 and it didn't write the key. I manually ran this immediately and rebooted and autologin worked.

/usr/bin/defaults write "/Library/Preferences/com.apple.loginwindow" autoLoginUser -string "${MYUSER}"

MagerValp commented 12 years ago

Alright, try this one: https://www.dropbox.com/s/9cuyz9w81azu9fp/CreateUserPkg-1.2b2.dmg

Sorry for the lack of testing on my part, I'll have access to test machines again on monday...

cgerke commented 12 years ago

np. tests run on 10.8 freshly imaged with one user and no pre-existing autologin. pkgs intstalled whilst logged targeting the booted system.

First test, created a package with autologin checked. Installed pkg via cli and received an error "The Installer encountered an error that caused the installation to fail."

Second test, created a package with autologin checked. Installed pkg via cli and received an error "The Installer encountered an error that caused the installation to fail."

Third test, created a package without autologin checked. Installed pkg via cli and didn't receive any error.

Console shows the following errors if auto login checked in your app.

Aug 3 20:56:56 computer installer[2637]: -[IFDInstallController(Private) _buildInstallPlan]: location = file://localhost Aug 3 20:56:56 computer installer[2637]: -[IFDInstallController(Private) _buildInstallPlan]: file://localhost/Users/cgerke/Desktop/create_testvar-1.0.pkg Aug 3 20:56:56 computer installer[2637]: Set authorization level to root for session Aug 3 20:56:56 computer runner[2640]: Administrator authorization granted. Aug 3 20:56:56 computer installer[2637]: Will use PK session Aug 3 20:56:56 computer installer[2637]: Starting installation: Aug 3 20:56:56 computer installer[2637]: Configuring volume "System" Aug 3 20:56:56 computer installer[2637]: Preparing disk for local booted install. Aug 3 20:56:56 computer installer[2637]: Free space on "System": 96.69 GB (96690270208 bytes). Aug 3 20:56:56 computer installer[2637]: Create temporary directory "/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T//Install.2637Fsr8kN" Aug 3 20:56:56 computer installer[2637]: IFPKInstallElement (1 packages) Aug 3 20:56:56 computer installer[2637]: Using authorization level of root for IFPKInstallElement Aug 3 20:56:56 computer installd[2641]: installd: Starting Aug 3 20:56:56 computer installd[2641]: installd: uid=0, euid=0 Aug 3 20:56:56 computer installd[2641]: PackageKit: ----- Begin install ----- Aug 3 20:56:56 computer installd[2641]: PackageKit: request=PKInstallRequest <1 packages, destination=/> Aug 3 20:56:56 computer installd[2641]: PackageKit: packages=( "PKLeopardPackage file://localhost/Users/cgerke/Desktop/create_testvar-1.0.pkg" ) Aug 3 20:56:56 computer installd[2641]: PackageKit: Extracting file://localhost/Users/cgerke/Desktop/create_testvar-1.0.pkg (destination=/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/Cleanup At Startup/PKInstallSandboxManager/1.sandbox/Root, uid=0) Aug 3 20:56:56 computer installd[2641]: PackageKit: prevent user idle system sleep Aug 3 20:56:56 computer installd[2641]: PackageKit: suspending backupd Aug 3 20:56:56 computer installd[2641]: PackageKit: Shoving /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/Cleanup At Startup/PKInstallSandboxManager/1.sandbox/Root (1 items) to / Aug 3 20:56:56 computer install_monitor[2645]: Temporarily excluding: /Applications, /Library, /System, /bin, /private, /sbin, /usr Aug 3 20:56:56 computer installd[2641]: PackageKit: Executing script "./postinstall" in /private/tmp/PKInstallSandbox.NX8zdx/Scripts/com.example.create_testvar.pkg.JN03PI Aug 3 20:56:56 computer installd[2641]: ./postinstall: /tmp/PKInstallSandbox.NX8zdx/Scripts/com.example.create_testvar.pkg.JN03PI/postinstall: line 74: unexpected EOF while looking for matching `"' Aug 3 20:56:56 computer installd[2641]: ./postinstall: /tmp/PKInstallSandbox.NX8zdx/Scripts/com.example.create_testvar.pkg.JN03PI/postinstall: line 81: syntax error: unexpected end of file Aug 3 20:56:56 computer install_monitor[2645]: Re-included: /Applications, /Library, /System, /bin, /private, /sbin, /usr Aug 3 20:56:57 computer installd[2641]: PackageKit: releasing backupd Aug 3 20:56:57 computer installd[2641]: PackageKit: allow user idle system sleep Aug 3 20:56:57 computer installd[2641]: PackageKit: Install Failed: Error Domain=PKInstallErrorDomain Code=112 "An error occurred while running scripts from the package “create_testvar-1.0”." UserInfo=0x7f87b21560c0 {NSFilePath=./postinstall, NSURL=file://localhost/Users/cgerke/Desktop/create_testvar-1.0.pkg, PKInstallPackageIdentifier=com.example.create_testvar.pkg, NSLocalizedDescription=An error occurred while running scripts from the package “create_testvar-1.0”.} { NSFilePath = "./postinstall"; NSLocalizedDescription = "An error occurred while running scripts from the package \U201ccreate_testvar-1.0\U201d."; NSURL = "file://localhost/Users/cgerke/Desktop/create_testvar-1.0.pkg"; PKInstallPackageIdentifier = "com.example.create_testvar.pkg"; } Aug 3 20:56:57 computer installer[2637]: install:didFailWithError:Error Domain=PKInstallErrorDomain Code=112 "An error occurred while running scripts from the package “create_testvar-1.0”." UserInfo=0x7ff51142f120 {NSFilePath=./postinstall, NSURL=file://localhost/Users/cgerke/Desktop/create_testvar-1.0.pkg, PKInstallPackageIdentifier=com.example.create_testvar.pkg, NSLocalizedDescription=An error occurred while running scripts from the package “create_testvar-1.0”.} Aug 3 20:56:57 computer installer[2637]: Install failed: The Installer encountered an error that caused the installation to fail. Contact the software manufacturer for assistance. Aug 3 20:57:16 computer installd[2641]: installd: Exiting. Aug 3 21:02:05 computer installer[2712]: Referenced component packages (1) trustLevel=100 Aug 3 21:02:06 computer installer[2712]: -[IFPKGDerivedDocument sortedPackageLocations]: result = ( "file://localhost" )

MagerValp commented 12 years ago

Dang, typo. Fixed in 7b4f6071434eb044664715f202a9c4badad968fd and uploaded 1.2b4. You can edit CreateUserPkg.app/Contents/Resources/create_package.py instead of downloading a new copy, the missing " should be on line 111 after com.apple.loginwindow.plist.

cgerke commented 12 years ago

Yup, tried that. No errors with install any more but autologin plist key still not created. Install.log shows "PlistArrayContains: Plist present but key is missing (autoLoginUser)"

Note the key doesn't exist by default, and when autologin is disabled manually via the GUI the key is actually deleted from the plist so you may want to alter your PlistArrayContains function

MagerValp commented 12 years ago

Thanks for your patience. I'll stop fumbling in the dark and fix this on monday when I can test things before releasing.

cgerke commented 12 years ago

Np, will be nice once done. One less pkg I need in my insta workflow. Over here if there is anything else you want to incorporate? https://github.com/cgerke/Insta

MagerValp commented 12 years ago

Alright, 1.2b5 added, which works on my test machine here. Please test again.

cgerke commented 12 years ago

Sorry no good, although I mentioned that the plist value is deleted if you manually disable Autologin via the GUI some people may have the value set empty (as in my case). Console shows error ./postinstall: Add: ":autoLoginUser" Entry Already Exists.

I altered line 84 of your create_package.py script from;

/usr/libexec/PlistBuddy -c "Add :autoLoginUser string \"USERNAME\"" /Library/Preferences/com.apple.loginwindow.plist

-to-

/usr/bin/defaults write "/Library/Preferences/com.apple.loginwindow.plist" autoLoginUser -string \"USERNAME\"

And its working.

Alternatively if you are set on using Plistbuddy, this will work too.

/usr/libexec/PlistBuddy -c "Add :autoLoginUser string \"USERNAME\"" /Library/Preferences/com.apple.loginwindow.plist /usr/libexec/PlistBuddy -c "Set :autoLoginUser \"USERNAME\"" /Library/Preferences/com.apple.loginwindow.plist

MagerValp commented 12 years ago

I'd argue that an empty value is a case of "don't hold it like that", but it might very well be set to a different username. /usr/bin/defaults appears to be available in the installer environment, so that seems like the best option.

Fixed in 41f328eeeb19828c589d18b405646d1fda787b17.

Thanks for your help and patience in testing this.

cgerke commented 12 years ago

Agreed, defaults gets around others mistakes. This version is good. Thanks. Simplifies my Insta workflow!