Skip to content

Commit

Permalink
update: install script and install.md doc
Browse files Browse the repository at this point in the history
  • Loading branch information
bimalkjha committed Dec 10, 2024
1 parent 281a647 commit 094da7d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
17 changes: 14 additions & 3 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ extract the file.
2. cd goapp
3. go install github.com/ibmdb/go_ibm_db/installer@latest
or
go install github.com/ibmdb/go_ibm_db/[email protected]
go install github.com/ibmdb/go_ibm_db/[email protected]
4. go env GOPATH
5. cd $GOPATH/pkg/mod/github.com/ibmdb/[email protected]/installer
6. go run setup.go
7. export IBM_DB_HOME=$GOPATH/pkg/mod/github.com/ibmdb/clidriver
8. source ./setenv.sh
```

It's Done.
Expand All @@ -135,6 +140,12 @@ It's Done.
3. git clone https://github.com/ibmdb/go_ibm_db/
4. cd go_ibm_db/installer
5. go run setup.go
6. source ./setenv.sh
7. cd ../testdata
8. Edit config.json file and update database connection info, save it.
9. go mod init testdata
10. go mod tidy
11. go run main.go
```

### 3.3 Download clidriver
Expand Down Expand Up @@ -175,11 +186,11 @@ source setenv.sh

* New MacOS systems comes with System Integrity Protection(SIP) enabled which discards setting of DYLD_LIBRARY_PATH env variable
* Disable SIP if your Go app gives error that: file `libdb2.dylib` not found.
* If you can not disable SIP, create softlink of `.../clidriver/lib/libdb2.dylib` file under your applications home directory.
* OR, if you can not disable SIP, create softlink of `.../clidriver/lib/libdb2.dylib` file under your applications home directory.
```
ln -s .../clidriver/lib/libdb2.dylib libdb2.dylib
```
* If you see `libdb2.dylib` file under `go_ibm_db` directory, you can copy it too in your app root directory.
* OR, if you see `libdb2.dylib` file under `go_ibm_db` directory, you can copy it too in your app root directory.

## <a name="inswin"></a> 4. Go_ibm_db Installation on Windows.

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/ibmdb/go_ibm_db

go 1.23.4
go 1.22.1

require github.com/ibmruntimes/go-recordio/v2 v2.0.0-20240416213906-ae0ad556db70
46 changes: 31 additions & 15 deletions installer/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,26 @@ func Unzipping(sourcefile string, targetDirectory string) {
}
}

func linux_untar(clidriver string, targetDirectory string) error {
func linux_untar(clidriver string, targetDirectory string, ibmdbDir string) error {
fmt.Printf("Extracting with tar -xzf %s -C %s\n", clidriver, targetDirectory)
out, err := exec.Command("tar", "xzf", "./../../" + clidriver, "-C", targetDirectory).Output()

fmt.Println(string(out))
if err != nil {
fmt.Println("Error while running tar: " + err.Error())
return err
}
} else {
fmt.Println("clidriver path = " + targetDirectory + "/clidriver")
fmt.Println("Now run below commands:")
fmt.Println("export IBM_DB_HOME=" + targetDirectory + "/clidriver")
fmt.Println("source " + ibmdbDir + "/installer/setenv.sh")
}

if runtime.GOOS == "darwin" {
// Create symlinks for libdb2
_, _ = exec.Command("ln", "-s", targetDirectory + "/clidriver/lib/libdb2.dylib", targetDirectory + "/libdb2.dylib").Output()
_, _ = exec.Command("ln", "-s", targetDirectory + "/clidriver/lib/libdb2.dylib", targetDirectory + "/go_ibm_db/libdb2.dylib").Output()
_, _ = exec.Command("ln", "-s", targetDirectory + "/clidriver/lib/libdb2.dylib", targetDirectory + "/go_ibm_db/testdata/libdb2.dylib").Output()
_, _ = exec.Command("ln", "-s", targetDirectory + "/clidriver/lib/libdb2.dylib", ibmdbDir + "/libdb2.dylib").Output()
_, _ = exec.Command("ln", "-s", targetDirectory + "/clidriver/lib/libdb2.dylib", ibmdbDir + "/testdata/libdb2.dylib").Output()
}

return nil
Expand All @@ -103,6 +109,12 @@ func aix_untar(clidriver string, targetDirectory string) error {
if err != nil {
fmt.Println("Error while running tar: " + err.Error())
return err
} else {
fmt.Println("clidriver path = " + targetDirectory + "/clidriver")
fmt.Println("Now run below commands:")
fmt.Println("export IBM_DB_HOME=" + targetDirectory + "/clidriver")
fmt.Println("export CGO_CFLAGS==\"-I$IBM_DB_HOME/include\"")
fmt.Println("export CGO_LDFLAGS==\"-L$IBM_DB_HOME/lib\"")
}

return nil
Expand Down Expand Up @@ -140,7 +152,7 @@ func checkincludepath(includepath string) bool {
}

func main() {
var target, cliFileName string
var target, ibmdbDir, cliFileName string
var unpackageType int
var err11 error
var out []byte
Expand All @@ -156,7 +168,7 @@ func main() {
if err11 != nil {
_, ok := os.LookupEnv("IBM_DB_HOME")
if !ok {
if runtime.GOOS == "windows" {
if runtime.GOOS == "windows" {
fmt.Println("Please set IBM_DB_HOME and add %IBM_DB_HOME%/bin to PATH and %IBM_DB_HOME%/lib to LIB environment variables after clidriver installation")
} else if runtime.GOOS == "aix" {
fmt.Println("Please set IBM_DB_HOME, CGO_CFLAGS, CGO_LDFLAGS and LIBPATH environment variables after clidriver installation")
Expand All @@ -181,13 +193,17 @@ func main() {
}

_, setupFile, _, ok := runtime.Caller(0)
if ok {
ibmdbDir = filepath.Dir(setupFile) + "/.."
} else {
ibmdbDir = "./.."
}
target = ibmdbDir + "/.."
ibmdbDir, _ = filepath.Abs(ibmdbDir)
target, _ = filepath.Abs(target)

if len(os.Args) == 2 {
target = os.Args[1]
} else if ok {
target = filepath.Dir(setupFile) + "/../.."
target, _ = filepath.Abs(target)
} else {
target = "./../.."
}

if _, err1 := os.Stat(target + "/clidriver"); !os.IsNotExist(err1) {
Expand All @@ -197,13 +213,13 @@ func main() {
//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")
fmt.Println("==> Direcotry \"" + target + "/clidriver\" exists.")
os.Exit(2)
} else {
fmt.Println("clidriver/lib folder is not exist, installing clidriver ....")
fmt.Println(target+"/clidriver/lib folder does not exist, installing clidriver ....")
}
} else {
fmt.Println("clidriver/include folder is not exist, installing clidriver ....")
fmt.Println(target+"/clidriver/include folder does not exist, installing clidriver ....")
}
}

Expand Down Expand Up @@ -301,7 +317,7 @@ func main() {
} else if unpackageType == 3 {
aix_untar(cliFileName, target)
} else {
linux_untar(cliFileName, target)
linux_untar(cliFileName, target, ibmdbDir)
}
}

Expand Down
3 changes: 0 additions & 3 deletions package.json

This file was deleted.

0 comments on commit 094da7d

Please sign in to comment.