MOTDs32/install.sh

309 lines
10 KiB
Bash
Raw Normal View History

2017-07-30 23:19:31 +02:00
#!/bin/sh
#
# MOTDs32 installation instructions
# ==================================
#
# (2017) New project MOTDs32 Customized by Erreur32
# Version 0.0.5
#
# https://gitlab.echosystem.fr/Erreur32/MOTDs32
#
# ,--. ,--. ,-----. ,--------.,------. ,----. ,---.
# | `.' |' .-. ''--. .--'| .-. \ ,---. '.-. |'.-. \
# | |'.'| || | | | | | | | \ :( .-' .' < .-' .'
# | | | |' '-' ' | | | '--' /.-' `)/'-' |/ '-.
# `--' `--' `-----' `--' `-------' `----' `----' '-----'
#
# | + |
#
# 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!):
#
2018-03-16 12:12:56 +01:00
# # ./install.sh
# or
# # bash install-sh
#
2017-07-30 23:19:31 +02:00
#
################################################################################
# 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
## clean terminal
#clear;
BG_BLUE="$(tput setab 4)"
BG_BLACK="$(tput setab 0)"
FG_GREEN="$(tput setaf 2)"
FG_WHITE="$(tput setaf 7)"
2018-03-16 12:12:56 +01:00
2017-07-30 23:19:31 +02:00
# Save screen
tput smcup
# Display menu until selection == 0
while [[ $REPLY != 0 ]]; do
echo -n ${BG_BLACK}${FG_WHITE}
clear
cat <<- "EOFMO"
| + |
,--. ,--. ,-----. ,--------.,------. ,----. ,---.
| `.' |' .-. ''--. .--'| .-. \ ,---. '.-. |'.-. \
| |'.'| || | | | | | | | \ :( .-' .' ; .-' .'
| | | |' '-' ' | | | '--' /.-' `)/'-' |/ '-.
`--' `--' `-----' `--' `-------' `----' `----' '-----'
By
EOFMO
echo -e "\033[1;30m # MOTDs32 is dynamicaly refreshing the /etc/motd file with current informations"
echo -e "\033[1;30m # about system status and usage."
echo -e "\n \e[34m Installation of in progress... \e[0m\n\n"
2018-03-16 12:12:56 +01:00
# Check dependenciess
2018-03-16 12:19:55 +01:00
echo -e "\e[34m Check required dependencies ! (need to be installed)"
2018-03-16 12:12:56 +01:00
# Check installed
2018-03-16 12:33:01 +01:00
if [ -f "/usr/sbin/sendmail" ]
then
echo -e " \e[34m- Posfix \e[92m OK\e[0m\n"
else
echo -e " \e[34m- Select option 1 \e[91m Missing package !! \e[0m\n"
fi
if [ -f "/usr/share/build-essential/essential-packages-list" ]
then
2018-03-16 12:33:26 +01:00
echo -e " \e[34m- build-dep \e[32m✔ installed.\e[0m"
2018-03-16 12:19:55 +01:00
else
2018-03-16 12:33:01 +01:00
echo -e " \e[34m- build-dep \e[1;31mSelect option 1 \e[91m Missing package !!\e[0m"
2018-03-16 12:19:55 +01:00
fi
2018-03-16 12:12:56 +01:00
2017-07-30 23:19:31 +02:00
# Check files
2018-03-16 12:12:56 +01:00
2017-07-30 23:19:31 +02:00
if hash figlet 2>/dev/null; then
2018-01-01 13:10:49 +01:00
echo -e " \e[34m- Figlet \e[32m✔ installed.\e[0m"
2017-07-30 23:19:31 +02:00
else
2018-03-16 12:19:55 +01:00
echo -e " \e[34m- Figlet \e[1;31m Select option 1 \e[91m Missing package !!\e[0m"
2017-07-30 23:19:31 +02:00
fi
if hash ntpd 2>/dev/null; then
2018-01-01 13:10:49 +01:00
echo -e " \e[34m- NTP \e[32m✔ installed.\e[0m"
2017-07-30 23:19:31 +02:00
else
2018-03-16 12:19:55 +01:00
echo -e " \e[34m- NTP \e[1;31mSelect option 1 \e[91m Missing package !!\e[0m"
2017-07-30 23:19:31 +02:00
fi
if hash make 2>/dev/null; then
2018-01-01 13:10:49 +01:00
echo -e " \e[34m- build-essential \e[32m✔ installed.\e[0m"
2017-07-30 23:19:31 +02:00
else
2018-03-16 12:19:55 +01:00
echo -e " \e[34m- build-essential \e[1;31mSelect option 1 \e[91m Missing package !!\e[0m"
2017-07-30 23:19:31 +02:00
fi
2018-03-16 12:19:55 +01:00
2017-07-30 23:43:06 +02:00
echo -e "\n YOU CAN SKIP (auto) install if you want"
2017-07-30 23:19:31 +02:00
echo -e "\n\e[92m Please Select:"
2017-07-30 23:43:06 +02:00
echo -e " 1. \e[0m(auto) Install Missing Package\e[92m"
2018-03-16 12:19:55 +01:00
echo -e " 2. \e[0mInstallation MOTDs32 script\e[92m"
echo -e " 3. \e[0mUninstall completly MOTDs32 script\e[92m"
2017-07-31 15:54:29 +02:00
echo -e " 0. \e[0m(Enter or any key) to Quit\n \e[0m"
read -p " Enter selection [0-3] or (Enter) to Quit > " selection
2017-07-30 23:19:31 +02:00
2018-03-16 12:19:55 +01:00
2017-07-30 23:19:31 +02:00
# Clear area beneath menu
tput cup 10 0
echo -n ${BG_BLACK}${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"
2018-03-16 13:26:53 +01:00
apt-get install --allow-unauthenticated -y build-essential ntp figlet postfix sasl2-bin
2017-07-30 23:19:31 +02:00
echo -e "\n\e[34m - apt-get installation build-essential ntp figlet \e[0m>> Succesfull"
if [ -f "/usr/bin/motds32" ]
then
2017-07-31 15:09:29 +02:00
echo -e "\n\e[34m - Make file \e[0m>> founded.\e[0m\n"
2017-07-31 18:57:37 +02:00
#make install
#echo -e "\n\e[34m - REMake file done.\e[0m\n"
2017-07-31 15:09:29 +02:00
else
2017-07-30 23:19:31 +02:00
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 /root/.bashrc` == 0 ]
then
echo -e " \e[1;31m code bash missing"
echo "cat /etc/motd" >> /root/.bashrc
echo -e "\e[92m - Code bash \e[0madded.\n"
else
grepmot=`grep '/etc/motd' /root/.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
2017-07-31 15:22:01 +02:00
if test ! -d /etc/motds32; then mkdir -p /etc/motds32; fi
2017-07-30 23:19:31 +02:00
if [ -f "/etc/motds32/Stats32" ]
then
echo -e " -->\e[34m Stats32 \e[92mFOUND\e[0m"
2017-07-31 16:38:24 +02:00
cp Stats32 /etc/motds32/Stats32 -Rf
2017-07-30 23:19:31 +02:00
else
cp Stats32 /etc/motds32/Stats32 -Rf
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 Font figlet \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
2017-07-31 19:14:54 +02:00
echo -e " \e[34m -Cron \e[0m>> already added.\e[0m"
2017-07-30 23:19:31 +02:00
else
echo -e "\e[34m - Cron added.\e[0m"
(crontab -l ; echo "*/5 * * * * /usr/bin/motds32 -g 2>1")| crontab -
fi
## Generate first stats
2017-07-31 19:08:20 +02:00
if test -f /usr/bin/motds32; then /usr/bin/motds32 -g; fi
2017-07-30 23:19:31 +02:00
2017-07-31 19:15:39 +02:00
echo -e "\n\n\e[34m \e[92m 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"
2018-03-16 13:39:32 +01:00
printf "\n \e[1;33m (Press 0 to exit)\e[0m"
printf "\n \e[1;33m (Or any key to go back.)\e[0m"
;;
2017-07-30 23:19:31 +02:00
2) echo -e "\n\e[92m"
if [ `grep -c /etc/motd /root/.bashrc` == 0 ]
then
echo -e " code bash missing"
echo "cat /etc/motd" >> /root/.bashrc
echo -e "\e[92m - Code bash \e[0madded.\n"
else
grepmot=`grep '/etc/motd' /root/.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
2017-07-31 15:22:01 +02:00
# Check if MOTDs32 is already add
if test ! -d /etc/motds32; then mkdir -p /etc/motds32; fi
2017-07-31 18:57:37 +02:00
if [ -f "/usr/bin/motds32" ]
then
echo -e "\n\e[34m - Make file \e[0m>> founded.\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
2017-07-30 23:19:31 +02:00
if [ -f "/etc/motds32/Stats32" ]
then
echo -e " -->\e[34m Stats32 \e[92mFOUND\e[0m"
2017-07-31 16:38:24 +02:00
cp Stats32 /etc/motds32/Stats32 -Rf
2017-07-30 23:19:31 +02:00
else
cp Stats32 /etc/motds32/Stats32 -Rf
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 Font figlet \e[92mOK\e[0m"
fi
# Check if motd ins talled 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
echo -e "\e[34m - Cron added.\e[0m"
(crontab -l ; echo "*/5 * * * * /usr/bin/motds32 -g 2>1")| crontab -
fi
## Generate first stats
2017-07-31 19:14:54 +02:00
if test -f /usr/bin/motds32; then /usr/bin/motds32 -g; fi
2017-07-31 15:25:00 +02:00
2017-07-31 19:15:39 +02:00
echo -e "\n\n\e[34m \e[92m 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"
2017-07-30 23:19:31 +02:00
printf "\n \e[1;33m (Press any key to exit.)\e[0m"
;;
2017-07-30 23:40:46 +02:00
3) echo -e "\n\e[34m Dsinstallation of in progress... \e[0m"
2017-07-30 23:38:05 +02:00
## remove file and directory
2017-07-30 23:40:46 +02:00
make uninstall
rm /etc/motds32/ -Rf
rm /usr/bin/motd -f
rm /var/cache/motds32/ -Rf
2017-07-30 23:38:05 +02:00
## remove cron
2017-07-30 23:40:46 +02:00
if crontab -l | grep -q '/usr/bin/motds32'; then
2017-07-31 15:54:29 +02:00
echo -e " \e[92m Cron localized\n"
2017-07-30 23:40:46 +02:00
crontab -l | grep -v '/usr/bin/motds32 -g 2>1' | crontab -u root -
2017-07-31 15:54:29 +02:00
echo -e " \e[92m Cron removed\n"
2017-07-30 23:40:46 +02:00
else
2017-07-31 15:54:29 +02:00
echo -e " \e[93m Cron not find\n"
2017-07-30 23:40:46 +02:00
fi
2017-07-30 23:38:05 +02:00
2017-07-30 23:40:46 +02:00
if [ `grep -c /etc/motd /root/.bashrc` == 0 ]
then
2017-07-31 15:54:29 +02:00
echo " Code bash not founded"
2017-07-30 23:40:46 +02:00
else
2017-07-31 15:54:29 +02:00
echo " code bash founded"
2017-07-30 23:40:46 +02:00
sed -i '/cat \/etc\/motd/d' /root/.bashrc
echo -e "\e[92m Code .bashrc remove.\e[0m"
grep -n '/etc/motd' /root/.bashrc
fi
2017-07-31 15:22:01 +02:00
2017-07-31 15:54:29 +02:00
echo -e "\n\e[92m Script has been completly removed \e[0m"
printf "\n \e[1;33m (Press any key.)\e[0m"
2017-07-30 23:38:05 +02:00
;;
2017-07-30 23:19:31 +02:00
0) break
;;
*) break
;;
esac
2017-07-31 15:33:37 +02:00
read -n 1
# echo -e "\n\n\e[34m \e[92m 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"
2017-07-31 18:53:47 +02:00
2017-07-30 23:19:31 +02:00
done
# Restore screen
tput rmcup
2017-07-31 15:28:15 +02:00
echo "Installation MOTDs32 terminated."