Shell
Installation​
go-c8y-cli
is available as a pre-built linux package which can be installed and updated via a package manager. Please following the instructions in 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.
After the installation, follow the instructions to setup your shell profile.
Debian / Ubuntu (apt)​
Install the apt dependencies
sudo apt-get install -y curl gnupg2 apt-transport-https
noteThe 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.Configure the repository
Debian >=9 and Ubuntu >= 16.04
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"noteThis step does not make use of
apt-key
as it has been deprecated. The gpg key is stored in an individual store only related to the go-c8y-cli repository, and it is linked via the apt.source settings using thesigned-by
property.Debian <=8 and Ubuntu <= 14.04
curl https://reubenmiller.github.io/go-c8y-cli-repo/debian/PUBLIC.KEY | sudo apt-key add -
sudo sh -c "echo 'deb https://reubenmiller.github.io/go-c8y-cli-repo/debian stable main' >> /etc/apt/sources.list"Update the repo then install/update
go-c8y-cli
sudo apt-get update
sudo apt-get install go-c8y-cliFollow the instructions to setup your shell profile
CentOS/RHEL/Fedora (dnf/yum)​
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.KEYUpdate the repo then install/update
go-c8y-cli
sudo dnf update
sudo dnf install go-c8y-cliFollow the instructions to setup your shell profile
You can install go-c8y-cli
via yum
by just replacing dnf
with yum
in the above commands.
Alpine (apk)​
The following commands require sudo. If you don't have sudo
installed, then remove the sudo
from the command, and run as root user.
Install the apk dependencies
sudo apk add wget
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/repositoriesUpdate the repo then install/update
go-c8y-cli
sudo apk update
sudo apk add go-c8y-cliFollow the instructions to setup your shell profile
MacOS/Linux (Homebrew)​
go-c8y-cli
can be installed using homebrew on either macOS or linux.
Add the tap
brew tap reubenmiller/go-c8y-cli
Update brew then install
go-c8y-cli
brew update
brew install go-c8y-clinoteRun the following if you want to update to the latest version (if not already installed)
brew upgrade go-c8y-cli
Edit your preferred shell by executing snippet (it will import functions each time you load your shell)
- Bash
- Zsh
- Fish
- PowerShell
echo 'source "$(brew --prefix)/etc/go-c8y-cli/shell/c8y.plugin.sh"' >> ~/.bashrc
echo 'source "$(brew --prefix)/etc/go-c8y-cli/shell/c8y.plugin.zsh"' >> ~/.zshrc
mkdir -p ~/.config/fish
echo 'source "$(brew --prefix)/etc/go-c8y-cli/shell/c8y.plugin.fish"' >> ~/.config/fish/config.fishNew-Item -type directory -path ~/.config/powershell -Force
'. "$(brew --prefix)/etc/go-c8y-cli/shell/c8y.plugin.ps1"' >> ~/.config/powershell/Microsoft.PowerShell_profile.ps1Restart your shell to reload your profile
You can also view the instructions on how to source the relevant plugin via the command brew info go-c8y-cli
Manually (via script)​
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.
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
Install go-c8y-cli binary
~/.go-c8y-cli/install.sh
Add the installation path to your
PATH
variable (ideally in your shell profile)- Bash
- Zsh
- Fish
file: ~/.bashrcexport PATH="$HOME/bin:$PATH"
file: ~/.zshrcexport PATH="$HOME/bin:$PATH"
file: ~/.config/fish/config.fishset -gx PATH "$HOME/bin:$PATH"
Reload your shell, or source your profile directly, i.e. bash:
source ~/.bashrc
Verify that the
c8y
binary is executable and can be found on the command linewhich c8y
Output/home/myuser/bin/c8y
tipTry closing your console and re-opening it so you can be sure that your setup will work next time
Setting up your shell profile​
Add the following line to your shell profile to enable the shell functions like set-session
and to configure tab completion for go-c8y-cli
.
- Bash
- Zsh
- Fish
- PowerShell
source "/etc/go-c8y-cli/shell/c8y.plugin.sh"
# or if you installed it via the script
source "$HOME/.go-c8y-cli/shell/c8y.plugin.sh"
source "/etc/go-c8y-cli/shell/c8y.plugin.zsh"
# or if you installed it via the script
source "$HOME/.go-c8y-cli/shell/c8y.plugin.zsh"
source "/etc/go-c8y-cli/shell/c8y.plugin.fish"
# or if you installed it via the script
source "$HOME/.go-c8y-cli/shell/c8y.plugin.fish"
. "/etc/go-c8y-cli/shell/c8y.plugin.ps1"
# or if you installed it via the script
. "$HOME/.go-c8y-cli/shell/c8y.plugin.ps1"
If you don't import the plugin script, then you will have to use the following to set your session:
- Bash
- Zsh
- Fish
- PowerShell
eval $(c8y sessions set --shell bash)
eval $(c8y sessions set --shell zsh)
c8y sessions set --shell fish | source
c8y sessions set --shell powershell | out-string | Invoke-Expression
Other recommended tools​
jq​
Since the output of the c8y cli tool 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"
Getting started​
After go-c8y-cli
has been installed, follow the Getting started section for instructions how to use it.