podterminal/readConfig.go

52 lines
1.4 KiB
Go
Raw Normal View History

2024-01-30 16:45:03 +01:00
package main
import (
"log"
"os"
"github.com/spf13/viper"
"git.jmbit.de/jmb/podterminal/utils"
2024-01-30 16:45:03 +01:00
)
func readConfigFile() {
sessionKey, _ := utils.RandomString(64)
2024-01-30 16:45:03 +01:00
log.Println("Reading Config")
viper.SetConfigFile("/etc/podterminal/config.yaml")
viper.SetDefault("port", 80)
viper.SetDefault("ip_addr", "0.0.0.0")
2024-02-01 17:32:46 +01:00
viper.SetDefault("image", "git.jmbit.de/jmb/webtop-plus:latest")
2024-01-30 16:45:03 +01:00
viper.SetDefault("maxAge", 10800)
viper.SetDefault("dri", false)
viper.SetDefault("dir_node", "/dev/dri/renderD128")
2024-01-30 19:41:10 +01:00
viper.SetDefault("skel", "/etc/podterminal/skel.tar.gz")
2024-01-31 13:12:43 +01:00
viper.SetDefault("skel_chown", false)
viper.SetDefault("skel_target", "/")
2024-02-01 17:32:46 +01:00
viper.SetDefault("skel_user", "")
2024-01-30 16:45:03 +01:00
viper.SetDefault("block_filebrowser", false)
viper.SetDefault("session_key", sessionKey)
viper.SetDefault("container_port", 3000)
2024-02-03 11:11:10 +01:00
viper.SetDefault("container_protocol", "http")
viper.SetDefault("timeout_on_restart", true)
2024-01-30 16:45:03 +01:00
viper.SetDefault("envvars",
map[string]string{
"CUSTOM_USER": "user",
"PASSWORD": "",
"TITLE": "Podterminal",
},
)
if _, err := os.Stat("/etc/podterminal/config.yaml"); os.IsNotExist(err) {
log.Println("Config file does not exist, creating")
os.MkdirAll("/etc/podterminal", 755)
err := viper.WriteConfig()
if err != nil {
log.Fatalln("could not write default config", err)
}
}
err := viper.ReadInConfig()
if err != nil {
log.Fatalln("could not read config file", err)
}
log.Println("Finished reading Config")
}