#!/usr/bin/python
# Copyright (c) 2008 Alon Swartz <alon@turnkeylinux.org> - all rights reserved

import os
import sys

from common import dilive_system, preset_debconf, target_mounted

def main():
    if not target_mounted('/target'):
        sys.exit(10) #return to menu

    templates = ['passwd/shadow',
                 'passwd/root-login',
                 'passwd/root-password',
                 'passwd/root-password-again',
                 'passwd/root-password-crypted',
                 'passwd/make-user',
                 'passwd/username',
                 'passwd/user-password',
                 'passwd/user-password-again',
                 'passwd/user-password-crypted']

    # force user to set root password and skip user account creation
    preseeds = [('passwd/root-login', 'true'),
                ('passwd/make-user', 'false')]

    preset_debconf(resets=templates, preseeds=preseeds)

    # skip check if root already has a password
    os.environ['OVERRIDE_ROOT_PASSWORD'] = 'y'

    dilive_system('/usr/lib/di-live/user-setup/user-setup-ask', '/target')
    dilive_system('/usr/lib/di-live/user-setup/user-setup-apply', '/target')


if __name__ == "__main__":
    main()

