diff mbox series

[isar-cip-core,RFC,v2] swupdate.bbclass: add script section to the swu file

Message ID 20240124094502.293170-1-Quirin.Gylstorff@siemens.com (mailing list archive)
State Superseded
Headers show
Series [isar-cip-core,RFC,v2] swupdate.bbclass: add script section to the swu file | expand

Commit Message

Gylstorff Quirin Jan. 24, 2024, 9:44 a.m. UTC
From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

This allows the user to add scripts[1] to the swu file by
setting the variable `SWU_SCRIPTS`. Scripts can be used to
prepare the system for an update.

```
SWU_SCRIPTS = "<script_file_name>@<script_type>@<optional_data>"
```
This will add  `file://<script_file_name>` to the variable `SRC_URI` and
`<script_file_name>` to `SWU_ADDTIONAL_FILES`. The sw-description will contain
the following section:
```
    scripts: (
        {
          filename = "<script_file_name>";
          type = "<script_type>";
          data = "<optional_data>";
          sha256 = "<sha256 of postinstall.sh>";
        },):
```

[1]: https://sbabic.github.io/swupdate/sw-description.html?#scripts

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---

Changes v2:
 - change seperator from `:` to `@` as it already used for the
   configfilecheck
 - add optional data entry
 - add warning if less then 2 parameters are given for entry

 classes/swupdate.bbclass                    | 37 +++++++++++++++++++++
 doc/README.swupdate.md                      | 30 +++++++++++++++++
 recipes-core/images/swu/sw-description.tmpl |  1 +
 3 files changed, 68 insertions(+)

Comments

Felix Moessbauer Jan. 25, 2024, 8:43 a.m. UTC | #1
On Wed, 2024-01-24 at 10:44 +0100, Quirin Gylstorff wrote:
> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> 
> This allows the user to add scripts[1] to the swu file by
> setting the variable `SWU_SCRIPTS`. Scripts can be used to
> prepare the system for an update.
> 
> ```
> SWU_SCRIPTS = "<script_file_name>@<script_type>@<optional_data>"
> ```
> This will add  `file://<script_file_name>` to the variable `SRC_URI`
> and
> `<script_file_name>` to `SWU_ADDTIONAL_FILES`. The sw-description
> will contain
> the following section:
> ```
>     scripts: (
>         {
>           filename = "<script_file_name>";
>           type = "<script_type>";
>           data = "<optional_data>";
>           sha256 = "<sha256 of postinstall.sh>";

---------------------------------^
shouldn't that be sha256 of <script_file_name> ?

>         },):
> ```
> 
> [1]: https://sbabic.github.io/swupdate/sw-description.html?#scripts
> 
> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> ---
> 
> Changes v2:
>  - change seperator from `:` to `@` as it already used for the
>    configfilecheck
>  - add optional data entry
>  - add warning if less then 2 parameters are given for entry
> 
>  classes/swupdate.bbclass                    | 37
> +++++++++++++++++++++
>  doc/README.swupdate.md                      | 30 +++++++++++++++++
>  recipes-core/images/swu/sw-description.tmpl |  1 +
>  3 files changed, 68 insertions(+)
> 
> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
> index 8f1215d..256a60f 100644
> --- a/classes/swupdate.bbclass
> +++ b/classes/swupdate.bbclass
> @@ -58,6 +58,7 @@ IMAGE_TEMPLATE_VARS:swu = " \
>      SWU_NAME \
>      SWU_FILE_NODES \
>      SWU_BOOTLOADER_FILE_NODE \
> +    SWU_SCRIPTS_NODE \
>      "
>  
>  # Add the bootloader file
> @@ -123,6 +124,42 @@ python add_ebg_update(){
>     d.appendVar('SWU_ADDITIONAL_FILES', " " + efi_boot_loader_file)
>  }
>  
> +SWU_EXTEND_SW_DESCRIPTION += "add_scripts"
> +python add_scripts(){
> +    swu_scripts = d.getVar('SWU_SCRIPTS')
> +    if not swu_scripts:
> +        return
> +    swu_script_entries = [ s for s in swu_scripts.split() ]
> +    script_node_list = []
> +    for entry in swu_script_entries:
> +        script_elems = entry.split('@')
> +        if len(script_elems) < 2:
> +            bb.warn(f"SWU_SCRIPTS entry:'{entry}' is missing
> elements.")
> +            continue
> +
> +        script_file = script_elems[0]
> +        script_type = script_elems[1]
> +        script_data = None
> +        if len(script_elems) > 2:
> +            script_data = script_elems[2]
> +        node = f"""
> +        {{
> +          filename = "{script_file}";
> +          type = "{script_type}";
> +        """
> +        if script_data:
> +            node += f"""  data = "{script_data}";"""
> +        node += f"""
> +          sha256 = "{script_file}-sha256";
> +        }}"""
> +        script_node_list.append(node)
> +        d.appendVar('SWU_ADDITIONAL_FILES', " " + script_file)
> +        d.appendVar('SRC_URI', f" file://{script_file}")
> +
> +    swu_scripts_node = "scripts: (" + ','.join([n for n in
> script_node_list]) + ");"
> +    d.appendVar('SWU_SCRIPTS_NODE', swu_scripts_node)
> +}
> +
>  # convert between swupdate compressor name and imagetype extension
>  def get_swu_compression_type(d):
>      swu_ct = d.getVar('SWU_COMPRESSION_TYPE')
> diff --git a/doc/README.swupdate.md b/doc/README.swupdate.md
> index 1c94699..b393caa 100644
> --- a/doc/README.swupdate.md
> +++ b/doc/README.swupdate.md
> @@ -21,6 +21,36 @@ window is still possible.
>  If the variable `SWU_EBG_UPDATE` is set to `"1"` the update is also
> stored in
>  the `*.swu` file.
>  
> +## SWUpdate scripts
> +
> +It is possible to add
> [scripts](https://sbabic.github.io/swupdate/sw-description.html?#scri
> pts) to a swu file.
> +
> +To add a script entry in isar-cip-core set the variable
> `SWU_SCRIPTS`.
> +The content of the variable has the following pattern:
> +`<script_file_name>@<script_type>@<optional_data>`
> +
> +The file referenced by `<script_file_name>` is added to the
> variables `SRC_URI`
> +and `SWU_ADDITIONAL_FILES`. Therefore, it needs to be safed in a
> `FILESPATH`
> +location.
> +
> +Example:
> +
> +```
> +SWU_SCRIPTS = "postinstall.sh@postinstall@some_data"
> +```
> +This will add  `file://postinstall.sh` to the variable `SRC_URI` and
> +`postinstall.sh` to `SWU_ADDTIONAL_FILES`. The sw-description will
> contain

How about the lua scripts, where the preinst / postinst are just
functions within a single script? Could you please also give an example
regarding how to specify that.

Felix

> +the following section:
> +```
> +    scripts: (
> +        {
> +          filename = "postinstall.sh";
> +          type = "postinstall";
> +          data = "some_data"
> +          sha256 = "<sha256 of postinstall.sh>";
> +        },):
> +```
> +
>  # Building and testing the CIP Core image
>  
>  Set up `kas-container` as described in the [top-level
> README](../README.md).
> diff --git a/recipes-core/images/swu/sw-description.tmpl b/recipes-
> core/images/swu/sw-description.tmpl
> index c52372c..88cb475 100644
> --- a/recipes-core/images/swu/sw-description.tmpl
> +++ b/recipes-core/images/swu/sw-description.tmpl
> @@ -35,4 +35,5 @@ software =
>              };
>              sha256 = "linux.efi-sha256";
>      }${SWU_FILE_NODES});
> +    ${SWU_SCRIPTS_NODE}
>  }
Gylstorff Quirin Jan. 25, 2024, 9:07 a.m. UTC | #2
On 1/25/24 09:43, Moessbauer, Felix (T CED OES-DE) wrote:
> On Wed, 2024-01-24 at 10:44 +0100, Quirin Gylstorff wrote:
>> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>
>> This allows the user to add scripts[1] to the swu file by
>> setting the variable `SWU_SCRIPTS`. Scripts can be used to
>> prepare the system for an update.
>>
>> ```
>> SWU_SCRIPTS = "<script_file_name>@<script_type>@<optional_data>"
>> ```
>> This will add  `file://<script_file_name>` to the variable `SRC_URI`
>> and
>> `<script_file_name>` to `SWU_ADDTIONAL_FILES`. The sw-description
>> will contain
>> the following section:
>> ```
>>      scripts: (
>>          {
>>            filename = "<script_file_name>";
>>            type = "<script_type>";
>>            data = "<optional_data>";
>>            sha256 = "<sha256 of postinstall.sh>";
> 
> ---------------------------------^
> shouldn't that be sha256 of <script_file_name> ?

copy paste from the readme.
> 
>>          },):
>> ```
>>
>> [1]: https://sbabic.github.io/swupdate/sw-description.html?#scripts
>>
>> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>> ---
>>
>> Changes v2:
>>   - change seperator from `:` to `@` as it already used for the
>>     configfilecheck
>>   - add optional data entry
>>   - add warning if less then 2 parameters are given for entry
>>
>>   classes/swupdate.bbclass                    | 37
>> +++++++++++++++++++++
>>   doc/README.swupdate.md                      | 30 +++++++++++++++++
>>   recipes-core/images/swu/sw-description.tmpl |  1 +
>>   3 files changed, 68 insertions(+)
>>
>> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
>> index 8f1215d..256a60f 100644
>> --- a/classes/swupdate.bbclass
>> +++ b/classes/swupdate.bbclass
>> @@ -58,6 +58,7 @@ IMAGE_TEMPLATE_VARS:swu = " \
>>       SWU_NAME \
>>       SWU_FILE_NODES \
>>       SWU_BOOTLOADER_FILE_NODE \
>> +    SWU_SCRIPTS_NODE \
>>       "
>>   
>>   # Add the bootloader file
>> @@ -123,6 +124,42 @@ python add_ebg_update(){
>>      d.appendVar('SWU_ADDITIONAL_FILES', " " + efi_boot_loader_file)
>>   }
>>   
>> +SWU_EXTEND_SW_DESCRIPTION += "add_scripts"
>> +python add_scripts(){
>> +    swu_scripts = d.getVar('SWU_SCRIPTS')
>> +    if not swu_scripts:
>> +        return
>> +    swu_script_entries = [ s for s in swu_scripts.split() ]
>> +    script_node_list = []
>> +    for entry in swu_script_entries:
>> +        script_elems = entry.split('@')
>> +        if len(script_elems) < 2:
>> +            bb.warn(f"SWU_SCRIPTS entry:'{entry}' is missing
>> elements.")
>> +            continue
>> +
>> +        script_file = script_elems[0]
>> +        script_type = script_elems[1]
>> +        script_data = None
>> +        if len(script_elems) > 2:
>> +            script_data = script_elems[2]
>> +        node = f"""
>> +        {{
>> +          filename = "{script_file}";
>> +          type = "{script_type}";
>> +        """
>> +        if script_data:
>> +            node += f"""  data = "{script_data}";"""
>> +        node += f"""
>> +          sha256 = "{script_file}-sha256";
>> +        }}"""
>> +        script_node_list.append(node)
>> +        d.appendVar('SWU_ADDITIONAL_FILES', " " + script_file)
>> +        d.appendVar('SRC_URI', f" file://{script_file}")
>> +
>> +    swu_scripts_node = "scripts: (" + ','.join([n for n in
>> script_node_list]) + ");"
>> +    d.appendVar('SWU_SCRIPTS_NODE', swu_scripts_node)
>> +}
>> +
>>   # convert between swupdate compressor name and imagetype extension
>>   def get_swu_compression_type(d):
>>       swu_ct = d.getVar('SWU_COMPRESSION_TYPE')
>> diff --git a/doc/README.swupdate.md b/doc/README.swupdate.md
>> index 1c94699..b393caa 100644
>> --- a/doc/README.swupdate.md
>> +++ b/doc/README.swupdate.md
>> @@ -21,6 +21,36 @@ window is still possible.
>>   If the variable `SWU_EBG_UPDATE` is set to `"1"` the update is also
>> stored in
>>   the `*.swu` file.
>>   
>> +## SWUpdate scripts
>> +
>> +It is possible to add
>> [scripts](https://sbabic.github.io/swupdate/sw-description.html?#scri
>> pts) to a swu file.
>> +
>> +To add a script entry in isar-cip-core set the variable
>> `SWU_SCRIPTS`.
>> +The content of the variable has the following pattern:
>> +`<script_file_name>@<script_type>@<optional_data>`
>> +
>> +The file referenced by `<script_file_name>` is added to the
>> variables `SRC_URI`
>> +and `SWU_ADDITIONAL_FILES`. Therefore, it needs to be safed in a
>> `FILESPATH`
>> +location.
>> +
>> +Example:
>> +
>> +```
>> +SWU_SCRIPTS = "postinstall.sh@postinstall@some_data"
>> +```
>> +This will add  `file://postinstall.sh` to the variable `SRC_URI` and
>> +`postinstall.sh` to `SWU_ADDTIONAL_FILES`. The sw-description will
>> contain
> 
> How about the lua scripts, where the preinst / postinst are just
> functions within a single script? Could you please also give an example
> regarding how to specify that.
>

This would be

```
SWU_SCRIPTS = "installscript.lua@lua@some_data"
```

and the installscript contains:

```
function preinst()

end

function postinst()

end
```	

I can add the script to `recipes-core/images/swu/` if this helps, but 
currently we have no functionality in cip-core.

Quirin

> Felix
> 
>> +the following section:
>> +```
>> +    scripts: (
>> +        {
>> +          filename = "postinstall.sh";
>> +          type = "postinstall";
>> +          data = "some_data"
>> +          sha256 = "<sha256 of postinstall.sh>";
>> +        },):
>> +```
>> +
>>   # Building and testing the CIP Core image
>>   
>>   Set up `kas-container` as described in the [top-level
>> README](../README.md).
>> diff --git a/recipes-core/images/swu/sw-description.tmpl b/recipes-
>> core/images/swu/sw-description.tmpl
>> index c52372c..88cb475 100644
>> --- a/recipes-core/images/swu/sw-description.tmpl
>> +++ b/recipes-core/images/swu/sw-description.tmpl
>> @@ -35,4 +35,5 @@ software =
>>               };
>>               sha256 = "linux.efi-sha256";
>>       }${SWU_FILE_NODES});
>> +    ${SWU_SCRIPTS_NODE}
>>   }
>
diff mbox series

Patch

diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
index 8f1215d..256a60f 100644
--- a/classes/swupdate.bbclass
+++ b/classes/swupdate.bbclass
@@ -58,6 +58,7 @@  IMAGE_TEMPLATE_VARS:swu = " \
     SWU_NAME \
     SWU_FILE_NODES \
     SWU_BOOTLOADER_FILE_NODE \
+    SWU_SCRIPTS_NODE \
     "
 
 # Add the bootloader file
@@ -123,6 +124,42 @@  python add_ebg_update(){
    d.appendVar('SWU_ADDITIONAL_FILES', " " + efi_boot_loader_file)
 }
 
+SWU_EXTEND_SW_DESCRIPTION += "add_scripts"
+python add_scripts(){
+    swu_scripts = d.getVar('SWU_SCRIPTS')
+    if not swu_scripts:
+        return
+    swu_script_entries = [ s for s in swu_scripts.split() ]
+    script_node_list = []
+    for entry in swu_script_entries:
+        script_elems = entry.split('@')
+        if len(script_elems) < 2:
+            bb.warn(f"SWU_SCRIPTS entry:'{entry}' is missing elements.")
+            continue
+
+        script_file = script_elems[0]
+        script_type = script_elems[1]
+        script_data = None
+        if len(script_elems) > 2:
+            script_data = script_elems[2]
+        node = f"""
+        {{
+          filename = "{script_file}";
+          type = "{script_type}";
+        """
+        if script_data:
+            node += f"""  data = "{script_data}";"""
+        node += f"""
+          sha256 = "{script_file}-sha256";
+        }}"""
+        script_node_list.append(node)
+        d.appendVar('SWU_ADDITIONAL_FILES', " " + script_file)
+        d.appendVar('SRC_URI', f" file://{script_file}")
+
+    swu_scripts_node = "scripts: (" + ','.join([n for n in script_node_list]) + ");"
+    d.appendVar('SWU_SCRIPTS_NODE', swu_scripts_node)
+}
+
 # convert between swupdate compressor name and imagetype extension
 def get_swu_compression_type(d):
     swu_ct = d.getVar('SWU_COMPRESSION_TYPE')
diff --git a/doc/README.swupdate.md b/doc/README.swupdate.md
index 1c94699..b393caa 100644
--- a/doc/README.swupdate.md
+++ b/doc/README.swupdate.md
@@ -21,6 +21,36 @@  window is still possible.
 If the variable `SWU_EBG_UPDATE` is set to `"1"` the update is also stored in
 the `*.swu` file.
 
+## SWUpdate scripts
+
+It is possible to add [scripts](https://sbabic.github.io/swupdate/sw-description.html?#scripts) to a swu file.
+
+To add a script entry in isar-cip-core set the variable `SWU_SCRIPTS`.
+The content of the variable has the following pattern:
+`<script_file_name>@<script_type>@<optional_data>`
+
+The file referenced by `<script_file_name>` is added to the variables `SRC_URI`
+and `SWU_ADDITIONAL_FILES`. Therefore, it needs to be safed in a `FILESPATH`
+location.
+
+Example:
+
+```
+SWU_SCRIPTS = "postinstall.sh@postinstall@some_data"
+```
+This will add  `file://postinstall.sh` to the variable `SRC_URI` and
+`postinstall.sh` to `SWU_ADDTIONAL_FILES`. The sw-description will contain
+the following section:
+```
+    scripts: (
+        {
+          filename = "postinstall.sh";
+          type = "postinstall";
+          data = "some_data"
+          sha256 = "<sha256 of postinstall.sh>";
+        },):
+```
+
 # Building and testing the CIP Core image
 
 Set up `kas-container` as described in the [top-level README](../README.md).
diff --git a/recipes-core/images/swu/sw-description.tmpl b/recipes-core/images/swu/sw-description.tmpl
index c52372c..88cb475 100644
--- a/recipes-core/images/swu/sw-description.tmpl
+++ b/recipes-core/images/swu/sw-description.tmpl
@@ -35,4 +35,5 @@  software =
             };
             sha256 = "linux.efi-sha256";
     }${SWU_FILE_NODES});
+    ${SWU_SCRIPTS_NODE}
 }