-
Notifications
You must be signed in to change notification settings - Fork 421
/
ssm_plugin_install_latest_binary_linux.go
61 lines (55 loc) · 1.76 KB
/
ssm_plugin_install_latest_binary_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// Package exec provides an interface to execute certain commands.
package exec
import (
"fmt"
"os"
"path/filepath"
"strings"
)
// InstallLatestBinary installs the latest ssm plugin.
func (s SSMPluginCommand) InstallLatestBinary() error {
if s.tempDir == "" {
dir, err := os.MkdirTemp("", "ssmplugin")
if err != nil {
return fmt.Errorf("create a temporary directory: %w", err)
}
defer os.RemoveAll(dir)
s.tempDir = dir
}
isUbuntu, err := s.isUbuntu()
if err != nil {
return err
}
if isUbuntu {
return s.installUbuntuBinary()
}
return s.installLinuxBinary()
}
func (s SSMPluginCommand) isUbuntu() (bool, error) {
if err := s.runner.Run("uname", []string{"-a"}, Stdout(&s.linuxDistVersionBuffer)); err != nil {
return false, fmt.Errorf("get linux distribution version: %w", err)
}
return strings.Contains(s.linuxDistVersionBuffer.String(), "Ubuntu"), nil
}
func (s SSMPluginCommand) installLinuxBinary() error {
if err := download(s.http, filepath.Join(s.tempDir, "session-manager-plugin.rpm"), linuxSSMPluginBinaryURL); err != nil {
return fmt.Errorf("download ssm plugin: %w", err)
}
if err := s.runner.Run("sudo", []string{"yum", "install", "-y",
filepath.Join(s.tempDir, "session-manager-plugin.rpm")}); err != nil {
return err
}
return nil
}
func (s SSMPluginCommand) installUbuntuBinary() error {
if err := download(s.http, filepath.Join(s.tempDir, "session-manager-plugin.deb"), ubuntuSSMPluginBinaryURL); err != nil {
return fmt.Errorf("download ssm plugin: %w", err)
}
if err := s.runner.Run("sudo", []string{"dpkg", "-i",
filepath.Join(s.tempDir, "session-manager-plugin.deb")}); err != nil {
return err
}
return nil
}