#!/bin/bash function _kdev_failed { local kb="https://kb.datto.com/hc/en-us/articles/204953800" echo echo "The development packages for the running kernel are not installed" echo "Correct the issue and try again" echo "See ${kb} for more information" exit 1 } function fedora { if [[ "$(uname -r)" =~ "debug" ]]; then sudo dnf -y install kernel-debug-devel-$(uname -r) || _kdev_failed else sudo dnf -y install kernel-devel-$(uname -r) || _kdev_failed fi sudo dnf -y install --nogpgcheck https://cpkg.datto.com/datto-rpm/repoconfig/datto-fedora-rpm-release-${VERSION_ID}-latest.noarch.rpm || exit 1 sudo dnf -y install dlad || exit 1 } function _rhel_legacy { if [[ $(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release)) == 5* ]]; then local VERSION_ID=5 elif [[ $(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release)) == 6* ]]; then local VERSION_ID=6 fi if [[ "$(cat /etc/redhat-release)" =~ "Red Hat" ]]; then if [[ ${VERSION_ID} == "5" ]]; then sudo yum -y localinstall --nogpgcheck https://dl.fedoraproject.org/pub/archive/epel/epel-release-latest-${VERSION_ID}.noarch.rpm || exit 1 elif [[ ${VERSION_ID} == "6" ]]; then sudo yum -y localinstall --nogpgcheck https://dl.fedoraproject.org/pub/archive/epel/6/x86_64/epel-release-6-8.noarch.rpm || exit 1 else sudo yum -y localinstall --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-${VERSION_ID}.noarch.rpm || exit 1 sudo subscription-manager repos --enable=rhel-${VERSION_ID}-server-optional-rpms fi else sudo yum -y install epel-release || exit 1 fi if [[ "${VERSION_ID}" == "5" ]]; then curl https://cpkg.datto.com/datto-rpm/repoconfig/datto-el-rpm-release-5-latest.noarch.rpm -o /tmp/datto-el-rpm-release-5-latest.noarch.rpm || exit 1 sudo yum -y localinstall --nogpgcheck /tmp/datto-el-rpm-release-5-latest.noarch.rpm || exit 1 else sudo yum -y localinstall --nogpgcheck https://cpkg.datto.com/datto-rpm/repoconfig/datto-el-rpm-release-${VERSION_ID}-latest.noarch.rpm || exit 1 fi } function _rhel_base { sudo yum -y localinstall --nogpgcheck https://cpkg.datto.com/datto-rpm/repoconfig/datto-el-rpm-release-${VERSION_ID}-latest.noarch.rpm || exit 1 sudo yum -y install dlad || exit 1 } function rhel { if yum list installed kernel-ml-$(uname -r) > /dev/null 2>&1; then sudo yum --enablerepo=elrepo-kernel -y install kernel-ml-devel-$(uname -r) || _kdev_failed elif yum list installed kernel-lt-$(uname -r) > /dev/null 2>&1; then sudo yum --enablerepo=elrepo-kernel -y install kernel-lt-devel-$(uname -r) || _kdev_failed elif [[ "$(uname -r)" =~ "debug" ]]; then sudo yum -y install kernel-debug-devel-$(uname -r) || _kdev_failed else sudo yum -y install kernel-devel-$(uname -r) || _kdev_failed fi if [[ ! -r "/etc/os-release" ]]; then _rhel_legacy else if [[ "$VERSION_ID" == 7* ]]; then local VERSION_ID="7" elif [[ "$VERSION_ID" == 8* ]]; then local VERSION_ID="8" elif [[ "$VERSION_ID" == 9* ]]; then local VERSION_ID="9" fi if [[ "$ID" == "rhel" ]]; then sudo yum -y localinstall --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-${VERSION_ID}.noarch.rpm || exit 1 if [[ "$VERSION_ID" == 7 ]]; then sudo subscription-manager repos --enable=rhel-${VERSION_ID}-server-optional-rpms fi else sudo yum -y install epel-release || exit 1 fi fi _rhel_base } function oracle { if [[ $VERSION_ID == 5* ]]; then local VERSION_ID=5 elif [[ $VERSION_ID == 6* ]]; then local VERSION_ID=6 elif [[ $VERSION_ID == 7* ]]; then local VERSION_ID=7 elif [[ $VERSION_ID == 8* ]]; then local VERSION_ID=8 fi if [[ "$(uname -r)" =~ "debug" ]]; then if [[ "$(uname -r)" =~ "uek" ]]; then sudo yum -y install kernel-uek-debug-devel-$(uname -r) || _kdev_failed else sudo yum -y install kernel-debug-devel-$(uname -r) || _kdev_failed fi else if [[ "$(uname -r)" =~ "uek" ]]; then sudo yum -y install kernel-uek-devel-$(uname -r) || _kdev_failed else sudo yum -y install kernel-devel-$(uname -r) || _kdev_failed fi fi sudo yum -y localinstall --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-${VERSION_ID}.noarch.rpm || exit 1 sudo yum-config-manager --enable ol${VERSION_ID}_optional_latest _rhel_base } function opensuse { if [[ "$VERSION_ID" == 42* ]]; then local suse_rel=42.1 sudo zypper --gpg-auto-import-keys --non-interactive refresh || exit 1 elif [[ "$VERSION_ID" == 15* ]]; then local suse_rel=15.0 else echo "Unsupported version: ${VERSION_ID}" exit 1 fi local ktype=$(uname -r | awk -F '-' '{ print $NF }') local kver=$(uname -r | sed "s/-${ktype}//") sudo zypper --non-interactive install --no-confirm -C "kernel-syms = ${kver}" || _kdev_failed sudo zypper --no-gpg-checks --non-interactive install https://cpkg.datto.com/datto-rpm/repoconfig/datto-opensuse-rpm-release-${suse_rel}-latest.noarch.rpm || exit 1 sudo rpm --import /usr/lib/rpm/gnupg/keys/DATTO-PKGS-GPG-KEY sudo zypper --gpg-auto-import-keys --non-interactive refresh || exit 1 sudo zypper --non-interactive install --no-confirm --auto-agree-with-licenses dkms gcc make || exit 1 sudo zypper --non-interactive install --no-confirm --auto-agree-with-licenses dlad || exit 1 } function sles_legacy { local sle_rel=11 local ktype=$(uname -r | awk -F '-' '{ print $NF }') local kver=$(uname -r | sed "s/-${ktype}//") # XXX: SLE 11 requires the build revision to match the package version local kbuild=$(rpm -qa kernel-${ktype} | grep ${kver} | awk -F '.' '{ print $NF }') sudo zypper --non-interactive install --no-confirm -C "kernel-syms = ${kver}.${kbuild}" || _kdev_failed sudo zypper --no-gpg-checks --non-interactive install https://cpkg.datto.com/datto-rpm/repoconfig/datto-sle-rpm-release-${sle_rel}-latest.noarch.rpm || exit 1 sudo rpm --import /usr/lib/rpm/gnupg/keys/DATTO-LEGACYDIST-PKGS-GPG-KEY sudo zypper --gpg-auto-import-keys --non-interactive refresh || exit 1 sudo zypper --non-interactive install --no-confirm --agree-to-third-party-licenses dkms gcc make || exit 1 sudo zypper install dlad || exit 1 } function sles { if [[ "$VERSION_ID" == 11* ]]; then sles_legacy return elif [[ "$VERSION_ID" == 12* ]]; then sudo zypper --gpg-auto-import-keys --non-interactive refresh || exit 1 else sudo SUSEConnect -p PackageHub/${VERSION_ID}/x86_64 || exit 1 sudo zypper --gpg-auto-import-keys --non-interactive refresh || exit 1 fi local sle_rel=$(echo ${VERSION_ID} | cut -f1 -d".") local ktype=$(uname -r | awk -F '-' '{ print $NF }') local kver=$(uname -r | sed "s/-${ktype}//") sudo zypper --gpg-auto-import-keys --non-interactive install --no-confirm -C "kernel-syms = ${kver}" || _kdev_failed sudo zypper --no-gpg-checks --non-interactive install https://cpkg.datto.com/datto-rpm/repoconfig/datto-sle-rpm-release-${sle_rel}-latest.noarch.rpm || exit 1 sudo rpm --import /usr/lib/rpm/gnupg/keys/DATTO-PKGS-GPG-KEY sudo zypper --gpg-auto-import-keys --non-interactive refresh || exit 1 sudo zypper --non-interactive install --no-confirm --auto-agree-with-licenses dkms gcc make || exit 1 sudo zypper --non-interactive install --no-confirm --auto-agree-with-licenses dlad || exit 1 } function debubu { sudo apt-get update sudo apt-get -y install linux-headers-$(uname -r) || _kdev_failed SystemMapLocation="/lib/modules/$(uname -r)/System.map" if [ ! -f "$SystemMapLocation" ]; then SystemMapLocation="/boot/System.map-$(uname -r)" if [ ! -f "$SystemMapLocation" ] || ! grep -q "__per_cpu_start" "$SystemMapLocation"; then SystemMapLocation="/usr/lib/debug/boot/System.map-$(uname -r)" if [ ! -f "$SystemMapLocation" ] || ! grep -q "__per_cpu_start" "$SystemMapLocation"; then sudo apt-get install linux-image-$(uname -r)-dbg -y fi sudo cp /usr/lib/debug/boot/System.map-$(uname -r) "/boot/System.map-$(uname -r)" fi fi sudo apt-get -y install apt-transport-https dirmngr || exit 1 (wget -qO - https://cpkg.datto.com/DATTO-PKGS-GPG-KEY | sudo apt-key add -) || exit 1 release=$(lsb_release -sc) sudo bash -c "echo 'deb [arch=amd64] https://cpkg.datto.com/datto-deb/public/${release} ${release} main' > /etc/apt/sources.list.d/datto-linux-agent.list" sudo apt-get update sudo apt-get -y install dlad || exit 1 } agreed="no" for arg in "$@"; do case ${arg} in "--agree") agreed="yes" ;; *) ;; esac done if [[ "${agreed}" == "no" ]]; then if [[ ! -t 1 ]]; then echo "Unable to run interactively: stdin not available" exit 1 fi echo echo echo "To continue installing the Datto Linux Agent you must agree" echo "to the terms of the software license agreement located at" echo echo "https://www.datto.com/legal/agent-licensing-agreement" echo echo read -p "Install Datto Linux Agent? [Y/n] " prompt < /dev/tty prompt=$(echo ${prompt} | awk '{print tolower($0)}') case ${prompt} in "y"|"yes"|"") echo echo "Datto Linux Agent install starting" echo ;; *) echo echo "Datto Linux Agent install aborted" echo exit 0 ;; esac fi if [[ "$(uname -m)" != "x86_64" ]]; then echo "Architecture not supported ($(uname -m))" exit 1 fi function id_dispatch { if [[ "$1" == "fedora" ]]; then fedora elif [[ "$1" == "rhel" ]]; then rhel elif [[ "$1" == "ol" ]]; then oracle elif [[ "$1" == "ubuntu" ]] || [[ "$1" == "debian" ]]; then debubu elif [[ "$1" == "opensuse" ]] || [[ "$1" == "opensuse-leap" ]]; then opensuse elif [[ "$1" == "suse" ]] || [[ "$1" == "sles" ]] || [[ "$1" == "sled" ]] || [[ "$1" == "sles_sap" ]] || [[ "$1" == "oes" ]]; then sles else return 1 fi return 0 } if [[ -r "/etc/os-release" ]]; then source /etc/os-release IDS_LIKE=$(echo "$ID_LIKE" | tr " " "\n") if id_dispatch "$ID"; then exit 0 fi for LIKE in $IDS_LIKE do if id_dispatch "$LIKE"; then exit 0 fi done echo "Unsupported distro ID: $ID and ID_LIKEs: $ID_LIKE" exit 1 elif [[ -r "/etc/redhat-release" ]]; then rhel elif [[ -r "/etc/debian_version" ]]; then debubu elif [[ -r "/etc/SuSE-release" ]]; then sles_legacy else echo "There was an error, you may be on an unsupported distro..." exit 1 fi