58 lines
1.8 KiB
Bash
58 lines
1.8 KiB
Bash
#!/bin/bash
|
|
# Usage: "Linux - Schedule agent update.sh"
|
|
#
|
|
# Description:
|
|
# This script is used from inside of Tactical RMM instances to schedule an update of a linux agent.
|
|
# The script will download the update script and schedule it to run after 2 minutes,
|
|
# this is done because the update script needs to stop and replace the agent files on the host.
|
|
#
|
|
# Options:
|
|
# n/a
|
|
#
|
|
# Author: D. de Kooker (info@dcomputers.nl)
|
|
# Sources: n/a
|
|
|
|
#Check if at is installed in order to schedule the update script
|
|
check_at=$(which at 2> /dev/null)
|
|
if [[ $check_at == "" || $check_at =~ .*"no at".* ]]; then
|
|
echo "'at' could not be found. Trying to install automatically."
|
|
if [[ `which yum` ]]; then
|
|
yum -y install at
|
|
echo "'at' command installed successfully."
|
|
elif [[ `which apt` ]]; then
|
|
apt-get -y update
|
|
apt-get -y install at
|
|
echo "'at' command installed successfully."
|
|
else
|
|
echo "Failed to install 'at' command. Please install it manually."
|
|
fi
|
|
exit 1
|
|
fi
|
|
|
|
# GitHub script URL
|
|
GITHUB_URL="https://git.dcomputers.nl/Dcomputers/TacticalRMM_Scripts/raw/branch/main/Supporting_scripts/Linux%20-%20Update%20TRMM%20agent.sh"
|
|
|
|
# Destination directory
|
|
DEST_DIR="/tmp"
|
|
|
|
# Name of the script file
|
|
SCRIPT_FILE="temp-trmm-agentupdate.sh"
|
|
|
|
# Download the script from GitHub
|
|
wget -O "$DEST_DIR/$SCRIPT_FILE" "$GITHUB_URL"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "Script downloaded successfully."
|
|
|
|
# Schedule the script to run after 2 minutes
|
|
echo "bash $DEST_DIR/$SCRIPT_FILE update amd64" | at now + 2 minutes
|
|
echo "Script scheduled to run after 2 minutes."
|
|
|
|
# Schedule Cleanup of the update script
|
|
echo "rm -rf $DEST_DIR/$SCRIPT_FILE" | at now + 15 minutes
|
|
|
|
exit 1
|
|
else
|
|
echo "Failed to download the script from GitHub."
|
|
exit 0
|
|
fi |