344 lines
12 KiB
Bash
Executable file
344 lines
12 KiB
Bash
Executable file
#!/usr/bin/env bash
|
||
#
|
||
# MOTDs32 installation instructions
|
||
# ==================================
|
||
#
|
||
# (2017) New project MOTDs32 Customized by Erreur32
|
||
# Version 0.0.5
|
||
#
|
||
# https://gitlab.echosystem.fr/Erreur32/MOTDs32
|
||
#
|
||
# ,--. ,--. ,-----. ,--------.,------. ,----. ,---.
|
||
# | `.' |' .-. ''--. .--'| .-. \ ,---. '.-. |'.-. \
|
||
# | |'.'| || | | | | | | | \ :( .-' .' < .-' .'
|
||
# | | | |' '-' ' | | | '--' /.-' `)/'-' |/ '-.
|
||
# `--' `--' `-----' `--' `-------' `----' `----' '-----'
|
||
#
|
||
# | + Stats32 |
|
||
#
|
||
# MOTDstat is dynamicaly refreshing the /etc/motd file with current informations
|
||
# about system status and usage.
|
||
#
|
||
# Copyright 2017 🅴🆁🆁🅴🆄🆁32
|
||
# original project: Pavol Krigler <pavol.krigler@gelogic.net>
|
||
#
|
||
# make sur this file is executable +x
|
||
################################################################################
|
||
#
|
||
# Installation
|
||
# ============
|
||
#
|
||
# As root execute this command (the easy way!):
|
||
#
|
||
# # bash install.sh
|
||
#
|
||
#
|
||
################################################################################
|
||
# Make sure only root can run our script
|
||
if [[ $EUID -ne 0 ]]; then
|
||
echo "This script must be run as root" 1>&2
|
||
exit 1
|
||
fi
|
||
|
||
pathscript32="$(cd "$(dirname "$0")" && pwd)"
|
||
|
||
## clean terminal
|
||
BG_BLUE="$(tput setab 4)"
|
||
BG_BLACK="$(tput setab 0)"
|
||
FG_GREEN="$(tput setaf 2)"
|
||
FG_WHITE="$(tput setaf 7)"
|
||
|
||
# Save screen
|
||
tput smcup
|
||
# Display menu until selection == 0
|
||
while [[ $REPLY != 0 ]]; do
|
||
echo -n ${BG_BLACK}${FG_WHITE}
|
||
clear
|
||
echo -e "\e[33;3m"
|
||
cat <<- "EOFMO"
|
||
|
||
Installation of MOTDs32 | + Stats32 |
|
||
|
||
EOFMO
|
||
echo -e "\e[32m"
|
||
cat <<- "EOFMO2"
|
||
,--. ,--. ,-----. ,--------.,------. ,----. ,---.
|
||
| `.' |' .-. ''--. .--'| .-. \ ,---. '.-. |'.-. \
|
||
| |'.'| || | | | | | | | \ :( .-' .' ; .-' .'
|
||
| | | |' '-' ' | | | '--' /.-' `)/'-' |/ '-.
|
||
`--' `--' `-----' `--' `-------' `----' `----' '-----'
|
||
|
||
By Erreur32
|
||
|
||
EOFMO2
|
||
|
||
echo -e "\e[90m # MOTDs32 is dynamicaly refreshing the /etc/motd file with current informations"
|
||
echo -e "\e[90m # about system status and usage."
|
||
echo -e "\n\e[34m Check MOTDs32 dependencies... \n"
|
||
|
||
check_depend(){
|
||
# Check installed
|
||
if [ -f "/usr/sbin/sendmail" ]
|
||
then
|
||
echo -e " \e[34m- Posfix \e[32m✔ installed."
|
||
else
|
||
echo -e " \e[34m- Select option 1 \e[91m Missing package !!"
|
||
fi
|
||
|
||
if [ -f "/usr/share/build-essential/essential-packages-list" ]
|
||
then
|
||
echo -e " \e[34m- build-dep \e[32m✔ installed."
|
||
else
|
||
echo -e " \e[34m- build-dep \e[1;31mSelect option 1 \e[91m Missing package !!"
|
||
fi
|
||
# Check files
|
||
|
||
if hash figlet 2>/dev/null; then
|
||
echo -e " \e[34m- Figlet \e[32m✔ installed."
|
||
else
|
||
echo -e " \e[34m- Figlet \e[1;31m Select option 1 \e[91m Missing package !!"
|
||
fi
|
||
if hash ntpd 2>/dev/null; then
|
||
echo -e " \e[34m- NTP \e[32m✔ installed."
|
||
else
|
||
echo -e " \e[34m- NTP \e[1;31mSelect option 1 \e[91m Missing package !!"
|
||
fi
|
||
if hash make 2>/dev/null; then
|
||
echo -e " \e[34m- build-essential \e[32m✔ installed."
|
||
else
|
||
echo -e " \e[34m- build-essential \e[1;31mSelect option 1 \e[91m Missing package !!"
|
||
fi
|
||
|
||
}
|
||
# Check dependenciess
|
||
|
||
check_depend || echo -e "\e[34m Check required dependencies ! (need to be installed)"
|
||
|
||
|
||
echo -e "\n\e[32;3m YOU CAN SKIP (auto) install if you want"
|
||
echo -e "\n\e[92m Please Select:"
|
||
echo -e " 1. \e[97m(auto) Install Missing Package\e[92m"
|
||
echo -e " 2. \e[97mInstallation MOTDs32 script\e[92m"
|
||
echo -e " 3. \e[97mUpdate MOTDs32 script\e[92m"
|
||
echo -e " 4. \e[97mUninstall completly MOTDs32 script\e[92m"
|
||
echo -e " 0. \e[97m(Enter or any key) to Quit\n\e[33;3m"
|
||
read -p " Enter selection [0-3] or (Enter) to Quit > " selection
|
||
echo -e "\e[97m"
|
||
|
||
# Clear area beneath menu
|
||
tput cup 10 0
|
||
echo -n ${FG_GREEN}
|
||
tput ed
|
||
tput cup 11 0
|
||
|
||
# Act on selection
|
||
case $selection in
|
||
1) echo -e " \e[32m install missing package ...\e[0m\n"
|
||
apt-get install --allow-unauthenticated -y build-essential ntp figlet postfix sasl2-bin
|
||
echo -e "\n\e[34m - apt-get installation build-essential ntp figlet \e[0m>> Succesfull"
|
||
if [ -f "/usr/bin/motds32" ]
|
||
then
|
||
echo -e "\n\e[34m - Make file \e[0m>> found.\e[0m\n"
|
||
#make install
|
||
#echo -e "\n\e[34m - REMake file done.\e[0m\n"
|
||
else
|
||
echo -e "\n\e[92m -Building binary \e[0m\n"
|
||
make install
|
||
echo -e "\n\e[34m - Make file done.\e[0m\n"
|
||
fi
|
||
|
||
echo -e "\e[92m"
|
||
if [ `grep -c /etc/motd ~/.bashrc` == 0 ]
|
||
then
|
||
echo -e " \e[31m code bash missing\e[0m"
|
||
echo "cat /etc/motd" >> ~/.bashrc
|
||
echo -e "\e[92m - Code bash \e[0madded.\n"
|
||
else
|
||
grepmot=`grep '/etc/motd' ~/.bashrc`
|
||
echo -e " \e[1;30m Code bash found: \e[0m>>\e[0m $grepmot \e[0m<<\n"
|
||
echo -e " -->\e[34m Code bash: \e[92mOK\e[0m"
|
||
fi
|
||
|
||
# Check if MOTDs32 is already add
|
||
if test ! -d /etc/motds32; then mkdir -p /etc/motds32; fi
|
||
|
||
if [ -f "/etc/motds32/Stats32" ]
|
||
then
|
||
echo -e " -->\e[34m Stats32 \e[92mOK\e[0m"
|
||
cp -f Stats32 /etc/motds32/Stats32
|
||
else
|
||
cp -f Stats32 /etc/motds32/Stats32
|
||
echo -e " -->\e[34m Stats32 \e[92mINSTALLED\e[0m"
|
||
fi
|
||
|
||
# Copy font figlet
|
||
if [ -f "/usr/share/figlet" ]
|
||
then
|
||
echo -e " -->\e[31m figlet not FOUND\e[0m"
|
||
else
|
||
cp -Rf fonts/chunky.flf /usr/share/figlet/
|
||
echo -e " -->\e[34m figlet&font \e[92mOK\e[0m"
|
||
fi
|
||
|
||
# Check if motd is installed correctly
|
||
if [ -f "/usr/bin/motd" ]
|
||
then
|
||
echo -e " -->\e[34m motd check \e[92mOK\e[0m\n"
|
||
else
|
||
ln -s /usr/bin/motds32 /usr/bin/motd
|
||
echo -e " -->\e[34m motd bin \e[92mOK\e[0m\n"
|
||
fi
|
||
## Install Crontab
|
||
if crontab -l | grep -q '/usr/bin/motds32'; then
|
||
echo -e " \e[34m -Cron \e[0m>> already added.\e[0m"
|
||
else
|
||
(crontab -l ; echo "*/5 * * * * /usr/bin/motds32 -g >/dev/null 2>&1")| crontab -
|
||
echo -e "\e[34m - Cron added.\e[0m"
|
||
fi
|
||
## Generate first stats
|
||
if test -f /usr/bin/motds32; then /usr/bin/motds32 -g; fi
|
||
|
||
echo -e "\n\n\e[34m \e[92m Installation of MOTDs32 completed!\e[0m \n\n\n Help? Use: \n \033[1;30m /usr/bin/motds32\e[0m \n or \033[1;30m\n motd\e[0m\n"
|
||
printf "\n \e[1;33m (Press 0 to exit)\e[0m"
|
||
printf "\n \e[1;33m (Or any key to go back.)\e[0m"
|
||
;;
|
||
2) echo -n " Git " ; cd $pathscript32 && git pull ; echo -e "\n\e[92m" ;
|
||
grepmot="cat /etc/motd"
|
||
# if [ `grep -c "cat /etc/motd" ~/.bashrc` == 0 ]
|
||
if [ $(grep -c "cat /etc/motd" ~/.bashrc) == 0 ]
|
||
then
|
||
echo -e "\e[31m code bash missing\e[0m"
|
||
echo $grepmot >> ~/.bashrc
|
||
echo -e "\e[92m - Code bash \e[0madded.\n"
|
||
else
|
||
# sed -i '/cat \/etc\/motd/d' ~/.bashrc
|
||
# grepmot=$(grep "/etc/motd" ~/.bashrc)
|
||
echo -e " \e[32;1m Code bash found: \e[0m>>\e[0m $grepmot \e[0m<<\n"
|
||
echo -e " -->\e[34m Code bash: \e[92mOK\e[0m"
|
||
fi
|
||
|
||
# Check if MOTDs32 is already add
|
||
if test ! -d /etc/motds32; then mkdir -p /etc/motds32; fi
|
||
|
||
if [ -f "/usr/bin/motds32" ]
|
||
then
|
||
echo -e "\n\e[34m - Make file \e[0m>> found.\e[0m\n"
|
||
#make install -- see update
|
||
#echo -e "\n\e[34m - REMake file done.\e[0m\n"
|
||
else
|
||
echo -e "\n\e[92m -Building binary \e[0m\n"
|
||
make install
|
||
echo -e "\n\e[34m - Make file done.\e[0m\n"
|
||
fi
|
||
|
||
if [ -f "/etc/motds32/Stats32" ]
|
||
then
|
||
echo -e " -->\e[34m Stats32 \e[92mOK\e[0m"
|
||
cp -f Stats32 /etc/motds32/Stats32
|
||
else
|
||
cp -f Stats32 /etc/motds32/Stats32
|
||
echo -e " -->\e[34m Stats32 \e[92mINSTALLED\e[0m"
|
||
fi
|
||
|
||
# Copy font figlet
|
||
if [ -f "/usr/share/figlet" ]
|
||
then
|
||
echo -e " -->\e[31m figlet not FOUND\e[0m"
|
||
else
|
||
cp -Rf fonts/chunky.flf /usr/share/figlet/
|
||
echo -e " -->\e[34m figlet&font \e[92mOK\e[0m"
|
||
fi
|
||
|
||
# Check if motd is installed correctly
|
||
if [ -f "/usr/bin/motd" ]
|
||
then
|
||
echo -e " -->\e[34m motd check \e[92mOK\e[0m\n"
|
||
else
|
||
ln -s /usr/bin/motds32 /usr/bin/motd
|
||
echo -e " -->\e[34m motd bin \e[92mOK\e[0m\n"
|
||
fi
|
||
|
||
## Install Crontab
|
||
if crontab -l | grep -q '/usr/bin/motds32'; then
|
||
echo -e "\e[34m - Cron \e[0m>> already added.\e[0m"
|
||
/usr/bin/motds32 -g
|
||
else
|
||
(crontab -l ; echo "*/5 * * * * /usr/bin/motds32 -g >/dev/null 2>&1")| crontab -
|
||
echo -e "\e[34m - Cron added.\e[0m"
|
||
fi
|
||
## Generate first stats
|
||
# if test -f /usr/bin/motds32; then /usr/bin/motds32 -g; fi
|
||
|
||
echo -e "\n\n\n Help? Use: \n \033[1;30m /usr/bin/motds32\e[0m \n or \033[1;30m\n motd\e[0m\n"
|
||
echo -e "\n\n\e[34m \e[92m Installation of MOTDs32 completed!\e[0m"
|
||
printf "\n \e[1;33m (Press any key to exit.)\e[0m"
|
||
;;
|
||
3) echo -n " Git " ; cd $pathscript32 && git pull ; echo -e "\n\e[92m" ;
|
||
if [ -f "/etc/motds32/Stats32" ]
|
||
then
|
||
echo -e " -->\e[34m Stats32 \e[92mOK\e[0m"
|
||
cp -f $pathscript32/Stats32 /etc/motds32/Stats32
|
||
else
|
||
cp -f $pathscript32/Stats32 /etc/motds32/Stats32
|
||
echo -e " -->\e[32;4m Stats32 \e[92mOK\e[0m"
|
||
fi
|
||
if [ -f "/usr/bin/motds32" ]
|
||
then
|
||
echo -e "\n\e[34m - Make file \e[0m>> update.\e[0m\n"
|
||
make install > /dev/null
|
||
motd -g
|
||
echo -e "\n\e[32;1m - Update binary done.\e[0m\n"
|
||
echo -e "\n\e[1;33m (Press any key.)\e[0m"
|
||
else
|
||
echo -e "\e[32;4m - Make install first !\e[0m\n"
|
||
echo -e "\n\e[1;33m (Press any key.)\e[0m"
|
||
fi
|
||
# generate new stat
|
||
# motd -g
|
||
/usr/bin/motds32 -g
|
||
;;
|
||
4) echo -e "\n\e[34m Unistall of MOTDs32 in progress... \e[0m\n"
|
||
## remove file and directory
|
||
make uninstall
|
||
rm /etc/motds32/ -Rf
|
||
rm -f /usr/bin/motd
|
||
rm /var/cache/motds32/ -Rf
|
||
|
||
## remove cron
|
||
if crontab -l | grep -q '/usr/bin/motds32'; then
|
||
echo -e "\n \e[92m Cron localized\n"
|
||
crontab -l | grep -v '*/5 * * * * /usr/bin/motds32 -g >/dev/null 2>&1' | crontab -u root -
|
||
echo -e " \e[92m Cron removed\n"
|
||
else
|
||
echo -e "\n \e[93m Cron not find\n"
|
||
fi
|
||
|
||
if [ `grep -c /etc/motd ~/.bashrc` == 0 ]
|
||
then
|
||
echo " Code bash removed"
|
||
else
|
||
echo " Code bash found"
|
||
sed -i '/cat \/etc\/motd/d' ~/.bashrc
|
||
sed -i '/cat \/usr\/bin\/motds32 -g/d' ~/.bashrc
|
||
echo -e "\e[92m Code .bashrc removed.\e[0m"
|
||
grep -n '/etc/motd' ~/.bashrc
|
||
fi
|
||
|
||
echo -e "\n\e[92m Script MOTDs32 has been completly removed \e[0m"
|
||
printf "\n \e[1;33m (Press any key.)\e[0m"
|
||
;;
|
||
0) break
|
||
;;
|
||
*) break
|
||
;;
|
||
esac
|
||
read -n 1
|
||
|
||
# echo -e "\n\n\e[34m \e[92m Installation of MOTDs32 completed!\e[0m \n\n\n Help? Use: \n \033[1;30m /usr/bin/motds32\e[0m \n or \033[1;30m\n motd\e[0m\n"
|
||
# printf "\n \e[1;33m (Press any key to exit.)\e[0m"
|
||
|
||
done
|
||
|
||
# Restore screen
|
||
tput rmcup
|
||
echo "Installation MOTDs32 terminated."
|