Skip to content

Commit

Permalink
patch: add option SKIP_UBUNTU_CHECK and make sure dirname is not repl…
Browse files Browse the repository at this point in the history
…aced
  • Loading branch information
rockavoldy committed Jul 6, 2023
1 parent 7ff742d commit c49c784
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
15 changes: 15 additions & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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") {
Expand Down
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
36 changes: 36 additions & 0 deletions utils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}

0 comments on commit c49c784

Please sign in to comment.