parent
a3ff6b9cbe
commit
5ff68d5c42
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__.'/../../include/php/const';
|
||||
|
||||
function api_deploy(){
|
||||
|
||||
/* [1] Fetch api response
|
||||
=========================================================*/
|
||||
/* (1) Try to read response */
|
||||
$file_r = @file_get_contents(TMP_DIR.'/api.response');
|
||||
|
||||
/* (2) Check response */
|
||||
if( $file_r === false )
|
||||
return 127;
|
||||
|
||||
/* (3) Try to parse response */
|
||||
$arr_r = json_decode($file_r, true);
|
||||
|
||||
/* (4) Check parse error */
|
||||
if( is_null($arr_r) )
|
||||
return 127;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* [1] Check $1 argument
|
||||
=========================================================*/
|
||||
if( $argc < 2 || !in_array($argv[1], 'init', 'sync' ){
|
||||
echo 127;
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
echo api_deploy($argv[1]);
|
||||
|
||||
|
||||
|
||||
?>
|
|
@ -45,13 +45,14 @@
|
|||
}
|
||||
|
||||
/* (5) Fetch machine unlock code */
|
||||
$unlock_code = @file_get_contents(ID_CONF);
|
||||
$unlock_code = @file_get_contents(UNLOCK_CODE);
|
||||
|
||||
if( $unlock_code === false ){
|
||||
slog("Cannot find unlock code", 'api:init','update');
|
||||
return 127;
|
||||
}
|
||||
|
||||
$unlock_code = preg_replace('/\s/', '', $unlock_code);
|
||||
|
||||
|
||||
|
||||
|
@ -96,6 +97,8 @@
|
|||
return 127;
|
||||
}
|
||||
|
||||
$wh_tok = preg_replace('/\s/', '', $wh_tok);
|
||||
|
||||
/* (2) Set Auth header digest */
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Digest $wh_tok"
|
||||
|
@ -136,7 +139,7 @@
|
|||
file_put_contents(TMP_DIR.'/api.response', $response);
|
||||
|
||||
/* (2) Manage response deployement */
|
||||
$deploy = syscall(SOURCE_DIR.'/lib/api/deploy');
|
||||
$deploy = syscall(SOURCE_DIR.'/lib/api/deploy init');
|
||||
|
||||
/* (3) Return state */
|
||||
return ($deploy === true) ? 0 : 127;
|
||||
|
|
|
@ -85,6 +85,8 @@
|
|||
return 127;
|
||||
}
|
||||
|
||||
$wh_tok = preg_replace('/\s/', '', $wh_tok);
|
||||
|
||||
/* (2) Set Auth header digest */
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Digest $wh_tok"
|
||||
|
@ -121,13 +123,24 @@
|
|||
|
||||
/* [6] Response management
|
||||
=========================================================*/
|
||||
/* (1) Writes request to temporary pipe */
|
||||
/* (1) Try to json_decode response */
|
||||
$response_arr = json_decode($response, true);
|
||||
|
||||
// if cannot, abort
|
||||
if( is_null($response_arr) )
|
||||
return 127;
|
||||
|
||||
/* (2) Check response error */
|
||||
if( !isset($response_arr['error']) || $response_arr['error'] != 0 )
|
||||
return 127;
|
||||
|
||||
/* (3) Writes request to temporary pipe */
|
||||
file_put_contents(TMP_DIR.'/api.response', $response);
|
||||
|
||||
/* (2) Manage response deployement */
|
||||
$deploy = syscall(SOURCE_DIR.'/lib/api/deploy');
|
||||
/* (4) Manage response deployement */
|
||||
$deploy = syscall(SOURCE_DIR.'/lib/api/deploy sync');
|
||||
|
||||
/* (3) Return state */
|
||||
/* (5) Return state */
|
||||
return ($deploy === true) ? 0 : 127;
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ export ID_CONF="$CONF_DIR/machine.id";
|
|||
export URL_CONF="$CONF_DIR/api.url";
|
||||
export AUTH_CONF="$CONF_DIR/auth.list";
|
||||
export WAREHOUSE_TOK="$CONF_DIR/warehouse.token";
|
||||
export UNLOCK_CODE="$CONF_DIR/machine.unlock";
|
||||
|
||||
# LOG FILES
|
||||
export BOOT_LOG="$LOG_DIR/boot.log";
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
define('URL_CONF', CONF_DIR.'/api.url');
|
||||
define('AUTH_CONF', CONF_DIR.'/auth.list');
|
||||
define('WAREHOUSE_TOK', CONF_DIR.'/warehouse.token');
|
||||
define('UNLOCK_CODE', CONF_DIR.'/machine.unlock');
|
||||
|
||||
# LOG FILES
|
||||
define('BOOT_LOG', LOG_DIR.'/boot.log');
|
||||
|
|
Loading…
Reference in New Issue