2024-07-09 15:39:40 +09:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2024-07-15 23:29:21 +09:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2024-09-04 01:20:12 +09:00
|
|
|
|
2024-09-17 13:48:42 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/internal"
|
2024-09-04 01:20:12 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/internal/app"
|
2024-10-11 02:01:03 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/internal/shim"
|
2024-09-12 21:07:05 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/internal/verbose"
|
2024-07-09 15:39:40 +09:00
|
|
|
)
|
|
|
|
|
2024-09-04 01:20:12 +09:00
|
|
|
var (
|
2024-10-12 01:28:22 +09:00
|
|
|
flagVerbose bool
|
2024-09-04 01:20:12 +09:00
|
|
|
)
|
2024-07-09 15:39:40 +09:00
|
|
|
|
2024-10-12 01:28:22 +09:00
|
|
|
func init() {
|
|
|
|
flag.BoolVar(&flagVerbose, "v", false, "Verbose output")
|
2024-07-16 22:07:40 +09:00
|
|
|
}
|
|
|
|
|
2024-07-09 15:39:40 +09:00
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
2024-09-12 21:07:05 +09:00
|
|
|
verbose.Set(flagVerbose)
|
2024-07-15 23:29:21 +09:00
|
|
|
|
2024-09-22 00:29:36 +09:00
|
|
|
if internal.SdBootedV {
|
|
|
|
verbose.Println("system booted with systemd as init system")
|
|
|
|
}
|
|
|
|
|
2024-09-04 01:20:12 +09:00
|
|
|
// launcher payload early exit
|
2024-09-22 00:29:36 +09:00
|
|
|
if printVersion && printLicense {
|
2024-10-11 02:01:03 +09:00
|
|
|
shim.Try()
|
2024-09-22 00:29:36 +09:00
|
|
|
}
|
2024-07-15 23:29:21 +09:00
|
|
|
|
2024-10-12 19:46:40 +09:00
|
|
|
// version/license/template command early exit
|
2024-09-04 01:20:12 +09:00
|
|
|
tryVersion()
|
|
|
|
tryLicense()
|
2024-10-12 19:46:40 +09:00
|
|
|
tryTemplate()
|
2024-09-04 01:20:12 +09:00
|
|
|
|
2024-09-22 00:29:36 +09:00
|
|
|
// state query command early exit
|
|
|
|
tryState()
|
|
|
|
|
|
|
|
// invoke app
|
|
|
|
r := 1
|
|
|
|
a := app.New()
|
2024-10-12 01:51:06 +09:00
|
|
|
if err := a.Seal(loadConfig()); err != nil {
|
2024-09-22 00:29:36 +09:00
|
|
|
logBaseError(err, "fortify: cannot seal app:")
|
|
|
|
} else if err = a.Start(); err != nil {
|
|
|
|
logBaseError(err, "fortify: cannot start app:")
|
|
|
|
} else if r, err = a.Wait(); err != nil {
|
2024-10-12 02:11:43 +09:00
|
|
|
if r < 1 {
|
|
|
|
r = 1
|
2024-09-09 03:16:54 +09:00
|
|
|
}
|
2024-10-12 02:11:43 +09:00
|
|
|
logWaitError(err)
|
2024-09-09 03:16:54 +09:00
|
|
|
}
|
2024-09-22 00:29:36 +09:00
|
|
|
if err := a.WaitErr(); err != nil {
|
|
|
|
fmt.Println("fortify: inner wait failed:", err)
|
|
|
|
}
|
|
|
|
os.Exit(r)
|
|
|
|
}
|