#!/usr/bin/python
#
# This script helps the user quickly enable standard linux tools such as SSH and IPTables
# It also provides a way for the user to add a custom startup script
#
# Author: Dan Bracey -- 6/10/08
# Revision History:
# 6/17/08 -- 1.000 -- debracey -- Initial Creation

import os
import sys

bindir = os.path.abspath(os.path.dirname(os.path.realpath(sys.argv[0])))
libdir = os.path.join(bindir, "..", "python_lib")

sys.path.append(libdir)

import Internet2Lib       # Library functions
import Internet2Consts    # For constants
import Internet2Commands  # For startstop commands
import sys                # For stdin
import os                 # For standard OS commands
import readline           # Improve the usability of raw_input. Let you use those fancy "arrow" keys
import pwd                # verify the user exists

### MAIN ###
print "Welcome to the Internet2 pS-Performance Toolkit Password configuration program."
print "This program will help you set the passwords for built-in accounts: root"
print Internet2Consts.WHITE + "Default values are in []" + Internet2Consts.NORMAL + "\n"

# Must be root
if not Internet2Lib.isRoot():
    print Internet2Consts.YELLOW + "You must run this script as root. Please rerun this script with root permissions." + Internet2Consts.NORMAL
    sys.exit(1)

for name in [ "root" ]:
    try:
        pwd.getpwnam(name)
    except KeyError:
        continue

    done = False
    while not done:
        print "Please specify a password for the " + Internet2Consts.MAGENTA + name + Internet2Consts.NORMAL + " account."
        retVal = os.system("passwd " + name)

        if int(retVal) != 0:
            print Internet2Consts.YELLOW + "Couldn't set the password to what you specified. Please try again." + Internet2Consts.NORMAL
        else:
            done = True

Internet2Lib.touchFile(Internet2Consts.PASS_MARKER)

sys.exit(0)
