Allow installer to run without sudo & only need it when need to install Docker

This commit is contained in:
Socheat Sok 2025-05-29 15:59:21 +07:00
parent b467d6afa1
commit 56fd366a7d
No known key found for this signature in database
GPG key ID: 8967527396F3D1B5

View file

@ -57,12 +57,6 @@ type Config struct {
func main() {
reader := bufio.NewReader(os.Stdin)
// check if the user is root
if os.Geteuid() != 0 {
fmt.Println("This script must be run as root")
os.Exit(1)
}
var config Config
// check if there is already a config file
@ -81,6 +75,15 @@ func main() {
moveFile("config/docker-compose.yml", "docker-compose.yml")
if !isDockerInstalled() && runtime.GOOS == "linux" {
// Prompt to install Docker if not installed
// But only if the user is root, otherwise we exit with an error message
if os.Geteuid() != 0 {
fmt.Println("Docker is not installed. Please install Docker manually or run this installer as root.")
fmt.Println("You can run this installer with 'sudo' to install Docker automatically.")
fmt.Println("Exiting...")
os.Exit(1)
}
if readBool(reader, "Docker is not installed. Would you like to install it?", true) {
installDocker()
}
@ -619,4 +622,4 @@ func generateRandomSecretKey() string {
b[i] = charset[seededRand.Intn(len(charset))]
}
return string(b)
}
}