Skip to content

Commit 1f50040

Browse files
committed
fix: Prevent the root check while using Apx as a library
1 parent 46cc953 commit 1f50040

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

core/utils.go

-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ import (
1313

1414
var ProcessPath string
1515

16-
func init() {
17-
if RootCheck(false) {
18-
fmt.Println("Do not run Apx as root!")
19-
os.Exit(1)
20-
}
21-
}
22-
2316
func RootCheck(display bool) bool {
2417
if os.Geteuid() != 0 {
2518
if display {

locales/en.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ apx:
55
unknownCommand: "Unknown command: %s"
66
invalidInput: "Invalid input."
77
invalidChoice: "Invalid choice."
8+
noRoot: "Do not run Apx as root."
89
info:
910
aborting: "Aborting as requested."
1011
terminal:

main.go

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package main
1010

1111
import (
1212
"embed"
13+
"os"
1314

1415
"github.com/vanilla-os/apx/cmd"
1516
"github.com/vanilla-os/apx/core"
@@ -29,6 +30,12 @@ func main() {
2930

3031
apx = cmd.New(Version, fs)
3132

33+
// check if root, exit if so
34+
if core.RootCheck(false) {
35+
cmdr.Error.Println(apx.Trans("apx.errors.noRoot"))
36+
os.Exit(1)
37+
}
38+
3239
// root command
3340
root := cmd.NewRootCommand(Version)
3441
apx.CreateRootCommand(root)

0 commit comments

Comments
 (0)