#coding:utf-8

import os
import sys
import stat
import time
import base64
import sunhpc
from sunhpc.core.utils import SafeError
class Command(sunhpc.commands.create.security.command):
    """
    Update all user-related files (e.g., /etc/passwd, /etc/shadow, etc.)
    on all known hosts. Also, restart autofs on all known hosts.

    <arg type='string' name='safedir'>
    Provide a path to encrypt, default: /etc/safe.d
    </arg>

    <params type='string' name='safedir'>
    Provide a encrypt file output path, default: /etc/safe.d
    </params>

    <example cmd='create security users'>
    Encrypt sunhpc os all base data.
    </example>
    """
    def run(self, parms, args):
        (self.safedir, salt, quiet) = self.fillParams([
            ('safedir', '/etc/safe.d'),
            ('salt', None),
            ('quiet', 'yes')])

        quiet = self.str2bool(quiet)
        if not os.path.exists(self.safedir):
            os.makedirs(self.safedir)

        userdirs = ['/etc/passwd', '/etc/shadow', '/etc/group']
        services = ['/etc/auto.master', '/etc/auto.home', '/etc/auto.share']
        for i in userdirs + services:
            self.makeEncrypt(i, quiet=quiet)

RollName = "base"
