<repo_name>cp38510/scripts<file_sep>/init_server_with_gpu_mailru/install_all.sh
#!/bin/bash
# This script for install Nvidia drivers and CUDA 10.1 on Centos 7.6, relevant 12.07.2019

sudo -i

yum -y update
yum -y install pciutils
lspci | grep -i nvidia
yum -y install kernel-devel
yum -y group install "Development Tools"
yum -y install kernel-devel-$(uname -r) kernel-headers-$(uname -r)
yum -y install epel-release
yum -y install dkms
yum -y install wget


wget http://us.download.nvidia.com/tesla/418.67/NVIDIA-Linux-x86_64-418.67.run
sh NVIDIA-Linux-x86_64-418.67.run
wget https://developer.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda-repo-rhel7-10-1-local-10.1.168-418.67-1.0-1.x86_64.rpm
sudo rpm -i cuda-repo-rhel7-10-1-local-10.1.168-418.67-1.0-1.x86_64.rpm
sudo yum -y clean all
sudo yum -y install cuda



echo "export PATH=/usr/local/cuda/bin:$PATH" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH" >> ~/.bashrc
source ~/.bashrc


echo "Execute: nvidia-smi"
echo "Execute: nvcc --version"
echo "Execute: shutdown -r now"
<file_sep>/tomcat_getting_start.sh
#!/bin/bash
#dz2_tomcat_version 0.1
#
SCRIPT_LOG_PATH="/tmp/deploy_process.log"
GIT_PATH="https://github.com/mnryerasi/java_Test.git"
DIRECTORY_FOR_CLONE_GIT="/tmp/git"
REMOTE_SERVER_USER="root"
REMOTE_SERVER_IP="8.8.8.8"
REMOTE_FILE_SERVER_PATH="/var/lib/tomcat8/webapps/"
#
echo "$(date '+%Y-%m-%d %H:%M:%S') - Start deploy project ${GIT_PATH}" >> ${SCRIPT_LOG_PATH}
#Remove old directory, if it exist
rm -rf ${DIRECTORY_FOR_CLONE_GIT}
#Clone git repository
git clone ${GIT_PATH} ${DIRECTORY_FOR_CLONE_GIT}
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, project don't clone from git" >> ${SCRIPT_LOG_PATH} && exit 0; fi
#Collect application
mvn package -f ${DIRECTORY_FOR_CLONE_GIT}
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, project don't collect in Maven" >> ${SCRIPT_LOG_PATH} && exit 0; fi
#Remove old directory, if it exist
TMP_VAR=$(ls ${DIRECTORY_FOR_CLONE_GIT}/target/*.war |cut -d \/ -f 5 |cut -d \. -f 1)
ssh -o StrictHostKeychecking=no ${REMOTE_SERVER_USER}@${REMOTE_SERVER_IP} "rm -rf ${REMOTE_FILE_SERVER_PATH}/${TMP_VAR}*"
#Copy file to remote server
rsync --verbose --archive --compress-level=9 --stats ${DIRECTORY_FOR_CLONE_GIT}/target/*.war ${REMOTE_SERVER_USER}@${REMOTE_SERVER_IP}:${REMOTE_FILE_SERVER_PATH}
#Restart tomcat on remote server
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, *.war don't copy to remote server" >> ${SCRIPT_LOG_PATH} && exit 0; fi
ssh -o StrictHostKeychecking=no ${REMOTE_SERVER_USER}@${REMOTE_SERVER_IP} "systemctl restart tomcat8"
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, tomcat don't restart on remote server ${REMOTE_SERVER_IP}" >> ${SCRIPT_LOG_PATH} && exit 0; fi
#Test http code project
wget -O /dev/null -a ${DIRECTORY_FOR_CLONE_GIT}/testwget http://${REMOTE_SERVER_IP}:8080/grants/ && grep -c '200 OK' ${DIRECTORY_FOR_CLONE_GIT}/testwget
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, project don't start correct" >> ${SCRIPT_LOG_PATH} && exit 0; fi
echo "$(date '+%Y-%m-%d %H:%M:%S') - Success finish deploy project ${GIT_PATH}" >> ${SCRIPT_LOG_PATH}
<file_sep>/search_ip_addresses_owned_by_AS.sh
#!/bin/bash
#script to search all domain IP-addresses
#
function show_usage {
    echo -e "Usage: $0 domain_name\nExample: $0 vk.com\n"
    exit 1
}
#
if [ $# -ne 1 ]; then
    show_usage
else
#remove temporary files, if they exist
rm -rf /tmp/tmpvartmp777
rm -rf /tmp/tmpvartmp778
#find domain IP-addresses
dig $1 +short > /tmp/tmpvartmp777
#start search all AS(Autonomous System) owned by IP-addresses
while read ipaddr;
do
whois $ipaddr | grep origin | awk {'print $2'} > /tmp/tmpvartmp778
done < /tmp/tmpvartmp777
#sort unique AS(Autonomous System)
ASUNIQ="$(cat /tmp/tmpvartmp778 |sort -u)"
#find all IP-addresses owned by AS(Autonomous System)
whois -h whois.ripe.net -i origin $ASUNIQ | grep route | awk '{print $2}' | grep -ivE "vk|:" |egrep -v '[a-z]|[A-Z]'
#remove temporary files
rm -rf /tmp/tmpvartmp777
rm -rf /tmp/tmpvartmp778
echo "Done!"
fi
<file_sep>/backup/test_backup1.sh
#!/bin/bash
#scrypt #1_version 0.1
#
BACKUPLOG="/tmp/create_file_process.log"
FILE_SERVER_PATH="/tmp/test_backup.log"
#
echo "$(date '+%Y-%m-%d %H:%M:%S') - Start create file ${FILE_SERVER_PATH}" >> ${BACKUPLOG}
head -c 100000000 < /dev/urandom > ${FILE_SERVER_PATH}
if [ $? -ne 0 ];
then
echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR create file ${FILE_SERVER_PATH}" >> ${BACKUPLOG}
else
echo "$(date '+%Y-%m-%d %H:%M:%S') - Success finish create file ${FILE_SERVER_PATH}" >> ${BACKUPLOG}
fi
<file_sep>/backup/backup_site_20180321.sh
#!/bin/bash
#script_backup_some_web_site
#
BACKUPLOG="./backup.log"
SERVER_USER="user"
SERVER_IP="8.8.8.8"
FILE_SERVER_PATH="/var/www/"
FILE_SAVE_PATH="/home/user/backup/site-$(date +%Y%m%d)"
#
DATABASE_NAME="dbname"
DATABASE_USER="dbname"
DATABASE_PASS="<PASSWORD>"
#
#
#Create directory for safe files
mkdir ${FILE_SAVE_PATH}
#Dump database web site on remote server
sshpass -p $1 ssh -o StrictHostKeychecking=no ${SERVER_USER}@${SERVER_IP} "mysqldump -u'${DATABASE_USER}' ${DATABASE_NAME} -p'${DATABASE_PASS}' > dump.sql"
#Copy files web site to local server
sshpass -p $1 rsync --verbose --archive --compress-level=9 --stats ${SERVER_USER}@${SERVER_IP}:${FILE_SERVER_PATH} ${FILE_SAVE_PATH}
#Copy database to local server
sshpass -p $1 rsync --verbose --archive --compress-level=9 --stats ${SERVER_USER}@${SERVER_IP}:/home/${SERVER_USER}/dump.sql ${FILE_SAVE_PATH}
#Remove database frome remote server
sshpass -p $1 ssh -o StrictHostKeychecking=no ${SERVER_USER}@${SERVER_IP} "rm dump.sql"
#Compress web site files
tar -cvzf ${FILE_SAVE_PATH}.tar.gz ${FILE_SAVE_PATH}
#Move to another directory
mv ${FILE_SAVE_PATH}.tar.gz ./site
#Remove files
rm -rf ${FILE_SAVE_PATH}
echo "Done!"

<file_sep>/zimbra/zimbra_remove_messages_v1.sh
#!/bin/bash
#version 0.1
#
ZIMBRA_BIN=/opt/zimbra/bin
MAIL_DOMAIN=mail.ru
#
echo "Enter the mailbox name, use format: <EMAIL>:"
read THEACCOUNT
# Checking the existence of an account
$ZIMBRA_BIN/zmprov -l gaa $MAIL_DOMAIN |grep -xc $THEACCOUNT > /dev/null 2>&1
if [ $? -ne 0 ]; then "echo ERROR, account $THEACCOUNT not found" && exit 0; fi
#
echo "Enter the start date for the message deletion period, in mm/dd/yyyy format. Example: 04/1/2018"
read THEDATE1
if [ -z "$THEDATE1" ]; then echo "ERROR, variable not entered" && exit 0; fi
if [[ ! "$THEDATE1" =~ ^[0-9]{2}/[0-9]{2}/[0-9]{4}$ ]]; then echo "ERROR, invalid date format, use format: mm/dd/yyyy" && exit 0; fi
#
echo "Enter the end date for the message deletion period, in mm/dd/yyyy format. Example: 04/21/2018"
read THEDATE2
if [ -z "$THEDATE2" ]; then echo "ERROR, variable not entered" && exit 0; fi
if [[ ! "$THEDATE2" =~ ^[0-9]{2}/[0-9]{2}/[0-9]{4}$ ]]; then echo "ERROR, invalid date format, use format: mm/dd/yyyy" && exit 0; fi
#
echo "You will now be deleting ALL(Input and output) messages in $THEDATE1 - $THEDATE2 for $THEACCOUNT."
echo "Do you want to continue? (y/N): "
read ADD
#
themagic ()
{
rm -f /tmp/deleteOldMessagesList.txt; touch /tmp/deleteOldMessagesList.txt
rm -f /tmp/process.log; touch /tmp/process.log
for i in `$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT search -l 1000 "after:$THEDATE1 before:$THEDATE2" |awk '{print $2}'| sed 1,4d`
do
        if [[ $i =~ [-]{1} ]]
        then
        MESSAGEID=${i#-}
        echo "deleteMessage $MESSAGEID" >> /tmp/deleteOldMessagesList.txt
        else
        echo "deleteConversation $i" >> /tmp/deleteOldMessagesList.txt
        fi
done
#
while [ -s /tmp/deleteOldMessagesList.txt ]
do
        $ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT < /tmp/deleteOldMessagesList.txt >> /tmp/process.log
        rm -f /tmp/deleteOldMessagesList.txt; touch /tmp/deleteOldMessagesList.txt
        for i in `$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT search -l 1000 "after:$THEDATE1 before:$THEDATE2" |awk '{print $2}'| sed 1,4d`
        do
        if [[ $i =~ [-]{1} ]]
        then
        MESSAGEID=${i#-}
        echo "deleteMessage $MESSAGEID" >> /tmp/deleteOldMessagesList.txt
        else
        echo "deleteConversation $i" >> /tmp/deleteOldMessagesList.txt
        fi
        done
done
read -p "Completed. Run again for other user (y/n)? " REPLY
if [[ $REPLY =~ ^[Yy]$ ]]; then exec $0; else ADD=n; fi
}
#
while expr "$ADD" : ' *[Yy].*' > /dev/null
do themagic
done
<file_sep>/backup/test_backup2.sh
#!/bin/bash
#scrypt #2_version 0.1
#
BACKUPLOG="/tmp/backup_process.log"
REMOTE_SERVER_USER="root"
REMOTE_SERVER_IP="8.8.8.8"
REMOTE_FILE_SERVER_PATH="/tmp/test_backup.log"
LOCAL_FILE_SAVE_PATH="/home/backup_log/"
LOCAL_FILE_SAVE_NAME="$(date +%d%m%y)-test_backup.log.tar.gz"
#
echo "$(date '+%Y-%m-%d %H:%M:%S') - Start backup file ${REMOTE_FILE_SERVER_PATH})" >> ${BACKUPLOG}
#Check exist file
remote_file=$(ssh -o StrictHostKeychecking=no ${REMOTE_SERVER_USER}@${REMOTE_SERVER_IP} test -f ${REMOTE_FILE_SERVER_PATH})
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, file not exist ${REMOTE_FILE_SERVER_PATH}" >> ${BACKUPLOG} && exit 0; fi
#If file exist, clean old files in local directory
find ${LOCAL_FILE_SAVE_PATH} -type f -mtime +7 -exec rm -rf {} \;
#Compression file on remote server
ssh -o StrictHostKeychecking=no ${REMOTE_SERVER_USER}@${REMOTE_SERVER_IP} "tar -cvzf ${REMOTE_FILE_SERVER_PATH}.tar.gz ${REMOTE_FILE_SERVER_PATH}"
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, file not compress ${REMOTE_FILE_SERVER_PATH}" >> ${BACKUPLOG} && exit 0; fi
#Copy file from remote server
rsync --verbose --archive --compress-level=9 --stats ${REMOTE_SERVER_USER}@${REMOTE_SERVER_IP}:${REMOTE_FILE_SERVER_PATH}.tar.gz ${LOCAL_FILE_SAVE_PATH}${LOCAL_FILE_SAVE_NAME}
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, file not copy ${REMOTE_FILE_SERVER_PATH}" >> ${BACKUPLOG} && exit 0; fi
#Clean remote file
ssh -o StrictHostKeychecking=no ${REMOTE_SERVER_USER}@${REMOTE_SERVER_IP} "truncate -s 0 ${REMOTE_FILE_SERVER_PATH} & rm -rf ${REMOTE_FILE_SERVER_PATH}.tar.gz"
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, file not cleared  ${REMOTE_FILE_SERVER_PATH}" >> ${BACKUPLOG} && exit 0; fi
echo "$(date '+%Y-%m-%d %H:%M:%S') - Success finish backup file ${REMOTE_FILE_SERVER_PATH})" >> ${BACKUPLOG}
<file_sep>/deploy_app_to_docker_tomcat.sh
#!/bin/bash
#
#script deploy .war application from git_ver0.1
#
#For deploy we use 3 servers: SERVER_BUILD, SERVER_REGISTRY and SERVER_PROD.
#On server SERVER_BUILD install java and maven, download application from git,
#compile app in maven and build docker container with dockerfile, push to SERVER_REGISTRY.
#On SERVER_REGISTRY we start docker registry and keep container for transfer.
#On SERVER_PROD we only start container from SERVER_REGISTRY.
#
BUILD_IP=
REGISTRY_IP=
PROD_IP=
#
REGISTRY_USER="usertmp"
REGISTRY_PASS="<PASSWORD>"
CONTAINER_NAME="test1"
#
GIT_PATH="https://github.com/cp38510/java_Test.git"
DIRECTORY_FOR_CLONE_GIT="/tmp/git"
#
SCRIPT_LOG_PATH=/tmp/scriptdeploy.log
DATEFORM=$(date '+%Y-%m-%d %H:%M:%S')
#
#
function scriptdeploy {
#############################################################
#check enter servers IP's
if [ -z $BUILD_IP ] ; then echo "You don't set SERVER_BUILD IP" && exit 0; fi
if [ -z $REGISTRY_IP ] ; then echo "You don't set SERVER_REGISTRY IP" && exit 0; fi
if [ -z $PROD_IP ] ; then echo "You don't set SERVER_PROD IP" && exit 0; fi

#remove old RSA key's
ssh-keygen -R $BUILD_IP
ssh-keygen -R $REGISTRY_IP
ssh-keygen -R $PROD_IP
#############################################################
#SERVER_REGISTRY
SSHTMP1="ssh -o StrictHostKeychecking=no root@$REGISTRY_IP"
#update server
$SSHTMP1 "apt-get update > /dev/null"

#install docker
$SSHTMP1 "dpkg -s docker-ce > /dev/null 2>&1"
if [ $? -ne 0 ]; then $SSHTMP1 "curl https://get.docker.com/ | bash > /dev/null 2>&1"; fi

#check install docker
$SSHTMP1 "dpkg -s docker-ce > /dev/null 2>&1"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, docker didn't install on SERVER_REGISTRY" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#create directories for docker
$SSHTMP1 "rm -rf /home/docker"
$SSHTMP1 "mkdir -p /home/docker/{data,auth}"

#create authentication docker registry file htpasswd
$SSHTMP1 "rm -rf /home/docker/auth/htpasswd"
$SSHTMP1 "docker run --entrypoint htpasswd registry -Bbn $REGISTRY_USER $REGISTRY_PASS > /home/docker/auth/htpasswd"

#check exist file htpasswd
$SSHTMP1 "test -f /home/docker/auth/htpasswd"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, file /home/docker/auth/htpasswd didn't create on SERVER_REGISTRY" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#restart docker
$SSHTMP1 "systemctl restart docker"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, docker didn't restart on SERVER_REGISTRY" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#stop and remove all runing container
TMPDOCKERLIST=$($SSHTMP1 "docker ps -a" |awk '{print $1}' |grep -vi container |tr '\n' ' ')
$SSHTMP1 "docker stop $TMPDOCKERLIST && docker rm $TMPDOCKERLIST"

#start docker registry container
$SSHTMP1 "docker run -d -p 5000:5000 --restart=always --name registry -v /home/docker/data:/var/lib/registry -v /home/docker/auth:/auth -e \"REGISTRY_AUTH=htpasswd\" -e \"REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm\" -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry > /dev/null"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, docker registry container didn't start on SERVER_REGISTRY" >> ${SCRIPT_LOG_PATH} && exit 0; fi

echo -e "\e[32m Deploy SERVER_REGISTRY Done \e[0m"

#############################################################
#SERVER_BUILD
SSHTMP2="ssh -o StrictHostKeychecking=no root@$BUILD_IP"
#update server
$SSHTMP2 "apt-get update > /dev/null"

#add java repository
$SSHTMP2 "add-apt-repository ppa:webupd8team/java -y > /dev/null"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, java repository didn't add on SERVER_BUILD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#update server
$SSHTMP2 "apt-get update > /dev/null"

#install java
$SSHTMP2 "dpkg -s oracle-java8-installer > /dev/null 2>&1"
if [ $? -ne 0 ]; then
$SSHTMP2 "echo \"oracle-java8-installer shared/accepted-oracle-license-v1-1 select true\" | sudo debconf-set-selections > /dev/null 2>&1"
$SSHTMP2 "apt-get install -y oracle-java8-installer > /dev/null 2>&1"
fi
#export JAVA_HOME directory
$SSHTMP2 "export JAVA_HOME=/usr/lib/jvm/java-8-oracle/"

#check install java
$SSHTMP2 "dpkg -s oracle-java8-installer > /dev/null 2>&1"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, java didn't install on SERVER_BUILD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#install maven
$SSHTMP2 "dpkg -s maven > /dev/null 2>&1"
if [ $? -ne 0 ]; then $SSHTMP2 "apt-get install maven -y > /dev/null 2>&1"; fi
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, maven didn't install on SERVER_BUILD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#install git
$SSHTMP2 "dpkg -s git > /dev/null 2>&1"
if [ $? -ne 0 ]; then $SSHTMP2 "apt-get install git > /dev/null 2>&1"; fi
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, git didn't install on SERVER_BUILD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#clone git repository
$SSHTMP2 "rm -rf /tmp/git"
$SSHTMP2 "git clone ${GIT_PATH} ${DIRECTORY_FOR_CLONE_GIT} > /dev/null"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, project don't clone from git on SERVER_BUILD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#package application
$SSHTMP2 "mvn package -f /tmp/git > /dev/null"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, application didn't package on SERVER_BUILD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#install docker
$SSHTMP2 "dpkg -s docker-ce > /dev/null 2>&1"
if [ $? -ne 0 ]; then $SSHTMP2 "curl https://get.docker.com/ | bash > /dev/null 2>&1"; fi
#check install docker
$SSHTMP2 "dpkg -s docker-ce > /dev/null 2>&1"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, docker didn't install on SERVER_BUILD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#create dockerfile
$SSHTMP2 "NAMEWAR=$(find /tmp/git/ -name \"*.war\" -exec basename \{} \;)"
$SSHTMP2 "echo -e \"FROM tomcat:8\nADD ./$NAMEWAR /usr/local/tomcat/webapps/\nEXPOSE 8080\nCMD [\042catalina.sh\042, \042run\042]\" > /tmp/dockerfile"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, dockerfile didn't create on SERVER_BUILD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#docker build container
$SSHTMP2 "cd $DIRECTORY_FOR_CLONE_GIT/target/ && docker build -t $REGISTRY_IP:5000/$CONTAINER_NAME:latest -f /tmp/dockerfile ."
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, docker container didn't build on SERVER_BUILD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#create file for enable http connect to repository
$SSHTMP2 "echo -e \"{ '\042'insecure-registries'\042':['\042'$REGISTRY_IP:5000'\042'] }\" |tr -d '\047' > /etc/docker/daemon.json"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, file /etc/docker/daemon.json didn't create on SERVER_BUILD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#restart docker
$SSHTMP2 "systemctl restart docker"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, docker didn't restart on SERVER_BUILD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#login in remote docker registry
$SSHTMP2 "docker login --username=$REGISTRY_USER --password=$REGISTRY_PASS $REGISTRY_IP:5000"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, docker on SERVER_BUILD didn't login on remote SERVER_REGISTRY" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#push docker container to remote docker registry
$SSHTMP2 "docker push $REGISTRY_IP:5000/$CONTAINER_NAME:latest"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, docker container didn't push to remote SERVER_REGISTRY" >> ${SCRIPT_LOG_PATH} && exit 0; fi

echo -e "\e[32m Deploy SERVER_BUILD Done \e[0m"

#############################################################
#SERVER_PROD
SSHTMP3="ssh -o StrictHostKeychecking=no root@$PROD_IP"
#update server
$SSHTMP3 "apt-get update > /dev/null"

#install docker
$SSHTMP3 "dpkg -s docker-ce > /dev/null 2>&1"
if [ $? -ne 0 ]; then $SSHTMP3 "curl https://get.docker.com/ | bash > /dev/null 2>&1"; fi
#check install docker
$SSHTMP3 "dpkg -s docker-ce > /dev/null 2>&1"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, docker didn't install on SERVER_PROD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#create file for enable http connect to repository
$SSHTMP3 "echo -e \"{ '\042'insecure-registries'\042':['\042'$REGISTRY_IP:5000'\042'] }\" |tr -d '\047' > /etc/docker/daemon.json"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, file /etc/docker/daemon.json didn't create on SERVER_PROD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#restart docker
$SSHTMP3 "systemctl restart docker"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, docker didn't restart on SERVER_PROD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#login in remote docker registry
$SSHTMP3 "docker login --username=$REGISTRY_USER --password=$REGISTRY_PASS $REGISTRY_IP:5000"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, docker on SERVER_PROD didn't login on remote SERVER_REGISTRY" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#pull docker container from remote docker registry
$SSHTMP3 "docker pull $REGISTRY_IP:5000/$CONTAINER_NAME:latest"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, docker container didn't pull from remote SERVER_REGISTRY" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#add tag to container
$SSHTMP3 "docker tag $REGISTRY_IP:5000/$CONTAINER_NAME:latest tomcat/$CONTAINER_NAME:latest"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, tag didn't add to cantainer on SERVER_PROD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#run docker container
$SSHTMP3 "docker run -d -p 8080:8080 --restart=always tomcat/$CONTAINER_NAME:latest"
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, docker container didn't run on SERVER_PROD" >> ${SCRIPT_LOG_PATH} && exit 0; fi

#wait start container, before test
sleep 15s

#Test http code project
rm -rf /tmp/testwget
wget -O /dev/null -a /tmp/testwget http://$PROD_IP:8080/grants/ && grep -c ' 200 ' /tmp/testwget
if [ $? -ne 0 ]; then echo "$DATEFORM - ERROR, project didn't start correct on SERVER_PROD" >> ${SCRIPT_LOG_PATH} && exit 0; fi
rm -rf /tmp/testwget

echo -e "\e[32m Deploy SERVER_PROD Done \e[0m"
echo -e "\e[32m All task's well done! Go http://$PROD_IP:8080/grants/ \e[0m"

}
scriptdeploy
if [ $? -ne 0 ]; then echo "script execution ERROR! Look details ${SCRIPT_LOG_PATH}"; fi
<file_sep>/zimbra/zimbra_remove_messages_v2.sh
#!/bin/bash
#version 0.2
#
ZIMBRA_BIN=/opt/zimbra/bin
MAIL_DOMAIN=mail.ru
USER_LIST=/tmp/userlist.txt
#Enter the start date for the message deletion period, in mm/dd/yyyy format. Example: 04/1/2018
THEDATE1=05/20/2013
#Enter the end date for the message deletion period, in mm/dd/yyyy format. Example: 04/21/2018
THEDATE2=01/01/2017
#
cat $USER_LIST | while read line
do
#
rm -f /tmp/deleteOldMessagesList.txt
touch /tmp/deleteOldMessagesList.txt
rm -f /tmp/process.log
touch /tmp/process.log
for i in `$ZIMBRA_BIN/zmmailbox -z -m $line search -l 1000 "after:$THEDATE1 before:$THEDATE2" |awk '{print $2}'| sed 1,4d`
do
        if [[ $i =~ [-]{1} ]]
        then
        MESSAGEID=${i#-}
        echo "deleteMessage $MESSAGEID" >> /tmp/deleteOldMessagesList.txt
        else
        echo "deleteConversation $i" >> /tmp/deleteOldMessagesList.txt
        fi
done
#
while [ -s /tmp/deleteOldMessagesList.txt ]
do
        $ZIMBRA_BIN/zmmailbox -z -m $line < /tmp/deleteOldMessagesList.txt >> /tmp/process.log
        rm -f /tmp/deleteOldMessagesList.txt
        touch /tmp/deleteOldMessagesList.txt
        for i in `$ZIMBRA_BIN/zmmailbox -z -m $line search -l 1000 "after:$THEDATE1 before:$THEDATE2" |awk '{print $2}'| sed 1,4d`
        do
        if [[ $i =~ [-]{1} ]]
        then
        MESSAGEID=${i#-}
        echo "deleteMessage $MESSAGEID" >> /tmp/deleteOldMessagesList.txt
        else
        echo "deleteConversation $i" >> /tmp/deleteOldMessagesList.txt
        fi
        done

done
#
echo "Messages in $line delete" >> /tmp/deleteProcess.txt
echo "Done!"
done
<file_sep>/send_notify_abuse_script.sh
#!/bin/bash
#
#script_for_notify_the_owner_IP_about_abuse_v0.1
#
#file with ip - e-mail from WHOIS; example: 8.8.8.8 <EMAIL>
SPAMIPLIST=/tmp/spamiplist.txt
#file with log's abuse
SPAMLOGS=/tmp/logsmailserver.txt
#file for logging this script
SENDMAILLOG=/tmp/sendmail.log
#your text for subject mail
SUBJECTMAIL="SSH brute-force from your server"
#
#create list with uniq email's
cat $SPAMIPLIST |cut -d ' ' -f2|sort -u >/tmp/testtest111
UNIQLIST=/tmp/testtest111
#
while read MAILTO;
do
#create list IPs from mail
MAILIP="$(cat $SPAMIPLIST|grep $MAILTO|cut -d ' ' -f1)"
#change list IPs for search
IPFORGREP="$(echo $MAILIP|tr ' ' '\|')"
#grep logs for message
LOGS="$(cat $SPAMLOGS|egrep "$IPFORGREP")"
#create masseges for mail
MAILTEXT="Hello!\n\nAn attempt to brute-force account passwords(on our server mail.domain.com IP: 8.8.8.8) over SSH/FTP by a machine in your domain or in your network has been detected. Attached are the host who attacks and time / date of activity.\n\nPlease take the necessary action(s) to stop this activity immediately.\nIf you have any questions please reply to this email.\n\nHost attacker IP:\n$MAILIP\n\nLogs attack(time UTC+4):\n$LOGS\n\nSincerely,\nSystem administrator\nSurname Name\ndomain.com"
echo -e "${MAILTEXT}" |mail -aFrom:Surname_Name\<<EMAIL>\> -s "${SUBJECTMAIL}" "${MAILTO}"
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, mail did'n sent to $MAILTO" >> ${SENDMAILLOG}; fi
#
done <"${UNIQLIST}"
<file_sep>/google_cloud_test_settings2.sh
#!/bin/bash
#
#script for setup test server Ubuntu_16 on Google Cloud_version01
#
SCRIPTLOG="/tmp/startscriptlog"
#
timedatectl set-timezone Europe/Moscow
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, timezone don't set Europe/Moscow" >> ${SCRIPTLOG} && echo "look /tmp/startscriptlog"; fi
apt-get update -y
#yum update -y
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, system don't update" >> ${SCRIPTLOG} && echo "look /tmp/startscriptlog"; fi
apt-get install git less nano nmap -y
yum install git less nano -y
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, applications don't install" >> ${SCRIPTLOG} && echo "look /tmp/startscriptlog"; fi
sed -i -e 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' -e 's/PermitRootLogin no/PermitRootLogin yes/g'  -e 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
#egrep 'PermitRootLogin yes' /etc/ssh/sshd_config && grep 'PasswordAuthentication yes' /etc/ssh/sshd_config
#if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, settings in /etc/ssh/sshd_config don't change" >> ${SCRIPTLOG} && echo "look /tmp/startscriptlog"; fi
systemctl restart ssh
systemctl restart sshd
#if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, ssh.service don't restart" >> ${SCRIPTLOG} && echo "look /tmp/startscriptlog"; fi
#sed -i '/root/s/\:\*/\:$1$jYePn7UP$1Q6SYWeihp9IWcB3taOeq\//g' /etc/shadow
#grep root /etc/shadow |grep ':$1$jYePn7UP$1Q6SYWeihp9IWcB3taOeq/:'
#if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, root passwd don't change in /etc/shadow" >> ${SCRIPTLOG} && echo "look /tmp/startscriptlog"; fi
mkdir -p /root/.ssh
chmod 700 /root/.ssh
echo "ssh-rsa <KEY>2<KEY>EuCzFOhJ9pYBJ<KEY>Mu+d8X97zVk<KEY>jv<KEY>Za<KEY>stm+9VdUREe1PMdb8IAigi<KEY>Im<KEY>mc<KEY>dwMQiXwbBvOfzBDqtQ+Y9N24LHSZYLTAxhAqEyZ60/cJF root" >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
echo "Well done!"
<file_sep>/google_cloud_test_settings3.sh
#!/bin/bash
#
#script for setup test server Ubuntu_16 on Google Cloud_version01
#
SCRIPTLOG="/tmp/startscriptlog"
#
timedatectl set-timezone Europe/Moscow
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, timezone don't set Europe/Moscow" >> ${SCRIPTLOG} && echo "look /tmp/startscriptlog" && exit 0; fi
apt-get update
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, system don't update" >> ${SCRIPTLOG} && echo "look /tmp/startscriptlog" && exit 0; fi
apt-get install git less nano nmap -y
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, applications don't install" >> ${SCRIPTLOG} && echo "look /tmp/startscriptlog" && exit 0; fi
sed -i -e 's/PermitRootLogin prohibit-password/PermitRootLogin yes/g' -e 's/PermitRootLogin no/PermitRootLogin yes/g'  -e 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
egrep 'PermitRootLogin yes' /etc/ssh/sshd_config && grep 'PasswordAuthentication yes' /etc/ssh/sshd_config
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, settings in /etc/ssh/sshd_config don't change" >> ${SCRIPTLOG} && echo "look /tmp/startscriptlog" && exit 0; fi
systemctl restart ssh
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, ssh.service don't restart" >> ${SCRIPTLOG} && echo "look /tmp/startscriptlog" && exit 0; fi
sed -i '/root/s/\:\*/\:$1$jYePn7UP$1Q6SYWeihp9IWcB3taOeq\//g' /etc/shadow
grep root /etc/shadow |grep ':$1$jYePn7UP$1Q6SYWeihp9IWcB3taOeq/:'
if [ $? -ne 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR, root passwd don't change in /etc/shadow" >> ${SCRIPTLOG} && echo "look /tmp/startscriptlog" && exit 0; fi
echo "ssh-rsa <KEY> root" >> /root/.ssh/authorized_keys
echo "Well done!"
