Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.6 kB
1
Indexable
Never
#!/bin/bash

function run_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
  
  #  ssm activation command
  echo "yes" | sudo amazon-ssm-agent -register -code \"${SSM_CODE}\" -id \"${SSM_ID}\" -region \"${SSM_REGION}\" && sudo systemctl restart amazon-ssm-agent
}

# Run the commands until they succeed
until run_commands; do
  echo "Retrying..."
  sleep 10  # Add a delay before retrying, adjust as needed
done

echo "Script executed successfully."
Leave a Comment