From 076c5a56a6acf4ac1ce3a76ac92d0aa12971ed40 Mon Sep 17 00:00:00 2001 From: M33 <m33@tok715.net> Date: Sat, 2 May 2020 09:45:58 +0200 Subject: [PATCH] first Download. Adapt. Overcome. --- install.sh | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 install.sh diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..5717d13 --- /dev/null +++ b/install.sh @@ -0,0 +1,183 @@ +#!/bin/bash +# +# install.sh - A simple install script, for more script : aideCheck.sh +# +# https://github.com/m33m33/aideCheck.sh +# + +DST=/usr/local/bin/aideCheck.sh +SRC=https://raw.githubusercontent.com/m33m33/aideCheck.sh/master/aideCheck.sh +TMP=/tmp/.install-aideCheck.$$ +ON_UPDATE=0 +ON_CHANGED=1 +ON_DELETED=1 +ON_ADDED=1 +TO_EMAIL="" + +# +# int askYesNo(str question) - Ask for a y/n response +# return: 1=yes, 0=no +# +function askYesNo { + RV="" + loop=1 + + while [ $loop -eq 1 ]; do + echo "$1" + echo -n "(y/n): " + read r + echo $r | grep -q -i "y" + if [ $? -eq 0 ]; then + RV=1 + loop=0 + fi + echo $r | grep -q -i "n" + if [ $? -eq 0 ]; then + RV=0 + loop=0 + fi + done + + return $RV +} + + +# +# void setup() - Setup aideCheck.sh configuration +# +function setup { + echo "Now we will setup aideCheck.sh" + echo " " + echo "You will get only one summary email if files are added/changed/modified" + echo "You will not get any emails if you leave the destination address blank" + echo " " + + askYesNo "Would you know when files are changed ?" + ON_CHANGED=$? + + askYesNo "Would you know when files are added ?" + ON_ADDED=$? + + askYesNo "Would you know when files are deleted ?" + ON_DELETED=$? + + askYesNo "Would you update A.I.D.E. database after running a check (usefull for a few rounds and tackle false positives, not recommeded in production) ?" + ON_UPDATE=$? + + echo "Enter the destination email addres (leave empty if you don't want emails, and only check the return value of aideCheck.sh):" + read TO_MAIL + + echo " " +} + + +# +# void patch() - Patch aideCheck.sh with the configuration +# +function patch { + downloader=curl + + # prepares to rewrite settings + echo "s/^MAIL=.*/MAIL=$TO_MAIL/" > $TMP.sed + echo "s/^CHANGED_ALERT=.*/CHANGED_ALERT=$ON_CHANGED/" >> $TMP.sed + echo "s/^ADDED_ALERT=.*/ADDED_ALERT=$ON_ADDED/" >> $TMP.sed + echo "s/^DELETED_ALERT=.*/DELETED_ALERT=$ON_DELETED/" >> $TMP.sed + echo "s/^AIDE_UPDATE=.*/AIDE_UPDATE=$ON_UPDATE/" >> $TMP.sed + + # check for curl/wget presence on this host + $downloader --version 1>/dev/null 2>&1 + if [ $? -ne 0 ]; then + downloader="wget -q -O " + fi + + $downloader $SRC > $TMP.org 2>/dev/null + if [ $? -ne 0 ]; then + echo "Error: can't download aideCheck.sh file" + rm -f $TMP.org $TMP.sed + exit 1 + fi + cat $TMP.org | sed -f $TMP.sed > $TMP + if [ $? -ne 0 ]; then + echo "Error: can't configure aideCheck.sh" + rm -r $TMP $TMP.org $TMP.sed + exit 2 + fi + + rm -f $TMP.sed $TMP.org +} + +# +# void install() - Install it +# +function install { + mv -f $TMP $DST + if [ $? -ne 0 ]; then + echo "Error: can't install $DST" + exit 1 + fi + + chmod 500 $DST + + echo "Remeber to:" + echo "1. Run an initial aide --init to setup AIDE database" + # check for curl/wget presence on this host + $downloader --version 1>/dev/null 2>&1 + if [ $? -ne 0 ]; then + downloader="wget -q -O " + fi + + $downloader $SRC > $TMP.org 2>/dev/null + if [ $? -ne 0 ]; then + echo "Error: can't download aideCheck.sh file" + rm -f $TMP.org $TMP.sed + exit 1 + fi + cat $TMP.org | sed -f $TMP.sed > $TMP + if [ $? -ne 0 ]; then + echo "Error: can't configure aideCheck.sh" + rm -r $TMP $TMP.org $TMP.sed + exit 2 + fi + + rm -f $TMP.sed $TMP.org +} + +# +# void install() - Install it +# +function install { + mv -f $TMP $DST + if [ $? -ne 0 ]; then + echo "Error: can't install $DST" + exit 1 + fi + + chmod 500 $DST + + echo "Remeber to:" + echo "1. Run an initial aide --init to setup AIDE database" + echo "2. Add aideCheck.sh to your crontab, scheduler, or run it to peridically check this system" + echo " Ex: add this to your crontab" + echo " 30 */1 * * * $DST" + echo " " +} + +# +# int main() +# +function main { + + setup + + patch + + install + + echo "Done." + + rm -f $TMP + + exit 0 +} + +main $@ -- GitLab