Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added install scripts and missing check for resolvectl #160

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v1.0.22] - 2024-08-05

### Added
- install scripts for Linux, macOS and Windows
- check if `resolvectl` is available for `vpn` commands

### Fixed
- commands will now exit with exit code 1 for all error types

## [v1.0.20] - 2024-07-02

### Added
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012-2022 Scott Chacon and others
Copyright (c) 2023-2024 Zerops s.r.o.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,29 @@ for **CI/CD** development and CLI lovers.
* [wireguard](https://www.wireguard.com)

## Install zCLI
zCLI can be installed using npm:

### Windows
Execute following line in PowerShell
```powershell
irm https://raw.githubusercontent.com/zeropsio/zcli/main/install.ps1 | iex
```

### Linux/MacOS
Execute following line in Terminal
```shell
curl -L https://raw.githubusercontent.com/zeropsio/zcli/main/install.sh | sh
```

### Package managers

#### Npm
```
npm i -g @zerops/zcli
```

Currently, the zCLI is distributed for Linux (x86 & x64 architecture), macOS (x64 & M1 architecture) and Windows (x64 architecture).

To download the zCLI directly, use the latest release on GitHub.
To download the zCLI directly, use the [latest release](https://github.com/zeropsio/zcli/releases/latest/) on GitHub.

## Additional documentation

Expand Down
45 changes: 45 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env pwsh
# Copyright (c) 2023-2024 Zerops s.r.o. All rights reserved. MIT license.

$ErrorActionPreference = 'Stop'

if ($v) {
$Version = "v${v}"
}
if ($Args.Length -eq 1) {
$Version = $Args.Get(0)
}

$ZcliInstall = $env:ZCLI_INSTALL
$BinDir = if ($ZcliInstall) {
"${ZcliInstall}\bin"
} else {
"${Home}\.zerops\bin"
}

$ZcliExe = "$BinDir\zcli.exe"
$Target = 'win-x64'

$DownloadUrl = if (!$Version) {
"https://github.com/zeropsio/zcli/releases/latest/download/zcli-${Target}.exe"
} else {
"https://github.com/zeropsio/zcli/releases/download/${Version}/zcli-${Target}.exe"
}

if (!(Test-Path $BinDir)) {
New-Item $BinDir -ItemType Directory | Out-Null
}

curl.exe -Lo $ZcliExe $DownloadUrl

$User = [System.EnvironmentVariableTarget]::User
$Path = [System.Environment]::GetEnvironmentVariable('Path', $User)
if (!(";${Path};".ToLower() -like "*;${BinDir};*".ToLower())) {
[System.Environment]::SetEnvironmentVariable('Path', "${Path};${BinDir}", $User)
$Env:Path += ";${BinDir}"
}

Write-Output ""
Write-Output "ZCli was installed successfully to ${ZcliExe}"
Write-Output "Run 'zcli --help' to get started"
Write-Output "Stuck? Join our Discord https://discord.com/invite/WDvCZ54"
65 changes: 65 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/sh
# Copyright (c) 2023-2024 Zerops s.r.o. All rights reserved. MIT license.

set -e

case $(uname -sm) in
"Darwin x86_64") target="darwin-amd64" ;;
"Darwin arm64") target="darwin-arm64" ;;
"Linux i386") target="linux-i386" ;;
*) target="linux-amd64" ;;
esac

if [ $# -eq 0 ]; then
zcli_uri="https://github.com/zeropsio/zcli/releases/latest/download/zcli-${target}"
else
zcli_uri="https://github.com/zeropsio/zcli/releases/download/${1}/zcli-${target}"
fi

bin_dir="$HOME/.local/bin"
bin_path="$bin_dir/zcli"
bin_dir_existed=1

if [ ! -d "$bin_dir" ]; then
mkdir -p "$bin_dir"
bin_dir_existed=0

# By default `~/.local/bin` isn't included in PATH if it doesn't exist
# First try `.bash_profile`. It doesn't exist by default, but if it does, `.profile` is ignored by bash
if [ "$(uname -s)" = "Linux" ]; then
if [ -f "$HOME/.bash_profile" ]; then
. "$HOME/.bash_profile"
elif [ -f "$HOME/.profile" ]; then
. "$HOME/.profile"
fi
fi
fi

curl --fail --location --progress-bar --output "$bin_path" "$zcli_uri"
chmod +x "$bin_path"

echo
echo "zCLI was installed successfully to '$bin_path'"

if command -v zcli >/dev/null; then
echo "Run 'zcli --help' to get started"
if [ "$bin_dir_existed" = 0 ]; then
echo "ℹ️ You may need to relaunch your shell."
fi
else
if [ "$(uname -s)" = "Darwin" ]; then
echo 'Add following line to the `/etc/paths` file and relaunch your shell.';
echo " $HOME/.local/bin"
echo
echo 'You can do so by running:'
echo "sudo sh -c 'echo \"$HOME/.local/bin\" >> /etc/paths'"
else
echo "Manually add the directory to your '$HOME/.profile' (or similar) and relaunch your shell."
echo ' export PATH="$HOME/.local/bin:$PATH"'
fi
echo
echo "Run '$bin_path --help' to get started"
fi

echo
echo "Stuck? Join our Discord https://discord.com/invite/WDvCZ54"
2 changes: 2 additions & 0 deletions src/cmdBuilder/executeRootCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func printError(err error, uxBlocks uxBlock.UxBlocks) {

if userErr := errorsx.AsUserError(err); userErr != nil {
uxBlocks.PrintError(styles.ErrorLine(err.Error()))
os.Exit(1)
return
}

Expand All @@ -80,6 +81,7 @@ func printError(err error, uxBlocks uxBlock.UxBlocks) {
uxBlocks.PrintError(styles.ErrorLine(string(meta)))
}

os.Exit(1)
return
}

Expand Down
1 change: 1 addition & 0 deletions src/i18n/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ at https://docs.zerops.io/references/cli for further details.`,

// vpn shared
VpnWgQuickIsNotInstalled: "wg-quick is not installed, please visit https://www.wireguard.com/install/",
VpnResolveCtlIsNotInstalled: "resolvectl is not installed, please install systemd-resolved or equivalent for your distribution",
VpnWgQuickIsNotInstalledWindows: "wireguard is not installed, please visit https://www.wireguard.com/install/",

// flags description
Expand Down
1 change: 1 addition & 0 deletions src/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const (

// vpn shared
VpnWgQuickIsNotInstalled = "VpnWgQuickIsNotInstalled"
VpnResolveCtlIsNotInstalled = "VpnResolveCtlIsNotInstalled"
VpnWgQuickIsNotInstalledWindows = "VpnWgQuickIsNotInstalledWindows"

// flags description
Expand Down
8 changes: 5 additions & 3 deletions src/wg/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import (
)

func CheckWgInstallation() error {
_, err := exec.LookPath("wg-quick")
if err != nil {
if _, err := exec.LookPath("wg-quick"); err != nil {
return errors.New(i18n.T(i18n.VpnWgQuickIsNotInstalled))
}

// Debian does not have it by default anymore
if _, err := exec.LookPath("resolvectl"); err != nil {
return errors.New(i18n.T(i18n.VpnResolveCtlIsNotInstalled))
}
return nil
}

Expand Down
Loading