瀏覽代碼

added fetch remote home dir on Install

Piotr Labudda 9 年之前
父節點
當前提交
29c4ab2f3d
共有 1 個文件被更改,包括 27 次插入1 次删除
  1. 27 1
      SE/se-lib/Route/Install.php

+ 27 - 1
SE/se-lib/Route/Install.php

@@ -452,6 +452,29 @@ jQuery(document).ready(function () {
 		SE_Layout::dol();
 	}
 
+	public function _fetchRemoteHomeDir($appLicenceInfo) {
+		$this->_assertRsaKeyExists($appLicenceInfo);
+		$sshHostUsr = "{$appLicenceInfo->rootLogin}@{$appLicenceInfo->mainServer}";
+		$sshArgs = (22 != $appLicenceInfo->sshPort)? "-p {$appLicenceInfo->sshPort}" : '';
+		$rsyncSshPort = (22 != $appLicenceInfo->sshPort)? "-e 'ssh -p {$appLicenceInfo->sshPort}'" : '';
+
+		if (V::get('DBG_REMOTE', '', $_GET)) {// DBG
+			$cmd = "echo ~";
+			V::exec("ssh {$sshArgs} {$sshHostUsr} '{$cmd}'", $out, $ret);
+			DBG::_(true, true, "exec(ssh ... 'cmd'): {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
+			V::execRemote($appLicenceInfo->mainServer, $appLicenceInfo->rootLogin, $appLicenceInfo->rootPassword, $cmd, $out, $ret, $appLicenceInfo->sshPort);
+			DBG::_(true, true, "execRemote(cmd): {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
+			V::execRootRemote($appLicenceInfo->mainServer, $appLicenceInfo->rootLogin, $appLicenceInfo->rootPassword, $cmd, $out, $ret, $appLicenceInfo->sshPort);
+			DBG::_(true, true, "execRootRemote(cmd): {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
+		}
+
+		$cmd = "echo ~";
+		V::exec("ssh {$sshArgs} {$sshHostUsr} '{$cmd}'", $out, $ret);
+		DBG::_(true, true, "exec(ssh ... '{$cmd}') (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
+		if (empty($out) || empty($out[0])) throw new Exception("Cannot fetch remote home dir");
+		return $out[0];
+	}
+
 	public function _sendToRemoteTestDir($appLicenceInfo) {
 		$cmd = ''; $out = ''; $ret = '';
 
@@ -467,6 +490,8 @@ jQuery(document).ready(function () {
 			-t, --times                 preserve times
 			    --delete                delete extraneous files from dest dirs
 		*/
+		DBG::_(true, true, "remote home dir:", $this->_fetchRemoteHomeDir($appLicenceInfo), __CLASS__, __FUNCTION__, __LINE__);
+
 		$cmd = "
 ssh {$sshArgs} {$sshHostUsr} '[ ! -d ~/se.encrypted.upgrade ] && mkdir ~/se.encrypted.upgrade || echo 1';
 ssh {$sshArgs} {$sshHostUsr} 'rm -rf ~/se.encrypted.upgrade/SE';
@@ -514,7 +539,8 @@ ssh {$sshArgs} {$sshHostUsr} 'ln -s ~/se.encrypted.upgrade/SE /Library/Server/We
 		$this->_assertRsaKeyExists($appLicenceInfo);
 
 		$dateStr = date("Y-m-d_H-i-s");
-		$remoteHomeDir = "/Users/{$appLicenceInfo->rootLogin}";
+		// $remoteHomeDir = "/Users/{$appLicenceInfo->rootLogin}";// BUG: alias like in ams - login = prezes is alias for arkadiuszbinder
+		$remoteHomeDir = $this->_fetchRemoteHomeDir($appLicenceInfo);
 		$cmd = "
 rm -rf /Library/Server/Web/Data/Sites/Default/SE.test 2>&1
 cp -r {$remoteHomeDir}/se.encrypted.upgrade/SE /Library/Server/Web/Data/Sites/Default/SE.test 2>&1