#!/bin/bash

date=`date '+%d_%m_%Y'`
echo -e "\n#######################################################################"
echo "##                                                                   ##"
echo "##          XIVO Maintenance - Installation de paquets               ##"
echo "##                                                                   ##"
echo "#######################################################################"

#Vérification
echo -en "\nVérification ping\n"
myping=`ping -c 1 www.google.fr`

if [ "$myping" = '' ]; then
    echo -en "\nIl n'y a pas d'accès internet\n"
    exit 1 	
else 
    echo -en "\nAccès internet OK\n"
fi

#Update
echo -en "\nUPDATE IN PROGRESS\n"
sudo apt-get update

#Vérification taille
echo -en "\nAttention !!! Vérifiez votre espace disque : df -h :\n"
df -h

echo -en "\nVoulez-vous continuez avec cet espace disque [Y ou N] : "
read ouinon
if [ "$ouinon" = "y" ] || [ "$ouinon" = "Y" ]; then
    echo -en "OK"
elif [ "$ouinon" = "n" ] || [ "$ouinon" = "N" ]; then
    echo -en "OK, bye!"
    exit 2
else
    echo "Il faut taper Y ou N!! Pas $ouinon"
    exit 1
fi

#Installation
echo -en "\nTerminal\n"
sudo apt-get install tmux screen

echo -en "\nMonitoring\n"
sudo apt-get install atop htop iftop dstat sysstat dnsutils ldap-utils pciutils

echo -en "\nNetwork\n"
sudo apt-get install arping mtr-tiny nmap ntp whois tcpdump dhcpdump tshark telnet

echo -en "\nFiles\n"
sudo apt-get install vim multitail patch lsof ngrep curl libxml2-utils

echo -en "\nLinux\n" 
sudo apt-get install locate tree bash-completion sudo hdparm

echo -en "\nXivo-collect\n" 
wget -O /usr/local/sbin/xivo-collect http://mirror.xivo.solutions/debian/tools/xivo-collect

#Configuration
echo -en "Configuration atop"
cat << EOF > /etc/default/atop
INTERVAL=60
LOGPATH="/var/log/atop"
OUTFILE="$LOGPATH/daily.log"
EOF

echo -en "Configuration screen"
cat << EOF > /root/.screenrc
# set a big scrolling buffer
defscrollback 10000
# Set the caption on the bottom line
caption always "%{= kw}%-w%{= BW}%n %t%{-}%+w %-= @%H - %LD %d %LM - %c"
EOF

echo -en "Configuration bashrc"
cat << EOF > /root/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.

# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022

# You may uncomment the following lines if you want \`ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
EOF

echo -en "\nInstallation OK ! Pensez à recharger votre bash\n"
exit 0
