Skip to content

Commit

Permalink
Use package_info.json to manage version info
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Apr 12, 2023
1 parent a408e72 commit b444fdd
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 153 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

.vscode
bin

# Dependency directories (remove the comment below to include it)
# vendor/
81 changes: 4 additions & 77 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PKG=github.com/cyverse/gocommands
VERSION=v0.6.4
VERSION=v$(shell jq -r .version package_info.json)
GIT_COMMIT?=$(shell git rev-parse HEAD)
BUILD_DATE?=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS?="-X '${PKG}/commons.clientVersion=${VERSION}' -X '${PKG}/commons.gitCommit=${GIT_COMMIT}' -X '${PKG}/commons.buildDate=${BUILD_DATE}'"
Expand All @@ -14,79 +14,6 @@ build:
mkdir -p bin
CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o bin/gocmd ./cmd/*.go

.PHONY: install
install:
cp bin/gocmd ${GOPATH}/bin/gocmd
chmod 775 ${GOPATH}/bin/gocmd

.PHONY: build-release
build-release:
rm -rf release

# i386_linux
mkdir -p release/i386_linux
cd install && ./prep-install-script.sh ../release/i386_linux && cd ..
cd install && ./prep-shortcut-script.sh ../release/i386_linux && cd ..
CGO_ENABLED=0 GOARCH=386 GOOS=linux go build -ldflags=${LDFLAGS} -o release/i386_linux/gocmd cmd/*.go
cd release/i386_linux && tar cf gocommands_i386_linux_${VERSION}.tar * && mv *.tar .. && cd ../..
cd release/i386_linux && tar cf gocommands_i386_linux_${VERSION}_portable.tar gocmd && mv *.tar .. && cd ../..
rm -rf release/i386_linux

# amd64_linux
mkdir -p release/amd64_linux
cd install && ./prep-install-script.sh ../release/amd64_linux && cd ..
cd install && ./prep-shortcut-script.sh ../release/amd64_linux && cd ..
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags=${LDFLAGS} -o release/amd64_linux/gocmd cmd/*.go
cd release/amd64_linux && tar cf gocommands_amd64_linux_${VERSION}.tar * && mv *.tar .. && cd ../..
cd release/amd64_linux && tar cf gocommands_amd64_linux_${VERSION}_portable.tar gocmd && mv *.tar .. && cd ../..
rm -rf release/amd64_linux

# arm_linux
mkdir -p release/arm_linux
cd install && ./prep-install-script.sh ../release/arm_linux && cd ..
cd install && ./prep-shortcut-script.sh ../release/arm_linux && cd ..
CGO_ENABLED=0 GOARCH=arm GOOS=linux go build -ldflags=${LDFLAGS} -o release/arm_linux/gocmd cmd/*.go
cd release/arm_linux && tar cf gocommands_arm_linux_${VERSION}.tar * && mv *.tar .. && cd ../..
cd release/arm_linux && tar cf gocommands_arm_linux_${VERSION}_portable.tar gocmd && mv *.tar .. && cd ../..
rm -rf release/arm_linux

# arm64_linux
mkdir -p release/arm64_linux
cd install && ./prep-install-script.sh ../release/arm64_linux && cd ..
cd install && ./prep-shortcut-script.sh ../release/arm64_linux && cd ..
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -ldflags=${LDFLAGS} -o release/arm64_linux/gocmd cmd/*.go
cd release/arm64_linux && tar cf gocommands_arm64_linux_${VERSION}.tar * && mv *.tar .. && cd ../..
cd release/arm64_linux && tar cf gocommands_arm64_linux_${VERSION}_portable.tar gocmd && mv *.tar .. && cd ../..
rm -rf release/arm64_linux

# amd64_darwin
mkdir -p release/amd64_darwin
cd install && ./prep-install-script.sh ../release/amd64_darwin && cd ..
cd install && ./prep-shortcut-script.sh ../release/amd64_darwin && cd ..
CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build -ldflags=${LDFLAGS} -o release/amd64_darwin/gocmd cmd/*.go
cd release/amd64_darwin && tar cf gocommands_amd64_darwin_${VERSION}.tar * && mv *.tar .. && cd ../..
cd release/amd64_darwin && tar cf gocommands_amd64_darwin_${VERSION}_portable.tar gocmd && mv *.tar .. && cd ../..
rm -rf release/amd64_darwin

# arm64_darwin
mkdir -p release/arm64_darwin
cd install && ./prep-install-script.sh ../release/arm64_darwin && cd ..
cd install && ./prep-shortcut-script.sh ../release/arm64_darwin && cd ..
CGO_ENABLED=0 GOARCH=arm64 GOOS=darwin go build -ldflags=${LDFLAGS} -o release/arm64_darwin/gocmd cmd/*.go
cd release/arm64_darwin && tar cf gocommands_arm64_darwin_${VERSION}.tar * && mv *.tar .. && cd ../..
cd release/arm64_darwin && tar cf gocommands_arm64_darwin_${VERSION}_portable.tar gocmd && mv *.tar .. && cd ../..
rm -rf release/arm64_darwin

# i386_windows
mkdir -p release/i386_windows
CGO_ENABLED=0 GOARCH=386 GOOS=windows go build -ldflags=${LDFLAGS} -o release/i386_windows/gocmd.exe cmd/*.go
cd release/i386_windows && zip gocommands_i386_windows_${VERSION}.zip * && mv *.zip .. && cd ../..
cd release/i386_windows && zip gocommands_i386_windows_${VERSION}_portable.zip gocmd.exe && mv *.zip .. && cd ../..
rm -rf release/i386_windows

# amd64_windows
mkdir -p release/amd64_windows
CGO_ENABLED=0 GOARCH=amd64 GOOS=windows go build -ldflags=${LDFLAGS} -o release/amd64_windows/gocmd.exe cmd/*.go
cd release/amd64_windows && zip gocommands_amd64_windows_${VERSION}.zip * && mv *.zip .. && cd ../..
cd release/amd64_windows && zip gocommands_amd64_windows_${VERSION}_portable.zip gocmd.exe && mv *.zip .. && cd ../..
rm -rf release/amd64_windows
.PHONY: update_version
update_version:
./tools/update-version.sh README.md.template README.md
111 changes: 111 additions & 0 deletions README.md.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Gocommands
iRODS Command-line Tools written in Go


## Download pre-built binary
Please download binary file (bundled with `tar` or `zip`) at [https://github.com/cyverse/gocommands/releases](https://github.com/cyverse/gocommands/releases).
Be sure to download a binary for your target system architecture.

For Darwin-amd64 (Mac OS):
```bash
curl -L -o gocmd.tar.gz https://github.com/cyverse/gocommands/releases/download/v$VERSION/gocmd-v$VERSION-darwin-amd64.tar.gz && \
tar zxvf gocmd.tar.gz && rm gocmd.tar.gz
```

For Linux-amd64:
```bash
curl -L -o gocmd.tar.gz https://github.com/cyverse/gocommands/releases/download/v$VERSION/gocmd-v$VERSION-linux-amd64.tar.gz && \
tar zxvf gocmd.tar.gz && rm gocmd.tar.gz
```

For Linux-arm64:
```bash
curl -L -o gocmd.tar.gz https://github.com/cyverse/gocommands/releases/download/v$VERSION/gocmd-v$VERSION-linux-arm64.tar.gz && \
tar zxvf gocmd.tar.gz && rm gocmd.tar.gz
```


## How to use

### Using the iCommands configuration
`Gocommands` understands the iCommands' configuration files, `~/.irods/irods_environment.json`.
To create iCommands' configuration file, run `gocmd init` to create the configuration file under `~/.irods`.

```
gocmd init
```

If you already have iCommands' configuration files, you don't need any steps to do.

To check what configuration files you are loading
```
gocmd env
```

Run `ls`.
```
gocmd ls
```


### Using an external configuration file
`Gocommands` can read configuration from an `YAML` file.

Create `config.yaml` file using an editor and type in followings.
```yaml
irods_host: "data.cyverse.org"
irods_port: 1247
irods_user_name: "your username"
irods_zone_name: "iplant"
irods_user_password: "your password"
```

When you run `Gocommands`, provide the configuration file's path with `-c` flag.
```bash
gocmd -c config.yaml ls
```

Some of field values, such as `irods_user_password` can be omitted if you don't want to put it in clear text. `Gocommands` will ask you to type the missing field values in runtime.

### Using environmental variables
`Gocommands` can read configuration from environmental variables.

Set environmental variables
```bash
export IRODS_HOST="data.cyverse.org"
export IRODS_PORT=1247
export IRODS_USER_NAME="your username"
export IRODS_ZONE_NAME="iplant"
export IRODS_USER_PASSWORD="your password"
```

Then run `Gocommands` with `-e` flag.
```bash
gocmd -e ls
```

Some of field values, such as `IRODS_USER_PASSWORD` can be omitted if you don't want to put it in clear text. `Gocommands` will ask you to type the missing field values in runtime.

## Troubleshooting

### Getting `SYS_NOT_ALLOWED` error

`put`, `bput`, or `sync` subcommands throw `SYS_NOT_ALLOWED` error if iRODS server does not support data replication. To disable data replication, use `--no_replication` flag.


## License

Copyright (c) 2010-2023, The Arizona Board of Regents on behalf of The University of Arizona

All rights reserved.

Developed by: CyVerse as a collaboration between participants at BIO5 at The University of Arizona (the primary hosting institution), Cold Spring Harbor Laboratory, The University of Texas at Austin, and individual contributors. Find out more at http://www.cyverse.org/.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of CyVerse, BIO5, The University of Arizona, Cold Spring Harbor Laboratory, The University of Texas at Austin, nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission.


Please check [LICENSE](https://github.com/cyverse/gocommands/tree/master/LICENSE) file.
10 changes: 0 additions & 10 deletions install/install.sh.template

This file was deleted.

38 changes: 0 additions & 38 deletions install/prep-install-script.sh

This file was deleted.

18 changes: 0 additions & 18 deletions install/prep-shortcut-script.sh

This file was deleted.

10 changes: 0 additions & 10 deletions install/uninstall.sh.template

This file was deleted.

5 changes: 5 additions & 0 deletions package_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "gocommands",
"version": "0.6.4",
"git_repo": "https://github.com/cyverse/gocommands.git"
}
39 changes: 39 additions & 0 deletions tools/update-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
#
# This script updates variables in $1 and output to $2.
#
# It update following variables
#
# VERSION update it with "version" value in package_info.json

VERSION=$(jq -r .version package_info.json)


main()
{
expand_tmpl $1 > $2
}


# escapes / and \ for sed script
escape()
{
local var="$*"

# Escape \ first to avoid escaping the escape character, i.e. avoid / -> \/ -> \\/
var="${var//\\/\\\\}"

printf '%s' "${var//\//\\/}"
}


expand_tmpl()
{
cat <<EOF | sed --file - "$1"
s/\$VERSION/$(escape $VERSION)/g
EOF
}

set -e

main $1 $2

0 comments on commit b444fdd

Please sign in to comment.