Skip to content

Commit

Permalink
Add label parameter for format and luks-format
Browse files Browse the repository at this point in the history
  • Loading branch information
matbme committed Nov 10, 2023
1 parent 758d832 commit 9fdeb69
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions RECIPE.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Format an existing partition to a specified filesystem. This operation will dest
**Accepts**:
- *PartNum* (`int`): The partition number on disk (e.g. `/dev/sda3` is partition 3).
- *FsType* (`string`): The filesystem for the partition. Can be either `btrfs`, `ext[2,3,4]`, `linux-swap`, `ntfs`\*, `reiserfs`\*, `udf`\*, or `xfs`\*.
- *Label* (optional `string`): An optional filesystem label. If not given, no label will be set.

### luks-format

Expand All @@ -75,6 +76,7 @@ Same as `format` but encrypts the partition with LUKS2.
- *PartNum* (`int`): The partition number on disk (e.g. `/dev/sda3` is partition 3).
- *FsType* (`string`): The filesystem for the partition. Can be either `btrfs`, `ext[2,3,4]`, `linux-swap`, `ntfs`\*, `reiserfs`\*, `udf`\*, or `xfs`\*.
- *Password* (`string`): The password used to encrypt the partition.
- *Label* (optional `string`): An optional filesystem label. If not given, no label will be set.

### pvcreate

Expand Down
16 changes: 16 additions & 0 deletions core/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ func runSetupOperation(diskLabel, operation string, args []interface{}) error {
* **Accepts**:
* - *PartNum* (`int`): The partition number on disk (e.g. `/dev/sda3` is partition 3).
* - *FsType* (`string`): The filesystem for the partition. Can be either `btrfs`, `ext[2,3,4]`, `linux-swap`, `ntfs`\*, `reiserfs`\*, `udf`\*, or `xfs`\*.
* - *Label* (optional `string`): An optional filesystem label. If not given, no label will be set.
*/
case "format":
partNum, err := strconv.Atoi(args[0].(string))
Expand All @@ -246,6 +247,13 @@ func runSetupOperation(diskLabel, operation string, args []interface{}) error {
if err != nil {
return fmt.Errorf("failed to execute operation %s: %s", operation, err)
}
if len(args) == 3 {
label := args[2].(string)
err := disk.Partitions[partNum-1].SetLabel(label)
if err != nil {
return fmt.Errorf("failed to execute operation %s: %s", operation, err)
}
}
/* !! ### luks-format
*
* Same as `format` but encrypts the partition with LUKS2.
Expand All @@ -254,6 +262,7 @@ func runSetupOperation(diskLabel, operation string, args []interface{}) error {
* - *PartNum* (`int`): The partition number on disk (e.g. `/dev/sda3` is partition 3).
* - *FsType* (`string`): The filesystem for the partition. Can be either `btrfs`, `ext[2,3,4]`, `linux-swap`, `ntfs`\*, `reiserfs`\*, `udf`\*, or `xfs`\*.
* - *Password* (`string`): The password used to encrypt the partition.
* - *Label* (optional `string`): An optional filesystem label. If not given, no label will be set.
*/
case "luks-format":
partNum, err := strconv.Atoi(args[0].(string))
Expand Down Expand Up @@ -282,6 +291,13 @@ func runSetupOperation(diskLabel, operation string, args []interface{}) error {
if err != nil {
return fmt.Errorf("failed to execute operation %s: %s", operation, err)
}
if len(args) == 4 {
label := args[3].(string)
err := LUKSSetLabel(&part, label)
if err != nil {
return fmt.Errorf("failed to execute operation %s: %s", operation, err)
}
}
/* !! ### pvcreate
*
* Creates a new LVM physical volume from a partition.
Expand Down
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
albius (0.3.2) unstable; urgency=critical

* Fix luks-format command crash
* Add optional "label" parameter in format and luks-format

-- Mateus Melchiades <matbme@duck.com> Sat, 10 Nov 2023 20:20:00 -0300

Expand Down

0 comments on commit 9fdeb69

Please sign in to comment.