2024-01-27 11:20:40 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2024-01-28 15:31:58 +01:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
2024-01-29 16:45:51 +01:00
|
|
|
"golang.org/x/sync/errgroup"
|
2024-01-27 11:20:40 +01:00
|
|
|
|
|
|
|
"git.jmbit.de/jmb/podterminal/pods"
|
|
|
|
"git.jmbit.de/jmb/podterminal/utils"
|
|
|
|
"git.jmbit.de/jmb/podterminal/web"
|
|
|
|
)
|
|
|
|
|
2024-01-29 16:45:51 +01:00
|
|
|
var (
|
|
|
|
g errgroup.Group
|
|
|
|
)
|
|
|
|
|
2024-01-27 11:20:40 +01:00
|
|
|
func main() {
|
2024-01-28 15:31:58 +01:00
|
|
|
readConfigFile()
|
2024-01-27 11:20:40 +01:00
|
|
|
pods.ConnectSocket()
|
2024-01-29 16:45:51 +01:00
|
|
|
|
|
|
|
// Start Webserver
|
|
|
|
g.Go(web.Run)
|
|
|
|
|
2024-01-27 11:20:40 +01:00
|
|
|
utils.DropPrivileges("podterminal")
|
2024-01-28 15:31:58 +01:00
|
|
|
log.Println("Dropped Privileges")
|
2024-01-29 16:45:51 +01:00
|
|
|
g.Go(pods.GarbageCollector)
|
|
|
|
g.Go(pods.PullImage)
|
|
|
|
|
|
|
|
// prevent main thread from dying
|
|
|
|
if err := g.Wait(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2024-01-27 11:20:40 +01:00
|
|
|
}
|
2024-01-28 15:31:58 +01:00
|
|
|
|
|
|
|
func readConfigFile() {
|
|
|
|
log.Println("Reading Config")
|
|
|
|
viper.SetConfigFile("/etc/podterminal/config.yaml")
|
|
|
|
viper.SetDefault("port", 80)
|
2024-01-29 16:45:51 +01:00
|
|
|
viper.SetDefault("ip_addr", "0.0.0.0")
|
2024-01-28 15:31:58 +01:00
|
|
|
viper.SetDefault("image", "lscr.io/linuxserver/webtop")
|
|
|
|
viper.SetDefault("maxAge", 10800)
|
|
|
|
viper.SetDefault("dri", false)
|
|
|
|
viper.SetDefault("dir_node", "/dev/dri/renderD128")
|
2024-01-29 16:45:51 +01:00
|
|
|
viper.SetDefault("skel", "/etc/podterminal/skel")
|
2024-01-28 15:31:58 +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")
|
|
|
|
}
|