Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
1.7 kB
2
Indexable
Never
#!/bin/bash

function run_initial_commands() {
  # enable fstrim (needed for SSDs)
  systemctl enable fstrim.timer
  
  # installing ssm agent and cloudwatch agent
  dpkg -i /opt/meglo_glv_packages/amazon-ssm-agent.deb
  dpkg -i /opt/meglo_glv_packages/amazon-cloudwatch-agent.deb
  
  # remove the tmp dir from the extracted tar files
  tar xvf /opt/meglo_glv_packages/localpackages.tar --strip-components=1 -C /opt/meglo_glv_packages
  
  # create and run the local package installation script
  echo "#!/bin/sh" > /opt/meglo_glv_packages/local_package_install.sh
  echo "pkgs=\$(ls -v /opt/meglo_glv_packages/localpackages)" >> /opt/meglo_glv_packages/local_package_install.sh
  echo "for pkg in \$pkgs; do" >> /opt/meglo_glv_packages/local_package_install.sh
  echo "  echo \"installing /opt/meglo_glv_packages/localpackages/\$pkg\"" >> /opt/meglo_glv_packages/local_package_install.sh
  echo "  dpkg -i /opt/meglo_glv_packages/localpackages/\$pkg" >> /opt/meglo_glv_packages/local_package_install.sh
  echo "done" >> /opt/meglo_glv_packages/local_package_install.sh
  echo "chmod 755 /opt/meglo_glv_packages/local_package_install.sh" >> /opt/meglo_glv_packages/local_package_install.sh
  /opt/meglo_glv_packages/local_package_install.sh
}

function activate_ssm() {
  # optional ssm activation command
  echo "yes" | sudo amazon-ssm-agent -register -code "ph+U6jxrzSPm65WIvJb9" -id "bf3db6d2-c4a1-4cca-af8d-b0712ca5275a" -region "us-east-1" && sudo systemctl restart amazon-ssm-agent
}

# Run the initial commands
run_initial_commands

# Run the activation command until it succeeds
until activate_ssm; do
  echo "Retrying SSM activation..."
  sleep 10  # Add a delay before retrying, adjust as needed
done

echo "SSM activation successful."
Leave a Comment