Skip to main content

Shell

Installation​

go-c8y-cli is available as a pre-built binary which can be installed and updated via a package manager. Please following the instructions for your operating system.

It is recommended to install go-c8y-cli using a package manager as it makes it easier to update it in the future, and it will be available for all users.

Debian / Ubuntu (apt)​

  1. Install the apt dependencies

    sudo apt-get install -y curl gnupg2 apt-transport-https
    note

    The command requires you to already have sudo installed. Most installations will have sudo by default so you don't need to do anything, however if you don't have it, install it via apt when running as a root user.

  2. Configure the repository

    curl https://reubenmiller.github.io/go-c8y-cli-repo/debian/PUBLIC.KEY | gpg --dearmor | sudo tee /usr/share/keyrings/go-c8y-cli-archive-keyring.gpg >/dev/null
    sudo sh -c "echo 'deb [signed-by=/usr/share/keyrings/go-c8y-cli-archive-keyring.gpg] http://reubenmiller.github.io/go-c8y-cli-repo/debian stable main' >> /etc/apt/sources.list"
  3. Update the repo then install/update go-c8y-cli

    sudo apt-get update
    sudo apt-get install go-c8y-cli
  4. Install go-c8y-cli helper functions and reload your shell

    c8y cli install
  5. Go to the Getting started section for the next steps


CentOS/RHEL/Fedora (dnf/yum)​

  1. Configure the repository

    Create a new file using your editor of choice (vi, vim, nano etc.)

    sudo vi /etc/yum.repos.d/go-c8y-cli.repo

    Then add the following contents to it and save the file.

    /etc/yum.repos.d/go-c8y-cli.repo
    [go-c8y-cli]
    name=go-c8y-cli packages
    baseurl=https://reubenmiller.github.io/go-c8y-cli-repo/rpm/stable
    enabled=1
    gpgcheck=1
    gpgkey=https://reubenmiller.github.io/go-c8y-cli-repo/rpm/PUBLIC.KEY
  2. Update the repo then install/update go-c8y-cli

    sudo dnf update
    sudo dnf install go-c8y-cli
  3. Install go-c8y-cli helper functions and reload your shell

    c8y cli install
  4. Go to the Getting started section for the next steps

note

You can install go-c8y-cli via yum by just replacing dnf with yum in the above commands.


Alpine (apk)​

note

The following commands require sudo. If you don't have sudo installed, then remove the sudo from the command, and run as root user.

  1. Install the apk dependencies

    sudo apk add wget
  2. Configure the repository

    sudo wget -O /etc/apk/keys/reuben.d.miller\@gmail.com-61e3680b.rsa.pub https://reubenmiller.github.io/go-c8y-cli-repo/alpine/PUBLIC.KEY

    # Add the repo
    sudo sh -c "echo 'https://reubenmiller.github.io/go-c8y-cli-repo/alpine/stable/main'" >> /etc/apk/repositories
  3. Update the repo then install/update go-c8y-cli

    sudo apk update
    sudo apk add go-c8y-cli
  4. Install go-c8y-cli helper functions and reload your shell

    c8y cli install
  5. Go to the Getting started section for the next steps


MacOS/Linux (Homebrew)​

go-c8y-cli can be installed using homebrew on either macOS or linux.

  1. Add the tap

    brew tap reubenmiller/go-c8y-cli
  2. Update brew then install go-c8y-cli

    brew update
    brew install go-c8y-cli
    note

    Run the following if you want to update to the latest version (if not already installed)

    brew upgrade go-c8y-cli
  3. Install go-c8y-cli helper functions and reload your shell

    c8y cli install
  4. Go to the Getting started section for the next steps

note

You can also view the instructions on how to source the relevant plugin via the command brew info go-c8y-cli


Manually (via script)​

info

The install script currently requires you to have jq installed. jq is a cli json parsing tool which is recommended to have anyways to do complex json manipulations that you might need during your daily use of c8y.

See the jq website for details how to install it on your operating system.

go-c8y-cli can also be installed by cloning a git repository and running an install script. It will install the latest binary and add the plugin script to your shell profile.

This method does not require sudo rights, however the binary will be located inside your user's home folder.

  1. Clone the addons repository containing the install script, views and some example templates.

    git clone https://github.com/reubenmiller/go-c8y-cli-addons.git ~/.go-c8y-cli
  2. Install go-c8y-cli binary

    ~/.go-c8y-cli/install.sh
  3. Add the installation path to your PATH variable (ideally in your shell profile)

    file: ~/.bashrc
    export PATH="$HOME/bin:$PATH"

    Reload your shell, or source your profile directly, i.e. bash: source ~/.bashrc

  4. Verify that the c8y binary is executable and can be found on the command line

    which c8y
    Output
    /home/myuser/bin/c8y
    tip

    Try closing your console and re-opening it so you can be sure that your setup will work next time

  5. Install go-c8y-cli helper functions and reload your shell

    c8y cli install
  6. Go to the Getting started section for the next steps


jq​

Since the output of go-c8y-cli is mainly json, it is highly recommended that you install the json cli tool jq to help formatting the output.

Example: Get the id of each devices from a query​

c8y devices list --select id

# Or csv output using
c8y devices list --select id --output csvheader

If you are more familiar with the popular jq tool, then you can use it to extract information that you need.

c8y devices list | jq -r ".id"