-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[close #183]: Implement a update-initramfs command
- Loading branch information
1 parent
6652eac
commit d6b09fd
Showing
4 changed files
with
114 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package cmd | ||
|
||
/* License: GPLv3 | ||
Authors: | ||
Mirko Brombin <mirko@fabricators.ltd> | ||
Vanilla OS Contributors <https://github.com/vanilla-os/> | ||
Copyright: 2023 | ||
Description: | ||
ABRoot is utility which provides full immutability and | ||
atomicity to a Linux system, by transacting between | ||
two root filesystems. Updates are performed using OCI | ||
images, to ensure that the system is always in a | ||
consistent state. | ||
*/ | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/vanilla-os/abroot/core" | ||
"github.com/vanilla-os/orchid/cmdr" | ||
) | ||
|
||
func NewUpdateInitfsCommand() *cmdr.Command { | ||
cmd := cmdr.NewCommand( | ||
"update-initramfs", | ||
abroot.Trans("updateInitramfs.long"), | ||
abroot.Trans("updateInitramfs.short"), | ||
updateInitramfs, | ||
) | ||
|
||
cmd.WithBoolFlag( | ||
cmdr.NewBoolFlag( | ||
"dry-run", | ||
"d", | ||
abroot.Trans("updateInitramfs.dryRunFlag"), | ||
false)) | ||
|
||
cmd.Example = "abroot update-initramfs" | ||
|
||
return cmd | ||
} | ||
|
||
func updateInitramfs(cmd *cobra.Command, args []string) error { | ||
if !core.RootCheck(false) { | ||
cmdr.Error.Println(abroot.Trans("updateInitramfs.rootRequired")) | ||
return nil | ||
} | ||
|
||
dryRun, err := cmd.Flags().GetBool("dry-run") | ||
if err != nil { | ||
cmdr.Error.Println(err) | ||
return err | ||
} | ||
|
||
aBsys, err := core.NewABSystem() | ||
if err != nil { | ||
cmdr.Error.Println(err) | ||
return err | ||
} | ||
|
||
if dryRun { | ||
err = aBsys.RunOperation(core.DRY_RUN_INITRAMFS) | ||
} else { | ||
err = aBsys.RunOperation(core.INITRAMFS) | ||
} | ||
if err != nil { | ||
cmdr.Error.Printf(abroot.Trans("updateInitramfs.updateFailed"), err) | ||
return err | ||
} | ||
|
||
cmdr.Info.Println(abroot.Trans("updateInitramfs.updateSuccess")) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters