main.go 2.21 KB
Newer Older
Nicolas Giard's avatar
Nicolas Giard committed
1 2 3 4 5 6
package main

import (
	"fmt"
	"runtime"

7 8 9
	"github.com/bugsnag/bugsnag-go"
	"github.com/fatih/color"
	"gopkg.in/AlecAivazis/survey.v1"
Nicolas Giard's avatar
Nicolas Giard committed
10 11
)

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
var qs = []*survey.Question{
	{
		Name: "location",
		Prompt: &survey.Input{
			Message: "Where do you want to install Wiki.js?",
			Default: "./wiki",
		},
		Validate: survey.Required,
	},
	{
		Name: "dbtype",
		Prompt: &survey.Select{
			Message: "Select a DB Driver:",
			Options: []string{"MariabDB", "MS SQL Server", "MySQL", "PostgreSQL", "SQLite"},
			Default: "PostgreSQL",
		},
	},
	{
		Name: "port",
		Prompt: &survey.Input{
			Message: "Server Port:",
			Default: "3000",
		},
	},
}
37

Nicolas Giard's avatar
Nicolas Giard committed
38
func main() {
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
	bugsnag.Configure(bugsnag.Configuration{
		APIKey:       "37770b3b08864599fd47c4edba5aa656",
		ReleaseStage: "dev",
	})

	bold := color.New(color.FgWhite).Add(color.Bold)

	logo := `
  __    __ _ _    _    _
 / / /\ \ (_) | _(_)  (_)___
 \ \/  \/ / | |/ / |  | / __|
  \  /\  /| |   <| |_ | \__ \
   \/  \/ |_|_|\_\_(_)/ |___/
                    |__/
  `
	color.Yellow(logo)

	bold.Println("\nInstaller for Wiki.js 2.x")
57 58 59 60
	fmt.Printf("%s-%s\n\n", runtime.GOOS, runtime.GOARCH)

	// Check system requirements

61
	bold.Println("Verifying system requirements...")
62 63
	CheckNodeJs()
	CheckRAM()
64
	fmt.Println()
Nicolas Giard's avatar
Nicolas Giard committed
65

66 67 68 69 70 71
	// the answers will be written to this struct
	answers := struct {
		Location string
		DBType   string `survey:"dbtype"`
		Port     int
	}{}
Nicolas Giard's avatar
Nicolas Giard committed
72

73 74
	// perform the questions
	err := survey.Ask(qs, &answers)
Nicolas Giard's avatar
Nicolas Giard committed
75
	if err != nil {
76
		fmt.Println(err.Error())
Nicolas Giard's avatar
Nicolas Giard committed
77 78 79
		return
	}

80
	fmt.Printf("%s chose %d.", answers.Location, answers.Port)
Nicolas Giard's avatar
Nicolas Giard committed
81 82 83

	// Download archives...

84
	bold.Println("\nDownloading packages...")
85

86 87
	// uiprogress.Start()
	// bar := uiprogress.AddBar(100)
Nicolas Giard's avatar
Nicolas Giard committed
88

89 90
	// bar.AppendCompleted()
	// bar.PrependElapsed()
Nicolas Giard's avatar
Nicolas Giard committed
91

92 93 94 95 96 97 98 99 100 101 102 103 104
	// for bar.Incr() {
	// 	time.Sleep(time.Millisecond * 20)
	// }

	finish := `
  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  |                                                   |
  |    Open http://localhost:3000/ in your browser    |
  |    to complete the installation!                  |
  |                                                   |
  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  `
	color.Yellow("\n\n" + finish)
105

106 107
	fmt.Println("Press any key to continue.")
	fmt.Scanln()
Nicolas Giard's avatar
Nicolas Giard committed
108
}