Skip to content

Commit

Permalink
优化安装
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrohy committed Mar 26, 2020
1 parent e2e5135 commit eaf5304
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ exit:
fmt.Println()
fmt.Println(util.Cyan("欢迎使用trojan管理程序"))
fmt.Println()
menuList := []string{"trojan管理", "用户管理", "安装管理", "web管理", "查看配置", "生成客户端配置文件"}
menuList := []string{"trojan管理", "用户管理", "安装管理", "web管理", "查看配置", "生成json"}
for i := 0; i < len(menuList); i++ {
if i%2 == 0 {
fmt.Printf("%d.%-15s\t", i+1, menuList[i])
Expand Down
6 changes: 6 additions & 0 deletions core/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
"database/sql"
"errors"
"fmt"
mysqlDriver "github.com/go-sql-driver/mysql"
"io/ioutil"
"log"

// mysql sql驱动
_ "github.com/go-sql-driver/mysql"
"strconv"
Expand Down Expand Up @@ -33,6 +37,8 @@ type User struct {

// GetDB 获取mysql数据库连接
func (mysql *Mysql) GetDB() *sql.DB {
// 屏蔽mysql驱动包的日志输出
mysqlDriver.SetLogger(log.New(ioutil.Discard, "", 0))
conn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", mysql.Username, mysql.Password, mysql.ServerAddr, mysql.ServerPort, mysql.Database)
db, err := sql.Open("mysql", conn)
if err != nil {
Expand Down
17 changes: 11 additions & 6 deletions trojan/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ var (
func InstallMenu() {
fmt.Println()
menu := []string{"更新trojan", "证书申请", "安装mysql"}
switch util.LoopInput("请选择: ", menu, true) {
choice := util.LoopInput("请选择: ", menu, true)
fmt.Println()
switch choice {
case 1:
InstallTrojan()
case 2:
Expand All @@ -30,7 +32,6 @@ func InstallMenu() {
default:
return
}
Restart()
}

// InstallDocker 安装docker
Expand All @@ -49,17 +50,19 @@ func InstallTrojan() {
fmt.Println(err)
}
util.ExecCommand(data)
util.OpenPort(443)
util.ExecCommand("systemctl restart trojan")
util.ExecCommand("systemctl enable trojan")
util.OpenPort(443)
fmt.Println()
}

// InstallTls 安装证书
func InstallTls() {
domain := ""
choice := util.LoopInput("请选择使用证书方式: ", []string{"Let's Encrypt 证书", "自定义证书路径"}, true)
if choice == 1 {
if choice < 0 {
return
} else if choice == 1 {
localIP := util.GetLocalIP()
fmt.Printf("本机ip: %s\n", localIP)
for {
Expand Down Expand Up @@ -107,6 +110,7 @@ func InstallTls() {
}
}
core.SetValue("domain", domain)
Restart()
fmt.Println()
}

Expand All @@ -132,9 +136,9 @@ func InstallMysql() {
}
util.OpenPort(mysql.ServerPort)
util.ExecCommand(fmt.Sprintf(mysqlDodkcerRun, mysql.ServerPort, mysql.Password))
fmt.Println("mysql启动中, 请稍等...")
db := mysql.GetDB()
for {
db := mysql.GetDB()
fmt.Printf("%s mysql启动中,请稍等...\n", time.Now().Format("2006-01-02 15:04:05"))
err := db.Ping()
if err == nil {
db.Close()
Expand Down Expand Up @@ -179,5 +183,6 @@ func InstallMysql() {
if len(mysql.GetData()) == 0 {
AddUser()
}
Restart()
fmt.Println()
}

0 comments on commit eaf5304

Please sign in to comment.