mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
T#7156: use cron job to handle schedule Activate firmware image
This commit is contained in:
parent
7f0ca8ccd5
commit
a2db2419dc
8 changed files with 310 additions and 46 deletions
|
|
@ -21,7 +21,6 @@
|
||||||
static int read_next;
|
static int read_next;
|
||||||
static struct diagnostic_stats diag_stats = {0};
|
static struct diagnostic_stats diag_stats = {0};
|
||||||
static const int READ_BUF_SIZE = { 1024 * 16 };
|
static const int READ_BUF_SIZE = { 1024 * 16 };
|
||||||
static struct uloop_timeout activate_timer[MAX_TIME_WINDOW] = {0};
|
|
||||||
|
|
||||||
char *get_diagnostics_option(char *sec_name, char *option)
|
char *get_diagnostics_option(char *sec_name, char *option)
|
||||||
{
|
{
|
||||||
|
|
@ -572,38 +571,6 @@ end:
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void launch_activate_iamge_cb(struct uloop_timeout *t)
|
|
||||||
{
|
|
||||||
dmubus_call_set("system", "reboot", UBUS_ARGS{0}, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void activate_fw_images(char *start_time[])
|
|
||||||
{
|
|
||||||
for (int i = 0; i < MAX_TIME_WINDOW && DM_STRLEN(start_time[i]); i++) {
|
|
||||||
activate_timer[i].cb = launch_activate_iamge_cb;
|
|
||||||
uloop_timeout_set(&activate_timer[i], DM_STRTOL(start_time[i]) * 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int bbf_fw_image_activate(const char *bank_id, char *start_time[])
|
|
||||||
{
|
|
||||||
json_object *json_obj = NULL;
|
|
||||||
|
|
||||||
dmubus_call("fwbank", "set_bootbank", UBUS_ARGS{{"bank", bank_id, Integer}}, 1, &json_obj);
|
|
||||||
char *status = dmjson_get_value(json_obj, 1, "success");
|
|
||||||
if (strcmp(status, "true") != 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (DM_STRLEN(start_time[0])) {
|
|
||||||
activate_fw_images(start_time);
|
|
||||||
} else {
|
|
||||||
if (dmubus_call_set("system", "reboot", UBUS_ARGS{0}, 0) != 0)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void libtrace_cleanup(libtrace_t *trace, libtrace_packet_t *packet)
|
static void libtrace_cleanup(libtrace_t *trace, libtrace_packet_t *packet)
|
||||||
{
|
{
|
||||||
if (trace)
|
if (trace)
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,5 @@ int bbf_config_restore(const char *url, const char *username, const char *passwo
|
||||||
int bbf_fw_image_download(const char *url, const char *auto_activate, const char *username, const char *password,
|
int bbf_fw_image_download(const char *url, const char *auto_activate, const char *username, const char *password,
|
||||||
const char *file_size, const char *checksum_algorithm, const char *checksum,
|
const char *file_size, const char *checksum_algorithm, const char *checksum,
|
||||||
const char *bank_id, const char *command, const char *obj_path, const char *commandKey);
|
const char *bank_id, const char *command, const char *obj_path, const char *commandKey);
|
||||||
int bbf_fw_image_activate(const char *bank_id, char *start_time[]);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1005,15 +1005,6 @@ static operation_args firmware_image_activate_args = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const char *firmware_image_activate_in[] = {
|
|
||||||
"TimeWindow.1.Start",
|
|
||||||
"TimeWindow.2.Start",
|
|
||||||
"TimeWindow.3.Start",
|
|
||||||
"TimeWindow.4.Start",
|
|
||||||
"TimeWindow.5.Start",
|
|
||||||
};
|
|
||||||
|
|
||||||
static int get_operate_args_DeviceInfoFirmwareImage_Activate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
static int get_operate_args_DeviceInfoFirmwareImage_Activate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||||
{
|
{
|
||||||
*value = (char *)&firmware_image_activate_args;
|
*value = (char *)&firmware_image_activate_args;
|
||||||
|
|
@ -1023,13 +1014,101 @@ static int get_operate_args_DeviceInfoFirmwareImage_Activate(char *refparam, str
|
||||||
static int operate_DeviceInfoFirmwareImage_Activate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
static int operate_DeviceInfoFirmwareImage_Activate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||||
{
|
{
|
||||||
char *start_time[MAX_TIME_WINDOW] = {0};
|
char *start_time[MAX_TIME_WINDOW] = {0};
|
||||||
|
char *end_time[MAX_TIME_WINDOW] = {0};
|
||||||
|
char *mode[MAX_TIME_WINDOW] = {0};
|
||||||
|
char *user_message[MAX_TIME_WINDOW] = {0};
|
||||||
|
char *max_retries[MAX_TIME_WINDOW] = {0};
|
||||||
|
int res = 0, last_idx = -1;
|
||||||
|
|
||||||
for (int i = 0; i < ARRAY_SIZE(firmware_image_activate_in); i++)
|
for (int i = 0; i < MAX_TIME_WINDOW; i++) {
|
||||||
start_time[i] = dmjson_get_value((json_object *)value, 1, firmware_image_activate_in[i]);
|
char buf[32] = {0};
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "TimeWindow.%d.Start", i + 1);
|
||||||
|
start_time[i] = dmjson_get_value((json_object *)value, 1, buf);
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "TimeWindow.%d.End", i + 1);
|
||||||
|
end_time[i] = dmjson_get_value((json_object *)value, 1, buf);
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "TimeWindow.%d.Mode", i + 1);
|
||||||
|
mode[i] = dmjson_get_value((json_object *)value, 1, buf);
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "TimeWindow.%d.UserMessage", i + 1);
|
||||||
|
user_message[i] = dmjson_get_value((json_object *)value, 1, buf);
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "TimeWindow.%d.MaxRetries", i + 1);
|
||||||
|
max_retries[i] = dmjson_get_value((json_object *)value, 1, buf);
|
||||||
|
|
||||||
|
if (!DM_STRLEN(start_time[i]))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!DM_STRLEN(end_time[i]) || !DM_STRLEN(mode[i]))
|
||||||
|
return CMD_INVALID_ARGUMENTS;
|
||||||
|
|
||||||
|
if (dm_validate_unsignedInt(start_time[i], RANGE_ARGS{{NULL,NULL}}, 1))
|
||||||
|
return CMD_INVALID_ARGUMENTS;
|
||||||
|
|
||||||
|
if (dm_validate_unsignedInt(end_time[i], RANGE_ARGS{{NULL,NULL}}, 1))
|
||||||
|
return CMD_INVALID_ARGUMENTS;
|
||||||
|
|
||||||
|
if (DM_STRLEN(max_retries[i]) && dm_validate_int(max_retries[i], RANGE_ARGS{{"-1","10"}}, 1))
|
||||||
|
return CMD_INVALID_ARGUMENTS;
|
||||||
|
|
||||||
|
if (dm_validate_string(mode[i], -1, -1, FW_Mode, NULL))
|
||||||
|
return CMD_INVALID_ARGUMENTS;
|
||||||
|
|
||||||
|
if (DM_STRTOL(start_time[i]) > DM_STRTOL(end_time[i]))
|
||||||
|
return CMD_INVALID_ARGUMENTS;
|
||||||
|
|
||||||
|
if (i != 0 && DM_STRTOL(end_time[i - 1]) > DM_STRTOL(start_time[i]))
|
||||||
|
return CMD_INVALID_ARGUMENTS;
|
||||||
|
|
||||||
|
last_idx++;
|
||||||
|
}
|
||||||
|
|
||||||
char *bank_id = dmjson_get_value((json_object *)data, 1, "id");
|
char *bank_id = dmjson_get_value((json_object *)data, 1, "id");
|
||||||
|
if (!DM_STRLEN(bank_id))
|
||||||
|
return CMD_FAIL;
|
||||||
|
|
||||||
int res = bbf_fw_image_activate(bank_id, start_time);
|
if (DM_STRLEN(start_time[0])) {
|
||||||
|
FILE *file = fopen(CRONTABS_ROOT, "a");
|
||||||
|
if (!file)
|
||||||
|
return CMD_FAIL;
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_TIME_WINDOW && DM_STRLEN(start_time[i]); i++) {
|
||||||
|
char buffer[512] = {0};
|
||||||
|
time_t t_time = time(NULL);
|
||||||
|
t_time = t_time + DM_STRTOL(start_time[i]);
|
||||||
|
struct tm *tm_local = localtime(&t_time);
|
||||||
|
|
||||||
|
snprintf(buffer, sizeof(buffer), "%d %d %d %d * sh %s '%s' '%s' '%ld' '%d' '%s' '%s'\n",
|
||||||
|
tm_local->tm_min,
|
||||||
|
tm_local->tm_hour,
|
||||||
|
tm_local->tm_mday,
|
||||||
|
tm_local->tm_mon + 1,
|
||||||
|
ACTIVATE_HANDLER_FILE,
|
||||||
|
mode[i],
|
||||||
|
bank_id,
|
||||||
|
(DM_STRTOL(end_time[i]) - DM_STRTOL(start_time[i])),
|
||||||
|
(i == last_idx),
|
||||||
|
user_message[i],
|
||||||
|
max_retries[i]);
|
||||||
|
|
||||||
|
fprintf(file, "%s", buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
res = dmcmd_no_wait("/etc/init.d/cron", 1, "restart");
|
||||||
|
} else {
|
||||||
|
json_object *json_obj = NULL;
|
||||||
|
|
||||||
|
dmubus_call("fwbank", "set_bootbank", UBUS_ARGS{{"bank", bank_id, Integer}}, 1, &json_obj);
|
||||||
|
char *status = dmjson_get_value(json_obj, 1, "success");
|
||||||
|
if (strcasecmp(status, "true") != 0)
|
||||||
|
return CMD_FAIL;
|
||||||
|
|
||||||
|
res = dmubus_call_set("rpc-sys", "reboot", UBUS_ARGS{0}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
return res ? CMD_FAIL : CMD_SUCCESS;
|
return res ? CMD_FAIL : CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
110
docs/activate_firmware.md
Normal file
110
docs/activate_firmware.md
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Design For Firmware Activation
|
||||||
|
|
||||||
|
According to the TR181 data model, the Activate() command is an operation to activate the firmware image immediately or schedule it in another time.
|
||||||
|
|
||||||
|
In fact, the Linux system already provides us a cron to schedule some jobs. And since Openwrt is one of the Linux systems, so we can use a cron job as solution to handle the firmware activation.
|
||||||
|
|
||||||
|
The Activate() command has as arguments the TimeWindow object which is used to activate the required firmware in a specified time. For that, foreach TimeWindow instance a cron job will be created.
|
||||||
|
|
||||||
|
> Note: As per TR181 data model, max 5 instances of TimeWindow is supported.
|
||||||
|
|
||||||
|
Below is an example of an 'Activate()' command call with three TimeWindow instances. As a result, three jobs are created according to the defined TimeWindow.{i}.Start:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
root@iopsys-44d43771aff0:~# ubus call usp operate '{"path":"Device.DeviceInfo.FirmwareImage.2.", "action":"Activate()", "input":{"TimeWindow.1
|
||||||
|
.Start":"1800", "TimeWindow.1.End":"3600", "TimeWindow.1.Mode":"WhenIdle", "TimeWindow.2.Start":"5400", "TimeWindow.2.End":"9000", "TimeWindow
|
||||||
|
.2.Mode":"WhenIdle", "TimeWindow.3.Start":"86400", "TimeWindow.3.End":"172800", "TimeWindow.3.Mode":"Immediately"}}'
|
||||||
|
{
|
||||||
|
"Results": [
|
||||||
|
{
|
||||||
|
"path": "Device.DeviceInfo.FirmwareImage.2.Activate()",
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
root@iopsys-44d43771aff0:~# crontab -l
|
||||||
|
52 22 21 2 * sh /usr/share/bbfdm/bbf_activate_handler.sh 'WhenIdle' '2' '1800' '0' '' ''
|
||||||
|
52 23 21 2 * sh /usr/share/bbfdm/bbf_activate_handler.sh 'WhenIdle' '2' '3600' '0' '' ''
|
||||||
|
22 22 22 2 * sh /usr/share/bbfdm/bbf_activate_handler.sh 'Immediately' '2' '86400' '1' '' ''
|
||||||
|
root@iopsys-44d43771aff0:~#
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
For those cron jobs it is required to give the handler script to be executed which is in our case [bbf_activate_handler.sh](/scripts/bbf_activate_handler.sh). And, it is located under '/usr/share/bbfdm/' in the device.
|
||||||
|
|
||||||
|
|
||||||
|
## Cron job specification
|
||||||
|
|
||||||
|
For each cron job related to the activated firmware, it is needed to define it as below:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
* * * * * command to execute * * * * * *
|
||||||
|
- - - - - - - - - - - -
|
||||||
|
| | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | --- Message that informs the user of a new activation request
|
||||||
|
| | | | | | | | | | ----- Maximum number of retries
|
||||||
|
| | | | | | | | | ------- Force firmware activation when it's not idle (0 - 1)
|
||||||
|
| | | | | | | | --------- End of the time window
|
||||||
|
| | | | | | | ----------- Firmware Bank id to be activated
|
||||||
|
| | | | | | ------------- Mode (AnyTime, Immediately, WhenIdle, ConfirmationNeeded)
|
||||||
|
| | | | | -------------------------------- Activate firmware script 'bbf_activate_handler.sh'
|
||||||
|
| | | | ---------------------------------- Day of week (0 - 6) (Sunday =0)
|
||||||
|
| | | ------------------------------------ Month (1 - 12)
|
||||||
|
| | -------------------------------------- Day (1 - 31)
|
||||||
|
| ---------------------------------------- Hour (0 - 23)
|
||||||
|
------------------------------------------ Minute (0 - 59)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Activate Handler script
|
||||||
|
|
||||||
|
As described, we create a cron job for each TimeWindow in order to activate the required firmware within a specified time by running the [bbf_activate_handler.sh](/scripts/bbf_activate_handler.sh) handler script.
|
||||||
|
|
||||||
|
In fact, the aim of this script is to manage firmware images based on the **mode** and the other passed arguments.
|
||||||
|
|
||||||
|
|
||||||
|
### 1. Mode 'AnyTime' and 'Immediately':
|
||||||
|
|
||||||
|
For these modes and based on the firmware bank id, the required firmware image will be immediately activated at start time. The TimeWindow.{i}.End is ignored.
|
||||||
|
|
||||||
|
### 2. How to handle 'WhenIdle' mode:
|
||||||
|
|
||||||
|
Definition of WhenIdle may vary for each deployment and customer, to make it customizable [bbf_check_idle.sh](/scripts/bbf_check_idle.sh) script is used. It is assumed that customer shall overwrite this file using customer-config to match with there requirement.
|
||||||
|
|
||||||
|
In this mode, [bbf_activate_handler.sh](/scripts/bbf_activate_handler.sh) script calls this script [bbf_check_idle.sh](/scripts/bbf_check_idle.sh) to determine the idle state of the device. [bbf_activate_handler.sh](/scripts/bbf_activate_handler.sh) assumes the device as idle if the exit status of the above script is 0, or if the [bbf_check_idle.sh](/scripts/bbf_check_idle.sh) is not present in the predefined path "/usr/share/bbfdm/".
|
||||||
|
|
||||||
|
|
||||||
|
If the exit code from the idle script is zero then firmware image can be activated. Otherwise, it has to wait for next time slot which is defined by 'RETRY_TIME' variable.
|
||||||
|
|
||||||
|
> Note1: The time slot is set through 'RETRY_TIME' variable which is defined under '/usr/share/bbfdm/bbf_activate_handler.sh' script.
|
||||||
|
|
||||||
|
> Note2: The exit status of the script [bbf_check_idle.sh](/scripts/bbf_check_idle.sh) is important because based on it, the '[bbf_activate_handler.sh](/scripts/bbf_activate_handler.sh) script will decide whether the image can be activated or not.
|
||||||
|
|
||||||
|
> Note3: Algorithm/Logic to determine the Idle state of device is out of scope of this document and it is expected that users overwrite this script with the logic to determine the same in actual deployment.
|
||||||
|
|
||||||
|
> Note4: If 1 or more TimeWindow.{i}.Mode is set to 'WhenIdle' and all of them fails to get the idle state. The latest TimeWindow instance will force the device to activate the firmware image.
|
||||||
|
|
||||||
|
> Note5: If the idle script [bbf_check_idle.sh](/scripts/bbf_check_idle.sh) not present in the pre-defined path "/usr/share/bbfdm/", then the device is assumed to be in ideal state and the firmware shall be activated instantly.
|
||||||
|
|
||||||
|
> Note6: It is very likely that TimeWindow with 'WhenIdle' mode might not find any suitable Idle state, in that case firmware shall not be activated. If users/operators want to make sure that firmware gets activated at the end, then they can add a TimeWindow with 'AnyTime/Immediate' mode at the end, to activate the firmware.
|
||||||
|
|
||||||
|
|
||||||
|
## Good to know
|
||||||
|
|
||||||
|
* TimeWindow instance arguments are optional.
|
||||||
|
|
||||||
|
* TimeWindow instances attributes must not overlap.
|
||||||
|
|
||||||
|
* If TimeWindow.{i}.Start is set, TimeWindow.{i}.End and TimeWindow.{i}.Mode become mondatory.
|
||||||
|
|
||||||
|
* The firmware activation is done by [bbf_activate_handler.sh](/scripts/bbf_activate_handler.sh) script as per the defined Mode in TimeWindow, but if the TimeWindow is not defined, it will activate the requested FirmwareImage instance immediately.
|
||||||
|
|
||||||
|
* If the customer wants to be sure that the required firmware is getting activated at the end then they can define the TimeWindow.{i}.Mode as 'AnyTime' or 'Immediately' in the last TimeWindow instance.
|
||||||
|
|
||||||
|
* This document is only target for Firmware management using USP.
|
||||||
|
|
||||||
|
* TimeWindow.{i}.Mode = 'ConfirmationNeeded' is not supported.
|
||||||
|
|
@ -51,6 +51,7 @@ char *SupportedFrequencyBands[] = {"2.4GHz", "5GHz", NULL};
|
||||||
char *Provider_Bridge_Type[] = {"S-VLAN", "PE", NULL};
|
char *Provider_Bridge_Type[] = {"S-VLAN", "PE", NULL};
|
||||||
char *AdvPreferredRouterFlag[] = {"High", "Medium", "Low", NULL};
|
char *AdvPreferredRouterFlag[] = {"High", "Medium", "Low", NULL};
|
||||||
char *PowerState[] = {"On", "Power_Save", "Off", "Unsupported", NULL};
|
char *PowerState[] = {"On", "Power_Save", "Off", "Unsupported", NULL};
|
||||||
|
char *FW_Mode[] = {"AnyTime", "Immediately", "WhenIdle", "ConfirmationNeeded", NULL};
|
||||||
|
|
||||||
char *PIN[] = {"^\\d{4}|\\d{8}$", NULL};
|
char *PIN[] = {"^\\d{4}|\\d{8}$", NULL};
|
||||||
char *DestinationAddress[] = {"^\\d+/\\d+$", NULL};
|
char *DestinationAddress[] = {"^\\d+/\\d+$", NULL};
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,10 @@ extern char *SupportedFrequencyBands[];
|
||||||
extern char *Provider_Bridge_Type[];
|
extern char *Provider_Bridge_Type[];
|
||||||
extern char *AdvPreferredRouterFlag[];
|
extern char *AdvPreferredRouterFlag[];
|
||||||
extern char *PowerState[];
|
extern char *PowerState[];
|
||||||
|
extern char *FW_Mode[];
|
||||||
|
|
||||||
|
#define CRONTABS_ROOT "/etc/crontabs/root"
|
||||||
|
#define ACTIVATE_HANDLER_FILE "/usr/share/bbfdm/bbf_activate_handler.sh"
|
||||||
#define UPTIME "/proc/uptime"
|
#define UPTIME "/proc/uptime"
|
||||||
#define DEFAULT_CONFIG_DIR "/etc/config/"
|
#define DEFAULT_CONFIG_DIR "/etc/config/"
|
||||||
#define PROC_ROUTE "/proc/net/route"
|
#define PROC_ROUTE "/proc/net/route"
|
||||||
|
|
|
||||||
94
scripts/bbf_activate_handler.sh
Executable file
94
scripts/bbf_activate_handler.sh
Executable file
|
|
@ -0,0 +1,94 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Script to activate image in specified time.
|
||||||
|
#
|
||||||
|
# Copyright © 2022 IOPSYS Software Solutions AB
|
||||||
|
# Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||||
|
#
|
||||||
|
|
||||||
|
CHECK_IDLE_FILE="/usr/share/bbfdm/bbf_check_idle.sh"
|
||||||
|
RETRY_TIME=300
|
||||||
|
START_TIME=$(date +%s)
|
||||||
|
MODE="${1}"
|
||||||
|
|
||||||
|
log() {
|
||||||
|
echo "${@}"|logger -t usp.activate_firmware -p info
|
||||||
|
}
|
||||||
|
|
||||||
|
activate_and_reboot_device() {
|
||||||
|
local bank_id="${1}"
|
||||||
|
local success
|
||||||
|
|
||||||
|
success=$(ubus call fwbank set_bootbank "{'bank':${bank_id}}" | jsonfilter -e @.success)
|
||||||
|
if [ "${success}" != "true" ]; then
|
||||||
|
log "Can't activate the bank id ${bank_id}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "The device will restart after a few seconds"
|
||||||
|
ubus call rpc-sys reboot
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_whenidle_mode() {
|
||||||
|
local bank_id="${1}"
|
||||||
|
local end_time="${2}"
|
||||||
|
local force_activation="${3}"
|
||||||
|
local diff=0
|
||||||
|
|
||||||
|
[ ! -x "${CHECK_IDLE_FILE}" ] && {
|
||||||
|
activate_and_reboot_device "${bank_id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
sh "${CHECK_IDLE_FILE}"
|
||||||
|
if [ "$?" = "0" ]; then
|
||||||
|
activate_and_reboot_device "${bank_id}"
|
||||||
|
else
|
||||||
|
|
||||||
|
[ "${end_time}" -gt "$((diff + RETRY_TIME))" ] && {
|
||||||
|
sleep "${RETRY_TIME}"
|
||||||
|
}
|
||||||
|
|
||||||
|
diff=$(($(date +%s) - START_TIME))
|
||||||
|
fi
|
||||||
|
|
||||||
|
while [ "${end_time}" -gt "${diff}" ]; do
|
||||||
|
|
||||||
|
sh "${CHECK_IDLE_FILE}"
|
||||||
|
if [ "$?" = "0" ]; then
|
||||||
|
activate_and_reboot_device "${bank_id}"
|
||||||
|
else
|
||||||
|
|
||||||
|
if [ "${end_time}" -gt "$((diff + RETRY_TIME))" ]; then
|
||||||
|
sleep "${RETRY_TIME}"
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
diff=$(($(date +%s) - START_TIME))
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
[ "${force_activation}" = "1" ] && {
|
||||||
|
activate_and_reboot_device "${bank_id}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_confirmation_needed_mode() {
|
||||||
|
|
||||||
|
log "[ConfirmationNeeded] mode is not implemented"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
######################## main ########################
|
||||||
|
if [ "${MODE}" = "Immediately" ] || [ "${MODE}" = "AnyTime" ]; then
|
||||||
|
activate_and_reboot_device "${2}"
|
||||||
|
elif [ "${MODE}" = "WhenIdle" ]; then
|
||||||
|
handle_whenidle_mode "${2}" "${3}" "${4}"
|
||||||
|
elif [ "${MODE}" = "ConfirmationNeeded" ]; then
|
||||||
|
handle_confirmation_needed_mode "${2}" "${3}" "${4}" "${5}" "${6}"
|
||||||
|
else
|
||||||
|
log "[${MODE}] mode is not supported"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
11
scripts/bbf_check_idle.sh
Executable file
11
scripts/bbf_check_idle.sh
Executable file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Script to check idle state
|
||||||
|
#
|
||||||
|
# This script is used to determine if the device is in idle state or not
|
||||||
|
# And any idle state checking should be implemented here
|
||||||
|
# The value returned by this script is more important because based on it, will decide whether the image can be activated or not
|
||||||
|
# If (returned idle state == '0'), device is in idle state and can be activated. Otherwise, '1'
|
||||||
|
|
||||||
|
|
||||||
|
exit 0
|
||||||
Loading…
Add table
Reference in a new issue