Skip to content

Commit c8e8e57

Browse files
committed
Merge pull request 'feat: add turrisos support for installation check' (#191) from feat/add-turrisos-support-for-installation-check into main
Reviewed-on: https://gitea.obmondo.com/EnableIT/Linuxaid-cli/pulls/191
2 parents 7eb074e + 6b91605 commit c8e8e57

5 files changed

Lines changed: 67 additions & 42 deletions

File tree

constant/constants.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ const (
77
PuppetPackageName = "puppet-agent"
88
PuppetPath = "/sbin:/usr/sbin:/bin:/usr/bin:/opt/puppetlabs/puppet/bin"
99
PuppetConfig = "/etc/puppetlabs/puppet/puppet.conf"
10-
PuppetVersion = "8.23.1"
10+
OpenvoxVersion = "8.24.2"
1111
PuppetMajorVersion = "openvox8"
1212
PuppetCertEnv = "PUPPETCERT"
1313
PuppetPrivKeyEnv = "PUPPETPRIVKEY"
1414
InstallTokenEnv = "TOKEN"
1515
ExternalFacterFile = "/etc/puppetlabs/facter/facts.d/new_installation.yaml"
1616
PuppetPrivKeyPath = "/etc/puppetlabs/puppet/ssl/private_keys"
1717

18-
// Openvox
19-
OpenvoxAgentVersionTurris = "7.37.2"
20-
2118
// Lock and Disabled
2219
AgentDisabledLockFile = "/opt/puppetlabs/puppet/cache/state/agent_disabled.lock"
2320
AgentRunningLockFile = "/opt/puppetlabs/puppet/cache/state/agent_catalog_run.lock"

helper/os_release.go

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,28 @@ import (
1010
)
1111

1212
const (
13-
constDistributionNameUbuntu = "ubuntu"
14-
constDistributionNameDebian = "debian"
15-
constDistributionNameSLES = "sles"
16-
constDistributionNameCentOS = "centos"
17-
constDistributionNameRHEL = "rhel"
18-
constDistributionNameOracleLinux = "ol"
13+
ConstDistributionNameUbuntu = "ubuntu"
14+
ConstDistributionNameDebian = "debian"
15+
ConstDistributionNameSLES = "sles"
16+
ConstDistributionNameCentOS = "centos"
17+
ConstDistributionNameRHEL = "rhel"
18+
ConstDistributionNameOracleLinux = "ol"
19+
ConstDistributionNameTurrisOS = "turrisos"
1920

20-
constDistributionDebianUpdateRepoListCmd = "apt update"
21-
constDistributionSLESUpdateRepoListCmd = "zypper refresh"
22-
constDistributionRHELUpdateRepoListCmd = "yum repolist"
21+
constDistributionDebianUpdateRepoListCmd = "apt update"
22+
constDistributionSLESUpdateRepoListCmd = "zypper refresh"
23+
constDistributionRHELUpdateRepoListCmd = "yum repolist"
24+
constDistributionOpenWRTUpdateRepoListCmd = "opkg update"
2325

24-
constDistributionDebianCheckCACertificatesCmd = "dpkg-query -W ca-certificates openssl"
25-
constDistributionSLESCheckCACertificatesCmd = "rpm -q ca-certificates openssl ca-certificates-cacert ca-certificates-mozilla"
26-
constDistributionRHELCheckCACertificatesCmd = "rpm -q ca-certificates openssl"
26+
constDistributionDebianCheckCACertificatesCmd = "dpkg-query -W ca-certificates openssl"
27+
constDistributionSLESCheckCACertificatesCmd = "rpm -q ca-certificates openssl ca-certificates-cacert ca-certificates-mozilla"
28+
constDistributionRHELCheckCACertificatesCmd = "rpm -q ca-certificates openssl"
29+
constDistributionOpenWRTCheckCACertificatesCmd = "opkg list-installed ca-certificates openssl"
2730

28-
constDistributionDebianInstallCACertificatesCmd = "apt install -y ca-certificates"
29-
constDistributionSLESInstallCACertificatesCmd = "zypper install -y ca-certificates openssl ca-certificates-cacert ca-certificates-mozilla"
30-
constDistributionRHELInstallCACertificatesCmd = "yum install -y ca-certificates openssl"
31+
constDistributionDebianInstallCACertificatesCmd = "apt install -y ca-certificates"
32+
constDistributionSLESInstallCACertificatesCmd = "zypper install -y ca-certificates openssl ca-certificates-cacert ca-certificates-mozilla"
33+
constDistributionRHELInstallCACertificatesCmd = "yum install -y ca-certificates openssl"
34+
constDistributionOpenWRTInstallCACertificatesCmd = "opkg install libopenssl openssl-util libopenssl-conf"
3135
)
3236

3337
type CertificateManagerCommands struct {
@@ -57,24 +61,30 @@ func IsSupportedOS() (CertificateManagerCommands, error) {
5761
// 3. command to install CA certificates
5862
func getCommandsForInstallingCACertificates() (CertificateManagerCommands, error) {
5963
switch os.Getenv("ID") {
60-
case constDistributionNameUbuntu, constDistributionNameDebian:
64+
case ConstDistributionNameUbuntu, ConstDistributionNameDebian:
6165
return CertificateManagerCommands{
6266
updateRepoListCmd: constDistributionDebianUpdateRepoListCmd,
6367
checkCACertificatesCmd: constDistributionDebianCheckCACertificatesCmd,
6468
installCACertificatesCmd: constDistributionDebianInstallCACertificatesCmd,
6569
}, nil
66-
case constDistributionNameSLES:
70+
case ConstDistributionNameSLES:
6771
return CertificateManagerCommands{
6872
updateRepoListCmd: constDistributionSLESUpdateRepoListCmd,
6973
checkCACertificatesCmd: constDistributionSLESCheckCACertificatesCmd,
7074
installCACertificatesCmd: constDistributionSLESInstallCACertificatesCmd,
7175
}, nil
72-
case constDistributionNameCentOS, constDistributionNameRHEL, constDistributionNameOracleLinux:
76+
case ConstDistributionNameCentOS, ConstDistributionNameRHEL, ConstDistributionNameOracleLinux:
7377
return CertificateManagerCommands{
7478
updateRepoListCmd: constDistributionRHELUpdateRepoListCmd,
7579
checkCACertificatesCmd: constDistributionRHELCheckCACertificatesCmd,
7680
installCACertificatesCmd: constDistributionRHELInstallCACertificatesCmd,
7781
}, nil
82+
case ConstDistributionNameTurrisOS:
83+
return CertificateManagerCommands{
84+
updateRepoListCmd: constDistributionOpenWRTUpdateRepoListCmd,
85+
checkCACertificatesCmd: constDistributionOpenWRTCheckCACertificatesCmd,
86+
installCACertificatesCmd: constDistributionOpenWRTInstallCACertificatesCmd,
87+
}, nil
7888
}
7989
return CertificateManagerCommands{}, errors.New("unknown distribution")
8090
}

helper/provisioner/provisioner.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@ func NewService(apiClient api.ObmondoClient, puppet *puppet.Service, webtee *web
4141

4242
func (s *Provisioner) ProvisionPuppet() {
4343
switch os.Getenv("ID") {
44-
case "ubuntu", "debian":
44+
case helper.ConstDistributionNameUbuntu, helper.ConstDistributionNameDebian:
4545
if err := s.provisionForDebian(); err != nil {
4646
slog.Error("failed to install puppet", slog.Any("error", err))
4747
os.Exit(1)
4848
}
49-
case "sles":
49+
case helper.ConstDistributionNameSLES:
5050
if err := s.provisionForSuse(); err != nil {
5151
slog.Error("failed to install puppet", slog.Any("error", err))
5252
os.Exit(1)
5353
}
54-
case "centos", "rhel", "ol":
54+
case helper.ConstDistributionNameCentOS, helper.ConstDistributionNameRHEL, helper.ConstDistributionNameOracleLinux:
5555
if err := s.provisionForRedHat(); err != nil {
5656
slog.Error("failed to install puppet", slog.Any("error", err))
5757
os.Exit(1)
5858
}
59-
case "turrisos":
59+
case helper.ConstDistributionNameTurrisOS:
6060
s.provisionForTurris()
6161
default:
6262
slog.Error("unknown distribution, exiting")
@@ -85,7 +85,7 @@ func (s *Provisioner) provisionForDebian() error {
8585
return errors.New("unsupported system architecture")
8686
}
8787

88-
fullPuppetVersion := fmt.Sprintf("%s-1+%s", constant.PuppetVersion, ubuntuVersion)
88+
fullPuppetVersion := fmt.Sprintf("%s-1+%s", constant.OpenvoxVersion, ubuntuVersion)
8989
packageName := fmt.Sprintf("openvox-agent_%s_%s.deb", fullPuppetVersion, runtime.GOARCH)
9090
downloadPath := filepath.Join(tmpDir, packageName)
9191
url := fmt.Sprintf("https://repos.obmondo.com/openvox/apt/pool/%s/o/openvox-agent/%s",
@@ -116,7 +116,7 @@ func (s *Provisioner) provisionForRedHat() error {
116116
return errors.New("unsupported system architecture")
117117
}
118118

119-
fullPuppetVersion := fmt.Sprintf("%s-1.el%s", constant.PuppetVersion, majRelease)
119+
fullPuppetVersion := fmt.Sprintf("%s-1.el%s", constant.OpenvoxVersion, majRelease)
120120
packageName := fmt.Sprintf("openvox-agent-%s.%s", fullPuppetVersion, runtimeArch)
121121
downloadPath := filepath.Join(tmpDir, packageName+".rpm")
122122
url := fmt.Sprintf("https://repos.obmondo.com/openvox/yum/%s/el/%s/%s/%s.rpm",
@@ -148,7 +148,7 @@ func (s *Provisioner) provisionForSuse() error {
148148
return errors.New("unsupported system architecture")
149149
}
150150

151-
fullPuppetVersion := fmt.Sprintf("%s-1.sles%s", constant.PuppetVersion, majRelease)
151+
fullPuppetVersion := fmt.Sprintf("%s-1.sles%s", constant.OpenvoxVersion, majRelease)
152152
packageName := fmt.Sprintf("openvox-agent-%s.%s", fullPuppetVersion, runtimeArch)
153153
downloadPath := filepath.Join(tmpDir, packageName+".rpm")
154154
url := fmt.Sprintf("https://repos.obmondo.com/openvox/sles/%s/%s/%s/%s.rpm",
@@ -169,6 +169,6 @@ func (s *Provisioner) provisionForTurris() {
169169
s.webtee.RemoteLogObmondo([]string{"opkg update"}, s.certName)
170170
s.webtee.RemoteLogObmondo([]string{"opkg install ruby ruby-stdlib ruby-dev ruby-gems"}, s.certName)
171171

172-
installCmd := []string{fmt.Sprintf("gem install -v %s --no-document openvox", constant.OpenvoxAgentVersionTurris)}
172+
installCmd := []string{fmt.Sprintf("gem install -v %s --no-document openvox", constant.OpenvoxVersion)}
173173
s.webtee.RemoteLogObmondo(installCmd, s.certName)
174174
}

pkg/puppet/puppet.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,20 @@ func (*Service) EnableAgent() error {
5656

5757
// Disable puppet-agent service (sanity-check)
5858
func (s *Service) DisableAgentService() {
59-
// Disable unattended-upgrades so puppet-agent package does not update
60-
s.webtee.RemoteLogObmondo([]string{
61-
"puppet resource service unattended-upgrades ensure=stopped enable=false",
62-
}, s.certName)
59+
// There is no init script named unattended-upgrades, and puppet in /etc/init.d/ in TurrisOS system
60+
if os.Getenv("ID") != helper.ConstDistributionNameTurrisOS {
61+
// Disable unattended-upgrades so puppet-agent package does not update
62+
s.webtee.RemoteLogObmondo([]string{
63+
"puppet resource service unattended-upgrades ensure=stopped enable=false",
64+
}, s.certName)
6365

64-
// Stop puppet agent service, since we manage it via run_puppet service
65-
s.webtee.RemoteLogObmondo([]string{
66-
"puppet resource service puppet ensure=stopped enable=false",
67-
}, s.certName)
66+
// Stop puppet agent service, since we manage it via run_puppet service
67+
s.webtee.RemoteLogObmondo([]string{
68+
"puppet resource service puppet ensure=stopped enable=false",
69+
}, s.certName)
6870

69-
slog.Debug("puppet agent service disabled")
71+
slog.Debug("puppet agent service disabled")
72+
}
7073
}
7174

7275
// Disable agent with message
@@ -94,7 +97,14 @@ func (s *Service) RunAgent(remoteLog bool, noopMode string) int {
9497
slog.Info("running puppet agent", slog.String("mode", noopMode))
9598
pipe := script.Exec(cmd)
9699
if _, err := pipe.Stdout(); err != nil {
97-
if !slices.Contains(constant.PuppetSuccessExitCodes, pipe.ExitStatus()) {
100+
// We're patching the error handling for turrisos for now, since we're still updating
101+
// linuxaid support. Once done, we'll remove this special handling.
102+
successStatusCodes := constant.PuppetSuccessExitCodes
103+
if os.Getenv("ID") == helper.ConstDistributionNameTurrisOS {
104+
successStatusCodes = append(successStatusCodes, 4, 6) // nolint: mnd
105+
}
106+
107+
if !slices.Contains(successStatusCodes, pipe.ExitStatus()) {
98108
slog.Error("stdout error", slog.Any("error", err))
99109
}
100110
}
@@ -145,7 +155,7 @@ noop = true
145155
environment = %s
146156
`
147157
content := fmt.Sprintf(cfg, s.openvoxServer, s.certName, s.openvoxEnv)
148-
if _, err := script.Echo(content).WriteFile(constant.PuppetConfig); err != nil {
158+
if err := os.WriteFile(constant.PuppetConfig, []byte(content), os.FileMode(os.O_TRUNC|os.O_CREATE)); err != nil {
149159
s.webtee.RemoteLogObmondo([]string{fmt.Sprintf("echo failed to configure puppet: %s", err)}, s.certName)
150160
os.Exit(1)
151161
}

pkg/webtee/webtee.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"sync"
1414

1515
"gitea.obmondo.com/EnableIT/linuxaid-cli/constant"
16+
"gitea.obmondo.com/EnableIT/linuxaid-cli/helper"
1617
api "gitea.obmondo.com/EnableIT/linuxaid-cli/pkg/obmondo"
1718
)
1819

@@ -108,7 +109,14 @@ func (w *Webtee) RemoteLogObmondo(command []string, certname string) {
108109
}
109110

110111
func shouldIgnorePuppetAgentError(command []string, exitCode int) bool {
111-
return strings.Contains(strings.Join(command, " "), "puppet agent") && slices.Contains(constant.PuppetSuccessExitCodes, exitCode)
112+
// We're patching the error handling for turrisos for now, since we're still updating
113+
// linuxaid support. Once done, we'll remove this special handling.
114+
successStatusCodes := constant.PuppetSuccessExitCodes
115+
if os.Getenv("ID") == helper.ConstDistributionNameTurrisOS {
116+
successStatusCodes = append(successStatusCodes, 4, 6) // nolint: mnd
117+
}
118+
119+
return strings.Contains(strings.Join(command, " "), "puppet agent") && slices.Contains(successStatusCodes, exitCode)
112120
}
113121

114122
// readPipe reads a pipe, wraps every line in an "echo" command, prints it, and sends the line to

0 commit comments

Comments
 (0)