[fix] init management in deploy

This commit is contained in:
xdrm-brackets 2017-05-08 22:07:20 +02:00
parent fc4d805736
commit b013b84b8b
3 changed files with 26 additions and 17 deletions

View File

@ -1,3 +1,3 @@
#!/bin/sh
/usr/bin/env php $(realpath $(dirname $0))/source/deploy.php;
/usr/bin/env php $(realpath $(dirname $0))/source/deploy.php $*;

View File

@ -2,7 +2,7 @@
require_once __DIR__.'/../../include/php/const';
function api_deploy(){
function api_deploy($init){
/* [1] Fetch api response
=========================================================*/
@ -20,7 +20,7 @@
if( is_null($arr_r) )
return 127;
/* [2] Get system states (global_state)
=========================================================*/
/* (1) Check data */
@ -58,7 +58,7 @@
foreach($arr_r['chips'] as $chip)
$f->fwrite( json_encode([
(int) $chip['position'],
$chip['pins'],
$chip['states']
@ -82,7 +82,7 @@
foreach($arr_r['permissions'] as $code=>$perm)
$f->fwrite( json_encode([
$code,
(int) $perm['id_user'],
$perm['actions']
@ -107,7 +107,7 @@
foreach($arr_r['actions'] as $timeout=>$actions)
foreach($actions as $action)
$f->fwrite( json_encode([
(int) $timeout,
(int) $action['id_action'],
$action['previous'],
@ -121,6 +121,10 @@
/* [6] Remove history entries
=========================================================*/
/* (0) We are done if @init */
if( $init )
return 0;
/* (1) Check history entries count */
if( !isset($arr_r['saved']) || !is_array($arr_r['saved']) )
return 127;
@ -146,10 +150,15 @@
}
$exec = api_deploy();
/* Manage init vs. sync */
$is_init = false;
if( $argc > 1 && $argv[1] == 'init' )
$is_init = true;
$exec = api_deploy($is_init);
echo $exec;
die($exec);
?>

View File

@ -39,7 +39,7 @@
/* (4) Try new hash if available */
$new = syscall(SOURCE_DIR.'/lib/cyclic-hash/new');
if( $new === false ){
slog("cyclic-hash:new returned $new EXIT_STATUS", 'api:init','update');
return 127;
@ -55,7 +55,7 @@
$unlock_code = preg_replace('/\s/', '', $unlock_code);
/* [2] Create httpRequest base
=========================================================*/
@ -114,14 +114,14 @@
/* (2) Close request */
curl_close($curl);
/* (3) Return response as result */
if( $response === false ){
slog("Request error", 'api:init','update');
return 127;
}
/* [6] Response management
=========================================================*/
/* (1) Try to json_decode response */
@ -160,19 +160,19 @@
/* [8] Deploy received data
=========================================================*/
/* (1) Manage response deployement */
$deploy = syscall(SOURCE_DIR.'/lib/api/deploy');
$deploy = syscall(SOURCE_DIR.'/lib/api/deploy init');
/* (2) Return state */
return ($deploy === true) ? 0 : 127;
}
$exec = api_init();
echo $exec;
die($exec);
?>