Skip to content

Commit

Permalink
Image Customizer: Remove "sudo" calls.
Browse files Browse the repository at this point in the history
You don't need to call "sudo" if the entire program is run as root
already.
  • Loading branch information
cwize1 committed Oct 21, 2024
1 parent 6c73712 commit f5f1540
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion toolkit/tools/pkg/imagecustomizerlib/customizeoverlays.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func addEquivalencyRules(selinuxMode imagecustomizerapi.SELinuxMode,

for _, overlay := range overlays {
err = imageChroot.UnsafeRun(func() error {
return shell.ExecuteLiveWithErr(1, "sudo", "semanage", "fcontext", "-a", "-e", overlay.MountPoint, overlay.UpperDir)
return shell.ExecuteLiveWithErr(1, "semanage", "fcontext", "-a", "-e", overlay.MountPoint, overlay.UpperDir)
})
if err != nil {
return fmt.Errorf("failed to add equivalency rule between %s and %s:\n%w", overlay.MountPoint, overlay.UpperDir, err)
Expand Down
8 changes: 4 additions & 4 deletions toolkit/tools/pkg/imagecustomizerlib/shrinkfilesystems.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ func shrinkFilesystems(imageLoopDevice string, verityHashPartition *imagecustomi
}

// Check the file system with e2fsck
err = shell.ExecuteLive(true /*squashErrors*/, "sudo", "e2fsck", "-fy", partitionLoopDevice)
err = shell.ExecuteLive(true /*squashErrors*/, "e2fsck", "-fy", partitionLoopDevice)
if err != nil {
return fmt.Errorf("failed to check %s with e2fsck:\n%w", partitionLoopDevice, err)
}

// Shrink the file system with resize2fs -M
stdout, stderr, err := shell.Execute("sudo", "resize2fs", "-M", partitionLoopDevice)
stdout, stderr, err := shell.Execute("resize2fs", "-M", partitionLoopDevice)
if err != nil {
return fmt.Errorf("failed to resize %s with resize2fs:\n%v", partitionLoopDevice, stderr)
}
Expand All @@ -103,7 +103,7 @@ func shrinkFilesystems(imageLoopDevice string, verityHashPartition *imagecustomi
}

// Resize the partition with parted resizepart
_, stderr, err = shell.ExecuteWithStdin("yes" /*stdin*/, "sudo", "parted", "---pretend-input-tty",
_, stderr, err = shell.ExecuteWithStdin("yes" /*stdin*/, "parted", "---pretend-input-tty",
imageLoopDevice, "resizepart", strconv.Itoa(partitionNumber), end)
if err != nil {
return fmt.Errorf("failed to resizepart %s with parted:\n%v", partitionLoopDevice, stderr)
Expand All @@ -121,7 +121,7 @@ func shrinkFilesystems(imageLoopDevice string, verityHashPartition *imagecustomi
// Get the start sectors of all partitions.
// Ideally, we would use 'lsblk --output START' here. But that is only available in util-linux v2.38+.
func getStartSectors(imageLoopDevice string, partitionCount int) (partitionStarts map[string]int, err error) {
stdout, stderr, err := shell.Execute("sudo", "fdisk", "--list", imageLoopDevice)
stdout, stderr, err := shell.Execute("fdisk", "--list", imageLoopDevice)
if err != nil {
return nil, fmt.Errorf("fdisk failed to list partitions:\n%v", stderr)
}
Expand Down

0 comments on commit f5f1540

Please sign in to comment.