#!/usr/bin/python

import os
import shutil
import sys

import syslog
syslog.openlog("crypt-preinstall")

def fail(message):
    syslog.syslog(syslog.LOG_ALERT, message)
    sys.exit(1)

def move_old_plist():
    old_plist = '/private/var/root/recovery_key.plist'
    new_plist = '/private/var/root/crypt_output.plist'
    if os.path.exists('/private/var/root/recovery_key.plist'):
        # We have an old recovery key, move it to the new location
        try:
            shutil.move(old_plist, new_plist)
        except:
            fail('Could not move old plist to new location')

def remove_old_app():
    # remove old installdir
    old_install_dir = '/usr/local/crypt'
    if os.path.exists(old_install_dir):
        shutil.rmtree(old_install_dir)


def main():
    move_old_plist()

if __name__ == '__main__':
    main()
