Skip to content

Commit

Permalink
feat: add prompt-ui
Browse files Browse the repository at this point in the history
feat: configure and set algod data directory

fix: RX/TX display

fix: bit rate display for GB

fix: configuration override order

feat: handle invalid configuration and token gracefully

test: fix test state

fix: loading of custom endpoint address

fix: loading default port

test: clear viper settings

fix: finds path to directory and gives cmd instruction

feat: adds node start and node stop commands

fix: add -y

fix: turn script into indivudal commands

feat: check if sudo, clarify shell

chore: make more go idiomatic

fix: fix proper path check

fix: interact with systemctl, cleanup prompts

fix: remove sudo

fix: separate commands

fix: proper algorand service name

fix: calling with sudo

chore: testing systemctl

fix: checks algorand system service has been enabled directly

feat: implements editAlgorandServiceFile

fix: else statement

fix: quick check branch

fix: string template

feat: adds upgrade

chore: removeu nnecessary code

fix: check that installed and candidate are the same

chore: improve print

chore: add more output

fix: single quote

fix: -y

fix: systemctl

fix: upgrade and sudo text

chore: go mod tidy

fix: upgrade

feat: disable ui elements while syncing

feat: skip account loading on syncing
feat: remove offline account expires date

feat: installs algod and sets up service on mac

feat: refactor, + mac

feat: adds uninstall, mac only

fix: remove plist file

chore: rename

test: protocol snapshots and 100%

test: status snapshots and 100%

test: error page snapshots and 100%

test: controls snapshots

test: accounts snapshots

build: go mod tidy

README: Add alpha/dev warnings & notes

README: Moved note

README: added note

README: added note about admin token

README: reordered

README: numbered build steps

README: final note

test: add codecov reporter

ci: temp node test flow

chore: only when push

systemctl ENABLE

fix: rm -f file

fix: install start and uninstall for redhat

fix: add systemctl check

chore: printout

fix: ubuntu-based uninstall

fix: uninstallation remove service

fix: adds extar systemctl daemon-reload

chroe: temp

fix: provide output

chore: dont fail silently

fix: wildcard

fix: remove extra daemon-reload

fix: remore unnecessary output

chore: rephrase

ci: run in pushes
  • Loading branch information
HashMapsData2Value committed Nov 25, 2024
1 parent ecf00bd commit 415ea46
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 57 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/code_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ jobs:
run: go build -o bin/algorun *.go

- name: Test with the Go CLI
run: go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./...
run: go test ./... -coverprofile=./coverage.txt -covermode=atomic -coverpkg=./...

- name: Check test coverage
uses: vladopajic/go-test-coverage@v2
- name: Upload results to Codecov
uses: codecov/codecov-action@v4
with:
config: ./.testcoverage.yaml
token: ${{ secrets.CODECOV_TOKEN }}
58 changes: 58 additions & 0 deletions .github/workflows/node_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
## This is a temporary flow, until we have our custom docker images that work with systemd for linux.
## Once we have that, we can remove this and use docker containers in parallel, covering the various OS:es.

name: Node Command OS-Matrix Test

on:
workflow_dispatch:
push:
paths:
- "cmd/**"
pull_request:
paths:
- "cmd/**"

jobs:
ubuntu:
runs-on: ubuntu-latest

steps:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.22
- name: Run Ubuntu commands
run: |
git clone https://github.com/algorandfoundation/hack-tui.git
cd hack-tui
go build .
sudo ./hack-tui node install
sudo ./hack-tui node start
systemctl status algorand.service
export TOKEN=$(cat /var/lib/algorand/algod.admin.token)
curl http://localhost:8080/v2/participation -H "X-Algo-API-Token: $TOKEN" | grep "null"
sudo ./hack-tui node stop
sudo ./hack-tui node upgrade
# sudo ./hack-tui node configure
sudo ./hack-tui node uninstall
macos:
runs-on: macos-latest
steps:
- name: Run MacOs commands
run: |
brew install go
cd ~/
git clone https://github.com/algorandfoundation/hack-tui.git
cd hack-tui
go build .
sudo ./hack-tui node install
sudo ./hack-tui node start
sudo launchctl print system/com.algorand.algod
sleep 5
export TOKEN=$(cat ~/.algorand/algod.admin.token)
curl http://localhost:8080/v2/participation -H "X-Algo-API-Token: $TOKEN" | grep "null"
sudo ./hack-tui node stop
sudo ./hack-tui node upgrade
# sudo ./hack-tui node configure
sudo ./hack-tui node uninstall
26 changes: 0 additions & 26 deletions .testcoverage.yaml

This file was deleted.

33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,60 @@
---

Terminal UI for managing Algorand nodes.
Built with [bubbles](https://github.com/charmbracelet/bubbles)/[bubbletea](https://github.com/charmbracelet/bubbletea)
Built with [bubbles](https://github.com/charmbracelet/bubbles) & [bubbletea](https://github.com/charmbracelet/bubbletea)

> [!CAUTION]
> This project is in alpha state and under heavy development. We do not recommend performing actions (e.g. key management) on participation nodes connected to public networks.
# 🚀 Get Started

Run the build or ~~download the latest cli(WIP)~~.

> [!NOTE]
> We do not have pre-built binaries yet. If you are comfortable doing so, you are welcome to build it yourself and provide feedback.
## Building

Clone the repository
1. Clone the repository

```bash
git clone git@github.com:algorandfoundation/hack-tui.git
git clone https://github.com/algorandfoundation/hack-tui.git
```

Change to the project directory
2. Change to the project directory

```bash
cd hack-tui
```

Run the build command
3. Run the build command

```bash
make build
```

Start a participation node
4. Start a participation node

```bash
docker compose up
```

Connect to the node
> [!NOTE]
> The docker image is used for development and testing purposes. TUI will also work with native algod.
> If you have a node installed already, you can skip this step.
5. Connect to the node

```bash
./bin/algorun --server http://localhost:8080 --token aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
```

> [!CAUTION]
> This project is in alpha state and under heavy development. We do not recommend performing actions (e.g. key management) on participation nodes connected to public networks.
> [!NOTE]
> If you skipped the docker container, try running `./bin/algorun` standalone, which will detect your algorand data directory from the `ALGORAND_DATA` environment variable that works for `goal`. Otherwise, provide the `--server` and `--token` arguments so that it can find your node. Note that algorun requires the admin algod token.
# ℹ️ Usage

## ⚙️ Configuration
Expand Down Expand Up @@ -99,6 +115,9 @@ The application supports the `server` and `token` flags for configuration.
algorun --server http://localhost:8080 --token aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
```

> [!IMPORTANT]
> TUI requires the *admin* token in order to access participation key information. This can be found in the `algod.admin.token` file, e.g. `/var/lib/algorand/algod.admin.token`

## 🧑‍💻 Commands

The default command will launch the full TUI application
Expand Down
26 changes: 12 additions & 14 deletions cmd/node/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ var installCmd = &cobra.Command{
func installNode() {
fmt.Println("Checking if Algod is installed...")

// Check that we are calling with sudo
if !isRunningWithSudo() {
fmt.Println("This command must be run with super-user priviledges (sudo).")
os.Exit(1)
}

// Check if Algod is installed
if !isAlgodInstalled() {
fmt.Println("Algod is not installed. Installing...")
Expand All @@ -48,12 +54,6 @@ func installNode() {
func installNodeLinux() {
fmt.Println("Installing Algod on Linux")

// Check that we are calling with sudo
if !isRunningWithSudo() {
fmt.Println("This command must be run with super-user priviledges (sudo).")
os.Exit(1)
}

var installCmds [][]string
var postInstallHint string

Expand Down Expand Up @@ -87,7 +87,9 @@ func installNodeLinux() {
{"dnf", "install", "-y", "dnf-command(config-manager)"},
{"dnf", "config-manager", "--add-repo=https://releases.algorand.com/rpm/stable/algorand.repo"},
{"dnf", "install", "-y", "algorand-devtools"},
{"systemctl", "start", "algorand"},
{"systemctl", "enable", "algorand.service"},
{"systemctl", "start", "algorand.service"},
{"rm", "-f", "rpm_algorand.pub"},
}
} else if checkCmdToolExists("yum") { // On CentOs7 we use the yum package manager
fmt.Println("Using yum package manager")
Expand All @@ -97,7 +99,9 @@ func installNodeLinux() {
{"yum", "install", "yum-utils"},
{"yum-config-manager", "--add-repo", "https://releases.algorand.com/rpm/stable/algorand.repo"},
{"yum", "install", "-y", "algorand-devtools"},
{"systemctl", "start", "algorand"},
{"systemctl", "enable", "algorand.service"},
{"systemctl", "start", "algorand.service"},
{"rm", "-f", "rpm_algorand.pub"},
}
} else {
fmt.Println("Unsupported package manager, possibly due to non-Debian or non-Red Hat based Linux distribution. Will attempt to install using updater script.")
Expand Down Expand Up @@ -134,12 +138,6 @@ func installNodeLinux() {
func installNodeMac() {
fmt.Println("Installing Algod on macOS...")

// Check that we are calling with sudo
if !isRunningWithSudo() {
fmt.Println("This command must be run with super-user privileges (sudo).")
os.Exit(1)
}

// Homebrew is our package manager of choice
if !checkCmdToolExists("brew") {
fmt.Println("Could not find Homebrew installed. Please install Homebrew and try again.")
Expand Down
67 changes: 63 additions & 4 deletions cmd/node/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"runtime"
"strings"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -34,14 +35,14 @@ func unInstallNode() {
os.Exit(0)
}

fmt.Println("Algod is installed. Uninstalling...")

// Check if Algod is running
if isAlgodRunning() {
fmt.Println("Algod is running. Please run *node stop*.")
fmt.Println("Algod is running. Please run *node stop* first to stop it.")
os.Exit(1)
}

fmt.Println("Algod is installed. Proceeding...")

// Uninstall Algod based on OS
switch runtime.GOOS {
case "linux":
Expand Down Expand Up @@ -96,4 +97,62 @@ func unInstallNodeMac() {
fmt.Println("Algorand uninstalled successfully.")
}

func unInstallNodeLinux() {}
func unInstallNodeLinux() {

var unInstallCmds [][]string

if checkCmdToolExists("apt") { // On Ubuntu and Debian we use the apt package manager
fmt.Println("Using apt package manager")
unInstallCmds = [][]string{
{"apt", "remove", "algorand-devtools", "-y"},
{"apt", "autoremove", "-y"},
}
} else if checkCmdToolExists("apt-get") {
fmt.Println("Using apt-get package manager")
unInstallCmds = [][]string{
{"apt-get", "remove", "algorand-devtools", "-y"},
{"apt-get", "autoremove", "-y"},
}
} else if checkCmdToolExists("dnf") { // On Fedora and CentOs8 there's the dnf package manager
fmt.Println("Using dnf package manager")
unInstallCmds = [][]string{
{"dnf", "remove", "algorand-devtools", "-y"},
}
} else if checkCmdToolExists("yum") { // On CentOs7 we use the yum package manager
fmt.Println("Using yum package manager")
unInstallCmds = [][]string{
{"yum", "remove", "algorand-devtools", "-y"},
}
} else {
fmt.Println("Could not find a package manager to uninstall Algorand.")
os.Exit(1)
}

// Commands to clear systemd algorand.service and any other files, like the configuration override
unInstallCmds = append(unInstallCmds, []string{"bash", "-c", "sudo rm -rf /etc/systemd/system/algorand*"})
unInstallCmds = append(unInstallCmds, []string{"systemctl", "daemon-reload"})

// Run each installation command
for _, cmdArgs := range unInstallCmds {
fmt.Println("Running command:", strings.Join(cmdArgs, " "))
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Printf("Command failed: %s\nOutput: %s\nError: %v\n", strings.Join(cmdArgs, " "), output, err)
cobra.CheckErr(err)
}
}

// Check the status of the algorand service
cmd := exec.Command("systemctl", "status", "algorand")
output, err := cmd.CombinedOutput()
if err != nil && strings.Contains(string(output), "Unit algorand.service could not be found.") {
fmt.Println("Algorand service has been successfully removed.")
} else {
fmt.Printf("Failed to verify Algorand service uninstallation: %v\n", err)
fmt.Printf("Output: %s\n", string(output))
os.Exit(1)
}

fmt.Println("Algorand successfully uninstalled.")
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymanbagabas/go-udiff v0.2.0 // indirect
github.com/charmbracelet/x/ansi v0.3.2 // indirect
github.com/charmbracelet/x/exp/golden v0.0.0-20241022174419-46d9bb99a691 // indirect
github.com/charmbracelet/x/ansi v0.3.2
github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand Down

0 comments on commit 415ea46

Please sign in to comment.