diff --git a/src/Core/System/SystemConfiguration.php b/src/Core/System/SystemConfiguration.php index d83117ade..40f4cb443 100644 --- a/src/Core/System/SystemConfiguration.php +++ b/src/Core/System/SystemConfiguration.php @@ -54,37 +54,38 @@ public function tryRestoreConf():void $backupDir = str_replace(['/storage/usbdisk1','/mountpoint'], ['',''], $confBackupDir); $confFile = $this->configDBPath; foreach ($storages as $dev => $fs){ - SystemMessages::echoToTeletype(" - mount $dev ..."."\n", true); + SystemMessages::echoToTeletype(" - mount $dev ...".PHP_EOL, true); Util::mwMkdir($tmpMountDir."/$dev"); $res = Storage::mountDisk($dev, $fs, $tmpMountDir."/$dev"); if(!$res){ - SystemMessages::echoToTeletype(" - fail mount $dev ..."."\n", true); + SystemMessages::echoToTeletype(" - fail mount $dev ...".PHP_EOL, true); } } $tail = Util::which('tail'); $sort = Util::which('sort'); $find = Util::which('find'); - $mount = Util::which('umount'); - $rm = Util::which('rm'); $cut = Util::which('cut'); - $gzip = Util::which('gzip'); - $sqlite3 = Util::which('sqlite3'); $lastBackUp = trim(shell_exec("$find $tmpMountDir/dev/*$backupDir -type f -printf '%T@ %p\\n' | $sort -n | $tail -1 | $cut -f2- -d' '")); - if(empty($lastBackUp)){ - return; - } - SystemMessages::echoToTeletype(" - Restore $lastBackUp ..."."\n", true); - shell_exec("$rm -rf {$confFile}*"); - shell_exec("$gzip -c -d $lastBackUp | sqlite3 $confFile"); - Processes::mwExec("$sqlite3 $confFile 'select * from m_Storage'", $out, $ret); - if($ret !== 0){ - SystemMessages::echoToTeletype(" - restore $lastBackUp failed..."."\n", true); - copy(self::DEFAULT_CONFIG_DB, $confFile); - }elseif(!$this->isDefaultConf()){ - System::reboot(); + if(!empty($lastBackUp)){ + $rm = Util::which('rm'); + $gzip = Util::which('gzip'); + $sqlite3= Util::which('sqlite3'); + + SystemMessages::echoToTeletype(" - Restore $lastBackUp ...".PHP_EOL, true); + shell_exec("$rm -rf {$confFile}*"); + shell_exec("$gzip -c -d $lastBackUp | sqlite3 $confFile"); + Processes::mwExec("$sqlite3 $confFile 'select * from m_Storage'", $out, $ret); + if($ret !== 0){ + SystemMessages::echoToTeletype(" - restore $lastBackUp failed...".PHP_EOL, true); + copy(self::DEFAULT_CONFIG_DB, $confFile); + }elseif(!$this->isDefaultConf()){ + System::reboot(); + } } + $mount = Util::which('umount'); foreach ($storages as $dev => $fs){ + SystemMessages::echoToTeletype(" - umount $dev ...".PHP_EOL, true); shell_exec("$mount $dev"); } }