summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-config
diff options
context:
space:
mode:
authorJames Meyer <james.meyer@operamail.com>2012-08-07 02:27:38 (GMT)
committerJames Meyer <james.meyer@operamail.com>2012-08-07 02:27:38 (GMT)
commitdb36c399fcfe215e0bc9e0fe484918ff14286764 (patch)
tree5ec1e516335062ded4dad9f5844392bb1892390f /abs/core/LinHES-config
parent9f3eafdf95237972c0ec30cf2977b1ae870c0946 (diff)
downloadlinhes_pkgbuild-db36c399fcfe215e0bc9e0fe484918ff14286764.zip
linhes_pkgbuild-db36c399fcfe215e0bc9e0fe484918ff14286764.tar.gz
linhes_pkgbuild-db36c399fcfe215e0bc9e0fe484918ff14286764.tar.bz2
gnupg
-new
Diffstat (limited to 'abs/core/LinHES-config')
-rw-r--r--abs/core/LinHES-config/PKGBUILD13
-rwxr-xr-xabs/core/LinHES-config/mv_install.py222
-rw-r--r--abs/core/LinHES-config/myth_user_call319
3 files changed, 356 insertions, 198 deletions
diff --git a/abs/core/LinHES-config/PKGBUILD b/abs/core/LinHES-config/PKGBUILD
index e872bcf..52303f9 100644
--- a/abs/core/LinHES-config/PKGBUILD
+++ b/abs/core/LinHES-config/PKGBUILD
@@ -5,9 +5,10 @@ conflicts=(MythVantage-config MythVantage-config-dev LinHES-config-dev LinHes-co
pkgdesc="Install and configure your system"
depends=('bc' 'libstatgrab' 'mysql-python' 'expect' 'curl' 'dnsutils' 'parted'
'sg3_utils' 'nmbscan' 'system-templates' 'rsync' 'python-parted'
- 'ddcxinfo' 'python-pexpect' 'python-netifaces' 'LinHES-timezone'
+ 'python-pexpect' 'python-netifaces'
'python-iplib' 'mythinstall>=2-10')
-arch=('i686')
+#LinHES-timezone
+arch=('i686' 'x86_64')
source=(mv_install.py
mv_config.py
@@ -19,7 +20,7 @@ source=(mv_install.py
install_db_chroot.sh
restore_default_settings.sh
myth_settings_wrapper.sh
- xconfig.sh
+ xconfig.sh
timezip.py
soundconfig.sh
LinHES-release
@@ -102,12 +103,12 @@ build() {
#Copy in the branding stuff
install -m 0755 LinHES-release $startdir/pkg/etc/LinHES-release
- install -m 0755 issue $startdir/pkg/etc/issue
+ #install -m 0755 issue $startdir/pkg/etc/issue
}
-md5sums=('18af4fe481e1fc2ae02050026eb5cd27'
+md5sums=('4ef6a2f04f5cb1777ac3772eeccdc78f'
'16b98fcb3753ef6cfc35075c326d30e4'
- 'e36da536dd651ef182e7642337889e77'
+ '2596460462cf6c889cf8f95485537b20'
'985891a43f7c4c983eb2a362162f1a0f'
'13172731c8b08d669336da31cece5775'
'5a31addfbdc1154b05997f972a32fa33'
diff --git a/abs/core/LinHES-config/mv_install.py b/abs/core/LinHES-config/mv_install.py
index 2e60ab7..c7a002d3 100755
--- a/abs/core/LinHES-config/mv_install.py
+++ b/abs/core/LinHES-config/mv_install.py
@@ -129,7 +129,7 @@ def mdadm_assemble_all():
def copy_updates():
try:
- MVROOT = os.environ["MV_ROOT"]
+ MVROOT = os.environ["MV_ROOT"].strip()
except:
logging.debug("MVROOT was not defined, using the default value")
MVROOT = "/usr/MythVantage"
@@ -475,20 +475,118 @@ def create_squashlist():
logging.debug(i)
f.close()
+def mount_for_copy_it():
+
+ image_mount='/image_mount/root'
+ try:
+ os.makedirs(image_mount)
+ except:
+ pass
+ image_mount='/image_mount/root'
+
+ image_mount='/image_mount/usr/share'
+ try:
+ os.makedirs(image_mount)
+ except:
+ pass
+
+ image_mount='/image_mount/lib/modules'
+ try:
+ os.makedirs(image_mount)
+ except:
+ pass
+
+ image_mount='/image_mount/var/cache/pacman'
+ try:
+ os.makedirs(image_mount)
+ except:
+ pass
+
+ image_mount='/image_mount/var/lib/pacman'
+ try:
+ os.makedirs(image_mount)
+ except:
+ pass
+
+ fsimage='root-image'
+ cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/root' %(fsimage,fsimage)
+ rc = runcmd(cmd)[0]
+ if rc != 0 :
+ error_out("Mount image root")
+
+ fsimage='lib-modules'
+ cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/lib/modules' %(fsimage,fsimage)
+ rc = runcmd(cmd)[0]
+ if rc != 0 :
+ error_out("Mount image lib-modules")
+
+ fsimage='usr-share'
+ cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/usr/share' %(fsimage,fsimage)
+ rc = runcmd(cmd)[0]
+ if rc != 0 :
+ error_out("Mount image usr share")
+
+ fsimage='var-lib-pacman'
+ cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/var/lib/pacman' %(fsimage,fsimage)
+ rc = runcmd(cmd)[0]
+ if rc != 0 :
+ error_out("Mount image var-lib-pacman")
+
+ fsimage='var-cache-pacman'
+ cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/var/cache/pacman' %(fsimage,fsimage)
+ rc = runcmd(cmd)[0]
+ if rc != 0 :
+ error_out("Mount image var-cahce-pacman")
+
+
+def umount_for_copy_it():
+ cmd='umount %s' %('/image_mount/lib/modules')
+ rc = runcmd(cmd)[0]
+ if rc != 0 :
+ error_out("unMount image lib_modules")
+
+ cmd='umount %s' %('/image_mount/usr/share')
+ rc = runcmd(cmd)[0]
+ if rc != 0 :
+ error_out("unMount image usr_share")
+
+ cmd='umount %s' %('/image_mount/root')
+ rc = runcmd(cmd)[0]
+ if rc != 0 :
+ error_out("unMount image /")
+
+ cmd='umount %s' %('/image_mount/var/cache/pacman')
+ rc = runcmd(cmd)[0]
+ if rc != 0 :
+ error_out("unMount image var-cache-pacman")
+
+ cmd='umount %s' %('/image_mount/var/lib/pacman')
+ rc = runcmd(cmd)[0]
+ if rc != 0 :
+ error_out("unMount image var-lib-pacman")
+
+
def copy_it(install_type):
logging.info("______Transferring to disk______")
+ mount_for_copy_it()
logging.debug( install_type)
if ( install_type == "install"):
logging.info("Transferring system")
- cmd = " unsquashfs -f -d %s /.livesys/medium/larch/system.sqf" %(data_config.MOUNTPOINT)
- #runcmd(cmd)
- rc = runcmd(cmd)[0]
- if rc != 0 :
- error_out("Running unsquashfs")
+ cmdlist = ['rsync -avrp /image_mount/root/* /new_boot',
+ 'rsync -arvp /image_mount/lib/* /new_boot/lib/',
+ 'rsync -arvp /image_mount/usr /new_boot',
+ 'rsync -arvp /image_mount/var /new_boot']
+
+ #'rsync -arvp /image_mount/lib /new_boot',
+
+ for cmd in cmdlist:
+ #runcmd(cmd)
+ rc = runcmd(cmd)[0]
+ if rc != 0 :
+ error_out("Running %s" %cmd)
+
- #logging.debug(cmd)
- #cmdout=commands.getoutput(cmd)
if ( install_type == "upgrade"):
logging.info("Upgrading system")
@@ -533,12 +631,10 @@ def copy_it(install_type):
runcmd(cmd)
cmd = "chmod +s %s/bin/mount" %(data_config.MOUNTPOINT)
runcmd(cmd)
- cmd = "rm %s/etc/*.larch*" %(data_config.MOUNTPOINT)
- runcmd(cmd)
- cmd = "rm %s/etc/mkinitcpio.d/larch*" %(data_config.MOUNTPOINT)
- runcmd(cmd)
- cmd = "rm %s/etc/rc.d/functions.d/*larch*" %(data_config.MOUNTPOINT)
- runcmd(cmd)
+ apply_pristine()
+ post_process()
+
+ umount_for_copy_it()
logging.debug("__End of copy_it__")
def create_fstab(extralines):
@@ -636,6 +732,7 @@ def fstab_it(install_type):
elif os.path.exists("/tmp/etc/fstab"):
logging.debug(" Upgrade and not Knoppmyth, using old fstab")
cp_and_log("/tmp/etc/fstab", fstabfile)
+
# Catch all for creating new fstab
if not os.path.exists(data_config.MOUNTPOINT+"/etc"):
os.makedirs(data_config.MOUNTPOINT+"/etc")
@@ -735,11 +832,31 @@ def fstab_it(install_type):
def grub_it():
logging.info("______Start of grub install______")
+ cmd = "chroot %s grub-install --target=i386-pc --recheck --debug /dev/%s" %(data_config.MOUNTPOINT,hostoptions["rootdisk"])
+ logging.info("Running grub-install")
+ runcmd(cmd)
+
+ cmd = " mkinitcpio -g %s/boot/initramfs-linux.img" %(data_config.MOUNTPOINT)
+ logging.info("Running mkinitcpio")
+ runcmd(cmd)
+
+
+ cmd="chroot %s grub-mkconfig -o /boot/grub/grub.cfg" %data_config.MOUNTPOINT
+ runcmd(cmd)
+ #rootuuid = find_uuid(hostoptions["rootpartition"])
+ #cmd = " mkinitcpio -b %s -g %s/boot/kernel26.img" %(data_config.MOUNTPOINT, data_config.MOUNTPOINT)
+ #cmd = " mkinitcpio -g %s/boot/initramfs-linux.img" %(data_config.MOUNTPOINT)
+ #logging.info("Running mkinitcpio")
+ #runcmd(cmd)
+
+def grub_it1():
+ logging.info("______Start of grub install______")
cmd = " grub-install --recheck --no-floppy --root-directory=%s \"(hd0)\" " % data_config.MOUNTPOINT
logging.info("Running grub-install")
runcmd(cmd)
rootuuid = find_uuid(hostoptions["rootpartition"])
cmd = " mkinitcpio -b %s -g %s/boot/kernel26.img" %(data_config.MOUNTPOINT, data_config.MOUNTPOINT)
+ cmd = " mkinitcpio -g %s/boot/initramfs-linux.img" %(data_config.MOUNTPOINT)
logging.info("Running mkinitcpio")
runcmd(cmd)
logging.info("Adding root uuid to grub menu")
@@ -755,6 +872,20 @@ def grub_it():
logging.debug(" Found kernel Root grubline:")
logging.debug( templine)
templine[2] = "root=/dev/disk/by-uuid/%s" %(rootuuid)
+ templine[1] = "/boot/vmlinuz-linux"
+ newline = ''
+ for i in templine:
+ newline+=i
+ newline+=" "
+ newline+="\n"
+ logging.debug(" New grub menu.lst line:")
+ logging.debug( newline)
+ newgrub.append(newline)
+ elif line.startswith("initrd"):
+ templine = line.split()
+ logging.debug(" Found initrd grubline:")
+ logging.debug( templine)
+ templine[1] = "/boot/initramfs-linux.img"
newline = ''
for i in templine:
newline+=i
@@ -823,7 +954,7 @@ def apply_new_auth():
logging.info("_____Applying Password updates_______")
passfile = "/root/myth_user_call.out"
try:
- MVROOT = os.environ["MV_ROOT"]
+ MVROOT = os.environ["MV_ROOT"].strip()
except:
logging.debug("MVROOT was not defined, using the default value")
MVROOT = "/usr/MythVantage"
@@ -1030,10 +1161,48 @@ def restore_default_settings():
copy_updates()
fix_permissions()
+def apply_pristine():
+ logging.info("_____Applying Pristine files_______")
+ if data_config.NOOPDEBUG == "FALSE":
+ cmd = "chroot " + data_config.MOUNTPOINT + " " + "tar -xvf /pristine.tar"
+ else:
+ cmd = "echo chroot " + data_config.MOUNTPOINT + " " + "tar -xvf /pristine.tar"
+ try:
+# Using os.system because runcmd fails
+ logging.debug(cmd)
+ os.system(cmd)
+ except:
+ logging.debug("Applying pristine files failed %s", passfile)
+ logging.debug
+
+ try:
+ removefile="%s/pristine.tar" %(data_config.MOUNTPOINT)
+ os.remove(removefile)
+ except OSError:
+ logging.debug(" Couldn't remove pristine.tar")
+ pass
+
+def post_process():
+ logging.info("_____Post processing_______")
+ if data_config.NOOPDEBUG == "FALSE":
+ cmd = "chroot " + data_config.MOUNTPOINT + " " + "/root/.post_process/go.sh"
+ else:
+ cmd = "echo chroot " + data_config.MOUNTPOINT + " " + "/root/.post_process/go.sh"
+ try:
+# Using os.system because runcmd fails
+ logging.debug(cmd)
+ os.system(cmd)
+ except:
+ logging.debug("Applying post_process_failed %s", passfile)
+ logging.debug
+
+
+
+
def full_install(hostoptions):
logging.info("______Start of full install______")
try:
- MVROOT = os.environ["MV_ROOT"]
+ MVROOT = os.environ["MV_ROOT"].strip()
except:
logging.debug(" MVROOT was not defined, using the default value")
MVROOT = "/usr/MythVantage"
@@ -1088,7 +1257,10 @@ def full_install(hostoptions):
msg = "Configuring system"
update_status(msg)
progress(98)
+ mount_bind_chroot()
grub_it()
+ umount_bind_chroot()
+
genlocale()
special_hardware_check()
# Configuring the system
@@ -1118,7 +1290,7 @@ def full_install(hostoptions):
logging.info("______Installing Database in CHROOT________")
mysqldb("stop", '')
mount_bind_chroot()
- cmd = " chroot %s %s/bin/install_db_chroot.sh |tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT)
+ cmd = "chroot %s %s/bin/install_db_chroot.sh |tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT)
runcmd(cmd)
logging.info("Running systemconfig in chroot")
#cmd = " chroot %s %s/bin/systemconfig.sh misc, hostype, network, advanced, user, this_is_install" %(data_config.MOUNTPOINT, MVROOT)
@@ -1135,7 +1307,7 @@ def full_install(hostoptions):
else:
logging.info("______No database required, continuing configuration________")
mount_bind_chroot()
- cmd = " chroot %s DISPLAY=127.0.0.1:0 %s/bin/MythVantage -t restore, default 1" %(data_config.MOUNTPOINT, MVROOT)
+ cmd = "chroot %s DISPLAY=127.0.0.1:0 %s/bin/MythVantage -t restore, default 1" %(data_config.MOUNTPOINT, MVROOT)
runcmd(cmd)
# Need to check for to touch /tmp/.dbsysfailed
#cmd = " chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t syssettings " %(data_config.MOUNTPOINT, MVROOT)
@@ -1282,7 +1454,7 @@ def upgrade_mount_search():
def upgrade(hostoptions):
try:
- MVROOT = os.environ["MV_ROOT"]
+ MVROOT = os.environ["MV_ROOT"].strip()
except:
logging.debug("MVROOT was not defined, using the default value")
MVROOT = "/usr/MythVantage"
@@ -1385,23 +1557,23 @@ def upgrade(hostoptions):
if ( systemconfig["SystemType"] == "Master_backend" or systemconfig["SystemType"] == "Standalone" ):
if clean_upgrade() or not backup_sql_check():
logging.info("Installing new database")
- cmd = " chroot %s %s/bin/install_db_chroot.sh |tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT)
+ cmd = "chroot %s %s/bin/install_db_chroot.sh |tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT)
runcmd(cmd)
else:
logging.info("Restoring database")
- cmd = " chroot %s %s/bin/restore_km_db_chroot.sh %s|tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT, hostoptions["backupfile"])
+ cmd = "chroot %s %s/bin/restore_km_db_chroot.sh %s|tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT, hostoptions["backupfile"])
runcmd(cmd)
if os.path.exists("/tmp/etc/KnoppMyth-version"):
- cmd = " chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t hostsettings " %(data_config.MOUNTPOINT, MVROOT)
+ cmd = "chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t hostsettings " %(data_config.MOUNTPOINT, MVROOT)
runcmd(cmd)
logging.debug("Correcting permissions because of km->linhes upgrade")
- cmd = " chown -R mythtv:mythtv %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT)
+ cmd = "chown -R mythtv:mythtv %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT)
runcmd(cmd)
- cmd = " chown -R root:root %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT+"/backup")
+ cmd = "chown -R root:root %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT+"/backup")
runcmd(cmd)
else:
- cmd = " chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t syssettings " %(data_config.MOUNTPOINT, MVROOT)
+ cmd = "chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t syssettings " %(data_config.MOUNTPOINT, MVROOT)
runcmd(cmd)
logging.info("Running systemconfig in chroot 2nd time")
diff --git a/abs/core/LinHES-config/myth_user_call b/abs/core/LinHES-config/myth_user_call
index 0914b03..1b8d315 100644
--- a/abs/core/LinHES-config/myth_user_call
+++ b/abs/core/LinHES-config/myth_user_call
@@ -1,174 +1,159 @@
-#!/bin/bash
+#!/usr/bin/python2
+# -*- coding: utf-8 -*-
#Wrapper script to manage USERNAME accounts + web security
# myth_USERNAME_all -c add -u USERNAME
# myth_USERNAME_all -c delete -u USERNAME
# myth_USERNAME_all -c pass -u USERNAME -p pass
# myth_USERNAME_all -c web -u USERNAME -p pass
-INIT_CHECK=TRUE
-FULL_CALL="$@"
-function CHROOT_CHECK {
- INIT=`ps -p 1 -o comm=`
- if [ x$INIT = xrunit ]
- then
- CHROOT_NEEDED=FALSE
- else
- CHROOT_NEEDED=TRUE
- fi
-}
-
-function store_commands () {
- echo "$FULL_CALL" >> /root/myth_user_call.out
- chmod 600 /root/myth_user_call.out
-}
-
-
-function add_user() {
- if [ $CHROOT_NEEDED = TRUE ]
- then
- echo "calling myth_call_user in chroot to add user"
- store_commands
- else
- echo "adding user $USERNAME"
- useradd -m -s /bin/bash $USERNAME -G audio,video,optical,storage,users
- usermod -a -G mythtv $USERNAME
-
- fi
-
-}
-
-
-function del_user() {
- if [ $CHROOT_NEEDED = TRUE ]
- then
- echo "calling myth_call_user in chroot to delete user"
- store_commands
- else
- echo "removing user $USERNAME"
- userdel $USERNAME
- fi
-
-}
-
-
-function pass_change() {
- if [ $CHROOT_NEEDED = TRUE ]
- then
- echo "calling myth_call_user in chroot to change password"
- store_commands
- else
- echo "changing password for $USERNAME"
- echo $USERNAME:$PASSWORD | chpasswd
- fi
-
-}
-
-
-function web_security {
-
- grep -q ${USERNAME}: /etc/lighttpd/lighttpd.user
- if [ $? = 0 ]
- then
- #delete user
- sed -i "/${USERNAME}\:/d" /etc/lighttpd/lighttpd.user
- fi
- echo "${USERNAME}:${PASSWORD}" >> /etc/lighttpd/lighttpd.user
-
-}
-
-function ARG_ERR() {
- if [ x$OPTARG = "x" ]
- then
- echo "$SWITCH NEEDS AND ARG"
- exit 11
- fi
-}
-
-
-function print_help {
-
- echo "Valid options are:"
- echo " -c (add|delete|pass|web)"
- echo " -u USERNAMEname"
- echo " -p password"
- exit 1
-}
-
-if [ $# -eq 0 ]
-then
- print_help
-fi
-
-declare -r OPTSTRING="c:u:p:i"
-while getopts "$OPTSTRING" SWITCH
-do
- case $SWITCH in
-
- c) ARG_ERR
- OPERATION=$OPTARG
- ;;
- u) ARG_ERR
- USERNAME=$OPTARG
- ;;
- p) ARG_ERR
- PASSWORD=$OPTARG
- ;;
- i) INIT_CHECK=FALSE
-
- esac
-done
-
-if [ $INIT_CHECK = TRUE ]
-then
- CHROOT_CHECK
-else
- CHROOT_NEEDED=FALSE
-fi
-
-case $OPERATION in
- add)
- if [ x$USERNAME = x ]
- then
- print_help
- fi
- add_user
- ;;
- delete)
- if [ x$USERNAME = x ]
- then
- print_help
- fi
- del_user
- ;;
- pass)
- if [ x$USERNAME = x ]
- then
- print_help
- fi
-
- if [ x$PASSWORD = x ]
- then
- print_help
- fi
- pass_change
- ;;
-
- web)
- if [ x$USERNAME = x ]
- then
- print_help
- fi
-
-
- if [ x$PASSWORD = x ]
- then
- print_help
- fi
- echo "adding webUSERNAME $USERNAME with pass $PASSWORD"
- web_security
- ;;
- *) print_help
- ;;
-esac
-
+import pexpect, sys, time
+import os, re, getopt
+import mv_common
+
+
+
+
+def chroot_check():
+ if not INIT_CHECK :
+ return False
+ cmd = '''ps -p 1 -o comm='''
+ init = mv_common.runcmd_output(cmd).strip()
+ if init == "runit":
+ return False
+ else:
+ return True
+
+
+def store_commands(full_call):
+ file_name = "/root/myth_user_call.out"
+ try:
+ f = open(file_name,'a')
+ except:
+ print "%s could not be opened" % file_name
+ sys.exit(1)
+ f.write(full_call)
+ f.write("\n")
+ f.close()
+ try:
+ os.chmod(600,file_name)
+ except:
+ pass
+
+
+def add_user(username,full_call):
+ if chroot_check() :
+ print "calling myth_call_user in chroot to add user"
+ store_commands(full_call)
+ else:
+ print "Adding user %s" %username
+ cmd = '''useradd -m -s /bin/bash %s -G audio,video,optical,storage,users''' %username
+ mv_common.runcmd(cmd)
+ cmd = ''' usermod -a -G mythtv %s ''' %username
+
+
+def del_user(username,full_call):
+ if chroot_check() :
+ print "calling myth_call_user in chroot to del user"
+ store_commands(full_call)
+ else:
+ print "Removing user %s" %username
+ cmd = '''userdel %s ''' %username
+ mv_common.runcmd(cmd)
+
+
+def pass_change(username,password,full_call) :
+ if chroot_check() :
+ print "calling myth_call_user in chroot to change password"
+ store_commands(full_call)
+ else:
+ print "changing password for %s" %username
+ passwd = pexpect.spawn("/usr/bin/passwd %s" % username)
+
+ for repeat in (1, 2):
+ passwd.expect("password: ")
+ passwd.sendline(password)
+ time.sleep(0.1)
+
+def web_security(username,password) :
+ file_name = "/etc/lighttpd/lighttpd.user"
+ file_contents = ''
+ if os.path.exists(file_name):
+ try:
+ f = open(file_name,'r')
+ file_contents = f.readlines()
+ except:
+ print " couldn't read %s" % file_name
+ try:
+ f = open(file_name,'w')
+ except:
+ print "%s could not be opened for writing" % file_name
+ return
+
+ for line in file_contents:
+ if not re.search(username, line):
+ f.write(line)
+ line = "%s:%s" %(username, password)
+ f.write(line)
+ f.write("\n")
+ f.close()
+
+
+def usage ():
+ print "Valid options are:"
+ print " -c (add|delete|pass|web)"
+ print " -u USERNAME"
+ print " -p password"
+ sys.exit(0)
+
+def main(argv):
+ global INIT_CHECK
+ full_call = ""
+ INIT_CHECK = True
+ try:
+ opts, args = getopt.getopt(argv, 'c:u:p:ih' )
+ except getopt.GetoptError, why:
+ print why
+ usage()
+ print "exception happened"
+ sys.exit(2)
+
+ for opt, arg in opts:
+ if opt in ("-h", "--help"):
+ usage()
+ sys.exit(0)
+ elif opt in ("-c") :
+ module = arg
+ full_call += ''' -c %s ''' %re.escape(arg)
+ elif opt in ("-u") :
+ username = arg
+ full_call += ''' -u %s ''' %re.escape(arg)
+ elif opt in ("-p") :
+ password = arg
+ full_call += ''' -p %s ''' %re.escape(arg)
+ elif opt in ("-i") :
+ INIT_CHECK = False
+ full_call += ''' -i '''
+ try:
+ username
+ except:
+ usage()
+
+ if module == "add":
+ add_user(username,full_call)
+ elif module == "delete":
+ del_user(username,full_call)
+ elif module == "pass":
+ try:
+ password
+ except:
+ print "needs a password"
+ usage()
+ pass_change(username,password,full_call)
+ elif module == "web":
+ web_security(username,password)
+ else:
+ usage()
+
+if __name__ == "__main__":
+ main(sys.argv[1:])