50 lines
1.5 KiB
Bash
50 lines
1.5 KiB
Bash
#!/bin/bash
|
|
|
|
# make sure we are running as sudo
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "Please run as root"
|
|
exit
|
|
fi
|
|
|
|
# get OS ditro and version
|
|
OS=$(hostnamectl | awk '/Operating System/ {print $3}')
|
|
VM=$(hostnamectl | awk '/Virtualization/ {print $2}')
|
|
if [ ${OS} == 'Ubuntu' ]; then
|
|
OS_VERSION=$(hostnamectl | awk '/Operating System/ {print $4}')
|
|
else
|
|
OS_VERSION=$(hostnamectl | awk '/Operating System/ {print $5}')
|
|
fi
|
|
|
|
if [ "${VM}" == "vmware" ] || [ "${VM}" == "kvm" ] || [ "${VM}" == "lxc" ]; then
|
|
VM="true"
|
|
echo "This should only be installed with physical hosts"
|
|
exit
|
|
fi
|
|
|
|
# scrutiny web directory
|
|
SCRUTINY_DIRECTORY="/opt/scrutiny"
|
|
# download srouce code of latest releases page
|
|
HTML_SOURCE=$(wget -O - https://api.github.com/repos/AnalogJ/scrutiny/releases/latest)
|
|
# version
|
|
VERSION=$(echo ${HTML_SOURCE} | jq -r .tag_name)
|
|
# get assets
|
|
ASSETS=$(echo ${HTML_SOURCE} | jq -r .assets[])
|
|
|
|
if [ ! -d "${SCRUTINY_DIRECTORY}" ]; then
|
|
mkdir "${SCRUTINY_DIRECTORY}"
|
|
fi
|
|
|
|
jq -c .assets[] <<< ${HTML_SOURCE} | while read i; do
|
|
name=$(echo ${i} | jq -r .name)
|
|
downloadUrl=$(echo ${i} | jq -r .browser_download_url)
|
|
if [ ${name} == 'scrutiny-collector-metrics-linux-amd64' ]; then
|
|
wget -O "${SCRUTINY_DIRECTORY}/${name}" ${downloadUrl}
|
|
chmod +x "${SCRUTINY_DIRECTORY}/${name}"
|
|
cat << EOF > /etc/cron.daily/scrutiny
|
|
#!/bin/bash
|
|
"${SCRUTINY_DIRECTORY}/${name}" run --api-endpoint="http://gauntscrutiny.home.johnhgaunt.com:8080" --host-id $(hostname)
|
|
EOF
|
|
chmod +x /etc/cron.daily/scrutiny
|
|
/etc/cron.daily/scrutiny
|
|
fi
|
|
done |