mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
System upgrade
This commit is contained in:
parent
3c080c7c24
commit
2e2f0937f1
6 changed files with 98 additions and 14 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
npm install
|
||||
sudo npm install -g grunt-cli
|
||||
sudo npm install -g grunt-cli
|
||||
sudo npm install -g mocha
|
||||
sudo npm install -g bower
|
||||
|
|
|
|||
|
|
@ -27,14 +27,19 @@
|
|||
<p>{{'settings.upgrade.online.info'|translate}}</p>
|
||||
<luci-config-lines>
|
||||
<luci-config-line title="">
|
||||
<button class="btn btn-lg btn-default">{{'Check for Update'|translate}}</button>
|
||||
<strong ng-show="onlineUpgrade">New version available: {{onlineUpgrade}}</strong>
|
||||
<button ng-hide="onlineUpgrade" class="btn btn-lg btn-default">{{'Check for Update'|translate}}</button>
|
||||
<button ng-show="onlineUpgrade" class="btn btn-lg btn-default">{{'Upgrade'|translate}}</button>
|
||||
</luci-config-line>
|
||||
</luci-config-lines>
|
||||
<h3>{{'USB Firmware Upgrade'|translate}}</h3>
|
||||
<p>{{'settings.upgrade.usb.info'|translate}}</p>
|
||||
<luci-config-lines>
|
||||
<luci-config-line title="{{'Firmware File: '|translate}} - {{usbFileName}}">
|
||||
<button class="btn btn-lg btn-default">{{'Install Upgrade'|translate}}</button>
|
||||
<luci-config-line title="{{usbUpgrade}}" ng-show="usbUpgrade">
|
||||
<button class="btn btn-lg btn-default" ng-click="onUpgradeUSB()">{{'Install Upgrade'|translate}}</button>
|
||||
</luci-config-line>
|
||||
<luci-config-line title="{{usbUpgrade}}" ng-hide="usbUpgrade">
|
||||
<button class="btn btn-lg btn-default" ng-click="onCheckUSB()">{{'Check for Update'|translate}}</button>
|
||||
</luci-config-line>
|
||||
</luci-config-lines>
|
||||
</luci-config-section>
|
||||
|
|
|
|||
|
|
@ -115,6 +115,14 @@ $juci.module("settings")
|
|||
$scope.usbFileName = "()";
|
||||
console.log("SID: "+$scope.sessionID);
|
||||
|
||||
function upgradeStart(path){
|
||||
$rpc.luci2.system.upgrade_start({"path": path}).done(function(){
|
||||
alert("Upgrade process has started. The web gui will not be available until the process has finished and the box has restarted!");
|
||||
}).fail(function(response){
|
||||
alert("Upgrade process failed! "+JSON.stringify(result||""));
|
||||
});
|
||||
}
|
||||
|
||||
$uci.sync("system").done(function(){
|
||||
if($uci.system.upgrade && $uci.system.upgrade.fw_upload_path.value){
|
||||
$scope.uploadFilename = $uci.system.upgrade.fw_upload_path.value;
|
||||
|
|
@ -122,6 +130,24 @@ $juci.module("settings")
|
|||
}
|
||||
});
|
||||
|
||||
$scope.onCheckOnline = function(){
|
||||
$rpc.luci2.system.upgrade_check({type: "online"}).done(function(response){
|
||||
$scope.onlineUpgrade = response.stdout.replace("\n", "");
|
||||
});
|
||||
}
|
||||
$scope.onUpgradeOnline = function(){
|
||||
upgradeStart($scope.onlineUpgrade);
|
||||
}
|
||||
|
||||
$scope.onCheckUSB = function(){
|
||||
$rpc.luci2.system.upgrade_check({type: "usb"}).done(function(response){
|
||||
$scope.usbUpgrade = response.stdout.replace("\n", "");
|
||||
});
|
||||
}
|
||||
$scope.onUpgradeUSB = function(){
|
||||
upgradeStart($scope.usbUpgrade);
|
||||
}
|
||||
|
||||
$scope.onUploadComplete = function(result){
|
||||
console.log("Upload completed: "+JSON.stringify(result));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,20 @@ describe("Settings", function(){
|
|||
it("should have required rpc functions", function(){
|
||||
expect($rpc.luci2.system.password_set).to.be.a(Function);
|
||||
});
|
||||
it("should be able to check for online upgrade", function(done){
|
||||
$rpc.luci2.system.upgrade_check({type: "online"}).done(function(){
|
||||
done();
|
||||
}).fail(function(){
|
||||
throw new Error("Could not check for online upgrade!");
|
||||
});
|
||||
});
|
||||
it("should be able to check for usb upgrade", function(done){
|
||||
$rpc.luci2.system.upgrade_check({type: "usb"}).done(function(){
|
||||
done();
|
||||
}).fail(function(){
|
||||
throw new Error("Could not check for online upgrade!");
|
||||
});
|
||||
});
|
||||
it("should not be able to set password without providing current password", function(done){
|
||||
console.log("Trying to set password for user "+PARAMS.username);
|
||||
$rpc.luci2.system.password_set({"user": PARAMS.username, "password": "abrakadabra"}).done(function(){
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@
|
|||
"sshkeys_get",
|
||||
"upgrade_test",
|
||||
"upgrade_clean",
|
||||
"upgrade_check",
|
||||
"upgrade_start"
|
||||
],
|
||||
"asterisk": [
|
||||
|
|
|
|||
|
|
@ -1039,7 +1039,8 @@ rpc_luci2_upgrade_test(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
struct ubus_request_data *req, const char *method,
|
||||
struct blob_attr *msg)
|
||||
{
|
||||
const char *fwpath = "/tmp/firmware.bin";
|
||||
const char fwpath[255];
|
||||
strcpy(fwpath, "/tmp/firmware.bin");
|
||||
|
||||
struct uci_package *p;
|
||||
struct uci_element *e;
|
||||
|
|
@ -1066,7 +1067,7 @@ rpc_luci2_upgrade_test(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
|
||||
if (ptr.o && ptr.o->type == UCI_TYPE_STRING)
|
||||
{
|
||||
fwpath = strdup(ptr.o->v.string);
|
||||
strncpy(fwpath, sizeof(fwpath), ptr.o->v.string);
|
||||
}
|
||||
|
||||
uci_unload(cursor, p);
|
||||
|
|
@ -1081,15 +1082,51 @@ rpc_luci2_upgrade_start(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
struct ubus_request_data *req, const char *method,
|
||||
struct blob_attr *msg)
|
||||
{
|
||||
struct blob_attr *tb[__RPC_BACKUP_MAX];
|
||||
const char fwpath[255];
|
||||
strcpy(fwpath, "/tmp/firmware.bin");
|
||||
|
||||
blobmsg_parse(rpc_backup_policy, __RPC_BACKUP_MAX, tb,
|
||||
blob_data(msg), blob_len(msg));
|
||||
|
||||
struct blob_attr *filename = tb[RPC_BACKUP_PASSWORD];
|
||||
|
||||
if (filename && blobmsg_data_len(filename) > 0 && blobmsg_data(filename) && strlen(blobmsg_data(filename)) > 0){
|
||||
const char *cmd[] = { "sysupgrade", blobmsg_data(filename), NULL };
|
||||
//const char *keep = "";
|
||||
bool found = false;
|
||||
|
||||
struct blob_attr *tb[__RPC_UPGRADE_MAX];
|
||||
blobmsg_parse(rpc_upgrade_policy, __RPC_UPGRADE_MAX, tb, blob_data(msg), blob_len(msg));
|
||||
|
||||
if (tb[RPC_UPGRADE_PATH] && strlen(blobmsg_data(tb[RPC_UPGRADE_PATH]))) {
|
||||
fwpath = strncpy(fwpath, sizeof(fwpath), blobmsg_data(tb[RPC_UPGRADE_PATH]));
|
||||
found = true;
|
||||
}
|
||||
|
||||
/* if (tb[RPC_UPGRADE_KEEP] && !blobmsg_data(tb[RPC_UPGRADE_KEEP]))*/
|
||||
/* keep = "-n";*/
|
||||
|
||||
struct uci_package *p;
|
||||
struct uci_element *e;
|
||||
struct uci_section *s;
|
||||
struct uci_ptr ptr = { .package = "system" };
|
||||
|
||||
if (!found)
|
||||
uci_load(cursor, ptr.package, &p);
|
||||
|
||||
if (p)
|
||||
{
|
||||
uci_foreach_element(&p->sections, e)
|
||||
{
|
||||
s = uci_to_section(e);
|
||||
|
||||
if (strcmp(s->type, "upgrade"))
|
||||
continue;
|
||||
|
||||
ptr.o = NULL;
|
||||
ptr.option = "fw_upload_path";
|
||||
ptr.section = e->name;
|
||||
uci_lookup_ptr(cursor, &ptr, NULL, true);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ptr.o && ptr.o->type == UCI_TYPE_STRING)
|
||||
{
|
||||
strncpy(fwpath, sizeof(fwpath), ptr.o->v.string);
|
||||
}
|
||||
|
||||
return ops->exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue