miles@Oscar 9 lat temu
rodzic
commit
b6cce04806
3 zmienionych plików z 15 dodań i 8 usunięć
  1. 6 1
      README.md
  2. 3 3
      auto_deploy.sh
  3. 6 4
      index.php

+ 6 - 1
README.md

@@ -5,7 +5,7 @@ Simple tools for git auto deploy in linux
 Settings
 ---
 ### Githooks
-Copy the contents in [post-receive.sample] to your server's hooks, you may replace the ```url``` and ```token``` with your own settings
+Copy the contents in [post-receive.sample](post-receive.sample) to your server's hooks, you may replace the ```url``` and ```token``` with your own settings
 
 ### Server
 Put the files ```auto_deploy.sh``` and ```index.php``` to your website in the same directory. For example, you may access ```index.php``` from the url ```http://myweb.com/auto_deploy/index.php```, also it is to-post url in the githooks
@@ -17,6 +17,11 @@ Replace your ```toCheckToken``` and ```validIP``` in ```index.php```
 ### Permission
 Web user should have permission to run the git command!
 Let's say that your ```nginx``` user is ```www``` (of course you can check this by ```exec(whoami)```), and it's recommended ssh key of ```www``` should be added to this project's SSH deploy key.
+For example:
+```
+sudo -u www ssh-keygen -t rsa -C "YOUR_COMMENT"
+```
+Use above suggestion incase your web user is set to nologin via ssh
 
 Usage
 ---

+ 3 - 3
auto_deploy.sh

@@ -3,8 +3,8 @@ path=YOUR_DEPLOY_DIR
 cd $path
 
 # Save local changes
-git stash
+git stash 2>&1
 
 # Auto deploy by using hard reset
-git fetch --all
-git reset --hard origin/master
+git fetch --all 2>&1
+git reset --hard origin/master 2>&1

+ 6 - 4
index.php

@@ -12,10 +12,12 @@ $validIP = array('123.45.67.89');
 $remoteIP = $_SERVER['REMOTE_ADDR'];
 $time = date("Y-m-d H:i:s");
 
-if ($logFile) {
+if (isset($logFile)) {
     $log = true;
     $fs = fopen($logFile, 'a');
     fwrite($fs, "[start deploy] time:{$time}".PHP_EOL);
+} else {
+	$log = false;
 }
 
 # Check IP
@@ -34,8 +36,8 @@ if (!$data || empty($data)) {
 }
 
 # Check token
-if ($data->token != $toCheckToken) {
-    $msg = "Invalid token:".$data->token;
+if (!isset($data->token) || $data->token != $toCheckToken) {
+    $msg = "Invalid token";
     echo $msg;
     $log && fwrite($fs, $msg.PHP_EOL);
     exit(0);
@@ -56,5 +58,5 @@ foreach ($output as $val) {
 # log
 $msg = "Finish auto deploy at ".$time;
 $log && fwrite($fs, $msg.PHP_EOL);
-$fs && fclose($fs);
+isset($fs) && fclose($fs);