2018-04-28 22:02:36 +08:00
|
|
|
//go:generate go run assets-generator.go
|
|
|
|
|
2018-01-26 18:40:01 +08:00
|
|
|
package main
|
|
|
|
|
2018-01-28 14:55:43 +08:00
|
|
|
import (
|
2018-03-05 08:14:58 +08:00
|
|
|
"os"
|
2018-03-09 22:15:45 +08:00
|
|
|
fp "path/filepath"
|
2018-03-05 08:14:58 +08:00
|
|
|
|
2018-01-28 14:55:43 +08:00
|
|
|
"github.com/RadhiFadlillah/shiori/cmd"
|
2018-04-28 22:02:36 +08:00
|
|
|
dt "github.com/RadhiFadlillah/shiori/database"
|
2018-03-05 08:14:58 +08:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
2018-05-01 11:12:55 +08:00
|
|
|
apppaths "github.com/muesli/go-app-paths"
|
|
|
|
"github.com/sirupsen/logrus"
|
2018-01-28 14:55:43 +08:00
|
|
|
)
|
2018-01-26 18:40:01 +08:00
|
|
|
|
|
|
|
func main() {
|
2018-05-01 11:12:55 +08:00
|
|
|
// Create database path
|
|
|
|
dbPath := createDatabasePath()
|
2018-03-09 22:15:45 +08:00
|
|
|
|
2018-05-01 11:12:55 +08:00
|
|
|
// Make sure directory exist
|
|
|
|
os.MkdirAll(fp.Dir(dbPath), os.ModePerm)
|
2018-03-05 08:14:58 +08:00
|
|
|
|
2018-05-01 11:12:55 +08:00
|
|
|
// Open database
|
|
|
|
sqliteDB, err := dt.OpenSQLiteDatabase(dbPath)
|
2018-03-05 08:14:58 +08:00
|
|
|
checkError(err)
|
|
|
|
|
2018-05-01 11:12:55 +08:00
|
|
|
// Start cmd
|
2018-04-28 22:02:36 +08:00
|
|
|
shioriCmd := cmd.NewShioriCmd(sqliteDB)
|
|
|
|
if err := shioriCmd.Execute(); err != nil {
|
|
|
|
logrus.Fatalln(err)
|
|
|
|
}
|
2018-03-05 08:14:58 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 11:12:55 +08:00
|
|
|
func createDatabasePath() string {
|
|
|
|
// Try to look at environment variables
|
|
|
|
dbPath, found := os.LookupEnv("ENV_SHIORI_DB")
|
|
|
|
if found {
|
|
|
|
// If ENV_SHIORI_DB is directory, append "shiori.db" as filename
|
|
|
|
if f1, err := os.Stat(dbPath); err == nil && f1.IsDir() {
|
|
|
|
dbPath = fp.Join(dbPath, "shiori.db")
|
|
|
|
}
|
|
|
|
|
|
|
|
return dbPath
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to use platform specific app path
|
|
|
|
userScope := apppaths.NewScope(apppaths.User, "shiori", "shiori")
|
|
|
|
dataDir, err := userScope.DataDir()
|
|
|
|
if err == nil {
|
|
|
|
return fp.Join(dataDir, "shiori.db")
|
2018-03-12 17:45:49 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 11:12:55 +08:00
|
|
|
// When all fail, create database in working directory
|
|
|
|
return "shiori.db"
|
2018-03-12 17:45:49 +08:00
|
|
|
}
|
|
|
|
|
2018-03-05 08:14:58 +08:00
|
|
|
func checkError(err error) {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|