forked from crc-org/crc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue crc-org#570 Print a reason why root access is needed before usi…
…ng it The RunWithPrivilege func now takes a string as its first argument which is a 'reason' why root access is needed, this change is made so that users are not scared by seeing unreasonable prompt asking them to enter their password by sudo. In windows the ExecuteAsAdmin and ShellExecuteAsAdmin funcs take a first argument which is the reason why it needs to run as admin. Since the crc setup o/p is slightly changed, the integration test are updated to match the new o/p.
- Loading branch information
Showing
10 changed files
with
86 additions
and
37 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package os | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/code-ready/crc/pkg/crc/logging" | ||
) | ||
|
||
func WriteToFileAsRoot(reason, content, filepath string) error { | ||
logging.Infof("Will use root: %s", reason) | ||
cmd := exec.Command("sudo", "tee", filepath) | ||
cmd.Stdin = strings.NewReader(content) | ||
buf := new(bytes.Buffer) | ||
cmd.Stderr = buf | ||
if err := cmd.Run(); err != nil { | ||
return fmt.Errorf("Failed writing to file as root: %s: %s: %v", filepath, buf.String(), err) | ||
} | ||
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