On 03/03/2012 01:45 PM, Jörgen Maas wrote:
On Fri, Mar 2, 2012 at 10:22 PM, Leonid Flaks <fl...@bnl.gov
<mailto:fl...@bnl.gov>> wrote:

    I was bitten by the bug in keep_ssh_host_keys snippet while
    installing Fedora-16 virtual guest system. The keys where not
    preserved. Did some digging and came up with this attached fix. It
    turned out that anaconda created temporary partition on /dev/dm-0
    and it had an empty /etc/ssh directory. On a virtual guest it was
    listed first in the output of 'cat /proc/partitions' and original
    findkeys function was setting the 'keys_found' flag to yes although
    nothing was copied and no other partitions were tried. Now I am
    setting this flag only on successful copy.
    This was not an issue on a physical system as this partition was
    listed last and never actually got mounted.

    We use very similar snippets keep_files and keep_cfengine_keys which
    use the same function. I have not changed those yet. If kickstart
    file uses all of them together, then the same function is defined
    more then once and I don't like it. It would make more sense to put
    it into separate snippet , which should be loaded before any of
    those. I can easily do it if anybody else likes this idea.

    I made a fork on the github at github.com/lflaks/cobbler-ssh-__keys
    <http://github.com/lflaks/cobbler-ssh-keys> for this commit and
    pushed it.


Hi there Leon,

This looks good to me, i will merge it into my local tree before merging
into the cobbler repo.
Any further improvements to snippets are much appreciated!

Thanks!

--
Grtz,
Jörgen Maas



Now with Jörgen's blessing, I made identical changes to other 2 snippets that are using the same function - keep_files and keep_cfengine_keys. Pushed to the same fork, patch is attached.


--

Leon
diff --git a/snippets/keep_cfengine_keys b/snippets/keep_cfengine_keys
index 1c7b428..78116ab 100644
--- a/snippets/keep_cfengine_keys
+++ b/snippets/keep_cfengine_keys
@@ -30,14 +30,12 @@ function findkeys
       continue
     fi
     # Copy current host keys out to be reused
-    if [ -d /tmp/$tmpdir$SEARCHDIR ]; then
-        cp -a /tmp/$tmpdir$SEARCHDIR/${PATTERN}* /tmp/$TEMPDIR
+    if [ -d /tmp/$tmpdir$SEARCHDIR ] && cp -a 
/tmp/$tmpdir$SEARCHDIR/${PATTERN}* /tmp/$TEMPDIR; then
         keys_found="yes"
        umount /tmp/$tmpdir
        rm -r /tmp/$tmpdir
        break
-    elif [ -n "$SHORTDIR" ] && [ -d /tmp/$tmpdir$SHORTDIR ]; then
-       cp -a /tmp/$tmpdir$SHORTDIR/${PATTERN}* /tmp/$TEMPDIR
+    elif [ -n "$SHORTDIR" ] && [ -d /tmp/$tmpdir$SHORTDIR ] && cp -a 
/tmp/$tmpdir$SHORTDIR/${PATTERN}* /tmp/$TEMPDIR; then
        keys_found="yes"
         umount /tmp/$tmpdir
        rm -r /tmp/$tmpdir
diff --git a/snippets/keep_files b/snippets/keep_files
index 5913d8b..858db5d 100644
--- a/snippets/keep_files
+++ b/snippets/keep_files
@@ -35,14 +35,12 @@ function findkeys
       continue                                                           
     fi                                                                   
     # Copy current host keys out to be reused
-    if [ -d /tmp/$tmpdir$SEARCHDIR ]; then
-        cp -a /tmp/$tmpdir$SEARCHDIR/${PATTERN}* /tmp/$TEMPDIR
+    if [ -d /tmp/$tmpdir$SEARCHDIR ] && cp -a 
/tmp/$tmpdir$SEARCHDIR/${PATTERN}* /tmp/$TEMPDIR; then
         keys_found="yes"
        umount /tmp/$tmpdir
        rm -r /tmp/$tmpdir
        break
-    elif [ -n "$SHORTDIR" ] && [ -d /tmp/$tmpdir$SHORTDIR ]; then
-       cp -a /tmp/$tmpdir$SHORTDIR/${PATTERN}* /tmp/$TEMPDIR
+    elif [ -n "$SHORTDIR" ] && [ -d /tmp/$tmpdir$SHORTDIR ] && cp -a 
/tmp/$tmpdir$SHORTDIR/${PATTERN}* /tmp/$TEMPDIR; then
        keys_found="yes"
         umount /tmp/$tmpdir
        rm -r /tmp/$tmpdir
_______________________________________________
cobbler-devel mailing list
cobbler-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/cobbler-devel

Reply via email to