Skip to content

Commit 465d65c

Browse files
authored
Image Customizer: Remove "sudo" calls. (#10803)
You don't need to call "sudo" if the entire program is run as root already.
1 parent 6c73712 commit 465d65c

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

toolkit/tools/pkg/imagecustomizerlib/customizeoverlays.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func addEquivalencyRules(selinuxMode imagecustomizerapi.SELinuxMode,
176176

177177
for _, overlay := range overlays {
178178
err = imageChroot.UnsafeRun(func() error {
179-
return shell.ExecuteLiveWithErr(1, "sudo", "semanage", "fcontext", "-a", "-e", overlay.MountPoint, overlay.UpperDir)
179+
return shell.ExecuteLiveWithErr(1, "semanage", "fcontext", "-a", "-e", overlay.MountPoint, overlay.UpperDir)
180180
})
181181
if err != nil {
182182
return fmt.Errorf("failed to add equivalency rule between %s and %s:\n%w", overlay.MountPoint, overlay.UpperDir, err)

toolkit/tools/pkg/imagecustomizerlib/shrinkfilesystems.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ func shrinkFilesystems(imageLoopDevice string, verityHashPartition *imagecustomi
7979
}
8080

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

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

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

0 commit comments

Comments
 (0)