diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 17868d0..4619da4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -100,7 +100,6 @@ jobs: zip odoo-one-click_arm64.zip odoo-one-click rm -f odoo-one-click - - name: Delete old prerelease tag with v0.x.x if: (env.OLD_PRE_TAG == env.BUMP_TAG) && (env.BUMP_TAG != 'NULL') uses: dev-drprasad/delete-tag-and-release@v0.2.0 diff --git a/cmd/init.go b/cmd/init.go index 65bc306..f93c419 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -17,8 +17,8 @@ func init() { var initCmd = &cobra.Command{ Use: "init", - Short: "First initialization, install pyenv, configure postgresql and clone odoo", - Long: "First initialization for installing pyenv, configure postgresql, and clone odoo", + Short: "First initialization to install pyenv, and configure postgresql", + Long: "First initialization to install pyenv, and configure postgresql for local development", Run: func(cmd *cobra.Command, args []string) { CheckRequirement() checkPyenv() @@ -26,9 +26,10 @@ var initCmd = &cobra.Command{ } func CheckRequirement() { + // Check requirement for ubuntu and derivatives fmt.Println("Checking requirement") - // first, need to confirm if it is ubuntu or derivatives - listOfDeps := []string{"postgresql", "postgresql-client", "libxml2-dev", "libxslt1-dev", "libldap2-dev", "libsasl2-dev", "libtiff5-dev", "libjpeg8-dev", "libopenjp2-7-dev", "zlib1g-dev", "libfreetype6-dev", "liblcms2-dev", "libwebp-dev", "libharfbuzz-dev", "libpq-dev", "git", "libsqlite3-dev", "libreadline-dev", "libbz2-dev", "tk-dev"} + + listOfDeps := []string{"build-essential", "postgresql", "postgresql-client", "libxml2-dev", "libssl-dev", "libffi-dev", "libxslt1-dev", "libldap2-dev", "libsasl2-dev", "libtiff5-dev", "libjpeg8-dev", "libopenjp2-7-dev", "zlib1g-dev", "libfreetype6-dev", "liblcms2-dev", "libwebp-dev", "libharfbuzz-dev", "libpq-dev", "git", "libsqlite3-dev", "libreadline-dev", "libbz2-dev", "tk-dev"} notInstalledDeps := make([]string, 0) @@ -92,7 +93,9 @@ func CheckRequirement() { fmt.Println("Database successfully configured") } - fmt.Printf("User database %s with password %s now have superuser access\n", config.DBUsername(), config.DB_PASSWORD) + fmt.Printf("Database user '%s' with password '%s' created with superuser access\n", config.DBUsername(), config.DB_PASSWORD) + + utils.PyenvInfoBash() } func checkDBAccess() (bool, error) { diff --git a/cmd/install.go b/cmd/install.go index 2899d1c..5f1f7dd 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -30,7 +30,7 @@ func init() { var installCmd = &cobra.Command{ Use: "install [flags] directory_name", - Short: "Install and configure odoo", + Short: "clone and configure odoo", Args: func(cmd *cobra.Command, args []string) error { if len(args) > 1 { return fmt.Errorf("too many arguments") @@ -41,6 +41,19 @@ var installCmd = &cobra.Command{ return nil }, + PreRun: func(cmd *cobra.Command, args []string) { + // Check first if pyenv already installed + if !utils.IsPyenvInstalled() { + fmt.Println("Please install pyenv first.") + os.Exit(1) + } + // Check if pyenv already configured + if !utils.IsPyenvConfigured() { + fmt.Println("Please follow following steps to configure pyenv, and run the command again.") + utils.PyenvInfoBash() + os.Exit(1) + } + }, Run: func(cmd *cobra.Command, args []string) { if isEnterprise { // when enterprise is checked, ask for github username and token @@ -125,24 +138,29 @@ func (ic InstallConf) InstallOdoo() { Logger.Println("Initialize pyenv: ", err) } + fmt.Println("Installing requirements") err = ic.installOdooDeps() if err != nil { Logger.Println("Install odoo dependencies: ", err) } + fmt.Println("Creating database") err = exec.Command("createdb", ic.dbName).Run() if err != nil { Logger.Println("CreateDB odoo: ", err) } + fmt.Println("Create odoo.conf file to run odoo") err = ic.createOdooConf() if err != nil { Logger.Println("Create odoo conf: ", err) } dirName := utils.DirName(ic.odooVer, ic.isEnterprise) - fmt.Printf("Your odoo %s is ready to use at\n%s\n", dirName, config.OdooDir()+"/"+ic.dirName) - fmt.Println("for the first run, you need to initialize the db with base addons by add -i base") + fmt.Printf("Your odoo %s is ready to use at\n%s\n\n", dirName, config.OdooDir()+"/"+ic.dirName) + fmt.Println("for the first run, you need to initialize the db with base addons run this command") + fmt.Println("python3 odoo-bin -c odoo.conf -i base --stop-after-init") + fmt.Printf("\nNow you can run the odoo instance with 'python3 odoo-bin -c odoo.conf'\n") } func (ic InstallConf) cloneOdooCommunity() error { @@ -187,17 +205,20 @@ func (ic InstallConf) cloneOdooEnterprise() error { func (ic InstallConf) initPyenv() error { Logger.Println("Initializing pyenv") + fmt.Println("Check if python version needed by odoo already installed by pyenv") isPyVerInstalled, err := utils.CheckPythonInstalled(ic.pythonVer) if err != nil { Logger.Println(err) } if !isPyVerInstalled { + fmt.Println("Installing python version needed by odoo, please wait...") err := exec.Command("pyenv", "install", ic.pythonVer).Run() if err != nil { return err } } + fmt.Printf("python %s already installed with pyenv\n", ic.pythonVer) isVenvCreated, err := utils.CheckVenvCreated(ic.dirName) if err != nil { @@ -205,6 +226,7 @@ func (ic InstallConf) initPyenv() error { } if !isVenvCreated { + fmt.Println("Creating virtual environment for odoo, please wait...") err = exec.Command("pyenv", "virtualenv", ic.pythonVer, ic.dirName).Run() if err != nil { Logger.Println("Error on create venv: ", err) @@ -212,6 +234,7 @@ func (ic InstallConf) initPyenv() error { } } + fmt.Println("Activating virtual environment for odoo, please wait...") err = exec.Command("pyenv", "local", ic.dirName).Run() if err != nil { return err @@ -222,6 +245,8 @@ func (ic InstallConf) initPyenv() error { func (ic InstallConf) installOdooDeps() error { Logger.Println("Installing Odoo Dependencies") + _ = exec.Command("pip", "install", "setuptools==57.5", "wheel").Run() + err := exec.Command("pip", "install", "-r", "requirements.txt").Run() if err != nil { return err @@ -238,22 +263,7 @@ func (ic InstallConf) installOdooDeps() error { func (ic InstallConf) createOdooConf() error { Logger.Println("Creating Odoo Configuration") - confFile := fmt.Sprintf(` -[options] -admin_passwd = admin -db_host = localhost -db_port = 5432 -db_user = %s -db_password = %s -db_name = %s -addons_path = ./addons, ./odoo/addons`, config.DBUsername(), config.DB_PASSWORD, ic.dbName) - - if ic.isEnterprise { - // When it's enterprise, add enterprise addons path to odoo.conf - confFile = confFile + ", ./enterprise\n" - } else { - confFile = confFile + "\n" - } + confFile := utils.OdooConf(ic.isEnterprise, config.DBUsername(), config.DB_PASSWORD, ic.dbName) err := os.WriteFile("odoo.conf", []byte(confFile), 0644) if err != nil { diff --git a/cmd/root.go b/cmd/root.go index 1d43a91..eea3fde 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,7 +6,6 @@ import ( "odoo-one-click/config" "odoo-one-click/utils" "os" - "os/exec" "github.com/spf13/cobra" ) @@ -21,13 +20,6 @@ var rootCmd = &cobra.Command{ TraverseChildren: true, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { Logger = utils.Logger(config.Verbose) - os.Setenv("PYENV_ROOT", config.PyenvBin()) - os.Setenv("PATH", fmt.Sprintf("%s:%s", config.PyenvBin(), os.Getenv("PATH"))) - installed, _ := isPyenvInstalled() - if installed { - exec.Command("eval", "$(pyenv init -)").Run() - exec.Command("eval", "$(pyenv virtualenv-init -)").Run() - } return nil }, Run: func(cmd *cobra.Command, args []string) { diff --git a/cmd/run.go b/cmd/run.go index cea1326..528a2d0 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -1,17 +1,13 @@ package cmd -import ( - "github.com/spf13/cobra" -) - func init() { - rootCmd.AddCommand(runCmd) + // rootCmd.AddCommand(runCmd) } -var runCmd = &cobra.Command{ - Use: "run", - Short: "Run odoo instance", - Run: func(cmd *cobra.Command, args []string) { - - }, -} +// var runCmd = &cobra.Command{ +// Use: "run", +// Short: "Run odoo instance", +// Run: func(cmd *cobra.Command, args []string) { +// fmt.Println("Run will be here") +// }, +// } diff --git a/config/constant.go b/config/constant.go index eefb12e..ec6f980 100644 --- a/config/constant.go +++ b/config/constant.go @@ -30,7 +30,7 @@ func OdooDir() string { return home + "/odoo" } -func PyenvBin() string { +func PyenvDir() string { home, _ := os.UserHomeDir() return home + "/.pyenv" } diff --git a/utils/helper.go b/utils/helper.go index 474ce1a..c06071a 100644 --- a/utils/helper.go +++ b/utils/helper.go @@ -3,8 +3,9 @@ package utils import ( "fmt" "log" + "odoo-one-click/config" + "os" "os/exec" - "strconv" "strings" ) @@ -32,7 +33,6 @@ func DirName(odooVer string, isEnterprise bool) string { } func CheckPythonInstalled(pythonVer string) (bool, error) { - log.Println("Check python version if it already innstalled by pyenv") bashCommand := fmt.Sprintf("pyenv versions | grep %s", pythonVer) out, err := exec.Command("bash", "-c", bashCommand).Output() if err != nil { @@ -44,7 +44,6 @@ func CheckPythonInstalled(pythonVer string) (bool, error) { } func CheckVenvCreated(venv string) (bool, error) { - log.Println("Check if virtualenv with the same name already created") bashCommand := fmt.Sprintf("pyenv virtualenvs | grep %s", venv) out, err := exec.Command("bash", "-c", bashCommand).Output() if err != nil { @@ -56,12 +55,15 @@ func CheckVenvCreated(venv string) (bool, error) { } func GetPythonBasedOdooVer(odooVer string) string { - ver, _ := strconv.Atoi(strings.Split(odooVer, ".")[0]) - if ver < 13 { - return "3.7.13" - } + // Because of some issue with py3.8 (gevent, cython, etc) + // it's better to use python3.7 for odoo 11.0 to 16.0 + return "3.7.13" + // ver, _ :=รท strconv.Atoi(strings.Split(odooVer, ".")[0]) + // if ver < 13 { + // return "3.7.13" + // } - return "3.8.13" + // return "3.8.13" } func RemoveNewLine(data string) string { @@ -84,3 +86,56 @@ func IsValidDirName(dirName string) bool { return true } + +func OdooConf(isEnterprise bool, dbUser, dbPass, dbName string) string { + // [options] + // admin_passwd = admin + // db_host = localhost + // db_port = 5432 + // db_user = %s + // db_password = %s + // db_name = %s + // addons_path = ./addons, ./odoo/addons + + confFile := fmt.Sprintf(` +[options] +admin_passwd = admin +db_host = localhost +db_port = 5432 +db_user = %s +db_password = %s +db_name = %s +addons_path = ./addons, ./odoo/addons`, dbUser, dbPass, dbName) + if isEnterprise { + confFile += ", ./enterprise\n" + } else { + confFile += "\n" + } + + return confFile +} + +func PyenvInfoBash() { + fmt.Println() + fmt.Println("One more thing you need to do, please add this line to your ~/.bashrc file:") + fmt.Println("(Just copy and paste to your terminal line per line)") + fmt.Println() + fmt.Println(`echo 'PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc`) + fmt.Println(`echo 'PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc`) + fmt.Println(`echo 'eval "$(pyenv init -)"' >> ~/.bashrc`) + fmt.Println(`echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc`) + fmt.Println() + fmt.Println("Then run this command to reload your bashrc file") + fmt.Println("source ~/.bashrc") + fmt.Printf("\n\nIf you have zsh as your shell, changes '~/.bashrc' here with '~/.zshrc'\n\n") +} + +func IsPyenvConfigured() bool { + _, err := exec.LookPath("pyenv") + return err == nil +} + +func IsPyenvInstalled() bool { + _, err := os.Stat(config.PyenvDir()) + return err == nil +}