Added support for including files in templates.

Also added support for breaking lines with \ at the end.
This commit is contained in:
Martin Gracik 2009-06-11 14:26:54 +02:00
parent 032438ddbc
commit 8fd23eca0b
18 changed files with 460 additions and 107 deletions

View File

@ -0,0 +1,175 @@
# initrd template
# create required directories
makedir @initrd@/modules
makedir @initrd@/sbin
makedir @initrd@/dev
makedir @initrd@/etc
makedir @initrd@/etc/udev/rules.d
makedir @initrd@/lib/udev/rules.d
makedir @initrd@/proc
makedir @initrd@/selinux
makedir @initrd@/sys
makedir @initrd@/etc/terminfo/a
makedir @initrd@/etc/terminfo/d
makedir @initrd@/etc/terminfo/l
makedir @initrd@/etc/terminfo/s
makedir @initrd@/etc/terminfo/v
makedir @initrd@/etc/terminfo/x
makedir @initrd@/etc/terminfo/g
makedir @initrd@/tmp
makedir @initrd@/usr/libexec
makedir @initrd@/usr/@libdir@/NetworkManager
makedir @initrd@/usr/share/dbus-1/system-services
makedir @initrd@/var/cache/hald
makedir @initrd@/var/lib/dbus
makedir @initrd@/var/lib/dhclient
makedir @initrd@/var/lock/rpm
makedir @initrd@/var/run
makedir @initrd@/var/run/dbus
makedir @initrd@/var/run/hald
makedir @initrd@/var/run/NetworkManager
makedir @initrd@/etc/dbus-1/system.d
makedir @initrd@/etc/modprobe.d
makedir @initrd@/etc/NetworkManager/dispatcher.d
makedir @initrd@/@libdir@/dbus-1
makedir @initrd@/etc/sysconfig/network-scripts
makedir @initrd@/usr/share/PolicyKit/policy
makedir @initrd@/etc/PolicyKit
makedir @initrd@/var/lib/misc
makedir @initrd@/etc/hal/fdi
makedir @initrd@/usr/share/hal/fdi
makedir @initrd@/usr/share/hwdata
makedir @initrd@/etc/rc.d/init.d
makedir @initrd@/usr/sbin
makedir @initrd@/var/run/wpa_supplicant
# set the buildarch
edit @initrd@/etc/arch text "@buildarch@"
# copy etc stuff
copy @instroot@/etc/passwd to @initrd@/etc mode 0644
copy @instroot@/etc/group to @initrd@/etc mode 0644
copy @instroot@/etc/nsswitch.conf to @initrd@/etc mode 0644
# copy mount/umount
copy @instroot@/bin/mount to @initrd@/sbin
copy @instroot@/bin/umount to @initrd@/sbin
copy @instroot@/sbin/mount.nfs to @initrd@/sbin
link @initrd@/sbin/umount.nfs to mount.nfs
# copy udev
copy @instroot@/sbin/udevd to @initrd@/sbin
copy @instroot@/sbin/udevadm to @initrd@/sbin
link @initrd@/sbin/udevinfo to udevadm
link @initrd@/sbin/udevsettle to udevadm
# udev rules
copy @instroot@/etc/udev/udev.conf to @initrd@/etc/udev mode 0644
copy @instroot@/lib/udev/* to @initrd@/lib/udev mode 0644
remove @initrd@/lib/udev/rules.d/*persistent*
remove @initrd@/lib/udev/rules.d/*generator*
copy @instroot@/etc/udev/rules.d/*.rules to @initrd@/etc/udev/rules.d mode 0644
# copy bash
copy @instroot@/bin/bash to @initrd@/sbin
link @initrd@/sbin/sh to bash
copy @instroot@/sbin/consoletype to @initrd@/sbin
copy @instroot@/usr/bin/logger to @initrd@/sbin
copy @instroot@/etc/rc.d/init.d/functions to @initrd@/etc/rc.d/init.d
copy @instroot@/etc/sysconfig/network-scripts/network-functions* to @initrd@/etc/sysconfig/network-scripts
link @initrd@/etc/init.d to /etc/rc.d/init.d
# dhcp and dhcpv6 client daemons and support programs
copy @instroot@/sbin/dhclient to @initrd@/sbin
copy @instroot@/sbin/dhcp6c to @initrd@/sbin
touch @initrd@/etc/resolv.conf
# hwdata
copy @instroot@/usr/share/hwdata/pci.ids to @initrd@/usr/share/hwdata
copy @instroot@/usr/share/hwdata/usb.ids to @initrd@/usr/share/hwdata
# hal
copy @instroot@/usr/sbin/hald to @initrd@/sbin
copy @instroot@/usr/libexec/hald-runner to @initrd@/usr/libexec
copy @instroot@/usr/libexec/hald-generate-fdi-cache to @initrd@/usr/libexec
copy @instroot@/usr/libexec/hal*storage* to @initrd@/usr/libexec
touch @initrd@/var/run/hald.acl-list
copy @instroot@/usr/share/hal/fdi/* to @initrd@/usr/share/hal/fdi
copy @instroot@/etc/hal/fdi/* to @initrd@/etc/hal/fdi
copy @instroot@/etc/dbus-1/system.d/hal.conf to @initrd@/etc/dbus-1/system.d
# policykit
copy @instroot@/etc/PolicyKit/PolicyKit.conf to @initrd@/etc/PolicyKit
copy @instroot@/usr/share/dbus-1/system-services/org.freedesktop.PolicyKit.service to @initrd@/usr/share/dbus-1/system-services
copy @instroot@/usr/share/PolicyKit/policy/org.freedesktop.policykit.policy to @initrd@/usr/share/PolicyKit/policy
copy @instroot@/var/lib/misc/PolicyKit.reload to @initrd@/var/lib/misc
# dbus
copy @instroot@/bin/dbus-uuidgen to @initrd@/sbin
copy @instroot@/bin/dbus-daemon to @initrd@/sbin
copy @instroot@/etc/dbus-1/system.conf to @initrd@/etc/dbus-1
copy @instroot@/@libdir@/dbus-1/dbus-daemon-launch-helper to @initrd@/@libdir@/dbus-1
chown @initrd@/@libdir@/dbus-1/dbus-daemon-launch-helper user root group dbus
chmod @initrd@/@libdir@/dbus-1/dbus-daemon-launch-helper mode 04750
# wpa_supplicant
copy @instroot@/usr/sbin/wpa_passphrase to @initrd@/usr/sbin
copy @instroot@/usr/sbin/wpa_supplicant to @initrd@/usr/sbin
copy @instroot@/etc/dbus-1/system.d/wpa_supplicant.conf to @initrd@/etc/dbus-1/system.d
copy @instroot@/etc/wpa_supplicant/wpa_supplicant.conf to @initrd@/etc/wpa_supplicant
copy @instroot@/usr/share/dbus-1/system-services/fi.epitest.hostap.WPASupplicant.service to @initrd@/usr/share/dbus-1/system-services
# networkmanager
copy @instroot@/usr/sbin/NetworkManager to @initrd@/usr/sbin
copy @instroot@/usr/sbin/nm-system-settings to @initrd@/usr/sbin
copy @instroot@/etc/dbus-1/system.d/nm-*.conf to @initrd@/etc/dbus-1/system.d
copy @instroot@/etc/dbus-1/system.d/NetworkManager.conf to @initrd@/etc/dbus-1/system.d
copy @instroot@/etc/NetworkManager/nm-system-settings.conf to @initrd@/etc/NetworkManager
copy @instroot@/usr/@libdir@/NetworkManager/libnm-settings-plugin-ifcfg-fedora.so to @initrd@/usr/@libdir@/NetworkManager
copy @instroot@/usr/libexec/nm-* to @initrd@/usr/libexec
copy @instroot@/usr/share/dbus-1/system-services/org.freedesktop.NetworkManagerSystemSettings.service to @initrd@/usr/share/dbus-1/system-services
copy @instroot@/usr/share/dbus-1/system-services/org.freedesktop.nm_dispatcher.service to @initrd@/usr/share/dbus-1/system-services
# modprobe
copy @instroot@/sbin/modprobe to @initrd@/sbin
copy @instroot@/sbin/insmod to @initrd@/sbin
copy @instroot@/sbin/rmmod to @initrd@/sbin
# profile
edit @initrd@/.profile text "PATH=/bin:/usr/bin:/usr/sbin:/mnt/sysimage/sbin:/mnt/sysimage/usr/sbin:/mnt/sysimage/bin:/mnt/sysimage/usr/bin\nexport PATH"
# terminfos
copy @instroot@/usr/share/terminfo/a/ansi to @initrd@/etc/terminfo/a mode 0644
copy @instroot@/usr/share/terminfo/d/dumb to @initrd@/etc/terminfo/d mode 0644
copy @instroot@/usr/share/terminfo/l/linux to @initrd@/etc/terminfo/l mode 0644
copy @instroot@/usr/share/terminfo/s/screen to @initrd@/etc/terminfo/s mode 0644
copy @instroot@/usr/share/terminfo/v/vt100 to @initrd@/etc/terminfo/v mode 0644
copy @instroot@/usr/share/terminfo/v/vt100-nav to @initrd@/etc/terminfo/v mode 0644
copy @instroot@/usr/share/terminfo/v/vt102 to @initrd@/etc/terminfo/v mode 0644
copy @instroot@/usr/share/terminfo/x/xterm to @initrd@/etc/terminfo/x mode 0644
copy @instroot@/usr/share/terminfo/x/xterm-color to @initrd@/etc/terminfo/x mode 0644
copy @instroot@/usr/share/terminfo/g/gnome to @initrd@/etc/terminfo/g mode 0644
# misc
link @initrd@/init to /sbin/init
link @initrd@/etc/mtab to /proc/mounts
link @initrd@/bin to sbin
link @initrd@/var/lib/xkb to ../../tmp
# loader
copy @instroot@/usr/lib/anaconda-runtime/loader/loader to @initrd@/sbin
copy @instroot@/usr/lib/anaconda-runtime/loader/loader.tr to @initrd@/etc mode 0644
# indirect dependencies
copy @instroot@/@libdir@/libfreebl3.so to @initrd@/@libdir@
copy @instroot@/@libdir@/libsoftokn3.so to @initrd@/@libdir@
copy @instroot@/usr/@libdir@/libsqlite3.so.0 to @initrd@/usr/@libdir@
copy @instroot@/@libdir@/libnss_dns.so.2 to @initrd@/@libdir@
copy @instroot@/@libdir@/libnss_files.so.2 to @initrd@/@libdir@
copy @instroot@/@libdir@/libgcc_s.so.1 to @initrd@/@libdir@
# langtable
copy @instroot@/usr/lib/anaconda/lang-table to @initrd@/etc

View File

@ -1,76 +0,0 @@
# initrd template
# create required directories
makedir @initrd@/modules
makedir @initrd@/sbin
makedir @initrd@/dev
makedir @initrd@/etc
makedir @initrd@/etc/udev/rules.d
makedir @initrd@/lib/udev/rules.d
makedir @initrd@/proc
makedir @initrd@/selinux
makedir @initrd@/sys
makedir @initrd@/etc/terminfo/a
makedir @initrd@/etc/terminfo/b
makedir @initrd@/etc/terminfo/d
makedir @initrd@/etc/terminfo/l
makedir @initrd@/etc/terminfo/s
makedir @initrd@/etc/terminfo/v
makedir @initrd@/etc/terminfo/x
makedir @initrd@/tmp
makedir @initrd@/usr/libexec
makedir @initrd@/usr/@libdir@/NetworkManager
makedir @initrd@/usr/share/dbus-1/system-services
makedir @initrd@/var/cache/hald
makedir @initrd@/var/lib/dbus
makedir @initrd@/var/lib/dhclient
makedir @initrd@/var/lock/rpm
makedir @initrd@/var/run
makedir @initrd@/var/run/dbus
makedir @initrd@/var/run/hald
makedir @initrd@/var/run/NetworkManager
makedir @initrd@/etc/dbus-1/system.d
makedir @initrd@/etc/modprobe.d
makedir @initrd@/etc/NetworkManager/dispatcher.d
makedir @initrd@/@libdir@/dbus-1
makedir @initrd@/etc/sysconfig/network-scripts
makedir @initrd@/usr/share/PolicyKit/policy
makedir @initrd@/etc/PolicyKit
makedir @initrd@/var/lib/misc
makedir @initrd@/etc/hal/fdi
makedir @initrd@/usr/share/hal/fdi
makedir @initrd@/usr/share/hwdata
makedir @initrd@/etc/rc.d/init.d
makedir @initrd@/usr/sbin
makedir @initrd@/var/run/wpa_supplicant
# set the buildarch
edit @initrd@/etc/arch text "@buildarch@"
# copy etc
copy @instroot@/etc/passwd to @initrd@/etc
copy @instroot@/etc/group to @initrd@/etc
copy @instroot@/etc/nsswitch.conf to @initrd@/etc
# copy mount/umount
copy @instroot@/bin/mount to @initrd@/sbin/mount
copy @instroot@/bin/umount to @initrd@/sbin/umount
copy @instroot@/sbin/mount.nfs to @initrd@/sbin/mount.nfs
link @initrd@/sbin/umount.nfs to mount.nfs
# copy udev
copy @instroot@/sbin/udevd to @initrd@/sbin
copy @instroot@/sbin/udevadm to @initrd@/sbin
link @initrd@/sbin/udevinfo to udevadm
link @initrd@/sbin/udevsettle to udevadm
# copy bash
copy @instroot@/bin/bash to @initrd@/sbin/bash
link @initrd@/sbin/sh to bash
copy @instroot@/sbin/consoletype to @initrd@/sbin/consoletype
copy @instroot@/usr/bin/logger to @initrd@/sbin/logger
copy @instroot@/etc/rc.d/init.d/functions to @initrd@/etc/rc.d/init.d
copy @instroot@/etc/sysconfig/network-scripts/network-functions* to @initrd@/etc/sysconfig/network-scripts
link @initrd@/etc/init.d to /etc/rc.d/init.d

1
etc/templates/initrd.alpha Symbolic link
View File

@ -0,0 +1 @@
initrd.i386

12
etc/templates/initrd.i386 Normal file
View File

@ -0,0 +1,12 @@
# initrd template
#include includes/initrd/initrd.common
# loader
copy @instroot@/usr/lib/anaconda-runtime/loader/init to @initrd@/sbin/init
link @initrd@/sbin/reboot to init
link @initrd@/sbin/halt to init
link @initrd@/sbin/poweroff to init
# screenfont
copy @instroot@/usr/lib/anaconda-runtime/screenfont-@buildarch@.gz to @initrd@/etc/screenfont.gz

1
etc/templates/initrd.ia64 Symbolic link
View File

@ -0,0 +1 @@
initrd.i386

1
etc/templates/initrd.ppc Symbolic link
View File

@ -0,0 +1 @@
initrd.i386

1
etc/templates/initrd.ppc64 Symbolic link
View File

@ -0,0 +1 @@
initrd.i386

51
etc/templates/initrd.s390 Normal file
View File

@ -0,0 +1,51 @@
# initrd template
#include includes/initrd/initrd.common
# create required directories
makedir @initrd@/var/empty/sshd mode 0111
makedir @initrd@/etc/pam.d
makedir @initrd@/etc/security
makedir @initrd@/@libdir@/security
# copy some files
copy @instroot@/usr/bin/xauth to @initrd@/sbin
copy @instroot@/usr/sbin/cmsfs* to @initrd@/sbin
copy @instroot@/@libdir@/libpam_misc.so.0.* to @initrd@/@libdir@/libpam_misc.so.0
link @initrd@/var/state/xkb to /tmp
# loader
copy @instroot@/usr/lib/anaconda-runtime/loader/shutdown to @initrd@/sbin
copy @instroot@/usr/lib/anaconda-runtime/loader/linuxrc.s390 to @initrd@/sbin/init
copy @instroot@/usr/sbin/dasdfmt to @initrd@/sbin
# setup shell environment
edit @initrd@/etc/protocols text "tcp\t6\tTCP\n"
copy @instroot@/@libdir@/security/pam_limits.so to @initrd@/@libdir@/security
copy @instroot@/@libdir@/security/pam_env.so to @initrd@/@libdir@/security
copy @instroot@/@libdir@/security/pam_unix.so to @initrd@/@libdir@/security
copy @instroot@/@libdir@/security/pam_deny.so to @initrd@/@libdir@/security
copy @instroot@/etc/pam.d/other to @initrd@/etc/pam.d
copy @datadir@/etc/pam.d/login to @initrd@/etc/pam.d/login
copy @datadir@/etc/pam.d/login to @initrd@/etc/pam.d/sshd
copy @datadir@/etc/pam.d/login to @initrd@/etc/pam.d/remote
copy @instroot@/etc/security/limits.conf to @initrd@/etc/security
copy @Instroot@/etc/security/pam_env.conf to @initrd@/etc/security
# generate keys
makedir @initrd@/etc/ssh mode 0700
genkey @initrd@/etc/ssh/ssh_host_key type rsa1
genkey @initrd@/etc/ssh/ssh_host_rsa_key type rsa
genkey @initrd@/etc/ssh/ssh_host_dsa_key type dsa
copy @datadir@/etc/ssh/sshd_config to @initrd@/etc/ssh/sshd_config mode 0600
# copy in the binaries
copy @instroot@/bin/login to @initrd@/sbin/login
copy @instroot@/usr/sbin/sshd to @initrd@/sbin/sshd
copy @instroot@/usr/bin/busybox to @initrd@/sbin/busybox

1
etc/templates/initrd.s390x Symbolic link
View File

@ -0,0 +1 @@
initrd.s390

1
etc/templates/initrd.sparc Symbolic link
View File

@ -0,0 +1 @@
initrd.i386

1
etc/templates/initrd.x86_64 Symbolic link
View File

@ -0,0 +1 @@
initrd.i386

9
share/etc/pam.d/login Normal file
View File

@ -0,0 +1,9 @@
#%PAM-1.0
auth required pam_env.so
auth sufficient pam_unix.so likeauth nullok
auth required pam_deny.so
account required pam_unix.so
password sufficient pam_unix.sp nullok use_authtok md5 shadow
password required pam_deny.so
session required pam_limits.so
session required pam_unix.so

17
share/etc/ssh/sshd_config Normal file
View File

@ -0,0 +1,17 @@
Port 22
HostKey /etc/ssh/ssh_host_key
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
PermitRootLogin yes
IgnoreRhosts yes
StrictModes yes
X11Forwarding yes
X11DisplayOffset 10
PrintMotd yes
XAuthLocation /sbin/xauth
KeepAlive yes
SyslogFacility AUTHPRIV
RSAAuthentication yes
PasswordAuthentication yes
PermitEmptyPasswords yes
PermitUserEnvironment yes

View File

@ -2,8 +2,11 @@
import os
import re
import pwd
import grp
import glob
from pylorax.utils.fileutils import cp, mv, touch, edit, replace
from pylorax.utils.fileutils import cp, mv, rm, touch, edit, replace
# command:action mapping
@ -11,11 +14,15 @@ from pylorax.utils.fileutils import cp, mv, touch, edit, replace
# if you want your new action to be supported, you have to include it in this mapping
COMMANDS = { 'copy': 'Copy',
'move': 'Move',
'remove': 'Remove',
'link': 'Link',
'touch': 'Touch',
'edit': 'Edit',
'replace': 'Replace',
'makedir': 'MakeDir' }
'makedir': 'MakeDir',
'chmod': 'Chmod',
'chown': 'Chown',
'genkey': 'GenerateSSHKey' }
class LoraxAction(object):
@ -75,7 +82,7 @@ class LoraxAction(object):
class Copy(LoraxAction):
REGEX = r'^(?P<src>.*?)\sto\s(?P<dst>.*?)(\smode\s(?P<mode>.*?))?$'
REGEX = r'^(?P<src>.*?)\sto\s(?P<dst>.*?)(\smode\s(?P<mode>[0-9]*?))?(\s(?P<install>install))?$'
def __init__(self, **kwargs):
LoraxAction.__init__(self)
@ -83,6 +90,12 @@ class Copy(LoraxAction):
self._attrs['dst'] = kwargs.get('dst')
self._attrs['mode'] = kwargs.get('mode')
install = kwargs.get('install', False)
if install:
self._attrs['install'] = True
else:
self._attrs['install'] = False
def execute(self, verbose=False):
cp(src=self.src, dst=self.dst, mode=self.mode, verbose=verbose)
self._attrs['success'] = True
@ -101,7 +114,10 @@ class Copy(LoraxAction):
@property
def install(self):
return self._attrs['src']
if self._attrs['install']:
return self._attrs['src']
else:
return None
@property
def getDeps(self):
@ -114,6 +130,24 @@ class Move(Copy):
self._attrs['success'] = True
class Remove(LoraxAction):
REGEX = r'^(?P<filename>.*?)$'
def __init__(self, **kwargs):
LoraxAction.__init__(self)
self._attrs['filename'] = kwargs.get('filename')
def execute(self, verbose=False):
for f in glob.iglob(self.filename):
rm(f)
self._attrs['success'] = True
@property
def filename(self):
return self._attrs['filename']
class Link(LoraxAction):
REGEX = r'^(?P<name>.*?)\sto\s(?P<target>.*?)$'
@ -159,7 +193,7 @@ class Touch(LoraxAction):
class Edit(Touch):
REGEX = r'^(?P<filename>.*?)\stext\s"(?P<text>.*?)"((?P<append>\sappend?))?$'
REGEX = r'^(?P<filename>.*?)\stext\s"(?P<text>.*?)"(\s(?P<append>append))?$'
def __init__(self, **kwargs):
Touch.__init__(self, **kwargs)
@ -238,3 +272,82 @@ class MakeDir(LoraxAction):
@property
def mode(self):
return self._attrs['mode']
class Chmod(LoraxAction):
REGEX = r'^(?P<filename>.*?)\smode\s(?P<mode>[0-9]*?)$'
def __init__(self, **kwargs):
LoraxAction.__init__(self)
self._attrs['filename'] = kwargs.get('filename')
self._attrs['mode'] = kwargs.get('mode')
def execute(self, verbose=False):
os.chmod(self.filename, int(self.mode))
self._attrs['success'] = True
@property
def filename(self):
return self._attrs['filename']
@property
def mode(self):
return self._attrs['mode']
class Chown(LoraxAction):
REGEX = r'^(?P<filename>.*?)\suser\s(?P<user>.*?)\sgroup\s(?P<group>.*?)$'
def __init__(self, **kwargs):
LoraxAction.__init__(self)
self._attrs['filename'] = kwargs.get('filename')
self._attrs['user'] = kwargs.get('user')
self._attrs['group'] = kwargs.get('group')
def execute(self, verbose=False):
uid = pwd.getpwnam(self.user)[2]
gid = grp.getgrnam(self.group)[2]
os.chown(self.filename, uid, gid)
self._attrs['success'] = True
@property
def filename(self):
return self._attrs['filename']
@property
def user(self):
return self._attrs['user']
@property
def group(self):
return self._attrs['group']
class GenerateSSHKey(LoraxAction):
REGEX = r'^(?P<file>.*?)\stype\s(?P<type>.*?)$'
def __init__(self, **kwargs):
LoraxAction.__init__(self)
self._attrs['file'] = kwargs.get('file')
self._attrs['type'] = kwargs.get('type')
def execute(self, verbose=False):
cmd = "/usr/bin/ssh-keygen -q -t %s -f %s -C '' -N ''" % (self.type, self.file)
err, output = commands.getstatusoutput(cmd)
if not err:
os.chmod(self.file, 0600)
os.chmod(self.file + '.pub', 0644)
self._attrs['success'] = True
@property
def file(self):
return self._attrs['file']
@property
def type(self):
return self._attrs['type']

View File

@ -1,6 +1,7 @@
# pylorax/config.py
import sys
import os
import re
from errors import TemplateError
@ -77,7 +78,10 @@ class Template(object):
def __init__(self):
self._actions = []
def parse(self, filename, supported_actions, variables):
self.lines = []
self.included_files = []
def preparse(self, filename):
try:
f = open(filename, 'r')
except IOError as why:
@ -87,6 +91,36 @@ class Template(object):
lines = f.readlines()
f.close()
self.included_files.append(filename)
for line in lines:
line = line.strip()
if line.startswith('#include'):
file_to_include = line.split()[1]
path = os.path.join(os.path.dirname(filename), file_to_include)
if path not in self.included_files:
self.preparse(path)
else:
self.lines.append(line)
def parse(self, supported_actions, variables):
lines = self.lines
# append next line if line ends with '\'
temp = []
for line in lines:
line = line.strip()
if line.endswith('\\'):
line = line[:-1]
line = line.rstrip()
line = line + ' '
else:
line = line + '\n'
temp.append(line)
temp = ''.join(temp)
lines = temp.splitlines()
# check template variables
for lineno, line in enumerate(lines, start=1):
for var in filter(lambda var: var not in variables, re.findall(r'@(.*?)@', line)):
@ -94,8 +128,6 @@ class Template(object):
# parse the template
for lineno, line in enumerate(lines, start=1):
line = line.strip()
line, sep, comment = line.partition('#')
if not line:
continue

View File

@ -4,6 +4,7 @@ import sys
import os
import commands
import re
import datetime
import actions
import actions.base
@ -21,11 +22,6 @@ class InitRD(object):
# get supported actions
supported_actions = actions.getActions()
initrd_templates = []
initrd_templates.append(os.path.join(self.conf.confdir, 'templates', 'initrd'))
initrd_templates.append(os.path.join(self.conf.confdir, 'templates', self.conf.buildarch,
'initrd'))
vars = { 'instroot': self.conf.treedir,
'initrd': self.conf.initrddir,
'libdir': self.conf.libdir,
@ -33,10 +29,11 @@ class InitRD(object):
'confdir' : self.conf.confdir,
'datadir': self.conf.datadir }
initrd_template = (os.path.join(self.conf.confdir, 'templates',
'initrd.%s' % self.conf.buildarch))
self.template = Template()
for filename in initrd_templates:
if os.path.isfile(filename):
self.template.parse(filename, supported_actions, vars)
self.template.preparse(initrd_template)
self.template.parse(supported_actions, vars)
self._actions = []
@ -50,7 +47,15 @@ class InitRD(object):
return packages
def getDeps(self):
ldd = LDD(libroot=os.path.join(self.conf.treedir, self.conf.libdir))
libroots = []
libroots.append(os.path.join(self.conf.treedir, self.conf.libdir))
libroots.append(os.path.join(self.conf.treedir, 'usr', self.conf.libdir))
# on 64 bit systems, add also normal lib directories
if self.conf.libdir.endswith('64'):
libroots.append(os.path.join(self.conf.treedir, self.conf.libdir[:-2]))
libroots.append(os.path.join(self.conf.treedir, 'usr', self.conf.libdir[:-2]))
ldd = LDD(libroots)
for action in filter(lambda action: hasattr(action, 'getDeps'), self.template.actions):
ldd.getDeps(action.getDeps)
@ -69,14 +74,22 @@ class InitRD(object):
self._actions.append(new_action)
def processActions(self):
# create the initrd temporary directory if it does not exist
if not os.path.isdir(self.conf.initrddir):
os.makedirs(self.conf.initrddir)
if os.path.isdir(self.conf.initrddir):
rm(self.conf.initrddir)
os.makedirs(self.conf.initrddir)
for action in self.template.actions + self._actions:
action.execute()
def create(self, dst):
# create the productfile
text = '%s\n' % self.conf.imageuuid
text = text + '%s\n' % self.conf.product
text = text + '%s\n' % self.conf.version
text = text + '%s\n' % self.conf.bugurl
edit(os.path.join(self.conf.initrddir, '.buildstamp'), text)
# create the initrd
err, output = commands.getstatusoutput('find %s | cpio --quiet -c -o | gzip -9 > %s' %
(self.conf.initrddir, dst))
@ -89,6 +102,13 @@ class Images(object):
self.conf = config
self.yum = yum
# make imageuuid
now = datetime.datetime.now()
arch = os.uname()[4] # XXX system arch, or build arch?
imageuuid = '%s.%s' % (now.strftime('%Y%m%d%H%M'), arch)
self.conf.addAttr('imageuuid')
self.conf.set(imageuuid=imageuuid)
self.initrd = InitRD(self.conf, self.yum)
# XXX don't see this used anywhere... maybe in some other script, have to check...

View File

@ -16,7 +16,7 @@ def cp(src, dst, mode=None, verbose=False):
errors.append('unable to copy "%s" to "%s"' % (name, dst))
else:
if mode:
os.chmod(dst, mode)
os.chmod(dst, int(mode))
return errors
@ -28,7 +28,7 @@ def mv(src, dst, mode=None, verbose=False):
errors.append('unable to move "%s" to "%s"' % (name, dst))
else:
if mode:
os.chmod(dst, mode)
os.chmod(dst, int(mode))
return errors

View File

@ -6,7 +6,7 @@ import re
class LDD(object):
def __init__(self, libroot='/lib'):
def __init__(self, libroots=['/lib', '/usr/lib']):
f = open('/usr/bin/ldd', 'r')
for line in f.readlines():
line = line.strip()
@ -15,14 +15,7 @@ class LDD(object):
break
f.close()
if libroot.endswith('/') and libroot != '/':
libroot = libroot[:-1]
libpaths = [libroot]
if libroot.endswith('64'):
libpaths.append(libroot[:-2])
self._ldd = 'LD_LIBRARY_PATH="%s" %s --list' % (':'.join(libpaths), ld_linux)
self._ldd = 'LD_LIBRARY_PATH="%s" %s --list' % (':'.join(libroots), ld_linux)
self._deps = set()
def getDeps(self, filename):