Parcourir la source

update linux script to check and set permissions
change relative path to use root path

CauseFX il y a 3 ans
Parent
commit
e2815ed4c8
1 fichiers modifiés avec 30 ajouts et 4 suppressions
  1. 30 4
      api/functions/update-functions.php

+ 30 - 4
api/functions/update-functions.php

@@ -2,6 +2,26 @@
 
 trait UpdateFunctions
 {
+	public function testScriptFilePermissions($script, $retest = false)
+	{
+		if (file_exists($script)) {
+			if (is_executable($script)) {
+				return true;
+			} elseif ($retest == false) {
+				$this->setLoggerChannel('Update')->notice('Attempting to set correct permissions', ['file' => $script]);
+				$permissions = shell_exec('chmod 677 ' . $script);
+				$permissions = shell_exec('chmod 777 ' . $script);
+				return $this->testScriptFilePermissions($script, true);
+			} else {
+				$this->setLoggerChannel('Update')->warning('Update script doesn\'t have the correct permissions', ['file' => $script]);
+				return false;
+			}
+		} else {
+			$this->setLoggerChannel('Update')->warning('Update script doesn\'t exist', ['file' => $script]);
+			return false;
+		}
+	}
+
 	public function updateOrganizr()
 	{
 		if ($this->docker) {
@@ -81,8 +101,8 @@ trait UpdateFunctions
 		$branch = ($this->config['branch'] == 'v2-master') ? '-m' : '-d';
 		ini_set('max_execution_time', 0);
 		set_time_limit(0);
-		$logFile = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'log.txt';
-		$windowsScript = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'windows-update.bat ' . $branch . ' > ' . $logFile . ' 2>&1';
+		$logFile = $this->root . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'log.txt';
+		$windowsScript = $this->root . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'windows-update.bat ' . $branch . ' > ' . $logFile . ' 2>&1';
 		$windowsUpdate = shell_exec($windowsScript);
 		$this->removeUpdateStatusFile();
 		if ($windowsUpdate) {
@@ -109,8 +129,14 @@ trait UpdateFunctions
 		$branch = $this->config['branch'];
 		ini_set('max_execution_time', 0);
 		set_time_limit(0);
-		$logFile = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'log.txt';
-		$script = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'linux-update.sh ' . $branch . ' > ' . $logFile . ' 2>&1';
+		$logFile = $this->root . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'log.txt';
+		$script = $this->root . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'linux-update.sh ' . $branch . ' > ' . $logFile . ' 2>&1';
+		$checkScript = $this->testScriptFilePermissions($script);
+		if (!$checkScript) {
+			$this->setResponse(500, 'Update script permissions error');
+			$this->removeUpdateStatusFile();
+			return false;
+		}
 		$update = shell_exec($script);
 		$this->removeUpdateStatusFile();
 		if ($update) {