#!/usr/bin/python3

# DO NOT MODIFY THIS SCRIPT!
# For custom scripts use the hookdir /etc/linuxmuster-linuxclient7/onShutdown.d

# This script is called in root context when the client is shutdown
try:
    import os, sys
    from linuxmusterLinuxclient7 import logging, hooks, shares, constants, keytab, realm, computer

    logging.info("====== onShutdown started ======")

    realm.pullKerberosTicketForComputerAccount()

    # mount sysvol
    rc, sysvolPath = shares.getLocalSysvolPath()
    if rc:
        os.putenv("SYSVOL", sysvolPath)

    # Run hooks
    hooks.runHook(hooks.Type.Shutdown)

    shares.unmountAllSharesOfUser(computer.krbHostName())

    logging.info("======> onShutdown end ======")

except Exception as e:
    try:
        logging.exception(e)
    except:
        print("A fatal error occured!")
