homebysix / jss-filevault-reissue

A framework for re-escrowing missing or invalid FileVault keys with Jamf Pro.
Apache License 2.0
186 stars 56 forks source link

Remove need for python by replacing python get user with native SH get user #31

Closed pboushy closed 3 years ago

pboushy commented 4 years ago

If you replace line 114:

CURRENT_USER=$(/usr/bin/python` -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username);')

With:

CURRENT_USER=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }')

You won't need Python for this script anymore.

jelockwood commented 4 years ago

Good suggestion.

It should be noted that Apple announced during the release of macOS Catalina that future versions of macOS would not include a Python runtime as standard. Therefore removing the need for Python will make it more likely that this script will continue to work 'out of the box'.

See https://developer.apple.com/documentation/macos-release-notes/macos-catalina-10_15-release-notes and scroll down to "Scripting Language Runtimes".

I have not yet checked to see if macOS Big Sur has already implemented this change.

mpanighetti commented 4 years ago

Removing Python dependency is a good step, but the bigger potential implication of macOS removing scripting language runtimes is the possibility of Bash also being removed, as indicated by the default shell switching to Zsh in macOS 10.15+. Switching the entire script to Zsh would be a good long-term move, though that may take a fair amount of testing and debugging.

pboushy commented 4 years ago

I was planning on re-writing the script to ZSH anyways. We have 10.13-10.5 in my environment, so we’ll at least have that much tested.