[Zope-Checkins] CVS: Zope/inst - Makefile.in:1.1.2.1 makeinstance.in:1.1.2.1 zpasswd.py:1.1.2.1 configure.py:1.1.2.8

Chris McDonough chrism@zope.com
Tue, 17 Sep 2002 00:52:31 -0400


Update of /cvs-repository/Zope/inst
In directory cvs.zope.org:/tmp/cvs-serv9909/inst

Modified Files:
      Tag: chrism-install-branch
	configure.py 
Added Files:
      Tag: chrism-install-branch
	Makefile.in makeinstance.in zpasswd.py 
Log Message:
Move Makefile.in and makeinstance.in to 'inst' directory.

Remove zpasswd.py from ZOPE_HOME and move it into both 'utilities' and
'inst' directories  (it's used by the installer, so it needs to be in
'inst' to be imported properly without playing path games).




=== Added File Zope/inst/Makefile.in ===
# Zope2 build and install Makefile.

# We do as much as possible in Python in order to avoid needing to
# learn autoconf or some other awful thing. ;-)

PYTHON=<<PYTHON>>
ZOPE_HOME=<<ZOPE_HOME>>
BUILD_DIR=<<BUILD_DIR>>
RM=rm -rf
FIND=find
XARGS=xargs

.PHONY : clean install uninstall instance

build:
	"${PYTHON}" "${BUILD_DIR}/setup.py" build_ext -i
	"${PYTHON}" -c "open('${BUILD_DIR}/build', 'w')"
	@echo Zope built.  Next, do \'make install\' \(or \'make instance\'
	@echo to run a Zope instance directly from the build directory\).
	@echo

install: build
	"${PYTHON}" "${BUILD_DIR}/inst/source_install.py" --src="${BUILD_DIR}"\
          --dst="${ZOPE_HOME}" --rm-from-dst="Makefile Makefile.in configure\
          stupid_clean w_pcgi.py wo_pcgi.py setup.py start stop build\
          inituser makeinstance.in *.pyc *.pyo"
	@echo
	@echo Zope binaries installed successfully.
	@echo Now run \'${ZOPE_HOME}/makeinstance.\'

instance: build
	"${PYTHON}" "${BUILD_DIR}/inst/make_instance.py"

uninstall:
	${RM} "${ZOPE_HOME}"

clean:
	${FIND} "${BUILD_DIR}" -name '*.o' -o -name '*.so' -o -name '*.py[co]'\
          -o -name 'core*' | ${XARGS} rm -f
	${RM} ${BUILD_DIR}/build


=== Added File Zope/inst/makeinstance.in ===
#!/bin/sh
"<<PYTHON>>" "<<ZOPE_HOME>>/inst/make_instance.py" $@


=== Added File Zope/inst/zpasswd.py ===
#!/usr/bin/env python
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Zope user bootstrap system"""

__version__='$Revision: 1.1.2.1 $ '[11:-2]

import sys,  sha, binascii, random, getopt, getpass, os

try:
    from crypt import crypt
except ImportError:
    crypt = None

def generate_salt():
    """Generate a salt value for the crypt function."""
    salt_choices = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                    "abcdefghijklmnopqrstuvwxyz"
                    "0123456789./")
    return random.choice(salt_choices)+random.choice(salt_choices)

def generate_passwd(password, encoding):
    encoding=encoding.upper()
    if encoding == 'SHA':
        pw = '{SHA}' + binascii.b2a_base64(sha.new(password).digest())[:-1]
    elif encoding == 'CRYPT':
        pw = '{CRYPT}' + crypt(password, generate_salt())
    elif encoding == 'CLEARTEXT':
        pw = password

    return pw

def write_generated_password(home, ac_path, username):
    pw_choices = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                  "abcdefghijklmnopqrstuvwxyz"
                  "0123456789!")
    acfile=open(ac_path, 'w')
    pw = ''
    for i in range(8):
        pw = pw + random.choice(pw_choices)
    acfile.write('%s:%s' % (username, generate_passwd(pw, 'SHA')))
    acfile.close()
    os.system('chmod 644 %s' % ac_path)
    return pw

def write_access(home, user='', group=''):
    ac_path=os.path.join(home, 'access')
    if not os.path.exists(ac_path):
        print '-'*78
        print 'creating default access file'
        pw = write_generated_password(home, ac_path, 'emergency')
        print """Note:
        The emergency user name and password are 'emergency'
        and '%s'.

        You can change the emergency name and password with the
        zpasswd script.  To find out more, type:

        %s zpasswd.py
        """ % (pw, sys.executable)

        import do; do.ch(ac_path, user, group)

def write_inituser(home, user='', group=''):
    ac_path=os.path.join(home, 'inituser')
    if not os.path.exists(ac_path):
        print '-'*78
        print 'creating default inituser file'
        pw = write_generated_password(home, ac_path, 'admin')
        print """Note:
        The initial user name and password are 'admin'
        and '%s'.

        You can change the name and password through the web
        interface or using the 'zpasswd.py' script.
        """ % pw

        import do; do.ch(ac_path, user, group)


def main(argv):
    short_options = ':u:p:e:d:'
    long_options = ['username=',
                    'password=',
                    'encoding=',
                    'domains=']

    usage = """Usage: %s [options] filename
If this program is called without command-line options, it will prompt
for all necessary information.  The available options are:

    -u / --username=
    Set the username to be used for the initial user or the emergency user

    -p / --password=
    Set the password

    -e / --encoding=
    Set the encryption/encoding rules.  Defaults to SHA-1. OPTIONAL

    -d / --domains=
    Set the domain names that the user user can log in from.  Defaults to
    any. OPTIONAL.

    Filename is required and should be the name of the file to store the
    information in (usually "inituser" or "access").

Copyright (C) 1999, 2000 Digital Creations, Inc.
""" % argv[0]

    try:
        if len(argv) < 2:
            raise "CommandLineError"

        optlist, args = getopt.getopt(sys.argv[1:], short_options, long_options)

        if len(args) != 1:
            raise "CommandLineError"

        access_file = open(args[0], 'w')

        if len(optlist) > 0:
            # Set the sane defaults
            username = ''
            encoding = 'SHA'
            domains = ''

            for opt in optlist:
                if (opt[0] == '-u') or (opt[0] == '--username'):
                    username = opt[1]
                elif (opt[0] == '-p') or (opt[0] == '--password'):
                    password = opt[1]
                elif (opt[0] == '-e') or (opt[0] == '--encoding'):
                    encoding = opt[1]
                elif (opt[0] == '-d') or (opt[0] == '--domains'):
                    domains = ":" + opt[1]

            # Verify that we got what we need
            if not username or not password:
                raise "CommandLineError"

            access_file.write(username + ':' +
                              generate_passwd(password, encoding) +
                              domains)

        else:
            # Run through the prompts
            while 1:
                username = raw_input("Username: ")
                if username != '':
                    break

            while 1:
                password = getpass.getpass("Password: ")
                verify = getpass.getpass("Verify password: ")
                if verify == password:
                    break
                else:
                    password = verify = ''
                    print "Password mismatch, please try again..."

            while 1:
                print """
Please choose a format from:

SHA - SHA-1 hashed password (default)
CRYPT - UNIX-style crypt password
CLEARTEXT - no protection
"""
                encoding = raw_input("Encoding: ")
                if encoding == '':
                    encoding = 'SHA'
                    break
                if encoding.upper() in ['SHA', 'CRYPT', 'CLEARTEXT']:
                    break

            domains = raw_input("Domain restrictions: ")
            if domains: domains = ":" + domains

            access_file.write(username + ":" +
                              generate_passwd(password, encoding) +
                              domains)

    except "CommandLineError":
        sys.stderr.write(usage)
        sys.exit(1)


# If called from the command line
if __name__=='__main__': main(sys.argv)


=== Zope/inst/configure.py 1.1.2.7 => 1.1.2.8 ===
--- Zope/inst/configure.py:1.1.2.7	Mon Sep 16 01:49:42 2002
+++ Zope/inst/configure.py	Tue Sep 17 00:52:30 2002
@@ -22,8 +22,9 @@
     BUILD_DIR=os.path.abspath(os.path.split(os.path.dirname(sys.argv[0]))[0])
     ZOPE_HOME='/usr/local/zope'
     PYTHON=sys.executable
-    MAKEINSTANCE=open(os.path.join(BUILD_DIR, 'makeinstance.in')).read()
-    MAKEFILE=open(os.path.join(BUILD_DIR, 'Makefile.in')).read()
+    HERE = os.path.join(BUILD_DIR, 'inst')
+    MAKEINSTANCE=open(os.path.join(HERE, 'makeinstance.in')).read()
+    MAKEFILE=open(os.path.join(HERE, 'Makefile.in')).read()
     REQUIRE_LF_ENABLED = 1
     zope_home = ZOPE_HOME
     build_dir = BUILD_DIR
@@ -51,10 +52,11 @@
     for k,v in idata.items():
         MAKEFILE = MAKEFILE.replace(k, v)
         MAKEINSTANCE = MAKEINSTANCE.replace(k, v)
-    f = open('Makefile', 'w')
+    f = open(os.path.join(BUILD_DIR, 'Makefile'), 'w')
     f.write(MAKEFILE)
     print "  - Makefile written."
     f = open('makeinstance', 'w')
+    f = open(os.path.join(BUILD_DIR, 'makeinstance'), 'w')
     f.write(MAKEINSTANCE)
     os.chmod('makeinstance', 0755)
     print "  - 'makeinstance' script written."