Skip to content

Commit a7beeba

Browse files
committed
chore: move agent config and key into dedicated directory
Create directory if doesn't exist.
1 parent e8b57b0 commit a7beeba

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

agent/installer.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
const (
17-
agentEnvFile = "/etc/shellhub-agent.env"
17+
agentEnvFile = "/etc/shellhub-agent/shellhub-agent.env"
1818
agentServiceFile = "/etc/systemd/system/shellhub-agent.service"
1919
agentServiceName = "shellhub-agent"
2020
)
@@ -26,7 +26,7 @@ Wants=network-online.target
2626
Requires=local-fs.target
2727
2828
[Service]
29-
EnvironmentFile=/etc/shellhub-agent.env
29+
EnvironmentFile=/etc/shellhub-agent/shellhub-agent.env
3030
ExecStart={{.BinaryPath}}
3131
Restart=on-failure
3232
RestartSec=5
@@ -83,12 +83,12 @@ func registerInstallerCommands(rootCmd *cobra.Command) {
8383

8484
installCmd.Flags().String("server-address", "", "ShellHub server address")
8585
installCmd.Flags().String("tenant-id", "", "Namespace tenant ID")
86-
installCmd.Flags().String("private-key", "/etc/shellhub.key", "Path to the agent private key file")
86+
installCmd.Flags().String("private-key", "/etc/shellhub-agent/shellhub.key", "Path to the agent private key file")
8787
installCmd.Flags().String("preferred-hostname", "", "Preferred device hostname")
8888
installCmd.Flags().String("preferred-identity", "", "Preferred device identity")
8989
installCmd.Flags().Uint("keepalive-interval", 30, "Keepalive interval in seconds")
9090
installCmd.MarkFlagRequired("server-address") //nolint:errcheck
91-
installCmd.MarkFlagRequired("tenant-id") //nolint:errcheck
91+
installCmd.MarkFlagRequired("tenant-id") //nolint:errcheck
9292

9393
rootCmd.AddCommand(installCmd)
9494

@@ -131,6 +131,10 @@ func agentInstall(cfg installerConfig) error {
131131
return fmt.Errorf("failed to resolve symlinks: %w", err)
132132
}
133133

134+
if err := os.MkdirAll(filepath.Dir(agentEnvFile), 0755); err != nil {
135+
return fmt.Errorf("failed to create directory %s: %w", filepath.Dir(agentEnvFile), err)
136+
}
137+
134138
if err := writeAgentEnvFile(cfg); err != nil {
135139
return fmt.Errorf("failed to write env file: %w", err)
136140
}

agent/packaging/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"__PREFERRED_HOSTNAME__",
1717
"__PREFERRED_IDENTITY__",
1818
"__KEEPALIVE_INTERVAL__",
19-
"SHELLHUB_PRIVATE_KEY=/host/etc/shellhub.key"
19+
"SHELLHUB_PRIVATE_KEY=/host/etc/shellhub-agent/shellhub.key"
2020
],
2121
"cwd": "/",
2222
"capabilities": {

install.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ podman_install() {
3939
esac
4040

4141
if [ -z "$MODE" ]; then
42-
ARGS="$ARGS -e SHELLHUB_PRIVATE_KEY=${PRIVATE_KEY:-/host/etc/shellhub.key}"
42+
ARGS="$ARGS -e SHELLHUB_PRIVATE_KEY=${PRIVATE_KEY:-/host/etc/shellhub-agent/shellhub.key}"
4343

4444
echo "🚀 Starting ShellHub container in Agent mode..."
4545
fi
@@ -106,7 +106,7 @@ docker_install() {
106106
esac
107107

108108
if [ -z "$MODE" ]; then
109-
ARGS="$ARGS -e SHELLHUB_PRIVATE_KEY=${PRIVATE_KEY:-/host/etc/shellhub.key}"
109+
ARGS="$ARGS -e SHELLHUB_PRIVATE_KEY=${PRIVATE_KEY:-/host/etc/shellhub-agent/shellhub.key}"
110110

111111
echo "🚀 Starting ShellHub container in Agent mode..."
112112
fi
@@ -165,7 +165,7 @@ snap_install() {
165165

166166
sudo snap set shellhub server-address="$SERVER_ADDRESS"
167167
sudo snap set shellhub tenant-id="$TENANT_ID"
168-
sudo snap set shellhub private-key="${PRIVATE_KEY:-/etc/shellhub.key}"
168+
sudo snap set shellhub private-key="${PRIVATE_KEY:-/etc/shellhub-agent/shellhub.key}"
169169

170170
sudo snap start shellhub
171171
} || {

0 commit comments

Comments
 (0)