diff --git a/src/IDF/Plugin/SyncGit/Cron.php b/src/IDF/Plugin/SyncGit/Cron.php index 6d136f4..ffff9d5 100644 --- a/src/IDF/Plugin/SyncGit/Cron.php +++ b/src/IDF/Plugin/SyncGit/Cron.php @@ -59,6 +59,16 @@ class IDF_Plugin_SyncGit_Cron $out .= sprintf($template, $cmd, $key->login, $content)."\n"; } } + $out = "# indefero start" . PHP_EOL . $out . "# indefero end" . PHP_EOL; + + // We update only the part of the file between IDF_START / IDF_END comment + $original_keys = file_get_contents($authorized_keys); + if (strstr($original_keys, "# indefero start") && strstr($original_keys, "# indefero end")) { + $out = preg_replace('/(#\sindefero\sstart).+(#\sindefero\send\s\s?)/isU', + $out, $original_keys); + } else { + $out .= $original_keys; + } file_put_contents($authorized_keys, $out, LOCK_EX); }