Skip to content

Commit

Permalink
Merge pull request #21 from ipinfo/uman/pre-v1-fixes
Browse files Browse the repository at this point in the history
Pre-v1 fixes/updates
  • Loading branch information
UmanShahzad authored Mar 31, 2021
2 parents 43ea452 + 62f6bbc commit 1db031b
Show file tree
Hide file tree
Showing 23 changed files with 626 additions and 419 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ After choosing a platform `PLAT` from above, run:

```bash
# for Windows, use ".zip" instead of ".tar.gz"
$ curl -L https://github.com/ipinfo/cli/releases/download/1.0.0b3/ipinfo_1.0.0b3_${PLAT}.tar.gz
$ curl -L https://github.com/ipinfo/cli/releases/download/1.0.0/ipinfo_1.0.0_${PLAT}.tar.gz
# OR
$ wget https://github.com/ipinfo/cli/releases/download/1.0.0b3/ipinfo_1.0.0b3_${PLAT}.tar.gz
$ wget https://github.com/ipinfo/cli/releases/download/1.0.0/ipinfo_1.0.0_${PLAT}.tar.gz

$ tar -xvf ipinfo_1.0.0b3_${PLAT}.tar.gz
$ mv ipinfo_1.0.0b3_${PLAT} /usr/local/bin/ipinfo
$ tar -xvf ipinfo_1.0.0_${PLAT}.tar.gz
$ mv ipinfo_1.0.0_${PLAT} /usr/local/bin/ipinfo
```

### Using Homebrew
Expand All @@ -64,8 +64,8 @@ $ mv ipinfo_1.0.0b3_${PLAT} /usr/local/bin/ipinfo
The `ipinfo` binary will be installed in `/usr/local/bin/ipinfo`:

```bash
$ curl -L https://github.com/ipinfo/cli/releases/download/1.0.0b3/ipinfo_1.0.0b3.deb
$ sudo dpkg -i ipinfo_1.0.0b3.deb
$ curl -L https://github.com/ipinfo/cli/releases/download/1.0.0/ipinfo_1.0.0.deb
$ sudo dpkg -i ipinfo_1.0.0.deb
```

### Using Linux package managers
Expand Down
41 changes: 41 additions & 0 deletions grepip/build-all-platforms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# Build binary for all platforms for version $1.

set -e

DIR=`dirname $0`
ROOT=$DIR/..

VSN=$1

if [ -z "$VSN" ]; then
echo "require version as first parameter" 2>&1
exit 1
fi

for t in \
darwin_amd64 \
dragonfly_amd64 \
freebsd_amd64 \
linux_amd64 \
netbsd_amd64 \
openbsd_amd64 \
plan9_amd64 \
solaris_amd64 \
windows_amd64 ;
do
os="${t%_*}"
arch="${t#*_}"
output="grepip_${VSN}_${os}_${arch}"

if [ "$os" == "windows" ] ; then
output+=".exe"
fi

GOOS=$os GOARCH=$arch go build \
-o $ROOT/build/${output} \
$ROOT/grepip &
done

wait
10 changes: 10 additions & 0 deletions grepip/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Build local binary.

DIR=`dirname $0`
ROOT=$DIR/..

go build \
-o $ROOT/build/grepip \
$ROOT/grepip
File renamed without changes.
11 changes: 11 additions & 0 deletions grepip/dist/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Source: grepip
Section: utils
Version: 1.0.0
Priority: optional
Maintainer: IPinfo <[email protected]>
Vcs-Git: https://github.com/ipinfo/cli
Vcs-browser: https://github.com/ipinfo/cli
Homepage: https://ipinfo.io
Package: grepip
Architecture: amd64
Description: A grep-like tool for filtering IPv4 and IPv6 addresses.
63 changes: 63 additions & 0 deletions grepip/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"fmt"
"os"
"path/filepath"

"github.com/ipinfo/cli/lib"
"github.com/spf13/pflag"
)

var progBase = filepath.Base(os.Args[0])
var version = "1.0.0"

func printHelp() {
fmt.Printf(
`Usage: grepip [<opts>]
Options:
General:
--only-matching, -o
print only matched IP in result line, excluding surrounding content.
--no-filename, -h
don't print source of match in result lines when more than 1 source.
--no-recurse
don't recurse into more directories in directory sources.
--version
show binary release number.
--help
show help.
Filters:
--ipv4, -4
match only IPv4 addresses.
--ipv6, -6
match only IPv6 addresses.
--exclude-reserved, -x
exclude reserved/bogon IPs.
full list can be found at https://ipinfo.io/bogon.
`)
}

func cmd() error {
var fVsn bool

f := lib.CmdGrepIPFlags{}
f.Init()
pflag.BoolVarP(&fVsn, "version", "", false, "print binary release number.")
pflag.Parse()

if fVsn {
fmt.Println(version)
return nil
}

return lib.CmdGrepIP(f, pflag.Args(), printHelp)
}

func main() {
if err := cmd(); err != nil {
fmt.Printf("err: %v\n", err)
}
}
44 changes: 44 additions & 0 deletions grepip/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# Build and upload (to GitHub) for all platforms for version $1.

set -e

DIR=`dirname $0`
ROOT=$DIR/..

VSN=$1

if [ -z "$VSN" ]; then
echo "require version as first parameter" 2>&1
exit 1
fi

# build
rm -f $ROOT/build/grepip_${VSN}*
$ROOT/grepip/build-all-platforms.sh "$VSN"

# archive
cd $ROOT/build
for t in grepip_${VSN}_* ; do
if [[ $t == grepip_*_windows_* ]]; then
zip -q ${t/.exe/.zip} $t
else
tar -czf ${t}.tar.gz $t
fi
done
cd ..

# dist: debian
rm -rf $ROOT/grepip/dist/usr
mkdir -p $ROOT/grepip/dist/usr/local/bin
cp $ROOT/build/grepip_${VSN}_linux_amd64 $ROOT/grepip/dist/usr/local/bin/grepip
dpkg-deb --build ${ROOT}/grepip/dist build/grepip_${VSN}.deb

# release
gh release create grepip-${VSN} \
-R ipinfo/cli \
-t "grepip-${VSN}" \
$ROOT/build/grepip_*.tar.gz \
$ROOT/build/grepip_*.zip \
$ROOT/build/grepip_*.deb
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 1db031b

Please sign in to comment.