feat(updater): backup before save and editorconfig

This commit is contained in:
Florian Schmitt 2024-02-15 21:42:51 +03:00
parent 5c7858c4e0
commit ce812cdcce
2 changed files with 329 additions and 274 deletions

17
.editorconfig Normal file
View file

@ -0,0 +1,17 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
[*.{js,php}]
charset = utf-8
[*.php]
indent_style = space
indent_size = 4
[*.js]
indent_style = space
indent_size = 2

View file

@ -36,7 +36,7 @@ function checkIP($domain, $withWww = false, $noip6 = false)
$foundCnameEntry = false; $foundCnameEntry = false;
$foundIp4 = false; $foundIp4 = false;
$foundIp6 = false; $foundIp6 = false;
foreach ($dnsentries as $key => $row) { foreach ($dnsentries as $row) {
if ($row['host'] == 'www.' . $domain && $row['type'] == 'CNAME' && $row['target'] == $domain) { if ($row['host'] == 'www.' . $domain && $row['type'] == 'CNAME' && $row['target'] == $domain) {
$foundCnameEntry = true; $foundCnameEntry = true;
} }
@ -285,7 +285,45 @@ function removePhpFpmConfig($user)
function upgradeWiki($srcDir, $destDir) function upgradeWiki($srcDir, $destDir)
{ {
$output = 'Update ' . $destDir; $filesToMove = ['actions', 'cache', 'custom', 'docker', 'docs', 'files', 'formatters', 'handlers', 'includes', 'javascripts', 'lang', 'private', 'setup', 'styles', 'templates', 'tests', 'themes', 'tools', 'vendor', 'docker-compose.yml', 'composer.json', 'composer.lock', 'index.php', 'INSTALL.md', 'interwiki.conf', 'LICENSE', 'Makefile', 'package.json', 'README.md', 'SECURITY.md', 'wakka.basic.css', 'wakka.css', 'wakka.php', 'yarn.lock', 'yeswicli'];
$filesToCopy = ['wakka.config.php'];
$bars = '============' . "\n";
$output = '== Update wiki in path: ' . $destDir . ' ' . $bars;
$user = posix_getpwuid(fileowner($destDir . '/wakka.config.php'))['name'];
$sudo = 'sudo -u ' . $user . ' ';
$tmpbackupDir = $destDir . '/tmpbackup';
if (is_dir($tmpbackupDir)) {
$output .= 'ERROR: found existing backup in "' . $tmpbackupDir . '" aborting' . "\n";
return $output;
} else {
exec($sudo . 'mkdir -p ' . $tmpbackupDir);
}
$output .= '==== Move files to temporary backup dir ' . $tmpbackupDir . ' ' . $bars;
foreach ($filesToMove as $f) {
if (file_exists($destDir . '/' . $f)) {
exec($sudo . 'mv ' . $destDir . '/' . $f . ' ' . $tmpbackupDir . '/' . $f);
} else {
$output .= 'File not found "' . $f . '"' . "\n";
}
}
foreach ($filesToCopy as $f) {
if (file_exists($destDir . '/' . $f)) {
exec($sudo . 'cp -rf ' . $destDir . '/' . $f . ' ' . $tmpbackupDir . '/' . $f);
} else {
$output .= 'File not found "' . $f . '"' . "\n";
}
}
$output .= '==== End Move files to temporary backup dir ' . $tmpbackupDir . ' ' . $bars;
$output .= '==== Update to latest sources ' . $bars;
foreach ($filesToMove as $f) {
if (file_exists($srcDir . '/' . $f)) {
exec($sudo . 'cp -R ' . $srcDir . '/' . $f . ' ' . $destDir . '/' . $f);
} else {
$output .= 'File not found "' . $f . '"' . "\n";
}
}
$output .= '==== End Update to latest sources ' . $bars;
$output .= '== End update wiki in path: ' . $destDir . ' ' . $bars;
return $output; return $output;
} }