super icon indicating copy to clipboard operation
super copied to clipboard

Check for charger/power adapter before restart

Open Luke-From-IT opened this issue 2 years ago • 3 comments

Currently Super doesn't prompt for charger, perhaps we could use the code from erase-install here?

`check_power_status() { # Check if device is on battery or AC power # If not, and our power_wait_timer is above 1, allow user to connect to power for specified time period # Acknowledgements: https://github.com/kc9wwh/macOSUpgrade/blob/master/macOSUpgrade.sh

# default power_wait_timer to 60 seconds
[[ ! $power_wait_timer ]] && power_wait_timer=60

power_wait_timer_friendly=$( printf '%02dh:%02dm:%02ds\n' $((power_wait_timer/3600)) $((power_wait_timer%3600/60)) $((power_wait_timer%60)) )

if /usr/bin/pmset -g ps | /usr/bin/grep "AC Power" > /dev/null ; then
    echo "   [check_power_status] OK - AC power detected"
else
    echo "   [check_power_status] WARNING - No AC power detected"
    if [[ "$power_wait_timer" -gt 0 ]]; then
        if [[ -f "$jamfHelper" ]]; then
            # use jamfHelper if possible
            "$jamfHelper" -windowType "utility" -title "${!dialog_power_title}" -description "${!dialog_power_desc} ${power_wait_timer_friendly}" -alignDescription "left" -icon "$dialog_confirmation_icon" &
            wait_for_power "jamfHelper"
        else
            # open_osascript_dialog syntax: title, message, button1, icon
            open_osascript_dialog "${!dialog_power_desc}  ${power_wait_timer_friendly}" "" "OK" stop &
            wait_for_power "osascript"
        fi
    else
        echo "   [check_power_status] ERROR - No AC power detected after ${power_wait_timer_friendly}, cannot continue."
        exit 1
    fi
fi

}`

Luke-From-IT avatar May 18 '22 11:05 Luke-From-IT

Thanks for the suggestion. Dealing with this issue is on the roadmap for super, and I will likely borrow from erase-install. However, what erase-install does isn't enough if the goal is "enforcement". I plan on devising something more "inconvenient" for the user to strongly encourage the user to plug in and stay plugged in.

Macjutsu avatar May 18 '22 11:05 Macjutsu

I did something similar in a user setup scripted workflow. looked for power to be to make sure encryption ran and completed. Put depnotify up in full screen mode until it was plugged in. Function to check power: checkMainsPower () { powerConnected=$(system_profiler SPPowerDataType | grep "Connected" | awk '{print $2}') /bin/echo "Mains power is on, $powerConnected " >> ${logfile} }

the user facing bit: if [ "$powerConnected" = "No" ] || [ "$filevaultStatus" = "1" ]; then if [ "$powerConnected" = "No" ]; then /bin/echo "Command: Image: /usr/local/outstuff/icons/logo.png" >> ${DEP_NOTIFY_LOG} /bin/echo "Command: MainTitle: Important! Connect mains power." >> ${DEP_NOTIFY_LOG} /bin/echo "Command: MainText: You must connect your mains charger in order to proceed.\n\nThis is to allow FileVault to encrypt your device." >> ${DEP_NOTIFY_LOG} /bin/echo "Status: Awaiting power connection" >> ${DEP_NOTIFY_LOG} /bin/echo "Command: DeterminateOff:" >> ${DEP_NOTIFY_LOG} sudo -u "${LOGGED_IN_USER}" open -a "/Applications/Utilities/DEPNotify.app/Contents/MacOS/DEPNotify" --args -fullScreen & while [ "$powerConnected" = "No" ]; do /bin/echo "awaiting mains power..." >> ${logfile} sleep 2 checkMainsPower done /bin/echo "mains power connected" >> ${logfile} fi

May be of use

PhantomPhixer avatar Jun 27 '22 15:06 PhantomPhixer

Thanks for this example. I do plan to implement something, though I think I'd like to have a mild suggestion and a more drastic action as well.

Macjutsu avatar Jun 27 '22 18:06 Macjutsu

Added in super v3.0b9.

Macjutsu avatar Mar 22 '23 01:03 Macjutsu