2024-09-13 18:53:05 -03:00
|
|
|
package main
|
|
|
|
|
2024-09-19 22:22:49 -03:00
|
|
|
import (
|
2024-09-20 15:19:25 -03:00
|
|
|
"log"
|
2024-09-19 22:22:49 -03:00
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2024-09-19 22:28:17 -03:00
|
|
|
const (
|
|
|
|
TMPDIR = "/tmp/spire"
|
|
|
|
PAYLOAD = TMPDIR + "/payload.json"
|
|
|
|
)
|
2024-09-13 18:53:05 -03:00
|
|
|
|
2024-09-20 15:19:25 -03:00
|
|
|
var GAME_PATH = os.Getenv("GAME_PATH")
|
2024-09-20 14:53:18 -03:00
|
|
|
|
2024-09-13 18:53:05 -03:00
|
|
|
func main() {
|
2024-09-20 14:53:18 -03:00
|
|
|
getCache()
|
2024-09-20 15:19:25 -03:00
|
|
|
if err := SanitizeInput(&GAME_PATH); err != nil {
|
|
|
|
log.Fatal("GAME_PATH is not set")
|
|
|
|
}
|
2024-09-20 15:06:43 -03:00
|
|
|
installBepinex()
|
2024-09-19 22:22:49 -03:00
|
|
|
}
|
|
|
|
|
2024-09-20 14:53:18 -03:00
|
|
|
func getCache() error {
|
2024-09-19 22:22:49 -03:00
|
|
|
info, err := os.Stat(PAYLOAD)
|
|
|
|
|
|
|
|
if err != nil {
|
2024-09-20 15:26:29 -03:00
|
|
|
// payload isn't accessible, requesting
|
2024-09-20 14:53:18 -03:00
|
|
|
DownloadCache()
|
2024-09-19 22:22:49 -03:00
|
|
|
} else if !(info.ModTime().After(time.Now().Add(-2 * time.Hour))) {
|
2024-09-20 14:53:18 -03:00
|
|
|
// download again if payload is older than 2 hours
|
|
|
|
DownloadCache()
|
2024-09-19 22:22:49 -03:00
|
|
|
}
|
2024-09-20 15:26:29 -03:00
|
|
|
// else payload was updated recently, won't update
|
2024-09-19 22:22:49 -03:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-09-20 15:06:43 -03:00
|
|
|
func installBepinex() {
|
2024-09-21 13:30:17 -03:00
|
|
|
if _, err := os.Stat(GAME_PATH + "/BepInEx"); err != nil {
|
2024-09-20 14:53:18 -03:00
|
|
|
// install bepinex
|
2024-09-20 15:06:43 -03:00
|
|
|
DownloadBepinex()
|
2024-09-19 22:22:49 -03:00
|
|
|
}
|
2024-09-20 15:26:29 -03:00
|
|
|
// else bepinex already installed
|
2024-09-13 18:53:05 -03:00
|
|
|
}
|