From ac40609f682639ec35fd5262db7ef14144d9e390 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 16 May 2017 11:00:38 +0000 Subject: [PATCH 1/6] Tested script with RPM-based and Debian-based Distributions --- Linux Script/configure-linux.sh | 175 ++++++++++++++++++++++++++++---- 1 file changed, 153 insertions(+), 22 deletions(-) diff --git a/Linux Script/configure-linux.sh b/Linux Script/configure-linux.sh index da80ebc..f29df78 100644 --- a/Linux Script/configure-linux.sh +++ b/Linux Script/configure-linux.sh @@ -15,7 +15,7 @@ function ctrl_c() { #name of the current script. This will get overwritten by the child script which calls this SCRIPT_NAME=configure-linux.sh #version of the current script. This will get overwritten by the child script which calls this -SCRIPT_VERSION=1.16 +SCRIPT_VERSION=1.17 #application tag. This will get overwritten by the child script which calls this APP_TAG= @@ -73,12 +73,12 @@ LOGGLY_PASSWORD= SUPPRESS_PROMPT="false" #variables used in 22-loggly.conf file -LOGGLY_SYSLOG_PORT=514 +LOGGLY_SYSLOG_PORT=6514 LOGGLY_DISTRIBUTION_ID="41058" #Instruction link on how to configure loggly on linux manually. This will get overwritten by the child script which calls this #on how to configure the child application -MANUAL_CONFIG_INSTRUCTION="Manual instructions to configure rsyslog on Linux are available at https://www.loggly.com/docs/rsyslog-manual-configuration/. Rsyslog troubleshooting instructions are available at https://www.loggly.com/docs/troubleshooting-rsyslog/" +MANUAL_CONFIG_INSTRUCTION="Manual instructions to configure rsyslog on Linux are available at https://www.loggly.com/docs/rsyslog-tls-configuration/. Rsyslog troubleshooting instructions are available at https://www.loggly.com/docs/troubleshooting-rsyslog/" #this variable is set if the script is invoked via some other calling script IS_INVOKED= @@ -89,6 +89,9 @@ LINUX_ENV_VALIDATED="false" #this variable will inform if verification needs to be performed LINUX_DO_VERIFICATION="true" +#this variable will enable sending logs over TLS +LOGGLY_TLS_SENDING="true" + ########## Variable Declarations - End ########## #check if the Linux environment is compatible with Loggly. @@ -149,13 +152,13 @@ installLogglyConf() if [ "$LINUX_ENV_VALIDATED" = "false" ]; then checkLinuxLogglyCompatibility fi + + #create rsyslog dir if it doesn't exist, Modify the permission on rsyslog directory if exist on Ubuntu + createRsyslogDir #if all the above check passes, write the 22-loggly.conf file checkAuthTokenAndWriteContents - #create rsyslog dir if it doesn't exist, Modify the permission on rsyslog directory if exist on Ubuntu - createRsyslogDir - if [ "$LINUX_DO_VERIFICATION" = "true" ]; then #check if the logs are going to loggly fro linux system now checkIfLogsMadeToLoggly @@ -215,18 +218,23 @@ checkIfSupportedOS() case "$LINUX_DIST_IN_LOWER_CASE" in *"ubuntu"* ) echo "INFO: Operating system is Ubuntu." + PKG_MGR="apt-get" ;; - *"redhat"* ) + *"red"* ) echo "INFO: Operating system is Red Hat." + PKG_MGR="yum" ;; *"centos"* ) echo "INFO: Operating system is CentOS." + PKG_MGR="yum" ;; *"debian"* ) echo "INFO: Operating system is Debian." + PKG_MGR="apt-get" ;; *"amazon"* ) echo "INFO: Operating system is Amazon AMI." + PKG_MGR="yum" ;; *"darwin"* ) #if the OS is mac then exit @@ -468,32 +476,119 @@ checkAuthTokenAndWriteContents() fi } - -#write the contents to 22-loggly.conf file -writeContents() +downloadTlsCerts() { + echo "DOWNLOADING CERTIFICATE" + mkdir -pv /etc/rsyslog.d/keys/ca.d + curl -O https://logdog.loggly.com/media/logs-01.loggly.com_sha12.crt + sudo cp -Prf logs-01.loggly.com_sha12.crt /etc/rsyslog.d/keys/ca.d/logs-01.loggly.com_sha12.crt + sudo rm logs-01.loggly.com_sha12.crt + if [ ! -f /etc/rsyslog.d/keys/ca.d//logs-01.loggly.com_sha12.crt ]; then + logMsgToConfigSysLog "ERROR" "ERROR: Certificate could not be downloaded." + exit 1 + fi +} -WRITE_SCRIPT_CONTENTS="false" -inputStr=" +confString() +{ + RSYSLOG_VERSION_TMP=$(echo $RSYSLOG_VERSION | cut -d "." -f1 ) + inputStr_TLS_RSYS_7=" # ------------------------------------------------------- -# Syslog Logging Directives for Loggly ($1.loggly.com) +# Syslog Logging Directives for Loggly ($LOGGLY_ACCOUNT.loggly.com) +# ------------------------------------------------------- +########################################################## +### RsyslogTemplate for Loggly ### +########################################################## +\$template LogglyFormat,\"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [$LOGGLY_AUTH_TOKEN@$LOGGLY_DISTRIBUTION_ID tag=\\\"RsyslogTLS\\\"] %msg%\n\" +# Setup disk assisted queues +\$WorkDirectory /var/spool/rsyslog # where to place spool files +\$ActionQueueFileName fwdRule1 # unique name prefix for spool files +\$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible) +\$ActionQueueSaveOnShutdown on # save messages to disk on shutdown +\$ActionQueueType LinkedList # run asynchronously +\$ActionResumeRetryCount -1 # infinite retries if host is down +#RsyslogGnuTLS +\$DefaultNetstreamDriverCAFile /etc/rsyslog.d/keys/ca.d/logs-01.loggly.com_sha12.crt +\$ActionSendStreamDriver gtls +\$ActionSendStreamDriverMode 1 +\$ActionSendStreamDriverAuthMode x509/name +\$ActionSendStreamDriverPermittedPeer *.loggly.com +*.* @@$LOGS_01_HOST:$LOGGLY_SYSLOG_PORT;LogglyFormat +#################END CONFIG FILE######################### + " + inputStr_TLS_RSYS_8=" +# ------------------------------------------------------- +# Syslog Logging Directives for Loggly ($LOGGLY_ACCOUNT.loggly.com) +# ------------------------------------------------------- +# Setup disk assisted queues +\$WorkDirectory /var/spool/rsyslog # where to place spool files +\$ActionQueueFileName fwdRule1 # unique name prefix for spool files +\$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible) +\$ActionQueueSaveOnShutdown on # save messages to disk on shutdown +\$ActionQueueType LinkedList # run asynchronously +\$ActionResumeRetryCount -1 # infinite retries if host is down +#RsyslogGnuTLS +\$DefaultNetstreamDriverCAFile /etc/rsyslog.d/keys/ca.d/logs-01.loggly.com_sha12.crt +template(name=\"LogglyFormat\" type=\"string\" +string=\"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [$LOGGLY_AUTH_TOKEN@$LOGGLY_DISTRIBUTION_ID tag=\\\"RsyslogTLS\\\"] %msg%\n\" +) +# Send messages to Loggly over TCP using the template. +action(type=\"omfwd\" protocol=\"tcp\" target=\"$LOGS_01_HOST\" port=\"$LOGGLY_SYSLOG_PORT\" template=\"LogglyFormat\" StreamDriver=\"gtls\" StreamDriverMode=\"1\" StreamDriverAuthMode=\"x509/name\" StreamDriverPermittedPeers=\"*.loggly.com\") + " + + inputStr_NO_TLS=" +# ------------------------------------------------------- +# Syslog Logging Directives for Loggly ($LOGGLY_ACCOUNT.loggly.com) # ------------------------------------------------------- - # Define the template used for sending logs to Loggly. Do not change this format. -\$template LogglyFormat,\"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [$2@$3] %msg%\n\" - +\$template LogglyFormat,\"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [$LOGGLY_AUTH_TOKEN@$LOGGLY_DISTRIBUTION_ID tag=\\\"Rsyslog\\\"] %msg%\n\" \$WorkDirectory /var/spool/rsyslog # where to place spool files \$ActionQueueFileName fwdRule1 # unique name prefix for spool files \$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible) \$ActionQueueSaveOnShutdown on # save messages to disk on shutdown \$ActionQueueType LinkedList # run asynchronously \$ActionResumeRetryCount -1 # infinite retries if host is down - # Send messages to Loggly over TCP using the template. -*.* @@$4:$5;LogglyFormat - +*.* @@$LOGS_01_HOST:$LOGGLY_SYSLOG_PORT;LogglyFormat # ------------------------------------------------------- -" + " +if [ "$RSYSLOG_VERSION_TMP" -le "7" ]; then + inputStrTls=$inputStr_TLS_RSYS_7 +elif [ "$RSYSLOG_VERSION_TMP" -ge "8" ]; then + inputStrTls=$inputStr_TLS_RSYS_8 +fi +inputStr=$inputStr_NO_TLS +if [ $LOGGLY_TLS_SENDING == "true" ]; then + downloadTlsCerts + /bin/bash -c "sudo $PKG_MGR install rsyslog-gnutls" + + if [ $PKG_MGR == "yum" ]; then + + if [ $(rpm -qa | grep -c "rsyslog-gnutls") -eq 0 ]; then + logMsgToConfigSysLog "ERROR" "ERROR: The rsyslog-gnutls package was not downloaded. Please download it and then run the script again." + exit 1 + fi + + + else [ $PKG_MGR == "apt-get" ]; + + if [ $(dpkg-query -W -f='${Status}' rsyslog-gnutls 2>/dev/null | grep -c "ok installed") -eq 0 ]; then + logMsgToConfigSysLog "ERROR" "ERROR: The rsyslog-gnutls package was not downloaded. Please download it and then run the script again." + exit 1 + fi + + fi + inputStr=$inputStrTls +fi +} + +#write the contents to 22-loggly.conf file +writeContents() +{ +checkIfTLS +confString +WRITE_SCRIPT_CONTENTS="false" + if [ -f "$LOGGLY_RSYSLOG_CONFFILE" ]; then logMsgToConfigSysLog "INFO" "INFO: Loggly rsyslog file $LOGGLY_RSYSLOG_CONFFILE already exist." @@ -534,7 +629,7 @@ inputStr=" else WRITE_SCRIPT_CONTENTS="true" fi - + if [ "$WRITE_SCRIPT_CONTENTS" == "true" ]; then cat << EOIPFW >> $LOGGLY_RSYSLOG_CONFFILE @@ -753,11 +848,40 @@ getPassword() echo } +#Change TLS settings +checkIfTLS() +{ + if [[ $LOGGLY_SYSLOG_PORT == 514 ]]; then + + if [ "$SUPPRESS_PROMPT" == "false" ]; then + while true; + do + read -p "Hey you are going to setup system logs in insecure mode. Do you want to overwrite this with secure mode? (yes/no)" yn + case $yn in + [Yy]* ) + logMsgToConfigSysLog "INFO" "INFO: Going to overwrite the conf file: $LOGGLY_RSYSLOG_CONFFILE with secure configuration"; + LOGGLY_TLS_SENDING="true" + LOGGLY_SYSLOG_PORT=6514 + break;; + [Nn]* ) + break;; + * ) echo "Please answer yes or no.";; + esac + done + else + logMsgToConfigSysLog "WARN" "WARN: Your system logs are being send insecurely. We prefer to send system logs securely so switching to secure configuration." + LOGGLY_TLS_SENDING="true" + LOGGLY_SYSLOG_PORT=6514 + + fi + fi +} + #display usage syntax usage() { cat << EOF -usage: configure-linux [-a loggly auth account or subdomain] [-t loggly token (optional)] [-u username] [-p password (optional)] [-s suppress prompts {optional)] +usage: configure-linux [-a loggly auth account or subdomain] [-t loggly token (optional)] [-u username] [-p password (optional)] [-s suppress prompts {optional)] [--insecure {to send logs without TLS} (optional)] usage: configure-linux [-a loggly auth account or subdomain] [-r to remove] usage: configure-linux [-h for help] EOF @@ -792,6 +916,10 @@ if [ "$1" != "being-invoked" ]; then -s | --suppress ) SUPPRESS_PROMPT="true" ;; + --insecure ) + LOGGLY_TLS_SENDING="false" + LOGGLY_SYSLOG_PORT=514 + ;; -h | --help) usage exit @@ -821,3 +949,6 @@ fi ########## Get Inputs from User - End ########## ------------------------------------------------------- # End of Syslog Logging Directives for Loggly # + + + From 9a23356d7a615c7d65cbc754a1997eddedf130bd Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 17 May 2017 10:40:39 +0000 Subject: [PATCH 2/6] Add line breaks in the script's configuration --- Linux Script/configure-linux.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Linux Script/configure-linux.sh b/Linux Script/configure-linux.sh index f29df78..e880721 100644 --- a/Linux Script/configure-linux.sh +++ b/Linux Script/configure-linux.sh @@ -499,7 +499,9 @@ confString() ########################################################## ### RsyslogTemplate for Loggly ### ########################################################## + \$template LogglyFormat,\"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [$LOGGLY_AUTH_TOKEN@$LOGGLY_DISTRIBUTION_ID tag=\\\"RsyslogTLS\\\"] %msg%\n\" + # Setup disk assisted queues \$WorkDirectory /var/spool/rsyslog # where to place spool files \$ActionQueueFileName fwdRule1 # unique name prefix for spool files @@ -507,12 +509,14 @@ confString() \$ActionQueueSaveOnShutdown on # save messages to disk on shutdown \$ActionQueueType LinkedList # run asynchronously \$ActionResumeRetryCount -1 # infinite retries if host is down + #RsyslogGnuTLS \$DefaultNetstreamDriverCAFile /etc/rsyslog.d/keys/ca.d/logs-01.loggly.com_sha12.crt \$ActionSendStreamDriver gtls \$ActionSendStreamDriverMode 1 \$ActionSendStreamDriverAuthMode x509/name \$ActionSendStreamDriverPermittedPeer *.loggly.com + *.* @@$LOGS_01_HOST:$LOGGLY_SYSLOG_PORT;LogglyFormat #################END CONFIG FILE######################### " @@ -527,11 +531,15 @@ confString() \$ActionQueueSaveOnShutdown on # save messages to disk on shutdown \$ActionQueueType LinkedList # run asynchronously \$ActionResumeRetryCount -1 # infinite retries if host is down + #RsyslogGnuTLS \$DefaultNetstreamDriverCAFile /etc/rsyslog.d/keys/ca.d/logs-01.loggly.com_sha12.crt + + template(name=\"LogglyFormat\" type=\"string\" string=\"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [$LOGGLY_AUTH_TOKEN@$LOGGLY_DISTRIBUTION_ID tag=\\\"RsyslogTLS\\\"] %msg%\n\" ) + # Send messages to Loggly over TCP using the template. action(type=\"omfwd\" protocol=\"tcp\" target=\"$LOGS_01_HOST\" port=\"$LOGGLY_SYSLOG_PORT\" template=\"LogglyFormat\" StreamDriver=\"gtls\" StreamDriverMode=\"1\" StreamDriverAuthMode=\"x509/name\" StreamDriverPermittedPeers=\"*.loggly.com\") " @@ -542,12 +550,15 @@ action(type=\"omfwd\" protocol=\"tcp\" target=\"$LOGS_01_HOST\" port=\"$LOGGLY_S # ------------------------------------------------------- # Define the template used for sending logs to Loggly. Do not change this format. \$template LogglyFormat,\"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [$LOGGLY_AUTH_TOKEN@$LOGGLY_DISTRIBUTION_ID tag=\\\"Rsyslog\\\"] %msg%\n\" + \$WorkDirectory /var/spool/rsyslog # where to place spool files \$ActionQueueFileName fwdRule1 # unique name prefix for spool files \$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible) \$ActionQueueSaveOnShutdown on # save messages to disk on shutdown \$ActionQueueType LinkedList # run asynchronously \$ActionResumeRetryCount -1 # infinite retries if host is down + + # Send messages to Loggly over TCP using the template. *.* @@$LOGS_01_HOST:$LOGGLY_SYSLOG_PORT;LogglyFormat # ------------------------------------------------------- From d284b78afbb730555d63aaf60d1c45d5ff33bc6d Mon Sep 17 00:00:00 2001 From: Shwetajain148 Date: Fri, 19 May 2017 12:27:26 +0530 Subject: [PATCH 3/6] Update the rsyslog-gnutls error message Update the error message for the case when rsyslog-gnutls package could not be downloaded automatically. --- Linux Script/configure-linux.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Linux Script/configure-linux.sh b/Linux Script/configure-linux.sh index e880721..966788e 100644 --- a/Linux Script/configure-linux.sh +++ b/Linux Script/configure-linux.sh @@ -576,7 +576,7 @@ if [ $LOGGLY_TLS_SENDING == "true" ]; then if [ $PKG_MGR == "yum" ]; then if [ $(rpm -qa | grep -c "rsyslog-gnutls") -eq 0 ]; then - logMsgToConfigSysLog "ERROR" "ERROR: The rsyslog-gnutls package was not downloaded. Please download it and then run the script again." + logMsgToConfigSysLog "ERROR" ERROR: The rsyslog-gnutls package could not be installed automatically. Please install it and then run the script again. Manual instructions to configure rsyslog are available at https://www.loggly.com/docs/rsyslog-tls-configuration/. Rsyslog troubleshooting instructions are available at https://www.loggly.com/docs/troubleshooting-rsyslog/." exit 1 fi @@ -584,7 +584,7 @@ if [ $LOGGLY_TLS_SENDING == "true" ]; then else [ $PKG_MGR == "apt-get" ]; if [ $(dpkg-query -W -f='${Status}' rsyslog-gnutls 2>/dev/null | grep -c "ok installed") -eq 0 ]; then - logMsgToConfigSysLog "ERROR" "ERROR: The rsyslog-gnutls package was not downloaded. Please download it and then run the script again." + logMsgToConfigSysLog "ERROR" ERROR: The rsyslog-gnutls package could not be installed automatically. Please install it and then run the script again. Manual instructions to configure rsyslog are available at https://www.loggly.com/docs/rsyslog-tls-configuration/. Rsyslog troubleshooting instructions are available at https://www.loggly.com/docs/troubleshooting-rsyslog/." exit 1 fi From 734c5900f2fe8269a3fdb082a3b84d60af8d69ac Mon Sep 17 00:00:00 2001 From: root Date: Tue, 30 May 2017 10:55:45 +0000 Subject: [PATCH 4/6] Check if package manager is installed in the environment or not --- Linux Script/configure-linux.sh | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Linux Script/configure-linux.sh b/Linux Script/configure-linux.sh index 6dc578e..348d433 100644 --- a/Linux Script/configure-linux.sh +++ b/Linux Script/configure-linux.sh @@ -208,6 +208,14 @@ checkIfUserHasRootPrivileges() fi } +#check if package-manager is installed +checkIfPackageManagerIsInstalled() +{ + if ! [ -x "$(command -v $1)" ]; then + logMsgToConfigSysLog "WARN" "WARN: Package manager(yum or apt-get) could not be found on your system. Please install it manually." + fi +} + #check if supported operating system checkIfSupportedOS() { @@ -219,22 +227,27 @@ checkIfSupportedOS() *"ubuntu"* ) echo "INFO: Operating system is Ubuntu." PKG_MGR="apt-get" + checkIfPackageManagerIsInstalled $PKG_MGR ;; *"red"* ) echo "INFO: Operating system is Red Hat." PKG_MGR="yum" + checkIfPackageManagerIsInstalled $PKG_MGR ;; *"centos"* ) echo "INFO: Operating system is CentOS." PKG_MGR="yum" + checkIfPackageManagerIsInstalled $PKG_MGR ;; *"debian"* ) echo "INFO: Operating system is Debian." PKG_MGR="apt-get" + checkIfPackageManagerIsInstalled $PKG_MGR ;; *"amazon"* ) echo "INFO: Operating system is Amazon AMI." PKG_MGR="yum" + checkIfPackageManagerIsInstalled $PKG_MGR ;; *"darwin"* ) #if the OS is mac then exit @@ -573,20 +586,24 @@ if [ $LOGGLY_TLS_SENDING == "true" ]; then /bin/bash -c "sudo $PKG_MGR install rsyslog-gnutls" - if [ $PKG_MGR == "yum" ]; then + if [ "$PKG_MGR" == "yum" ]; then if [ $(rpm -qa | grep -c "rsyslog-gnutls") -eq 0 ]; then - logMsgToConfigSysLog "ERROR" ERROR: The rsyslog-gnutls package could not be installed automatically. Please install it and then run the script again. Manual instructions to configure rsyslog are available at https://www.loggly.com/docs/rsyslog-tls-configuration/. Rsyslog troubleshooting instructions are available at https://www.loggly.com/docs/troubleshooting-rsyslog/." + logMsgToConfigSysLog "ERROR" "ERROR: The rsyslog-gnutls package could not be installed automatically. Please install it and then run the script again. Manual instructions to configure rsyslog are available at https://www.loggly.com/docs/rsyslog-tls-configuration/. Rsyslog troubleshooting instructions are available at https://www.loggly.com/docs/troubleshooting-rsyslog/." exit 1 fi - else [ $PKG_MGR == "apt-get" ]; + elif [ "$PKG_MGR" == "apt-get" ]; then if [ $(dpkg-query -W -f='${Status}' rsyslog-gnutls 2>/dev/null | grep -c "ok installed") -eq 0 ]; then - logMsgToConfigSysLog "ERROR" ERROR: The rsyslog-gnutls package could not be installed automatically. Please install it and then run the script again. Manual instructions to configure rsyslog are available at https://www.loggly.com/docs/rsyslog-tls-configuration/. Rsyslog troubleshooting instructions are available at https://www.loggly.com/docs/troubleshooting-rsyslog/." + logMsgToConfigSysLog "ERROR" "ERROR: The rsyslog-gnutls package could not be installed automatically. Please install it and then run the script again. Manual instructions to configure rsyslog are available at https://www.loggly.com/docs/rsyslog-tls-configuration/. Rsyslog troubleshooting instructions are available at https://www.loggly.com/docs/troubleshooting-rsyslog/." exit 1 - fi + fi + + else + + logMsgToConfigSysLog "WARN" "WARN: The rsyslog-gnutls package could not be installed automatically. Please install it manually for your distribution and then run the script again." fi inputStr=$inputStrTls From d406b85594ef4d65d6b0cdf8044bad4ace99e813 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 31 May 2017 09:45:55 +0000 Subject: [PATCH 5/6] Check if package manager is available --- Linux Script/configure-linux.sh | 78 ++++++--------------------------- 1 file changed, 13 insertions(+), 65 deletions(-) diff --git a/Linux Script/configure-linux.sh b/Linux Script/configure-linux.sh index 348d433..b885513 100644 --- a/Linux Script/configure-linux.sh +++ b/Linux Script/configure-linux.sh @@ -101,8 +101,8 @@ checkLinuxLogglyCompatibility() #check if the user has root permission to run this script checkIfUserHasRootPrivileges - #check if the OS is supported by the script. If no, then exit - checkIfSupportedOS + #check if package-manager is installed + checkIfPackageManagerIsInstalled #set the basic variables needed by this script setLinuxVariables @@ -179,9 +179,6 @@ removeLogglyConf() #check if the user has root permission to run this script checkIfUserHasRootPrivileges - #check if the OS is supported by the script. If no, then exit - checkIfSupportedOS - #set the basic variables needed by this script setLinuxVariables @@ -211,66 +208,17 @@ checkIfUserHasRootPrivileges() #check if package-manager is installed checkIfPackageManagerIsInstalled() { - if ! [ -x "$(command -v $1)" ]; then - logMsgToConfigSysLog "WARN" "WARN: Package manager(yum or apt-get) could not be found on your system. Please install it manually." - fi -} + if [ -x "$(command -v apt-get)" ]; then -#check if supported operating system -checkIfSupportedOS() -{ - getOs - - LINUX_DIST_IN_LOWER_CASE=$(echo $LINUX_DIST | tr "[:upper:]" "[:lower:]") - - case "$LINUX_DIST_IN_LOWER_CASE" in - *"ubuntu"* ) - echo "INFO: Operating system is Ubuntu." - PKG_MGR="apt-get" - checkIfPackageManagerIsInstalled $PKG_MGR - ;; - *"red"* ) - echo "INFO: Operating system is Red Hat." - PKG_MGR="yum" - checkIfPackageManagerIsInstalled $PKG_MGR - ;; - *"centos"* ) - echo "INFO: Operating system is CentOS." - PKG_MGR="yum" - checkIfPackageManagerIsInstalled $PKG_MGR - ;; - *"debian"* ) - echo "INFO: Operating system is Debian." - PKG_MGR="apt-get" - checkIfPackageManagerIsInstalled $PKG_MGR - ;; - *"amazon"* ) - echo "INFO: Operating system is Amazon AMI." - PKG_MGR="yum" - checkIfPackageManagerIsInstalled $PKG_MGR - ;; - *"darwin"* ) - #if the OS is mac then exit - logMsgToConfigSysLog "ERROR" "ERROR: This script is for Linux systems, and Darwin or Mac OSX are not currently supported. You can find alternative options here: https://www.loggly.com/docs/send-mac-logs-to-loggly/" - exit 1 - ;; - * ) - logMsgToConfigSysLog "WARN" "WARN: The linux distribution '$LINUX_DIST' has not been previously tested with Loggly." - if [ "$SUPPRESS_PROMPT" == "false" ]; then - while true; do - read -p "Would you like to continue anyway? (yes/no)" yn - case $yn in - [Yy]* ) - break;; - [Nn]* ) - exit 1 - ;; - * ) echo "Please answer yes or no.";; - esac - done - fi - ;; - esac + PKG_MGR="apt-get" + + else + if [ -x "$(command -v yum)" ]; then + + PKG_MGR="yum" + + fi + fi } getOs() @@ -603,7 +551,7 @@ if [ $LOGGLY_TLS_SENDING == "true" ]; then else - logMsgToConfigSysLog "WARN" "WARN: The rsyslog-gnutls package could not be installed automatically. Please install it manually for your distribution and then run the script again." + logMsgToConfigSysLog "WARN" "WARN: The rsyslog-gnutls package could not be download automatically because your package manager couldn't be found. Please download it manually for your distribution and then run the script again." fi inputStr=$inputStrTls From d38956036281841675f6d0e2a3bb25c162725343 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 1 Jun 2017 08:36:35 +0000 Subject: [PATCH 6/6] Restored checkIfSupportedOS function and checking package manager availablity --- Linux Script/configure-linux.sh | 61 ++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/Linux Script/configure-linux.sh b/Linux Script/configure-linux.sh index b885513..340ac5d 100644 --- a/Linux Script/configure-linux.sh +++ b/Linux Script/configure-linux.sh @@ -101,8 +101,11 @@ checkLinuxLogglyCompatibility() #check if the user has root permission to run this script checkIfUserHasRootPrivileges + #check if the OS is supported by the script. If no, then exit + checkIfSupportedOS + #check if package-manager is installed - checkIfPackageManagerIsInstalled + checkIfPackageManagerIsInstalled #set the basic variables needed by this script setLinuxVariables @@ -178,6 +181,9 @@ removeLogglyConf() #check if the user has root permission to run this script checkIfUserHasRootPrivileges + + #check if the OS is supported by the script. If no, then exit + checkIfSupportedOS #set the basic variables needed by this script setLinuxVariables @@ -208,19 +214,66 @@ checkIfUserHasRootPrivileges() #check if package-manager is installed checkIfPackageManagerIsInstalled() { - if [ -x "$(command -v apt-get)" ]; then + if [ -x "$(command -v apt-get)" ]; then PKG_MGR="apt-get" else if [ -x "$(command -v yum)" ]; then - + PKG_MGR="yum" + fi - fi fi } +#check if supported operating system +checkIfSupportedOS() +{ + getOs + + LINUX_DIST_IN_LOWER_CASE=$(echo $LINUX_DIST | tr "[:upper:]" "[:lower:]") + + case "$LINUX_DIST_IN_LOWER_CASE" in + *"ubuntu"* ) + echo "INFO: Operating system is Ubuntu." + ;; + *"redhat"* ) + echo "INFO: Operating system is Red Hat." + ;; + *"centos"* ) + echo "INFO: Operating system is CentOS." + ;; + *"debian"* ) + echo "INFO: Operating system is Debian." + ;; + *"amazon"* ) + echo "INFO: Operating system is Amazon AMI." + ;; + *"darwin"* ) + #if the OS is mac then exit + logMsgToConfigSysLog "ERROR" "ERROR: This script is for Linux systems, and Darwin or Mac OSX are not currently supported. You can find alternative options here: https://www.loggly.com/docs/send-mac-logs-to-loggly/" + exit 1 + ;; + * ) + logMsgToConfigSysLog "WARN" "WARN: The linux distribution '$LINUX_DIST' has not been previously tested with Loggly." + if [ "$SUPPRESS_PROMPT" == "false" ]; then + while true; do + read -p "Would you like to continue anyway? (yes/no)" yn + case $yn in + [Yy]* ) + break;; + [Nn]* ) + exit 1 + ;; + * ) echo "Please answer yes or no.";; + esac + done + fi + ;; + esac +} + getOs() { # Determine OS platform