SecondSonConsulting / Baseline

An MDM agnostic zero touch solution for macOS
MIT License
192 stars 22 forks source link

Add support for Log out instead of Restart #14

Closed guy-tallon closed 6 months ago

guy-tallon commented 1 year ago

Feature Request

The option to have (forced) log out instead of restart.

Reason

A log out is required for FileVault to be enabled and so this would be a great way to have that happen as the last step in the setup. At least in Jamf Now.

Possible workaround (for Jamf Now/Fundamentals)

Deploy a package that would create a script that can be called by Baseline.

1 . cat the script to a /tmp folder

  1. Package the script
  2. Deploy the packages (before baseline)
  3. add it to the keys

Script for to package it (just for completeness)

#!/bin/bash
cat > /tmp/logout.sh << 'EOF'
<script goes here>
chmod +x /tmp/logout.sh

Log out script

#!/bin/bash

# Get the username of the currently logged-in user
loggedInUser=$(stat -f "%Su" /dev/console)

# Log out the user using AppleScript
osascript -e "tell application \"/System/Library/CoreServices/loginwindow.app\" to «event aevtrlgo»"
BigMacAdmin commented 1 year ago

Hello, this feature has been added to v1.3beta1 pre release. Please test and provide feedback, either here or on Slack:

https://github.com/SecondSonConsulting/Baseline/releases/tag/v1.3beta1

guy-tallon commented 12 months ago

This is great, however it doesn't work for me. The first run doesn't install SwiftDialog but that's ok, I can deploy that separately.

2nd run, it installs Zoom, shows the Logout Dialog but, clicking on OK or leaving the countdown to finish doesn't log out. I guess the below log isn't that helpful but let me know if there's somewhere else I should look.

Report created: Fri Sep  8 17:40:06 BST 2023
Verified User is logged in: guytallon UID: 501
Dialog List Customization Found: --title
Dialog List Customization Found: --message
Dialog Success Customization Found: --title
Dialog Success Customization Found: --message
Dialog Success Customization Found: --message
Dialog Failure Customization Found: --title
Dialog Failure Customization Found: --message
No icon set, leaving blank

Exiting: **WARNING** SwiftDialog failed to launch after 10 attempts. This likely indicates an issue with the options in the configuration file. Check your file paths.

Report created: Fri Sep  8 18:13:51 BST 2023
Verified User is logged in: guytallon UID: 501
Dialog List Customization Found: --title
Dialog List Customization Found: --message
Dialog Success Customization Found: --title
Dialog Success Customization Found: --message
Dialog Success Customization Found: --message
Dialog Failure Customization Found: --title
Dialog Failure Customization Found: --message
No icon set, leaving blank```

```+cleanup_and_restart:3> check_restart_option
+check_restart_option:3> forceRestartSetting=+check_restart_option:3> /usr/libexec/PlistBuddy -c 'Print :Restart' '/Library/Managed Preferences/com.secondsonconsulting.baseline.plist'
+check_restart_option:3> forceRestartSetting=false 
+check_restart_option:5> [ false '=' false ']'
+check_restart_option:6> forceRestart=false 
+check_restart_option:11> logoutSetting=+check_restart_option:11> /usr/libexec/PlistBuddy -c 'Print :LogOut' '/Library/Managed Preferences/com.secondsonconsulting.baseline.plist'
+check_restart_option:11> logoutSetting=true 
+check_restart_option:12> [ true '=' true ']'
+check_restart_option:13> forceLogOut=true 
+cleanup_and_restart:6> cleanupAfterUse=+cleanup_and_restart:6> /usr/libexec/PlistBuddy -c 'Print :CleanupAfterUse' '/Library/Managed Preferences/com.secondsonconsulting.baseline.plist'
Print: Entry, ":CleanupAfterUse", Does Not Exist
+cleanup_and_restart:6> cleanupAfterUse='' 
+cleanup_and_restart:8> [ '' '=' false ']'
+cleanup_and_restart:11> cleanupBaselineDirectory=true 
+cleanup_and_restart:14> log_message 'Exiting: '
+log_message:2> [ -e /var/log/Baseline.log ']'
+log_message:3> date
+log_message:3> /bin/echo 'Fri Sep  8 18:18:28 BST 2023: Exiting: '
+log_message:6> [ '' '=' 1 ']'
+cleanup_and_restart:16> [ -e /Library/LaunchDaemons/com.secondsonconsulting.baseline.plist ']'
+cleanup_and_restart:17> rm_if_exists /Library/LaunchDaemons/com.secondsonconsulting.baseline.plist
+rm_if_exists:2> [ -n /Library/LaunchDaemons/com.secondsonconsulting.baseline.plist ']'
+rm_if_exists:2> [ -e /Library/LaunchDaemons/com.secondsonconsulting.baseline.plist ']'
+rm_if_exists:3> /bin/rm -rf /Library/LaunchDaemons/com.secondsonconsulting.baseline.plist
+cleanup_and_restart:18> sleep 1
+cleanup_and_restart:16> [ -e /Library/LaunchDaemons/com.secondsonconsulting.baseline.plist ']'
+cleanup_and_restart:21> kill 36603
+cleanup_and_restart:23> dialog_command quit:
+dialog_command:1> /bin/echo quit:
+dialog_command:2> sleep .1
+cleanup_and_restart:25> rm_if_exists /var/tmp/baselineDialog.IrtWaF
+rm_if_exists:2> [ -n /var/tmp/baselineDialog.IrtWaF ']'
+rm_if_exists:2> [ -e /var/tmp/baselineDialog.IrtWaF ']'
+rm_if_exists:3> /bin/rm -rf /var/tmp/baselineDialog.IrtWaF
+cleanup_and_restart:27> rm_if_exists /var/tmp/baselineJson.23V1
+rm_if_exists:2> [ -n /var/tmp/baselineJson.23V1 ']'
+rm_if_exists:2> [ -e /var/tmp/baselineJson.23V1 ']'
+rm_if_exists:3> /bin/rm -rf /var/tmp/baselineJson.23V1
+cleanup_and_restart:29> rm_if_exists /var/tmp/baselineTmpIcons.uYjm
+rm_if_exists:2> [ -n /var/tmp/baselineTmpIcons.uYjm ']'
+rm_if_exists:2> [ -e /var/tmp/baselineTmpIcons.uYjm ']'
+rm_if_exists:3> /bin/rm -rf /var/tmp/baselineTmpIcons.uYjm
+cleanup_and_restart:32> [ true '=' true ']'
+cleanup_and_restart:33> rm_if_exists /usr/local/Baseline
+rm_if_exists:2> [ -n /usr/local/Baseline ']'
+rm_if_exists:2> [ -e /usr/local/Baseline ']'
+rm_if_exists:3> /bin/rm -rf /usr/local/Baseline
+cleanup_and_restart:39> [ false '=' false ']'
+cleanup_and_restart:40> echo 'Force Restart is set to false. Exiting'
Force Restart is set to false. Exiting
+cleanup_and_restart:41> exit ''```
BigMacAdmin commented 12 months ago

I'm not sure whats up with the SwiftDialog error, you're the first to report that.

If you have both Restart and LogOut in the same configuration file (appears so based on the output) then there will be unexpected behavior. Can you please check? Even if Restart is set to false, this will cause a conflict.

guy-tallon commented 12 months ago

Hi, restart is set to false - snippet of my config below. If I remove the Restart key entirely though it works!

            <key>PayloadUUID</key>
            <string>0D049C71-F48A-48BB-8740-6918A6C242CC</string>
            <key>PayloadVersion</key>
            <integer>1</integer>
            <key>LogOut</key>
            <true/>
            <key>Restart</key>
            <false/>

SwiftDialog - I'm not sure. I ran all the commands and it downloads and installs. Can't tell why the function fails, it's probably something obvious but I can open another issue for that though, not get too off topic

BigMacAdmin commented 8 months ago

I've reworked the logic on this feature for v2.0beta2, and I believe this is ready for release.

You should now be able to use LogOut and Restart in the same configuration file without Baseline getting confused about it.

guy-tallon commented 8 months ago

Awesome! I'll try and make time to test this today