Skip to content

Commit 7bec295

Browse files
author
Samuel Vandamme
committed
Added latest version 2.8.3
1 parent 13833d5 commit 7bec295

File tree

4 files changed

+50
-27
lines changed

4 files changed

+50
-27
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
language: go
22
env:
3-
- GIMME_OS=linux GIMME_ARCH=amd64
4-
- GIMME_OS=darwin GIMME_ARCH=amd64
5-
- GIMME_OS=windows GIMME_ARCH=amd64
3+
- GIMME_OS=linux GIMME_ARCH=amd64 EXTENSION=
4+
- GIMME_OS=darwin GIMME_ARCH=amd64 EXTENSION=
5+
- GIMME_OS=windows GIMME_ARCH=amd64 EXTENSION=.exe
66
install:
77
- export GOPATH=`pwd`
88
- mkdir -p bin
99
script:
10-
- go build -o bin/coscale-cli-$GIMME_OS coscale
10+
- go build -o bin/coscale-cli-$GIMME_OS$EXTENSION coscale
1111
deploy:
1212
provider: releases
1313
api_key:
1414
secure: heF7EiZ6fwr456zR4fwFvbsAqWjAvsIz5RD6P8UnpB2UhZ05f9eC4Qc3crfedZiQKgInkF9EClf8+k5chIhz8/xvO772PN7uPFBJNR39/mbxCrJXXM5Hr2Jgbuhnt4+kw/OhBmpTyPn8SZ5XtHDAd1PM419sHZjAxm7OJ85xu8XswjCMSjZ/U3si0Syo6EY3BlMbjjN4X0iNBqtuX8lEqWQ0jXz0j3r5KMhtbKXKXKqNVJv+lgMqJ/79+NSfvuUcYppgozYcSHhrCzjhLXz7JCCCFyJMW0QQUeHZZCsowifSEeR7vwkihhuy6OPd5pEHWoFuXA8KWQliHQx5864v+6U8XkM8szyCicL0xQ/pekr8iy7TU92kthM/Qli72Miw8g9LBJKgV2C7TP1wMHJ9X57uMW385P7BJjVxyEFbFNwyyPUc/9nkqr1nGfeqwD3xPqP9qhw5/Lf5mTzndZ0/ykhUy6EddhPeS0gfeebPkWETmWPqslFbDZBjMAN/BAzbSQxJBwdoZipkk/hY58HIhkytPeqD/TNPQXUni/3BYM6gYjAGAo2LnX+b3pJFmAJcswCaFP9NUavlyogq/7tK6lgKX3f1ILyN7jsD95FbZPHwWg+msNF7RpHx0z2Xs3DAQ46F1LWT28RSm0X+Ihp2rAKhdKixGAS3B+7xYRMsrGQ=
15-
file: bin/coscale-cli-$GIMME_OS
15+
file: bin/coscale-cli-$GIMME_OS$EXTENSION
1616
skip_cleanup: true
1717
on:
1818
tags: true

build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22
# Tip: to remove '\r' use sed -i 's/\r//g' build.sh
3-
export GOPATH=`pwd`
3+
export GOPATH=`pwd`/cli
44
mkdir -p bin
5-
go build -o bin/coscale-cli coscale
5+
CGO_ENABLED=0 go build -a -tags netgo -ldflags '-w' -o bin/coscale-cli coscale

src/coscale/cli.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"os"
77
)
88

9+
const FIRST_RUN_SUCCESS int = 67
10+
911
//main command of Coscale coscale-cli
1012
func main() {
1113

@@ -22,6 +24,11 @@ func main() {
2224
var usage = os.Args[0] + ` <object> <action> [--<field>='<data>']`
2325
var app = command.NewCommand(os.Args[0], usage, subCommands)
2426
flag.Usage = func() { app.PrintUsage() }
27+
var firstRun bool
28+
flag.BoolVar(&firstRun, "first-run", false, "The first run of an updated agent: checks if everything is working properly.")
2529
flag.Parse()
30+
if firstRun {
31+
os.Exit(FIRST_RUN_SUCCESS)
32+
}
2633
app.Run(app, flag.Args())
2734
}

src/coscale/command/command.go

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -198,43 +198,59 @@ Use "coscale-cli [object] <help>" for more information about a command.
198198
`
199199

200200
// GetConfigPath is used to return the absolut path of the api configuration file
201-
func GetConfigPath() (string, error) {
202-
var carriageReturn string
203-
configFile := "/api.conf"
204-
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
205-
if err != nil {
206-
os.Exit(EXIT_FLAG_ERROR)
207-
}
208-
configPath := dir + configFile
209-
if _, err := os.Stat(configPath); err == nil {
210-
return configPath, nil
211-
}
212-
var cmdName string
201+
func GetConfigPath() (c string, e error) {
202+
command := os.Args[0]
203+
var configFile, backwardsConfigFile, dir, cmdName, carriageReturn string
204+
var err error
213205
if runtime.GOOS == "windows" {
206+
configFile = "api.conf"
207+
backwardsConfigFile = "api.conf"
214208
cmdName = "where"
215209
carriageReturn = "\r\n"
216210
} else {
211+
configFile = filepath.Join("etc", "api.conf")
212+
backwardsConfigFile = "api.conf" // once we had api.conf in the same folder as cli executable
217213
cmdName = "which"
218214
carriageReturn = "\n"
219215
}
220-
response, err := GetCommandOutput(cmdName, 2*time.Second, os.Args[0])
221-
path := string(bytes.Split(response, []byte(carriageReturn))[0])
222-
if err != nil {
223-
return "", err
216+
// we calculate folder where the command is
217+
218+
// 1. check if command is in PATH
219+
// if we check a command that doesn't exist on linux we get error
220+
response, err := GetCommandOutput(cmdName, 2*time.Second, command)
221+
if err == nil {
222+
command = string(bytes.Split(response, []byte(carriageReturn))[0])
224223
}
225-
// check if is a symlink
226-
file, err := os.Lstat(path)
224+
err = nil
225+
// 2. check if it is a symlink
226+
file, err := os.Lstat(command)
227227
if err != nil {
228228
return "", err
229229
}
230230
if file.Mode()&os.ModeSymlink == os.ModeSymlink {
231231
// This is a symlink
232-
path, err = filepath.EvalSymlinks(path)
232+
command, err = filepath.EvalSymlinks(command)
233233
if err != nil {
234234
return "", err
235235
}
236236
}
237-
return filepath.Dir(path) + configFile, nil
237+
// check if config file is in dir
238+
dir, err = filepath.Abs(filepath.Dir(command))
239+
if err != nil {
240+
os.Exit(EXIT_FLAG_ERROR)
241+
}
242+
configPath := filepath.Join(dir, configFile)
243+
_, err = os.Stat(configPath)
244+
if err == nil {
245+
return configPath, nil
246+
}
247+
// try the backwards compatible approach
248+
configPath = filepath.Join(dir, backwardsConfigFile)
249+
_, err = os.Stat(configPath)
250+
if err == nil {
251+
return configPath, nil
252+
}
253+
return "", err
238254
}
239255

240256
// GetCommandOutput returns stdout of command as a string

0 commit comments

Comments
 (0)