diff --git a/cmd/install.go b/cmd/install.go index 7a20b75..8230063 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -69,6 +69,10 @@ var installCmd = &cobra.Command{ if odooVer == "" { odooVer = config.OdooVersion() + } else { + if valid := utils.ValidateOdooVer(odooVer); !valid { + fmt.Println("Your odoo version is not valid, please use any one of this\n10.0 11.0 12.0 13.0 14.0 15.0 16.0") + } } if dbName == "" { @@ -175,6 +179,17 @@ func (ic InstallConf) cloneOdooCommunity() error { return err } + idx := 1 + for { + if exist := utils.CheckDirExist(config.OdooDir() + ic.dirName); !exist { + break + } + + // When it's already exist, put index and try to check again + ic.dirName = fmt.Sprintf("%s%d", ic.dirName, idx) + idx++ + } + err = exec.Command("git", "clone", "https://github.com/odoo/odoo", "--branch", ic.odooVer, "--depth", "1", ic.dirName).Run() if err != nil { if !strings.Contains(err.Error(), "exit status 128") { diff --git a/main.go b/main.go index 980bb9e..973a768 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( func main() { // OS Check, for now it's only for ubuntu and derivatives if runtime.GOOS != "linux" { - fmt.Println("This program only works on Ubuntu or derivatives") + fmt.Println("This application only works on Ubuntu or derivatives") os.Exit(1) } else { // Check if UBUNTU_CODENAME is on allowedOS @@ -27,15 +27,21 @@ func main() { } func checkOSVersion() error { + skipUbuntuCheck := os.Getenv("SKIP_UBUNTU_CHECK") + if skipUbuntuCheck != "" { + return nil + } + + // Continue to check the OS list when there is no skip ubuntu check out, err := exec.Command("bash", "-c", "source /etc/os-release; echo $UBUNTU_CODENAME").Output() if err != nil { return err } - // check if UBUNTU_CODENAME on allowedOS + // check if UBUNTU_CODENAME is n allowedOS codename := utils.RemoveNewLine(string(out)) if !config.IsAllowedOS(codename) { - return fmt.Errorf("ubuntu version is not supported") + return fmt.Errorf("ubuntu version is not supported\nIf it's a mistakes, try to run the app again with\nenv SKIP_UBUNTU_CHECK=YES odoo-one-click") } return nil diff --git a/utils/helper.go b/utils/helper.go index 8b80713..a55a6a5 100644 --- a/utils/helper.go +++ b/utils/helper.go @@ -32,6 +32,19 @@ func DirName(odooVer string, isEnterprise bool) string { return strings.Split(odooVer, ".")[0] + "c" } +func CheckDirExist(path string) bool { + _, err := os.Stat(path) + if err == nil { + return true + } + + if os.IsNotExist(err) { + return false + } + + return true +} + func CheckPythonInstalled(pythonVer string) (bool, error) { bashCommand := fmt.Sprintf("pyenv versions | grep %s", pythonVer) err := exec.Command("bash", "-c", bashCommand).Run() @@ -138,3 +151,26 @@ func IsPyenvInstalled() bool { _, err := os.Stat(config.PyenvDir()) return err == nil } + +func ValidateOdooVer(odooVer string) bool { + // TODO: change this validation later by taking the data directly from github branches name, or using regex? + // Only allow Odoo 10 and plus since it's the versions i have tried myself + switch odooVer { + case "10.0": + return true + case "11.0": + return true + case "12.0": + return true + case "13.0": + return true + case "14.0": + return true + case "15.0": + return true + case "16.0": + return true + default: + return false + } +}