diff --git a/etc/templates/includes/initrd/initrd.common b/etc/templates/includes/initrd/initrd.common index cea58186..cb008748 100644 --- a/etc/templates/includes/initrd/initrd.common +++ b/etc/templates/includes/initrd/initrd.common @@ -1,12 +1,10 @@ # initrd template # create required directories -makedir @initrd@/modules -makedir @initrd@/firmware -makedir @initrd@/lib +makedir @initrd@/lib/modules +makedir @initrd@/lib/firmware link @initrd@/modules to @initrd@/lib/modules link @initrd@/firmware to @initrd@/lib/firmware -makedir @initrd@/lib/firmware makedir @initrd@/sbin makedir @initrd@/dev makedir @initrd@/etc @@ -53,134 +51,149 @@ makedir @initrd@/var/run/wpa_supplicant 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 @instroot@/etc/hosts to @initrd@/etc/ mode 0644 +copy @instroot@ etc/passwd to @initrd@ etc +chmod @initrd@/etc/passwd mode 0644 + +copy @instroot@ etc/group to @initrd@ etc +chmod @initrd@/etc/group mode 0644 + +copy @instroot@ etc/nsswitch.conf to @initrd@ etc +chmod @initrd@/etc/nsswitch.conf mode 0644 + +copy @instroot@ etc/hosts to @initrd@ etc +chmod @initrd@/etc/hosts mode 0644 # copy mount/umount -copy @instroot@/bin/mount to @initrd@/sbin -copy @instroot@/bin/umount to @initrd@/sbin -copy @instroot@/sbin/mount.* to @initrd@/sbin -copy @instroot@/sbin/umount.* to @initrd@/sbin +copy @instroot@ bin/mount to @initrd@ sbin +copy @instroot@ bin/umount to @initrd@ sbin +copy @instroot@ sbin/mount.* to @initrd@ sbin +copy @instroot@ sbin/umount.* to @initrd@ sbin # copy udev -copy @instroot@/sbin/udevd to @initrd@/sbin -copy @instroot@/sbin/udevadm to @initrd@/sbin -copy @instroot@/sbin/udevinfo to @initrd@/sbin -copy @instroot@/sbin/udevsettle to @initrd@/sbin +copy @instroot@ sbin/udevd to @initrd@ sbin +copy @instroot@ sbin/udevadm to @initrd@ sbin +copy @instroot@ sbin/udevinfo to @initrd@ sbin +copy @instroot@ sbin/udevsettle to @initrd@ sbin # udev rules -copy @instroot@/etc/udev/udev.conf to @initrd@/etc/udev mode 0644 -copy @instroot@/lib/udev/* to @initrd@/lib/udev mode 0644 +copy @instroot@ etc/udev/udev.conf to @initrd@ etc/udev +chmod @initrd@/etc/udev/udev.conf mode 0644 + +copy @instroot@ lib/udev/* to @initrd@ lib/udev +chmod @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 @instroot@ etc/udev/rules.d/*.rules to @initrd@ etc/udev/rules.d +chmod @initrd@/etc/udev/rules.d/*.rules mode 0644 # copy bash -copy @instroot@/bin/bash to @initrd@/sbin +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 +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/dhclient-script to @initrd@/sbin -copy @instroot@/sbin/dhcp6c to @initrd@/sbin -copy @instroot@/sbin/arping to @initrd@/sbin -copy @instroot@/sbin/ifconfig to @initrd@/sbin -copy @instroot@/sbin/ip to @initrd@/sbin -copy @instroot@/bin/ipcalc to @initrd@/sbin -copy @instroot@/bin/hostname to @initrd@/sbin -copy @instroot@/sbin/ethtool to @initrd@/sbin -copy @instroot@/sbin/route to @initrd@/sbin +copy @instroot@ sbin/dhclient to @initrd@ sbin +copy @instroot@ sbin/dhclient-script to @initrd@ sbin +copy @instroot@ sbin/dhcp6c to @initrd@ sbin +copy @instroot@ sbin/arping to @initrd@ sbin +copy @instroot@ sbin/ifconfig to @initrd@ sbin +copy @instroot@ sbin/ip to @initrd@ sbin +copy @instroot@ bin/ipcalc to @initrd@ sbin +copy @instroot@ bin/hostname to @initrd@ sbin +copy @instroot@ sbin/ethtool to @initrd@ sbin +copy @instroot@ sbin/route 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 +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 +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 +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 +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 +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 +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 +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 +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 +copy @instroot@ usr/share/terminfo/a/ansi to @initrd@ etc/terminfo/a +copy @instroot@ usr/share/terminfo/d/dumb to @initrd@ etc/terminfo/d +copy @instroot@ usr/share/terminfo/l/linux to @initrd@ etc/terminfo/l +copy @instroot@ usr/share/terminfo/s/screen to @initrd@ etc/terminfo/s +copy @instroot@ usr/share/terminfo/v/vt100 to @initrd@ etc/terminfo/v +copy @instroot@ usr/share/terminfo/v/vt100-nav to @initrd@ etc/terminfo/v +copy @instroot@ usr/share/terminfo/v/vt102 to @initrd@ etc/terminfo/v +copy @instroot@ usr/share/terminfo/x/xterm to @initrd@ etc/terminfo/x +copy @instroot@ usr/share/terminfo/x/xterm-color to @initrd@ etc/terminfo/x +copy @instroot@ usr/share/terminfo/g/gnome to @initrd@ etc/terminfo/g +chmod @initrd@/etc/terminfo/*/* mode 0644 # misc -copy @instroot@/bin/awk to @initrd@/sbin -copy @instroot@/bin/gawk to @initrd@/sbin -copy @instroot@/bin/egrep to @initrd@/sbin -copy @instroot@/bin/fgrep to @initrd@/sbin -copy @instroot@/bin/grep to @initrd@/sbin -copy @instroot@/bin/kill to @initrd@/sbin -copy @instroot@/bin/ln to @initrd@/sbin -copy @instroot@/bin/readlink to @initrd@/sbin -copy @instroot@/bin/rm to @initrd@/sbin -copy @instroot@/bin/rmdir to @initrd@/sbin -copy @instroot@/bin/sed to @initrd@/sbin -copy @instroot@/bin/sleep to @initrd@/sbin -copy @instroot@/bin/touch to @initrd@/sbin +copy @instroot@ bin/awk to @initrd@ sbin +copy @instroot@ bin/gawk to @initrd@ sbin +copy @instroot@ bin/egrep to @initrd@ sbin +copy @instroot@ bin/fgrep to @initrd@ sbin +copy @instroot@ bin/grep to @initrd@ sbin +copy @instroot@ bin/kill to @initrd@ sbin +copy @instroot@ bin/ln to @initrd@ sbin +copy @instroot@ bin/readlink to @initrd@ sbin +copy @instroot@ bin/rm to @initrd@ sbin +copy @instroot@ bin/rmdir to @initrd@ sbin +copy @instroot@ bin/sed to @initrd@ sbin +copy @instroot@ bin/sleep to @initrd@ sbin +copy @instroot@ bin/touch to @initrd@ sbin link @initrd@/init to /sbin/init link @initrd@/etc/mtab to /proc/mounts @@ -188,16 +201,17 @@ 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 +copy @instroot@ usr/lib/anaconda-runtime/loader/loader to @initrd@ sbin +copy @instroot@ usr/lib/anaconda-runtime/loader/loader.tr to @initrd@ etc +chmod @initrd/etc/loader.tr 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@ +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 +copy @instroot@ usr/lib/anaconda/lang-table to @initrd@ etc diff --git a/etc/templates/initrd.i386 b/etc/templates/initrd.i386 index d62eabc7..57501b24 100644 --- a/etc/templates/initrd.i386 +++ b/etc/templates/initrd.i386 @@ -3,13 +3,10 @@ #include includes/initrd/initrd.common # loader -copy @instroot@/usr/lib/anaconda-runtime/loader/init to @initrd@/sbin/init +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 - -# keymaps -copy @instroot@/keymaps to @initrd@/etc/keymaps.gz \ No newline at end of file +copy @instroot@ usr/lib/anaconda-runtime/screenfont-@buildarch@.gz to @initrd@ etc/screenfont.gz diff --git a/etc/templates/initrd.s390 b/etc/templates/initrd.s390 index 8fc5d3f7..50494cde 100644 --- a/etc/templates/initrd.s390 +++ b/etc/templates/initrd.s390 @@ -9,36 +9,36 @@ 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@ 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 -copy @instroot@/@libdir@/libwrap*.so* to @initrd@/@libdir@ +copy @instroot@ @libdir@/libpam_misc.so.0.* to @initrd@ @libdir@/libpam_misc.so.0 +copy @instroot@ @libdir@/libwrap*.so* to @initrd@ @libdir@ 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/lib/anaconda-runtime/loader/lsznet.raw to @initrd@/sbin/lsznet -copy @instroot@/usr/lib/anaconda-runtime/loader/controlunits.sh @initrd@/sbin/controlunits -copy @instroot@/usr/sbin/dasdfmt to @initrd@/sbin +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/lib/anaconda-runtime/loader/lsznet.raw to @initrd@ sbin/lsznet +copy @instroot@ usr/lib/anaconda-runtime/loader/controlunits.sh @initrd@ sbin/controlunits +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@ @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@/pam.d/login to @initrd@/etc/pam.d/login -copy @datadir@/pam.d/login to @initrd@/etc/pam.d/sshd -copy @datadir@/pam.d/login to @initrd@/etc/pam.d/remote +copy @instroot@ etc/pam.d/other to @initrd@ etc/pam.d +copy @datadir@ pam.d/login to @initrd@ etc/pam.d/login +copy @datadir@ pam.d/login to @initrd@ etc/pam.d/sshd +copy @datadir@ 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 +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 @@ -46,8 +46,9 @@ 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@/sshd/sshd_config to @initrd@/etc/ssh/sshd_config mode 0600 +copy @datadir@ sshd/sshd_config to @initrd@ etc/ssh/sshd_config +chmod @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 \ No newline at end of file +copy @instroot@ bin/login to @initrd@ sbin/login +copy @instroot@ usr/sbin/sshd to @initrd@ sbin/sshd diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py index 0a853af0..a7cb2deb 100644 --- a/src/pylorax/__init__.py +++ b/src/pylorax/__init__.py @@ -26,6 +26,7 @@ import os import stat import commands import shutil +import glob import tempfile import time import datetime @@ -370,9 +371,11 @@ class Lorax(object): # copy updates if self.conf.updates and os.path.isdir(self.conf.updates): - cp(os.path.join(self.conf.updates, '*'), self.conf.treedir) + cp(src_root=self.conf.updates, src_path='*', + dst_root=self.conf.treedir, dst_path='') self.conf.delAttr('updates') + # XXX here comes a lot of crazy tree modification stuff, beware! XXX # create dogtail conf files @@ -380,7 +383,7 @@ class Lorax(object): if os.path.isfile(dogtailconf): dst = os.path.join(self.conf.treedir, '.gconf', 'desktop', 'gnome', 'interface') os.makedirs(dst) - cp(dogtailconf, dst) + shutil.copy2(dogtailconf, dst) touch(os.path.join(self.conf.treedir, '.gconf', 'desktop', '%gconf.xml')) touch(os.path.join(self.conf.treedir, '.gconf', 'desktop', 'gnome', '%gconf.xml')) @@ -405,17 +408,18 @@ class Lorax(object): 'syslogd'): src = os.path.join(self.conf.treedir, 'usr', 'lib', 'anaconda', file + '-stub') dst = os.path.join(self.conf.treedir, 'usr', 'bin', file) - cp(src, dst) + shutil.copy2(src, dst) # move anaconda executable src = os.path.join(self.conf.treedir, 'usr', 'sbin', 'anaconda') dst = os.path.join(self.conf.treedir, 'usr', 'bin', 'anaconda') - mv(src, dst) + shutil.move(src, dst) # move anaconda libraries src = os.path.join(self.conf.treedir, 'usr', 'lib', 'anaconda-runtime', 'lib*') dst = os.path.join(self.conf.treedir, 'usr', self.conf.libdir) - mv(src, dst) + for name in glob.iglob(src): + shutil.move(name, dst) # change tree permissions root_uid = pwd.getpwnam('root')[2] @@ -603,12 +607,12 @@ class Lorax(object): if os.path.exists(os.path.join(self.conf.treedir, 'etc', 'selinux', 'targeted')): src = os.path.join(self.conf.datadir, 'selinux', 'config') dst = os.path.join(self.conf.treedir, 'etc', 'selinux', 'config') - cp(src, dst) + shutil.copy2(src, dst) # create libuser.conf src = os.path.join(self.conf.datadir, 'libuser', 'libuser.conf') dst = os.path.join(self.conf.treedir, 'etc', 'libuser.conf') - cp(src, dst) + shutil.copy2(src, dst) # configure fedorakmod fedorakmodconf = os.path.join(self.conf.treedir, 'etc', 'yum', 'pluginconf.d', @@ -626,7 +630,7 @@ class Lorax(object): # move yum repos src = os.path.join(self.conf.treedir, 'etc', 'yum.repos.d') dst = os.path.join(self.conf.treedir, 'etc', 'anaconda.repos.d') - mv(src, dst) + shutil.move(src, dst) # remove libunicode-lite rm(os.path.join(self.conf.treedir, 'usr', self.conf.libdir, 'libunicode-lite*')) @@ -652,22 +656,22 @@ class Lorax(object): if file.startswith('memtest'): src = os.path.join(self.conf.treedir, 'boot', file) dst = os.path.join(bootpath, file) - cp(src, dst) + shutil.copy2(src, dst) elif self.conf.buildarch in ('sparc',): for file in os.listdir(os.path.join(self.conf.treedir, 'boot')): if file.endswith('.b'): src = os.path.join(self.conf.treedir, 'boot', file) dst = os.path.join(bootpath, file) - cp(src, dst) + shutil.copy2(src, dst) elif self.conf.buildarch in ('ppc', 'ppc64'): src = os.path.join(self.conf.treedir, 'boot', 'efika.forth') - cp(src, bootpath) + shutil.copy2(src, bootpath) elif self.conf.buildarch in ('alpha',): src = os.path.join(self.conf.treedir, 'boot', 'bootlx') - cp(src, bootpath) + shutil.copy2(src, bootpath) elif self.conf.buildarch in ('ia64',): src = os.path.join(self.conf.treedir, 'boot', 'efi', 'EFI', 'redhat', '*') - cp(src, bootpath) + shutil.copy2(src, bootpath) # remove not needed directories # XXX i need this for kernel @@ -752,13 +756,13 @@ class Lorax(object): # write the images/README src = os.path.join(self.conf.datadir, 'images', 'README') dst = os.path.join(self.conf.imagesdir, 'README') - cp(src, dst) + shutil.copy2(src, dst) replace(dst, r'@PRODUCT@', self.conf.product) # write the images/pxeboot/README src = os.path.join(self.conf.datadir, 'images', 'pxeboot', 'README') dst = os.path.join(self.conf.pxebootdir, 'README') - cp(src, dst) + shutil.copy2(src, dst) replace(dst, r'@PRODUCT@', self.conf.product) @@ -783,11 +787,11 @@ class Lorax(object): if os.path.exists(isolinuxbin): # copy the isolinux.bin - cp(isolinuxbin, self.conf.isolinuxdir) + shutil.copy2(isolinuxbin, self.conf.isolinuxdir) # copy the syslinux.cfg to isolinux/isolinux.cfg isolinuxcfg = os.path.join(self.conf.isolinuxdir, 'isolinux.cfg') - cp(os.path.join(bootdiskdir, 'syslinux.cfg'), isolinuxcfg) + shutil.copy2(os.path.join(bootdiskdir, 'syslinux.cfg'), isolinuxcfg) # set the product and version in isolinux.cfg replace(isolinuxcfg, r'@PRODUCT@', self.conf.product) @@ -797,14 +801,14 @@ class Lorax(object): replace(isolinuxcfg, r'initrd=initrd.img', 'initrd=initrd.img stage2=hd:LABEL=%s' % self.conf.product) # copy the grub.conf - cp(os.path.join(bootdiskdir, 'grub.conf'), self.conf.isolinuxdir) + shutil.copy2(os.path.join(bootdiskdir, 'grub.conf'), self.conf.isolinuxdir) # copy the splash files vesasplash = os.path.join(anacondadir, 'syslinux-vesa-splash.jpg') if os.path.isfile(vesasplash): - cp(vesasplash, os.path.join(self.conf.isolinuxdir, 'splash.jpg')) + shutil.copy2(vesasplash, os.path.join(self.conf.isolinuxdir, 'splash.jpg')) vesamenu = os.path.join(syslinuxdir, 'vesamenu.c32') - cp(vesamenu, self.conf.isolinuxdir) + shutil.copy2(vesamenu, self.conf.isolinuxdir) replace(isolinuxcfg, r'default linux', r'default vesamenu.c32') replace(isolinuxcfg, r'prompt 1', r'#prompt 1') else: @@ -816,40 +820,41 @@ class Lorax(object): splashlss) os.system(cmd) if os.path.isfile(splashlss): - cp(splashlss, self.conf.isolinuxdir) + shutil.copy2(splashlss, self.conf.isolinuxdir) # copy the .msg files for file in os.listdir(bootdiskdir): if file.endswith('.msg'): - cp(os.path.join(bootdiskdir, file), self.conf.isolinuxdir) + shutil.copy2(os.path.join(bootdiskdir, file), self.conf.isolinuxdir) replace(os.path.join(self.conf.isolinuxdir, file), r'@VERSION@', self.conf.version) # if present, copy the memtest - cp(os.path.join(self.conf.treedir, 'boot', 'memtest*'), - os.path.join(self.conf.isolinuxdir, 'memtest')) - if os.path.isfile(os.path.join(self.conf.isolinuxdir, 'memtest')): - text = "label memtest86\n" - text = text + " menu label ^Memory test\n" - text = text + " kernel memtest\n" - text = text + " append -\n" - edit(isolinuxcfg, text, append=True) + for fname in os.listdir(os.path.join(self.conf.treedir, 'boot')): + if fname.startswith('memtest'): + src = os.path.join(self.conf.treedir, 'boot', fname) + dst = os.path.join(self.conf.isolinuxdir, 'memtest') + shutil.copy2(src, dst) + + text = "label memtest86\n" + text = text + " menu label ^Memory test\n" + text = text + " kernel memtest\n" + text = text + " append -\n" + edit(isolinuxcfg, text, append=True) else: sys.stderr.write('ERROR: %s does not exist\n' % isolinuxbin) sys.exit(1) - # copy conf files to EFI tree dir - cp(os.path.join(bootdiskdir, '*.conf'), efitreedir) - def create_efi(self, kernelfile=None, initrd=None, kernelpath=None, initrdpath=None): rm(os.path.join(self.conf.efitreedir, '*')) # copy conf files to EFI tree dir - cp(os.path.join(self.conf.bootdiskdir, '*.conf'), self.conf.efitreedir) + cp(src_root=self.conf.bootdiskdir, src_path='*.conf', + dst_root=self.conf.efitreedir, dst_path='') # copy files to efi tree dir if kernelfile and initrd: - cp(kernelfile, os.path.join(self.conf.efitreedir, 'vmlinuz')) - cp(initrd, self.conf.efitreedir) + shutil.copy2(kernelfile, os.path.join(self.conf.efitreedir, 'vmlinuz')) + shutil.copy2(initrd, self.conf.efitreedir) efikernelpath = os.path.join(os.sep, 'EFI', 'BOOT', 'vmlinuz') efiinitrdpath = os.path.join(os.sep, 'EFI', 'BOOT', 'initrd.img') else: @@ -866,17 +871,17 @@ class Lorax(object): replace(grubconf, '@SPLASHPATH@', splashpath) src = os.path.join(self.conf.treedir, 'boot', 'efi', 'EFI', 'redhat', 'grub.efi') - cp(src, self.conf.efitreedir) + shutil.copy2(src, self.conf.efitreedir) # the first generation mactel machines get the bootloader name wrong if self.conf.efiarch in ('ia32'): src = os.path.join(self.conf.efitreedir, 'grub.efi') dst = os.path.join(self.conf.efitreedir, 'BOOT.efi') - cp(src, dst) + shutil.copy2(src, dst) src = os.path.join(self.conf.efitreedir, 'grub.conf') dst = os.path.join(self.conf.efitreedir, 'BOOT.conf') - cp(src, dst) + shutil.copy2(src, dst) efiarch = self.conf.efiarch if efiarch == 'x64': @@ -886,16 +891,16 @@ class Lorax(object): src = os.path.join(self.conf.efitreedir, 'grub.efi') dst = os.path.join(self.conf.efitreedir, 'BOOT%s.efi' % efiarch) - mv(src, dst) + shutil.move(src, dst) src = os.path.join(self.conf.efitreedir, 'grub.conf') dst = os.path.join(self.conf.efitreedir, 'BOOT%s.conf' % efiarch) - mv(src, dst) + shutil.move(src, dst) # copy splash src = os.path.join(self.conf.treedir, 'boot', 'grub', 'splash.xpm.gz') dst = os.path.join(self.conf.efitreedir, 'splash.xpm.gz') - cp(src, dst) + shutil.copy2(src, dst) # calculate the size of the dosfs cmd = 'du -kcs %s | tail -n1 | awk \'{print $1}\'' % self.conf.efitreedir @@ -912,8 +917,8 @@ class Lorax(object): (efiimage, tempdir) out = commands.getoutput(cmd) - src = os.path.join(self.conf.efitreedir, '*') - cp(src, tempdir) + cp(src_root=self.conf.efitreedir, src_path='*', + dst_root=tempdir, dst_path='') cmd = 'umount %s' % tempdir out = commands.getoutput(cmd) @@ -924,7 +929,9 @@ class Lorax(object): if os.path.exists(dst): rm(dst) os.makedirs(dst) - cp(os.path.join(self.conf.efitreedir, '*.conf'), dst) + + for name in glob.iglob(os.path.join(self.conf.efitreedir, '*.conf')): + shutil.copy2(name, dst) return efiimage @@ -952,15 +959,15 @@ class Lorax(object): self.yum.install() # copy the kernel file - cp(kernelfile, os.path.join(self.conf.isolinuxdir, 'vmlinuz')) - cp(kernelfile, os.path.join(self.conf.pxebootdir, 'vmlinuz')) + shutil.copy2(kernelfile, os.path.join(self.conf.isolinuxdir, 'vmlinuz')) + shutil.copy2(kernelfile, os.path.join(self.conf.pxebootdir, 'vmlinuz')) # create the initrd.img initrd.create(os.path.join(self.conf.isolinuxdir, 'initrd.img')) initrd.clean_up() # copy the initrd.img - cp(os.path.join(self.conf.isolinuxdir, 'initrd.img'), self.conf.pxebootdir) + shutil.copy2(os.path.join(self.conf.isolinuxdir, 'initrd.img'), self.conf.pxebootdir) # create efiimage efiimage = self.create_efi(kernelfile=kernelfile, @@ -1023,7 +1030,7 @@ class Lorax(object): initrd = images.InitRD(self.conf, self.yum, xenkernel) - cp(xenkernel, os.path.join(self.conf.pxebootdir, 'vmlinuz-PAE')) + shutil.copy2(xenkernel, os.path.join(self.conf.pxebootdir, 'vmlinuz-PAE')) initrd.create(os.path.join(self.conf.pxebootdir, 'initrd-PAE.img')) #initrd.clean_up() diff --git a/src/pylorax/actions/base.py b/src/pylorax/actions/base.py index 6ef79688..38d26b37 100644 --- a/src/pylorax/actions/base.py +++ b/src/pylorax/actions/base.py @@ -26,7 +26,7 @@ import pwd import grp import glob -from pylorax.utils.fileutils import cp, mv, rm, touch, edit, replace +from pylorax.utils.fileutils import cp, mv, rm, touch, edit, replace, chmod # command:action mapping @@ -94,7 +94,6 @@ class LoraxAction(object): @property def getDeps(self): - # FIXME hmmm, how can i do this more generic? return None @@ -102,13 +101,14 @@ class LoraxAction(object): class Copy(LoraxAction): - REGEX = r'^(?P.*?)\sto\s(?P.*?)(\smode\s(?P[0-9]*?))?(\s(?Pinstall))?$' + REGEX = r'^(?P.*?)\s(?P.*?)\sto\s(?P.*?)\s(?P.*?)(\s(?Pinstall))?$' def __init__(self, **kwargs): LoraxAction.__init__(self) - self._attrs['src'] = kwargs.get('src') - self._attrs['dst'] = kwargs.get('dst') - self._attrs['mode'] = kwargs.get('mode') + self._attrs['src_root'] = kwargs.get('src_root') + self._attrs['src_path'] = kwargs.get('src_path') + self._attrs['dst_root'] = kwargs.get('dst_root') + self._attrs['dst_path'] = kwargs.get('dst_path') install = kwargs.get('install', False) if install: @@ -117,16 +117,36 @@ class Copy(LoraxAction): self._attrs['install'] = False def execute(self, verbose=False): - cp(src=self.src, dst=self.dst, mode=self.mode, verbose=verbose) + cp(src_root=self.src_root, src_path=self.src_path, + dst_root=self.dst_root, dst_path=self.dst_path, + ignore_errors=True, verbose=verbose) self._attrs['success'] = True @property def src(self): - return self._attrs['src'] + path = os.path.join(self._attrs['src_root'], self._attrs['src_path']) + return os.path.normpath(path) + + @property + def src_root(self): + return self._attrs['src_root'] + + @property + def src_path(self): + return self._attrs['src_path'] @property def dst(self): - return self._attrs['dst'] + path = os.path.join(self._attrs['dst_root'], self._attrs['dst_path']) + return os.path.normpath(path) + + @property + def dst_root(self): + return self._attrs['dst_root'] + + @property + def dst_path(self): + return self._attrs['dst_path'] @property def mode(self): @@ -146,7 +166,9 @@ class Copy(LoraxAction): class Move(Copy): def execute(self, verbose=False): - mv(src=self.src, dst=self.dst, mode=self.mode, verbose=verbose) + mv(src_root=self.src_root, src_path=self.src_path, + dst_root=self.dst_root, dst_path=self.dst_path, + ignore_errors=True, verbose=verbose) self._attrs['success'] = True @@ -304,7 +326,7 @@ class Chmod(LoraxAction): self._attrs['mode'] = kwargs.get('mode') def execute(self, verbose=False): - os.chmod(self.filename, int(self.mode)) + chmod(self.filename, self.mode) self._attrs['success'] = True @property diff --git a/src/pylorax/images.py b/src/pylorax/images.py index 3d2764ff..27fde91e 100644 --- a/src/pylorax/images.py +++ b/src/pylorax/images.py @@ -22,6 +22,7 @@ import sys import os +import shutil import commands import re import fnmatch @@ -94,15 +95,16 @@ class InitRD(object): ldd.getDeps(action.getDeps) # resolve symlinks - ldd.getLinks() + # XXX we don't need this, because cp function gets the symlinks + #ldd.getLinks() # add dependencies to actions for dep in ldd.deps: kwargs = {} - kwargs['src'] = dep - kwargs['dst'] = re.sub(r'%s(?P.*)' % self.conf.treedir, - '%s\g' % self.conf.initrddir, - dep) + kwargs['src_tree'] = self.conf.treedir + kwargs['src_path'] = dep.replace(self.conf.treedir, '') + kwargs['dst_tree'] = self.conf.initrddir + kwargs['dst_path'] = dep.replace(self.conf.treedir, '') new_action = actions.base.Copy(**kwargs) self._actions.append(new_action) @@ -116,16 +118,19 @@ class InitRD(object): 'keymaps-override-%s' % self.conf.buildarch) if os.path.exists(override): print('Found keymap override, using it') - cp(override, os.path.join(self.conf.treedir, 'keymaps')) + shutil.copy2(override, os.path.join(self.conf.treedir, 'keymaps.gz')) else: cmd = '%s %s %s %s' % \ (os.path.join(self.conf.treedir, 'usr', 'lib', 'anaconda-runtime', 'getkeymaps'), - self.conf.buildarch, os.path.join(self.conf.treedir, 'keymaps'), self.conf.treedir) + self.conf.buildarch, os.path.join(self.conf.treedir, 'keymaps.gz'), self.conf.treedir) rc = commands.getstatus(cmd) if rc != 0: sys.stderr.write('Unable to create keymaps and thus can\'t create initrd\n') sys.exit(1) + shutil.copy2(os.path.join(self.conf.treedir, 'keymaps.gz'), + os.path.join(self.conf.initrddir, 'etc')) + def create_locales(self): os.makedirs(os.path.join(self.conf.initrddir, 'usr', 'lib', 'locale')) rc, output = commands.getstatusoutput('localedef -c -i en_US -f UTF-8 --prefix %s en_US' % self.conf.initrddir) @@ -186,7 +191,12 @@ class InitRD(object): srcdir = os.path.join(self.conf.treedir, 'lib', 'modules', self.kernelver) dstdir = os.path.join(self.conf.initrddir, 'lib', 'modules') - cp(os.path.join(srcdir, '*'), dstdir) + + cp(src_root=self.conf.treedir, + src_path=os.path.join('lib', 'modules', self.kernelver), + dst_root=self.conf.initrddir, + dst_path=os.path.join('lib', 'modules'), + ignore_errors=True) for root, dirs, files in os.walk(dstdir): for file in files: @@ -203,7 +213,7 @@ class InitRD(object): if not os.path.exists(dir): os.makedirs(dir) - cp(os.path.join(self.conf.treedir, 'lib', 'firmware', fw), dst) + shutil.copy2(os.path.join(self.conf.treedir, 'lib', 'firmware', fw), dst) # copy firmware srcdir = os.path.join(self.conf.treedir, 'lib', 'firmware') @@ -220,7 +230,10 @@ class InitRD(object): for module, file in fw: if module in modules: print('Copying firmware %s' % module) - cp(os.path.join(srcdir, file), dstdir) + cp(src_root=self.conf.treedir, + src_path=os.path.join('lib', 'firmware', file), + dst_root=self.conf.initrddir, + dst_path=os.path.join('lib', 'firmware')) # create modinfo dst = os.path.join(self.conf.initrddir, 'lib', 'modules', 'module-info') @@ -321,10 +334,26 @@ class InitRD(object): output.close() + def get_missing_links(self): + missing_files = [] + + for root, dnames, fnames in os.walk(self.conf.initrddir): + for fname in fnames: + file = os.path.join(root, fname) + if os.path.islink(file) and not os.path.exists(file): + # broken link + target = os.readlink(file) + missing = os.path.join(os.path.dirname(file), target) + missing = os.path.normpath(missing) + + missing_files.append(missing) + + print 'Missing files:', missing_files + def create(self, dst): # copy the productfile - cp(os.path.join(self.conf.treedir, '.buildstamp'), - os.path.join(self.conf.initrddir, '.buildstamp')) + shutil.copy2(os.path.join(self.conf.treedir, '.buildstamp'), + os.path.join(self.conf.initrddir, '.buildstamp')) print('Getting dependencies') self.get_deps() @@ -336,11 +365,15 @@ class InitRD(object): self.create_locales() print('Getting modules') self.get_modules() + print('Getting missing links') + self.get_missing_links() # create the initrd print('Creating the %s' % dst) - err, output = commands.getstatusoutput('find %s | cpio --quiet -c -o | gzip -9 > %s' % - (self.conf.initrddir, dst)) + cwd = os.getcwd() + os.chdir(self.conf.initrddir) + out = commands.getoutput('find . | cpio --quiet -c -o | gzip -9 > %s' % dst) + os.chdir(cwd) def clean_up(self): rm(self.conf.initrddir) @@ -352,13 +385,19 @@ class Install(object): def scrub(self): # move bin to usr/bin - cp(os.path.join(self.conf.treedir, 'bin', '*'), - os.path.join(self.conf.treedir, 'usr', 'bin')) + cp(src_root=self.conf.treedir, + src_path=os.path.join('bin', '*'), + dst_root=self.conf.treedir, + dst_path=os.path.join('usr', 'bin')) + rm(os.path.join(self.conf.treedir, 'bin')) # move sbin to /usr/sbin - cp(os.path.join(self.conf.treedir, 'sbin', '*'), - os.path.join(self.conf.treedir, 'usr', 'sbin')) + cp(src_root=self.conf.treedir, + src_path=os.path.join('sbin', '*'), + dst_root=self.conf.treedir, + dst_path=os.path.join('usr', 'sbin')) + rm(os.path.join(self.conf.treedir, 'sbin')) # remove dirs from root diff --git a/src/pylorax/utils/fileutils.py b/src/pylorax/utils/fileutils.py index 718931ae..65d642b1 100644 --- a/src/pylorax/utils/fileutils.py +++ b/src/pylorax/utils/fileutils.py @@ -28,146 +28,250 @@ import fileinput import re -def cp(src, dst, mode=None, verbose=False): - errors = [] - for name in glob.iglob(src): - rc = __copy(name, dst, verbose=verbose) - if not rc: - errors.append("unable to copy '%s' to '%s'" % (name, dst)) - else: - if mode: - os.chmod(dst, int(mode)) +def normalize(src_root, src_path, dst_root, dst_path): + src = os.path.join(src_root, src_path) + dst = os.path.join(dst_root, dst_path) + src = os.path.normpath(src) + dst = os.path.normpath(dst) - return errors + return src, dst -def mv(src, dst, mode=None, verbose=False): - errors = [] - for name in glob.iglob(src): - rc = __copy(name, dst, verbose=verbose, remove=True) - if not rc: - errors.append("unable to move '%s' to '%s'" % (name, dst)) - else: - if mode: - os.chmod(dst, int(mode)) - - return errors def rm(target, verbose=False): - for name in glob.iglob(target): - if os.path.islink(name): - os.unlink(name) + for fname in glob.iglob(target): + if verbose: + print "removing '%s'" % fname + + if os.path.isdir(fname): + shutil.rmtree(fname, ignore_errors=True) else: - if os.path.isdir(name): - if verbose: - print("removing directory '%s'" % name) - shutil.rmtree(name, ignore_errors=True) - else: - if verbose: - print("removing file '%s'" % name) - os.unlink(name) - - return True - - -def __copy(src, dst, verbose=False, remove=False): - if not os.path.exists(src): - sys.stderr.write("cannot stat '%s': No such file or directory\n" % src) - return False - - if os.path.isdir(dst): - basename = os.path.basename(src) - dst = os.path.join(dst, basename) - - if os.path.islink(src): - print('Got link %s' % src) - target = os.readlink(src) - - if os.path.exists(dst): - os.unlink(dst) - os.symlink(target, dst) - - if remove: - if verbose: - print("removing '%s'" % src) - os.unlink(src) - - return True - - if os.path.isdir(src): - if os.path.isfile(dst): - sys.stderr.write("omitting directory '%s'\n" % src) - return False - - if not os.path.isdir(dst): - os.makedirs(dst) - - names = map(lambda name: os.path.join(src, name), os.listdir(src)) - for name in names: - __copy(name, dst, verbose=verbose, remove=remove) - else: - if os.path.isdir(dst): - sys.stderr.write("cannot overwrite directory '%s' with non-directory\n" % dst) - return False - - try: - if verbose: - print("copying '%s' to '%s'" % (src, dst)) - - if os.path.exists(dst): - os.unlink(dst) - - shutil.copy2(src, dst) - except (shutil.Error, IOError) as why: - sys.stderr.write("cannot copy '%s' to '%s': %s\n" % (src, dst, why)) - return False - else: - if remove: - if verbose: - print("removing '%s'" % src) - os.unlink(src) - - return True - + os.unlink(fname) def touch(filename, verbose=False): - if os.path.exists(filename): - if verbose: - print("touching file '%s'" % filename) - os.utime(filename, None) - return True + if verbose: + print "touching '%s'" % filename - try: - if verbose: - print("creating file '%s'" % filename) - f = open(filename, 'w') - except IOError: - return False + if os.path.exists(filename): + os.utime(filename, None) else: - f.close() - return True + try: + f = open(filename, 'w') + except IOError as why: + print >> sys.stderr, "cannot create '%s': %s" % (filename, why) + return False + else: + f.close() + + return True + +def cp(src_path, dst_path, src_root='/', dst_root='/', ignore_errors=False, verbose=True): + filecopy = Copy(ignore_errors, verbose) + + src = os.path.join(src_root, src_path) + for fname in glob.iglob(src): + fname = fname.replace(src_root, '', 1) + + if src_path[0] != '/' and fname[0] == '/': + fname = fname[1:] + + filecopy.copy(fname, dst_path, src_root, dst_root) + + return filecopy.errors + +def mv(src_path, dst_path, src_root='/', dst_root='/', ignore_errors=False, verbose=True): + errors = cp(src_path, dst_path, src_root, dst_root, ignore_errors, verbose) + + # if everything was copied, remove the source + if not errors: + src, dst = normalize(src_root, src_path, dst_root, dst_path) + rm(src, verbose) + + return errors + +def chmod(target, mode, recursive=False, verbose=False): + for fname in glob.iglob(target): + if verbose: + print "changing permissions on '%s'" % fname + + os.chmod(fname, int(mode)) + + if recursive and os.path.isdir(fname): + for nested in os.listdir(fname): + nested = os.path.join(fname, nested) + chmod(nested, mode) def edit(filename, text, append=False, verbose=False): mode = 'w' if append: mode = 'a' + if verbose: + print "editing '%s'" % filename + try: - if verbose: - print("editing file '%s'" % filename) f = open(filename, mode) - except IOError: + except IOError as why: + print >> sys.stderr, "cannot edit '%s': %s" % (filename, why) return False else: f.write(text) f.close() - return True + + return True def replace(filename, find, replace, verbose=False): if verbose: - print("replacing '%s' for '%s' in file '%s'" % (find, replace, filename)) + print "replacing '%s' for '%s' in '%s'" % (find, replace, filename) + fin = fileinput.input(filename, inplace=1) for line in fin: line = re.sub(find, replace, line) sys.stdout.write(line) fin.close() + return True + + +class CopyError(Exception): + pass + +class Copy(object): + def __init__(self, ignore_errors=False, verbose=True): + self.Error = CopyError + + self.ignore_errors = ignore_errors + self.verbose = verbose + + self.errors = [] + + def copy(self, src_path, dst_path, src_root='/', dst_root='/'): + # normalize the source and destination paths + src, dst = normalize(src_root, src_path, dst_root, dst_path) + + # check if the source exists + if not os.path.exists(src): + err_msg = "cannot stat '%s': No such file or directory" % src + if not self.ignore_errors: + raise self.Error, err_msg + else: + print >> sys.stderr, err_msg + self.errors.append(err_msg) + return False # EXIT + + if os.path.isfile(src): + + # if destination is an existing directory, append the source filename + # to the destination path + if os.path.isdir(dst): + dst = os.path.join(dst, os.path.basename(src)) + + # check if the destination exists + if os.path.isfile(dst): + + # overwrite file + try: + if self.verbose: + print "overwriting '%s'" % dst + os.unlink(dst) + except OSError as why: + err_msg = "cannot overwrite file '%s': %s" % (dst, why) + if not self.ignore_errors: + raise self.Error, err_msg + else: + print >> sys.stderr, err_msg + self.errors.append(err_msg) + return False # EXIT + + elif os.path.isdir(dst): + + # do not overwrite directory with a file + err_msg = "cannot overwrite directory '%s' with non-directory" % dst + if not self.ignore_errors: + raise self.Error, err_msg + else: + print >> sys.stderr, err_msg + self.errors.append(err_msg) + return False # EXIT + + if os.path.islink(src): + + self.__copy_link(src_path, dst_path, src_root, dst_root, src, dst) + + else: + + self.__copy_file(src, dst) + + elif os.path.isdir(src): + + # append the source directory name to the destination path + dirname = os.path.basename(src) + new_dst = os.path.join(dst, dirname) + + if os.path.islink(src): + + self.__copy_link(src_path, dst_path, src_root, dst_root, src, new_dst) + + else: + + # create the destination directory if it does not exist + if not os.path.exists(new_dst): + os.makedirs(new_dst) + + if os.path.isfile(new_dst): + err_msg = "cannot overwrite file '%s' with a directory" % new_dst + if not self.ignore_errors: + raise self.Error, err_msg + else: + print >> sys.stderr, err_msg + self.errors.append(err_msg) + return False # EXIT + + new_dst_path = os.path.join(dst_path, dirname) + + fnames = [] + try: + fnames = os.listdir(src) + except OSError as why: + err_msg = "cannot list directory '%s': %s'" % (src, why) + if not self.ignore_errors: + raise self.Error, err_msg + else: + print >> sys.stderr, err_msg + self.errors.append(err_msg) + + for fname in fnames: + fname = os.path.join(src_path, fname) + self.copy(fname, new_dst_path, src_root, dst_root) + + def __copy_file(self, src, dst): + if self.verbose: + print "copying '%s' to '%s'" % (src, dst) + + try: + shutil.copy(src, dst) + except (shutil.Error, IOError) as why: + err_msg = "cannot copy '%s' to '%s': %s" % (src, dst, why) + if not self.ignore_errors: + raise self.Error, err_msg + else: + print >> sys.stderr, err_msg + self.errors.append(err_msg) + + def __copy_link(self, src_path, dst_path, src_root, dst_root, src, dst): + # read the link target + link_target = os.readlink(src) + + # get the target source and destination paths + target_src_path = os.path.join(os.path.dirname(src_path), link_target) + target_dst_path = os.path.join(dst_path, os.path.dirname(link_target)) + + # create the destination directory if it doesn't exist + target_dst = os.path.join(dst_root, target_dst_path) + if not os.path.exists(target_dst): + os.makedirs(target_dst) + + # copy the target along with the link + self.copy(target_src_path, target_dst_path, src_root, dst_root) + + # create the symlink named dst, pointing to link_target + os.symlink(link_target, dst) diff --git a/src/pylorax/utils/rpmutils.py b/src/pylorax/utils/rpmutils.py index ce19bf41..8266dbb1 100644 --- a/src/pylorax/utils/rpmutils.py +++ b/src/pylorax/utils/rpmutils.py @@ -96,6 +96,7 @@ class Yum(object): self.yumconf = os.path.abspath(yumconf) self.installroot = os.path.abspath(installroot) + self.err_file = err_file self.yb.preconf.fn = self.yumconf self.yb.preconf.root = self.installroot @@ -141,7 +142,7 @@ class Yum(object): # we should put the errors to some file, # which we can parse later for serious errors standard_err = os.dup(2) - my_err = open(err_file, 'w') + my_err = open(self.err_file, 'a') os.dup2(my_err.fileno(), 2) # now process the transactions without errors showing up self.yb.processTransaction(callback=cb, rpmDisplay=rpmcb)