2017-05-11 13:39:34 +08:00
|
|
|
|
package commands
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/astaxie/beego/orm"
|
2017-06-14 09:23:29 +08:00
|
|
|
|
"github.com/lifei6671/mindoc/conf"
|
|
|
|
|
"github.com/lifei6671/mindoc/models"
|
2017-05-11 13:39:34 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//系统安装.
|
|
|
|
|
func Install() {
|
2017-06-02 16:08:14 +08:00
|
|
|
|
|
|
|
|
|
fmt.Println("Initializing...")
|
|
|
|
|
|
|
|
|
|
err := orm.RunSyncdb("default", false, true)
|
|
|
|
|
if err == nil {
|
|
|
|
|
initialization()
|
|
|
|
|
} else {
|
|
|
|
|
panic(err.Error())
|
|
|
|
|
os.Exit(1)
|
2017-05-11 13:39:34 +08:00
|
|
|
|
}
|
2017-06-02 16:08:14 +08:00
|
|
|
|
fmt.Println("Install Successfully!")
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 15:26:51 +08:00
|
|
|
|
func Version() {
|
2017-05-30 20:46:00 +08:00
|
|
|
|
if len(os.Args) >= 2 && os.Args[1] == "version" {
|
|
|
|
|
fmt.Println(conf.VERSION)
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
//初始化数据
|
|
|
|
|
func initialization() {
|
|
|
|
|
|
2017-05-31 15:26:51 +08:00
|
|
|
|
err := models.NewOption().Init()
|
2017-05-11 13:39:34 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
2017-05-25 15:19:17 +08:00
|
|
|
|
panic(err.Error())
|
2017-05-11 13:39:34 +08:00
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
member, err := models.NewMember().FindByFieldFirst("account", "admin")
|
|
|
|
|
if err == orm.ErrNoRows {
|
|
|
|
|
|
|
|
|
|
member.Account = "admin"
|
|
|
|
|
member.Avatar = "/static/images/headimgurl.jpg"
|
|
|
|
|
member.Password = "123456"
|
2017-05-24 20:31:58 +08:00
|
|
|
|
member.AuthMethod = "local"
|
2017-05-11 13:39:34 +08:00
|
|
|
|
member.Role = 0
|
|
|
|
|
member.Email = "admin@iminho.me"
|
|
|
|
|
|
|
|
|
|
if err := member.Add(); err != nil {
|
|
|
|
|
panic("Member.Add => " + err.Error())
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
book := models.NewBook()
|
|
|
|
|
|
|
|
|
|
book.MemberId = member.MemberId
|
|
|
|
|
book.BookName = "MinDoc演示项目"
|
|
|
|
|
book.Status = 0
|
|
|
|
|
book.Description = "这是一个MinDoc演示项目,该项目是由系统初始化时自动创建。"
|
|
|
|
|
book.CommentCount = 0
|
|
|
|
|
book.PrivatelyOwned = 0
|
|
|
|
|
book.CommentStatus = "closed"
|
|
|
|
|
book.Identify = "mindoc"
|
|
|
|
|
book.DocCount = 0
|
|
|
|
|
book.CommentCount = 0
|
|
|
|
|
book.Version = time.Now().Unix()
|
|
|
|
|
book.Cover = conf.GetDefaultCover()
|
|
|
|
|
book.Editor = "markdown"
|
|
|
|
|
book.Theme = "default"
|
|
|
|
|
|
|
|
|
|
if err := book.Insert(); err != nil {
|
|
|
|
|
panic("Book.Insert => " + err.Error())
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|