mkinitrd unification across distributions
 help / color / mirror / Atom feed
* [PATCH] dracut-lib.sh: add copytree(), use it where applicable
@ 2012-05-22 21:55 Will Woods
       [not found] ` <1337723700-5123-1-git-send-email-wwoods-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Will Woods @ 2012-05-22 21:55 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

copytree() recursively copies the contents of SRC into DEST.

If DEST doesn't exist it is created; if it exists the contents of SRC
get merged into it (duplicate files are overwritten).
---
 modules.d/45ifcfg/write-ifcfg.sh        |    2 +-
 modules.d/90livenet/fetch-liveupdate.sh |    3 +--
 modules.d/99base/dracut-lib.sh          |   11 +++++++++++
 modules.d/99img-lib/img-lib.sh          |    2 +-
 4 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/modules.d/45ifcfg/write-ifcfg.sh b/modules.d/45ifcfg/write-ifcfg.sh
index 2b7cb5c..202a16a 100755
--- a/modules.d/45ifcfg/write-ifcfg.sh
+++ b/modules.d/45ifcfg/write-ifcfg.sh
@@ -225,6 +225,6 @@ echo "files /var/lib/dhclient" >> /run/initramfs/rwtab
 {
     cp /tmp/net.* /run/initramfs/
     cp /tmp/net.$netif.resolv.conf /run/initramfs/state/etc/resolv.conf
-    cp -a -t /run/initramfs/state/etc/sysconfig/network-scripts/ /tmp/ifcfg/*
+    copytree /tmp/ifcfg /run/initramfs/state/etc/sysconfig/network-scripts
     cp /tmp/ifcfg-leases/* /run/initramfs/state/var/lib/dhclient
 } > /dev/null 2>&1
diff --git a/modules.d/90livenet/fetch-liveupdate.sh b/modules.d/90livenet/fetch-liveupdate.sh
index 8a5fdec..88aa2b1 100755
--- a/modules.d/90livenet/fetch-liveupdate.sh
+++ b/modules.d/90livenet/fetch-liveupdate.sh
@@ -27,6 +27,5 @@ if [ $? != 0 ]; then
     warn "url: $url"
     return 1
 fi
-rm -rf /updates
-mv -f /updates.tmp.$$ /updates
+copytree /updates.tmp.$$ /updates
 mv /tmp/liveupdates.info /tmp/liveupdates.done
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
index 2fe8a5e..8a54a7a 100755
--- a/modules.d/99base/dracut-lib.sh
+++ b/modules.d/99base/dracut-lib.sh
@@ -532,6 +532,17 @@ mkuniqdir() {
     echo "${retdir}"
 }
 
+# Copy the contents of SRC into DEST, merging the contents of existing
+# directories (kinda like rsync, or cpio -p).
+# Creates DEST if it doesn't exist. Overwrites files with the same names.
+#
+# copytree SRC DEST
+copytree() {
+    local src="$1" dest="$2"
+    mkdir -p "$dest"; dest=$(readlink -e -q "$dest")
+    ( cd "$src"; cp -af . -t "$dest" )
+}
+
 # Evaluates command for UUIDs either given as arguments for this function or all
 # listed in /dev/disk/by-uuid.  UUIDs doesn't have to be fully specified.  If
 # beginning is given it is expanded to all matching UUIDs.  To pass full UUID to
diff --git a/modules.d/99img-lib/img-lib.sh b/modules.d/99img-lib/img-lib.sh
index 22507aa..48e56ce 100755
--- a/modules.d/99img-lib/img-lib.sh
+++ b/modules.d/99img-lib/img-lib.sh
@@ -53,7 +53,7 @@ unpack_fs() {
     local img="$1" outdir="$2" mnt="$(mkuniqdir /tmp unpack_fs.)"
     mount -o loop $img $mnt || { rmdir $mnt; return 1; }
     mkdir -p $outdir; outdir="$(cd $outdir; pwd)"
-    ( cd $mnt; cp -a -t $outdir . )
+    copytree $mnt $outdir
     umount $mnt
     rmdir $mnt
 }
-- 
1.7.10.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] dracut-lib.sh: add copytree(), use it where applicable
       [not found] ` <1337723700-5123-1-git-send-email-wwoods-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2012-05-29  9:41   ` Harald Hoyer
  0 siblings, 0 replies; 2+ messages in thread
From: Harald Hoyer @ 2012-05-29  9:41 UTC (permalink / raw)
  To: Will Woods; +Cc: initramfs-u79uwXL29TY76Z2rM5mHXA

Am 22.05.2012 23:55, schrieb Will Woods:
> copytree() recursively copies the contents of SRC into DEST.
> 
> If DEST doesn't exist it is created; if it exists the contents of SRC
> get merged into it (duplicate files are overwritten).
> ---
>  modules.d/45ifcfg/write-ifcfg.sh        |    2 +-
>  modules.d/90livenet/fetch-liveupdate.sh |    3 +--
>  modules.d/99base/dracut-lib.sh          |   11 +++++++++++
>  modules.d/99img-lib/img-lib.sh          |    2 +-
>  4 files changed, 14 insertions(+), 4 deletions(-)
> 

pushed

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-05-29  9:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-22 21:55 [PATCH] dracut-lib.sh: add copytree(), use it where applicable Will Woods
     [not found] ` <1337723700-5123-1-git-send-email-wwoods-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-05-29  9:41   ` Harald Hoyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox