Skip to content

Commit

Permalink
Added db2level check before installing clidriver (#193)
Browse files Browse the repository at this point in the history
* Added db2level check before installing clidriver

* Upated with db2cli validate check

* Updated setup.go with include and lib folder check

Co-authored-by: Vikas Mathur <[email protected]>
  • Loading branch information
vmathur12 and Vikas Mathur authored Jan 26, 2023
1 parent 07d128f commit bcd92b8
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Interface for GoLang to DB2 for z/OS, DB2 for LUW, DB2 for i.
## Prerequisite

Golang should be installed(Golang version should be >=1.12.x and <= 1.18.X)
Golang should be installed(Golang version should be >=1.12.x and <= 1.19.X)

Git should be installed in your system.

Expand Down
80 changes: 70 additions & 10 deletions installer/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"runtime"
"strings"
"bufio"
)

func downloadFile(filepath string, url string) error {
Expand Down Expand Up @@ -101,34 +102,93 @@ func aix_untar(clidriver string, targetDirectory string) error {
return nil
}

func getinstalledpath(validateout string) {
var line string

scanner := bufio.NewScanner(strings.NewReader(validateout))

for scanner.Scan() {
line = scanner.Text()

if(strings.Contains(line, "Install")) {
fields := strings.Split(line, " ")
fmt.Println(fields[7])
input1 := fields[7][0:len(fields[7])]
fmt.Println("Clidriver is already present")
fmt.Println("Please set IBM_DB_HOME to ", input1)
}
}
}

func checkincludepath( includepath string) bool {

if _, err1 := os.Stat(includepath + "/include"); !os.IsNotExist(err1) {
//fmt.Println("clidriver/include folder exists in the path")
if _, err2 := os.Stat(includepath + "/lib"); !os.IsNotExist(err2) {
//fmt.Println("clidriver/lib folder exists in the path")
return true
}
}

return false
}

func main() {
var target, cliFileName string
var unpackageType int
var err11 error
var out []byte

fmt.Println("NOTE: Environment variable DB2HOME name is changed to IBM_DB_HOME.")
value, ok := os.LookupEnv("IBM_DB_HOME")
if !ok {
if runtime.GOOS == "windows" {
fmt.Println("Please set IBM_DB_HOME and add this path to PATH environment variable")
os.Exit(1)
} else {
fmt.Println("Please set IBM_DB_HOME, CGO_CFLAGS, CGO_LDFLAGS and LD_LIBRARY_PATH or DYLD_LIBRARY_PATH environment variables", value)

out, err11 = exec.Command("db2cli", "validate").Output()
if err11 != nil {
_, ok := os.LookupEnv("IBM_DB_HOME")
if !ok {
if runtime.GOOS == "windows" {
fmt.Println("Please set IBM_DB_HOME add this path to PATH environment variable after clidriver installed")
} else {
fmt.Println("Please set IBM_DB_HOME, CGO_CFLAGS, CGO_LDFLAGS and LD_LIBRARY_PATH or DYLD_LIBRARY_PATH environment variables after clidriver installed")
}
}
}else {
path, ok := os.LookupEnv("IBM_DB_HOME")
if !ok {
//set IBM_DB_HOME
getinstalledpath(string(out))
os.Exit(1)
}else{
fmt.Println("clidriver folder exists in the path....", path)
if checkincludepath(path) {
os.Exit(1)
}
}
}



if len(os.Args) == 2 {
target = os.Args[1]
} else {
target = "./../.."
}

if _, err := os.Stat(target + "/clidriver"); !os.IsNotExist(err) {
if _, err1 := os.Stat(target + "/clidriver"); !os.IsNotExist(err1) {
fmt.Println("clidriver folder exists in the path")
os.Exit(2)

if _, err2 := os.Stat(target + "/clidriver/include"); !os.IsNotExist(err2) {
//fmt.Println("clidriver/include folder exists in the path")

if _, err3 := os.Stat(target + "/clidriver/lib"); !os.IsNotExist(err3) {
//fmt.Println("clidriver/lib folder exists in the path")
os.Exit(2)
} else {
fmt.Println("clidriver/lib folder is not exist, installing clidriver ....")
}
} else {
fmt.Println("clidriver/include folder is not exist, installing clidriver ....")
}
}

if runtime.GOOS == "windows" {
unpackageType = 1
const wordsize = 32 << (^uint(0) >> 32 & 1)
Expand Down

0 comments on commit bcd92b8

Please sign in to comment.