Skip to content

Commit 70b29c4

Browse files
committed
Merge pull request 'fix: handle non amd64 architecture via runtime identification' (#175) from fix/handle-non-amd64-architecture into main
Reviewed-on: https://gitea.obmondo.com/EnableIT/Linuxaid-cli/pulls/175
2 parents e54b39c + 3e0486e commit 70b29c4

7 files changed

Lines changed: 157 additions & 32 deletions

File tree

.goreleaser.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ version: 2
22

33
release:
44
footer: >-
5-
---
65
Released by [GoReleaser](https://github.com/goreleaser/goreleaser).
76
87
changelog:
@@ -27,10 +26,9 @@ archives:
2726
# This name template makes the OS and Arch compatible with the results of uname.
2827
name_template: >-
2928
{{ .ProjectName }}_
30-
{{- title .Os }}_
31-
{{- if eq .Arch "amd64" }}x86_64
32-
{{- else if eq .Arch "386" }}i386
33-
{{- else }}{{ .Arch }}{{ end }}
29+
{{ .Tag }}_
30+
{{- .Os }}_
31+
{{- .Arch }}_
3432
{{- if .Arm }}v{{ .Arm }}{{ end }}
3533
3634
before:

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
PATH := ./bin:$(PATH)
22
export NAME=linuxaid-cli
3-
export VERSION=v1.5.0
4-
export DIST=./dist
3+
export VERSION=$(shell ./scripts/latest-tag.sh)
54
export MAINTAINER=Ashish Jaiswal <ashish@obmondo.com>
6-
export PREFIX=/opt/obmondo/bin/
75
SOURCES := linuxaid
86

97
.PHONY: all dep build clean test format vet lint

README.md

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,72 @@
1-
# Go-Scripts
1+
# linuxaid-cli
22

3-
## obmondo-system-update Script
3+
> **Part of [Linuxaid](https://github.com/obmondo/linuxaid) by [Obmondo](https://obmondo.com)**
44
5-
## Flags
5+
A Linux system management toolkit that automates Puppet-based configuration management and system updates across Obmondo-managed infrastructure. The project provides two command-line applications for initial provisioning and ongoing system maintenance.
66

7-
- --no-reboot: Set this flag to prevent the system from rebooting after the update.
7+
## Applications
8+
9+
### linuxaid-install
10+
11+
Initial system provisioning tool that installs and configures the Puppet agent (openvox-agent). Requires an `TOKEN` environment variable for authentication.
12+
13+
**Usage:**
14+
15+
```bash
16+
TOKEN='your-token'
17+
linuxaid-install --certname web01.example --puppet-server your.openvoxserver.com
18+
```
19+
20+
### linuxaid-cli
21+
22+
System management CLI for Puppet-managed nodes with commands for automated maintenance operations.
23+
24+
**Commands:**
25+
26+
- `system-update` - Executes distribution-specific package updates with service window coordination
27+
- `run-openvox` - Runs Puppet agent with connectivity checks and status reporting
28+
29+
**Usage:**
30+
31+
```bash
32+
linuxaid-cli system-update --certname web01.example --no-reboot
33+
linuxaid-cli run-openvox --certname web01.example
34+
```
35+
36+
## Features
37+
38+
- **Automated Puppet Agent Management**: Complete lifecycle management including installation, configuration, and execution
39+
- **Remote Logging**: gRPC-based streaming of command execution output to Obmondo API
40+
- **Service Window Coordination**: Integrates with Obmondo backend for maintenance window management
41+
- **Multi-Distribution Support**: Ubuntu, Debian, RHEL, CentOS, SLES, and TurrisOS
42+
43+
## Building
44+
45+
```bash
46+
make build
47+
```
48+
49+
This produces two binaries: `linuxaid-install` and `linuxaid-cli`.
50+
51+
## Configuration
52+
53+
Configuration uses a three-tier precedence system via Viper:
54+
55+
1. Command-line flags (highest priority)
56+
2. Environment variables
57+
3. Default values
58+
59+
**Key Parameters:**
60+
61+
- `--certname` / `CERTNAME` - Certificate name (required)
62+
- `--puppet-server` / `PUPPET_SERVER` - Puppet server hostname
63+
- `--debug` / `DEBUG` - Enable debug logging
64+
- `--no-reboot` / `NO_REBOOT` - Disable automatic reboot after updates
65+
- `--skip-openvox` / `SKIP_OPENVOX` - Skip Puppet agent run
66+
67+
## Dependencies
68+
69+
- Cobra for CLI framework
70+
- Viper for configuration management
71+
- gRPC for remote logging
72+
- Bitfield/script for shell command execution

cmd/linuxaid-install/install.go

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,40 @@ func compatibilityCheck(puppetService *puppet.Service) error {
5252
return nil
5353
}
5454

55+
// func shouldContinueAfterConfirmation determines if the installation process should continue after user confirmation.
56+
// If the user provides no input (white spaces, newline, tab, etc), the same confirmation question is asked again.
57+
//
58+
// Inputs for continuation:
59+
// - y (case-insensitive)
60+
// - yes (case-insensitive)
61+
//
62+
// Anything other than this is considered as "no", and the program will exit.
63+
func shouldContinueAfterConfirmation() bool {
64+
// I'm really not a fan of infinite loops, but just for this time I'll pretend I didn't wrote this.
65+
for {
66+
prettyfmt.PrettyPrintf(" %s Please confirm to continue (Yes/No)? ", prettyfmt.IconQuestion)
67+
68+
// Accept user input for confirmation
69+
reader := bufio.NewReader(os.Stdin)
70+
input, _ := reader.ReadString('\n')
71+
input = strings.ToLower(input)
72+
input = strings.TrimSpace(input)
73+
74+
if input == "" {
75+
continue
76+
}
77+
78+
if input != "y" && input != "yes" {
79+
prettyfmt.PrettyPrintf("\n Exiting the setup...\n")
80+
return false
81+
}
82+
83+
// Dummy new line for better clarity of things
84+
prettyfmt.PrettyPrintln("")
85+
return true
86+
}
87+
}
88+
5589
func Install() {
5690
// Re-initialise the logger with progressbar writer to not disturb the
5791
// progressbar if we print any logs. Everything is handled by progressbar's
@@ -69,21 +103,12 @@ func Install() {
69103

70104
webtee.RemoteLogObmondo([]string{"echo Starting Linuxaid Install Setup "}, certname)
71105
prettyfmt.PrettyPrintf(" %s %s %s %s %s\n", prettyfmt.IconGear, prettyfmt.FontWhite("Configuring Linuxaid on"), prettyfmt.FontYellow(certname), prettyfmt.FontWhite("with puppetserver"), prettyfmt.FontYellow(puppetServer))
72-
prettyfmt.PrettyPrintf(" %s Running this tool will install and configure %s in your system.\n %s Please confirm to continue (Yes/No)? ", prettyfmt.IconGear, prettyfmt.FontYellow("Openvox agent"), prettyfmt.IconQuestion)
106+
prettyfmt.PrettyPrintf(" %s Running this tool will install and configure %s in your system.\n", prettyfmt.IconGear, prettyfmt.FontYellow("Openvox agent"))
73107

74-
// Accept user input for confirmation
75-
reader := bufio.NewReader(os.Stdin)
76-
input, _ := reader.ReadString('\n')
77-
input = strings.TrimSpace(input)
78-
79-
if input != "y" && input != "yes" {
80-
prettyfmt.PrettyPrintf("\n Exiting the setup...\n")
108+
if !shouldContinueAfterConfirmation() {
81109
return
82110
}
83111

84-
// Dummy new line for better clarity of things
85-
prettyfmt.PrettyPrintln("")
86-
87112
if err := progress.NonDeterministicFunc("Verifying Token", func() error {
88113
input := &api.InstallScriptInput{
89114
Certname: certname,

cmd/linuxaid-install/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var rootCmd = &cobra.Command{
5252
errMsg := "Uh ho. I couldn't figure out the token, please provide one as an ENV"
5353
prettyfmt.PrettyPrintf("\n %s %s %s\n", prettyfmt.IconCheckFail, prettyfmt.FontWhite(errMsg), prettyfmt.FontYellow(constant.InstallTokenEnv))
5454

55-
slog.Debug("install token is required. Provide via INSTALL_TOKEN environment variable")
55+
slog.Debug("install token is required. Provide via TOKEN environment variable")
5656
os.Exit(1)
5757
}
5858

helper/provisioner/provisioner.go

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package provisioner
22

33
import (
4+
"errors"
45
"fmt"
56
"log/slog"
67
"os"
78
"path/filepath"
9+
"runtime"
810

911
"gitea.obmondo.com/EnableIT/linuxaid-cli/constant"
1012
"gitea.obmondo.com/EnableIT/linuxaid-cli/helper"
@@ -13,7 +15,12 @@ import (
1315
"gitea.obmondo.com/EnableIT/linuxaid-cli/pkg/webtee"
1416
)
1517

16-
const tmpDir = "/tmp"
18+
const (
19+
tmpDir = "/tmp"
20+
21+
archAmd64 = "amd64"
22+
archArm64 = "arm64"
23+
)
1724

1825
type Provisioner struct {
1926
webtee *webtee.Webtee
@@ -72,8 +79,14 @@ func (s *Provisioner) provisionForDebian() error {
7279
ubuntuVersion = "ubuntu24.04"
7380
}
7481

82+
switch runtime.GOARCH {
83+
case archAmd64, archArm64:
84+
default:
85+
return errors.New("unsupported system architecture")
86+
}
87+
7588
fullPuppetVersion := fmt.Sprintf("%s-1+%s", constant.PuppetVersion, ubuntuVersion)
76-
packageName := fmt.Sprintf("openvox-agent_%s_amd64.deb", fullPuppetVersion)
89+
packageName := fmt.Sprintf("openvox-agent_%s_%s.deb", fullPuppetVersion, runtime.GOARCH)
7790
downloadPath := filepath.Join(tmpDir, packageName)
7891
url := fmt.Sprintf("https://repos.obmondo.com/openvox/apt/pool/%s/o/openvox-agent/%s",
7992
constant.PuppetMajorVersion, packageName)
@@ -93,11 +106,21 @@ func (s *Provisioner) provisionForRedHat() error {
93106

94107
majRelease := helper.GetMajorRelease()
95108

109+
runtimeArch := runtime.GOARCH
110+
switch runtimeArch {
111+
case archAmd64:
112+
runtimeArch = "x86_64"
113+
case archArm64:
114+
runtimeArch = "aarch64"
115+
default:
116+
return errors.New("unsupported system architecture")
117+
}
118+
96119
fullPuppetVersion := fmt.Sprintf("%s-1.el%s", constant.PuppetVersion, majRelease)
97-
packageName := fmt.Sprintf("openvox-agent-%s.x86_64", fullPuppetVersion)
120+
packageName := fmt.Sprintf("openvox-agent-%s.%s", fullPuppetVersion, runtimeArch)
98121
downloadPath := filepath.Join(tmpDir, packageName+".rpm")
99-
url := fmt.Sprintf("https://repos.obmondo.com/openvox/yum/%s/el/%s/x86_64/%s.rpm",
100-
constant.PuppetMajorVersion, majRelease, packageName)
122+
url := fmt.Sprintf("https://repos.obmondo.com/openvox/yum/%s/el/%s/%s/%s.rpm",
123+
constant.PuppetMajorVersion, majRelease, runtimeArch, packageName)
101124

102125
if err := s.puppet.DownloadAgent(downloadPath, url); err != nil {
103126
return err
@@ -115,11 +138,21 @@ func (s *Provisioner) provisionForSuse() error {
115138

116139
majRelease := helper.GetMajorRelease()
117140

141+
runtimeArch := runtime.GOARCH
142+
switch runtimeArch {
143+
case archAmd64:
144+
runtimeArch = "x86_64"
145+
case archArm64:
146+
runtimeArch = "aarch64"
147+
default:
148+
return errors.New("unsupported system architecture")
149+
}
150+
118151
fullPuppetVersion := fmt.Sprintf("%s-1.sles%s", constant.PuppetVersion, majRelease)
119-
packageName := fmt.Sprintf("openvox-agent-%s.x86_64", fullPuppetVersion)
152+
packageName := fmt.Sprintf("openvox-agent-%s.%s", fullPuppetVersion, runtimeArch)
120153
downloadPath := filepath.Join(tmpDir, packageName+".rpm")
121-
url := fmt.Sprintf("https://repos.obmondo.com/openvox/sles/%s/%s/x86_64/%s.rpm",
122-
constant.PuppetMajorVersion, majRelease, packageName)
154+
url := fmt.Sprintf("https://repos.obmondo.com/openvox/sles/%s/%s/%s/%s.rpm",
155+
constant.PuppetMajorVersion, majRelease, runtimeArch, packageName)
123156

124157
if err := s.puppet.DownloadAgent(downloadPath, url); err != nil {
125158
return err

scripts/latest-tag.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
# Exit on any error
3+
set -e
4+
5+
# Get the most recent tag sorted by commit date (most recent first)
6+
git describe --tags --abbrev=0 "$(git rev-list --tags --max-count=1)"

0 commit comments

Comments
 (0)