-
Notifications
You must be signed in to change notification settings - Fork 13
feat: Support Debian-based distros #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,6 +3,19 @@ exec > >(tee /var/log/user-data.log | logger -t user-data -s 2>/dev/console) 2>& | |||||||||||||||||||||
|
||||||||||||||||||||||
echo "Starting user-data script..." | ||||||||||||||||||||||
|
||||||||||||||||||||||
echo "Determining package manager..." | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Work with both dnf and apt-get. | ||||||||||||||||||||||
if command -v apt-get >/dev/null 2>&1; then | ||||||||||||||||||||||
PKG_MANAGER=apt-get | ||||||||||||||||||||||
INSTALL_CMD="apt-get install -y" | ||||||||||||||||||||||
else | ||||||||||||||||||||||
PKG_MANAGER=dnf | ||||||||||||||||||||||
INSTALL_CMD="dnf install -y" | ||||||||||||||||||||||
fi | ||||||||||||||||||||||
|
||||||||||||||||||||||
echo "Detected the following package manager: $PKG_MANAGER." | ||||||||||||||||||||||
|
||||||||||||||||||||||
echo "Enabling IP forwarding..." | ||||||||||||||||||||||
echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf | ||||||||||||||||||||||
echo 'net.ipv6.conf.all.forwarding = 1' >> /etc/sysctl.conf | ||||||||||||||||||||||
|
@@ -54,26 +67,61 @@ retry_command() { | |||||||||||||||||||||
return $exit_code | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Install CloudWatch Agent | ||||||||||||||||||||||
echo "Installing CloudWatch Agent..." | ||||||||||||||||||||||
retry_command "dnf install -y amazon-cloudwatch-agent" 5 | ||||||||||||||||||||||
# Function to install necessary packages per distro. | ||||||||||||||||||||||
install_packages() { | ||||||||||||||||||||||
case "$PKG_MANAGER" in | ||||||||||||||||||||||
apt-get) | ||||||||||||||||||||||
# Update package cache. | ||||||||||||||||||||||
echo "Updating package cache..." | ||||||||||||||||||||||
retry_command "$PKG_MANAGER update" 5 | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Install utilities. | ||||||||||||||||||||||
echo "Installing utilities..." | ||||||||||||||||||||||
retry_command "$INSTALL_CMD curl wget" 5 | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Install CloudWatch Agent. | ||||||||||||||||||||||
echo "Installing CloudWatch Agent..." | ||||||||||||||||||||||
distro=$(grep '^ID=' /etc/os-release | cut -d'=' -f2) | ||||||||||||||||||||||
arch=$(uname -m) | ||||||||||||||||||||||
case "$arch" in | ||||||||||||||||||||||
x86_64) | ||||||||||||||||||||||
arch=amd64 | ||||||||||||||||||||||
;; | ||||||||||||||||||||||
*) | ||||||||||||||||||||||
arch=arm64 | ||||||||||||||||||||||
;; | ||||||||||||||||||||||
esac | ||||||||||||||||||||||
retry_command "wget https://amazoncloudwatch-agent.s3.amazonaws.com/$distro/$arch/latest/amazon-cloudwatch-agent.deb" 5 | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Validate distro ID before using in URL construction. The script extracts the distro ID directly from Add validation for the distro ID: distro=$(grep '^ID=' /etc/os-release | cut -d'=' -f2)
+ # Remove quotes and validate distro ID
+ distro=$(echo "$distro" | tr -d '"' | grep -E '^[a-z0-9]+$')
+ if [ -z "$distro" ]; then
+ echo "Could not determine valid distro ID"
+ exit 1
+ fi
arch=$(uname -m) 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||
retry_command "dpkg -i -E ./amazon-cloudwatch-agent.deb" 5 | ||||||||||||||||||||||
;; | ||||||||||||||||||||||
*) | ||||||||||||||||||||||
# Install utilities. | ||||||||||||||||||||||
echo "Installing utilities..." | ||||||||||||||||||||||
retry_command "$INSTALL_CMD dnf-utils" 5 | ||||||||||||||||||||||
Comment on lines
+99
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Inconsistent utility installation between package managers. For apt-get systems, the script installs Ensure consistent utility installation: # Install utilities.
echo "Installing utilities..."
- retry_command "$INSTALL_CMD dnf-utils" 5
+ retry_command "$INSTALL_CMD curl wget dnf-utils" 5 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||
|
||||||||||||||||||||||
# Install CloudWatch Agent. | ||||||||||||||||||||||
echo "Installing CloudWatch Agent..." | ||||||||||||||||||||||
retry_command "$INSTALL_CMD amazon-cloudwatch-agent" 5 | ||||||||||||||||||||||
;; | ||||||||||||||||||||||
esac | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Install necessary packages. | ||||||||||||||||||||||
echo "Installing necessary packages..." | ||||||||||||||||||||||
install_packages | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Start the CloudWatch Agent. | ||||||||||||||||||||||
amazon-cloudwatch-agent-ctl -a start -m ec2 | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Install Tailscale | ||||||||||||||||||||||
echo "Installing Tailscale..." | ||||||||||||||||||||||
retry_command "dnf install -y dnf-utils" 5 | ||||||||||||||||||||||
retry_command "dnf config-manager --add-repo https://pkgs.tailscale.com/stable/amazon-linux/2/tailscale.repo" 5 | ||||||||||||||||||||||
retry_command "dnf install -y tailscale" 5 | ||||||||||||||||||||||
retry_command "curl -fsSL https://tailscale.com/install.sh | sh" 5 | ||||||||||||||||||||||
|
||||||||||||||||||||||
%{ if tailscaled_extra_flags_enabled == true } | ||||||||||||||||||||||
echo "Exporting FLAGS to /etc/default/tailscaled..." | ||||||||||||||||||||||
sed -i "s|^FLAGS=.*|FLAGS=\"${tailscaled_extra_flags}\"|" /etc/default/tailscaled | ||||||||||||||||||||||
%{ endif } | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Setup Tailscale | ||||||||||||||||||||||
echo "Enabling and starting tailscaled service..." | ||||||||||||||||||||||
systemctl enable --now tailscaled | ||||||||||||||||||||||
|
||||||||||||||||||||||
Comment on lines
-73
to
-76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove these lines @cmam? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah from your comment in PR description, it sounds like the new install script that you're invoking does this step? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed @Gowiem, if you check the install script provided by Tailscale, they cover the service registration (https://tailscale.com/install.sh). |
||||||||||||||||||||||
echo "Waiting for tailscaled to initialize..." | ||||||||||||||||||||||
sleep 5 | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve architecture detection for better compatibility.
The current architecture mapping is overly simplistic and may cause issues with other architectures like i386, s390x, or ppc64le.
Consider using a more comprehensive architecture mapping:
📝 Committable suggestion
🤖 Prompt for AI Agents