CoSync/internal/client/setup.go

105 lines
3.3 KiB
Go
Raw Permalink Normal View History

2025-01-01 22:18:08 +01:00
package client
import (
"cosync/internal/core"
)
const (
colorRed = "\033[0;31m"
colorGreen = "\033[1;32m"
colorNone = "\033[0m"
separator = "\n ============================================== \n\n"
)
func Setup() {
// Print logo
println(" ______ ______ \n .' ___ | .' ____ \\ \n/ .' \\_| .--. | (___ \\_| _ __ _ .--. .---. \n| | / .'`\\ \\ _.____`. [ \\ [ ][ `.-. | / /'`\\] \n\\ `.___.'\\| \\__. || \\____) | \\ '/ / | | | | | \\__. \n `.____ .' '.__.' \\______.'[\\_: / [___||__]'.___.' \n \\__.' ")
print(separator)
// Greeting
println("Hi, welcome to cosync, let's set it up")
println("Don't hesitate to give a look at the doc to know how it works ! :) \n -> https://docs.oblic-parallels.fr/cosync\n")
// Try create config files
err := core.MkConfig()
if err != nil {
println(colorRed + "Setup: Failed to create config files" + colorNone)
panic(err)
}
// Prompt for server/port assignation
print("Server address: ")
// ...
print("Port")
// ...
// Update config file accordingly
// ...
println(colorGreen + "Config has been updated with new values" + colorNone)
// Prompt to start service
print("Do you want to start CoSync now ? [Y/n]: ")
//...
}
//! This code no longer needs to exist as config is now handled by cosync/config
// Then it will be removed soon
// func mkConfigFiles(configFolderPath string, configFileName string, syncFileName string) {
// // Check if folder already exists
// _, err := os.Stat(configFolderPath)
// if err != nil && os.IsNotExist(err) {
// // Create config folder
// err = os.Mkdir(configFolderPath, os.ModePerm)
// if err != nil {
// println(colorRed + "\n\nCouldn't create the config folder" + colorNone)
// panic("Setup: Couldn't create " + configFolderPath + " -> " + err.Error())
// }
// }
// // Check if config file exists
// configFilePath := configFolderPath + configFileName
// _, err = os.Stat(configFilePath)
// if err != nil && os.IsNotExist(err) {
// // Create config file
// _, err = os.Create(configFilePath)
// if err != nil {
// println(colorRed + "\n\nCouldn't create the config file" + colorNone)
// panic("Setup: Couldn't create " + configFilePath + " -> " + err.Error())
// }
// }
// syncFilePath := configFolderPath + syncFileName
// _, err = os.Stat(syncFilePath)
// if err != nil && os.IsNotExist(err) {
// // Create config folder
// _, err = os.Create(syncFilePath)
// if err != nil {
// println(colorRed + "\n\nCouldn't create the sync file" + colorNone)
// panic("Setup: Couldn't create " + syncFilePath + " -> " + err.Error())
// }
// }
// }
// func WriteDefaultConfig(configFilePath string) {
// // Open file
// f, err := os.Open(configFilePath)
// if err != nil {
// println(colorRed + "\n\nCouldn't open the config file" + colorNone)
// panic("Setup: Couldn't access " + configFilePath + " -> " + err.Error())
// }
// defer f.Close()
// // Write file
// // TODO: import pre existing config file
// _, err = f.WriteString("{}")
// if err != nil {
// println(colorRed + "\n\nCouldn't open the config file" + colorNone)
// panic("Setup: Couldn't access " + configFilePath + " -> " + err.Error())
// }
// }