MOTDs32/install.sh

446 lines
14 KiB
Bash
Raw Permalink Normal View History

2020-04-04 11:57:16 +02:00
#!/usr/bin/env bash
2017-07-30 23:19:31 +02:00
#
# 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!):
#
2019-12-08 11:50:39 +01:00
# # bash install.sh
2018-03-16 12:12:56 +01:00
#
2017-07-30 23:19:31 +02:00
#
2020-05-18 20:10:19 +02:00
################################################################################
LSB=/usr/bin/lsb_release
## DEBUG
readonly PROGNAME=$(basename $0)
readonly PROGDIR=$(readlink -m $(dirname $0))
readonly PROGDIRSCRIPT="$(readlink -m $(dirname $0))/scripts"
readonly ARGS="$@"
## debug
set -e -u -o pipefail
IFS=$'\n\t'
on_error() { echo "Error on or near line $1; exiting with status $2"; exit "$2"; }
trap 'on_error ${LINENO} $?' ERR
2017-07-30 23:19:31 +02:00
################################################################################
# Make sure only root can run our script
2020-04-04 11:57:16 +02:00
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
2017-07-30 23:19:31 +02:00
2020-05-18 20:10:19 +02:00
crontab -l > $PROGDIR/crontab.backup
2020-04-19 18:32:08 +02:00
pathscript32="$(cd "$(dirname "$0")" && pwd)"
2020-05-18 20:10:19 +02:00
cronmotd="*/5 * * * * /usr/bin/motds32 -g >/dev/null 2>&1"
2020-04-19 18:32:08 +02:00
2017-07-30 23:19:31 +02:00
## clean terminal
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
2020-05-18 20:10:19 +02:00
#while [[ $REPLY != 0 ]]; do
while [[ $ARGS != 0 ]]; do
2017-07-30 23:19:31 +02:00
echo -n ${BG_BLACK}${FG_WHITE}
clear
2020-05-18 10:44:51 +02:00
echo -e "\e[33;3m"
2017-07-30 23:19:31 +02:00
cat <<- "EOFMO"
2020-05-18 10:44:51 +02:00
| + |
2017-07-30 23:19:31 +02:00
2020-05-18 10:44:51 +02:00
EOFMO
echo -e "\e[32m"
cat <<- "EOFMO2"
2017-07-30 23:19:31 +02:00
,--. ,--. ,-----. ,--------.,------. ,----. ,---.
| `.' |' .-. ''--. .--'| .-. \ ,---. '.-. |'.-. \
| |'.'| || | | | | | | | \ :( .-' .' ; .-' .'
| | | |' '-' ' | | | '--' /.-' `)/'-' |/ '-.
`--' `--' `-----' `--' `-------' `----' `----' '-----'
By
2020-05-18 10:44:51 +02:00
EOFMO2
2020-04-16 14:58:37 +02:00
2020-05-18 10:44:51 +02:00
echo -e "\e[90m # MOTDs32 is dynamicaly refreshing the /etc/motd file with current informations"
echo -e "\e[90m # about system status and usage."
2020-05-18 10:51:10 +02:00
echo -e "\n\e[34m Check dependencies... \n"
2017-07-30 23:19:31 +02:00
2020-05-18 10:55:52 +02:00
check_depend(){
2018-03-16 12:12:56 +01:00
# Check installed
2020-05-18 10:55:52 +02:00
if [ -f "/usr/sbin/sendmail" ]
2018-03-16 12:33:01 +01:00
then
2020-05-18 10:51:10 +02:00
echo -e " \e[34m- Posfix \e[32m✔ installed."
2018-03-16 12:33:01 +01:00
else
2020-05-18 10:51:10 +02:00
echo -e " \e[34m- Select option 1 \e[91m Missing package !!"
2020-05-18 10:55:52 +02:00
fi
if [ -f "/usr/share/build-essential/essential-packages-list" ]
2018-03-16 12:33:01 +01:00
then
2020-05-18 10:51:10 +02:00
echo -e " \e[34m- build-dep \e[32m✔ installed."
2018-03-16 12:19:55 +01:00
else
2020-05-18 10:51:10 +02:00
echo -e " \e[34m- build-dep \e[1;31mSelect option 1 \e[91m Missing package !!"
2020-05-18 10:55:52 +02:00
fi
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
2020-05-18 10:51:10 +02:00
echo -e " \e[34m- Figlet \e[32m✔ installed."
2017-07-30 23:19:31 +02:00
else
2020-05-18 10:51:10 +02:00
echo -e " \e[34m- Figlet \e[1;31m Select option 1 \e[91m Missing package !!"
2017-07-30 23:19:31 +02:00
fi
if hash ntpd 2>/dev/null; then
2020-05-18 10:51:10 +02:00
echo -e " \e[34m- NTP \e[32m✔ installed."
2017-07-30 23:19:31 +02:00
else
2020-05-18 10:51:10 +02:00
echo -e " \e[34m- NTP \e[1;31mSelect option 1 \e[91m Missing package !!"
2017-07-30 23:19:31 +02:00
fi
if hash make 2>/dev/null; then
2020-05-18 10:51:10 +02:00
echo -e " \e[34m- build-essential \e[32m✔ installed."
2017-07-30 23:19:31 +02:00
else
2020-05-18 10:51:10 +02:00
echo -e " \e[34m- build-essential \e[1;31mSelect option 1 \e[91m Missing package !!"
2017-07-30 23:19:31 +02:00
fi
2018-03-16 12:19:55 +01:00
2020-05-18 10:55:52 +02:00
}
# Check dependenciess
check_depend || echo -e "\e[34m Check required dependencies ! (need to be installed)"
2020-05-18 20:10:19 +02:00
Check_install_package(){
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
2020-03-30 23:17:18 +02:00
echo -e "\n\e[34m - Make file \e[0m>> found.\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"
2020-03-30 22:46:19 +02:00
if [ `grep -c /etc/motd ~/.bashrc` == 0 ]
2017-07-30 23:19:31 +02:00
then
2020-04-16 14:46:22 +02:00
echo -e " \e[31m code bash missing\e[0m"
2020-03-30 22:46:19 +02:00
echo "cat /etc/motd" >> ~/.bashrc
2020-05-18 20:10:19 +02:00
echo "/etc/motds32/Stats32" >> ~/.bashrc
2017-07-30 23:19:31 +02:00
echo -e "\e[92m - Code bash \e[0madded.\n"
else
2020-03-30 22:46:19 +02:00
grepmot=`grep '/etc/motd' ~/.bashrc`
2020-05-18 20:10:19 +02:00
# echo -e " \e[1;30m Code bash found: \e[0m>>\e[0m $grepmot \e[0m<<\n"
2020-03-30 22:25:26 +02:00
echo -e " -->\e[34m Code bash: \e[92mOK\e[0m"
2017-07-30 23:19:31 +02:00
fi
# Check if MOTDs32 is already add
2020-05-18 20:10:19 +02:00
if test ! -d /etc/motds32; then mkdir -p /etc/motds32; fi
2017-07-31 15:22:01 +02:00
2017-07-30 23:19:31 +02:00
if [ -f "/etc/motds32/Stats32" ]
then
2020-03-30 22:25:26 +02:00
echo -e " -->\e[34m Stats32 \e[92mOK\e[0m"
2020-04-16 14:46:22 +02:00
cp -f Stats32 /etc/motds32/Stats32
2017-07-30 23:19:31 +02:00
else
2020-04-13 14:30:40 +02:00
cp -f Stats32 /etc/motds32/Stats32
2017-07-30 23:19:31 +02:00
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/
2020-03-30 22:38:34 +02:00
echo -e " -->\e[34m figlet&font \e[92mOK\e[0m"
2017-07-30 23:19:31 +02:00
fi
2020-05-18 20:10:19 +02:00
2017-07-30 23:19:31 +02:00
# Check if motd is installed correctly
if [ -f "/usr/bin/motd" ]
then
2020-03-30 22:25:26 +02:00
echo -e " -->\e[34m motd check \e[92mOK\e[0m\n"
2017-07-30 23:19:31 +02:00
else
ln -s /usr/bin/motds32 /usr/bin/motd
2020-03-30 22:25:26 +02:00
echo -e " -->\e[34m motd bin \e[92mOK\e[0m\n"
2017-07-30 23:19:31 +02:00
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
2020-05-18 20:10:19 +02:00
(crontab -l ; echo $cronmotd)| crontab -u root -
# (crontab -l ; echo "*/5 * * * * /usr/bin/motds32 -g >/dev/null 2>&1")| crontab -
2020-05-18 10:23:07 +02:00
echo -e "\e[34m - Cron added.\e[0m"
2017-07-30 23:19:31 +02:00
fi
## Generate first stats
2020-04-19 16:41:54 +02:00
if test -f /usr/bin/motds32; then /usr/bin/motds32 -g; fi
2017-07-30 23:19:31 +02:00
2020-05-18 20:10:19 +02:00
echo -e "\n\n\e[34m \e[92m PACKAGE completed!\e[0m \n\n\n You can install \e[1;33m \n\e[92m Use: \033[1;30m option 2\e[0m \n\e[0m\n"
printf "\n \e[1;33m (Press 0 to exit) Or any key to go back."
}
#Check_install_package
Motds32_install(){
echo -n " Git " ; cd $pathscript32 && git pull ; echo -e "\n\e[92m" ;
grepmot="cat /etc/motd"
2020-04-19 16:41:54 +02:00
# if [ `grep -c "cat /etc/motd" ~/.bashrc` == 0 ]
if [ $(grep -c "cat /etc/motd" ~/.bashrc) == 0 ]
2017-07-30 23:19:31 +02:00
then
2020-04-16 14:49:57 +02:00
echo -e "\e[31m code bash missing\e[0m"
2020-04-19 16:41:54 +02:00
echo $grepmot >> ~/.bashrc
2020-05-18 20:10:19 +02:00
echo "/etc/motds32/Stats32" >> ~/.bashrc
echo -e "\e[92m - Code bash \e[0madded.\n"
2017-07-30 23:19:31 +02:00
else
2020-04-19 16:41:54 +02:00
# sed -i '/cat \/etc\/motd/d' ~/.bashrc
# grepmot=$(grep "/etc/motd" ~/.bashrc)
2020-04-16 14:49:57 +02:00
echo -e " \e[32;1m Code bash found: \e[0m>>\e[0m $grepmot \e[0m<<\n"
2017-07-30 23:19:31 +02:00
echo -e " -->\e[34m Code bash: \e[92mOK\e[0m"
fi
2020-05-18 20:10:19 +02:00
# 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
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
2020-03-30 22:46:19 +02:00
2017-07-31 18:57:37 +02:00
if [ -f "/usr/bin/motds32" ]
then
2020-03-30 23:17:18 +02:00
echo -e "\n\e[34m - Make file \e[0m>> found.\e[0m\n"
2020-05-18 10:23:07 +02:00
#make install -- see update
2017-07-31 18:57:37 +02:00
#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
2020-04-16 14:46:22 +02:00
2017-07-30 23:19:31 +02:00
if [ -f "/etc/motds32/Stats32" ]
then
2020-03-30 22:38:34 +02:00
echo -e " -->\e[34m Stats32 \e[92mOK\e[0m"
2020-04-19 16:41:54 +02:00
cp -f Stats32 /etc/motds32/Stats32
2017-07-30 23:19:31 +02:00
else
2020-04-19 16:41:54 +02:00
cp -f Stats32 /etc/motds32/Stats32
echo -e " -->\e[34m Stats32 \e[92mINSTALLED\e[0m"
2017-07-30 23:19:31 +02:00
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/
2020-03-30 22:38:34 +02:00
echo -e " -->\e[34m figlet&font \e[92mOK\e[0m"
2017-07-30 23:19:31 +02:00
fi
2020-04-19 16:41:54 +02:00
# Check if motd is installed correctly
2017-07-30 23:19:31 +02:00
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"
2020-05-18 20:10:19 +02:00
/usr/bin/motds32 -g
2017-07-30 23:19:31 +02:00
else
2020-05-18 20:10:19 +02:00
(crontab -l ; echo $cronmotd)| crontab -u root -
# (crontab -l ; echo "*/5 * * * * /usr/bin/motds32 -g >/dev/null 2>&1")| crontab -
2017-07-30 23:19:31 +02:00
echo -e "\e[34m - Cron added.\e[0m"
fi
## Generate first stats
2020-04-16 14:46:22 +02:00
# if test -f /usr/bin/motds32; then /usr/bin/motds32 -g; fi
2017-07-31 15:25:00 +02:00
2020-04-19 17:05:01 +02:00
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 completed!\e[0m"
2017-07-30 23:19:31 +02:00
printf "\n \e[1;33m (Press any key to exit.)\e[0m"
2020-05-18 20:10:19 +02:00
}
# Motds32_install
Motds32_update(){
echo -n " Git " ; cd $pathscript32 && git pull ; echo -e "\n\e[92m" ;
if [ $(grep -c "cat /etc/motd" ~/.bashrc) == 0 ]
2020-04-19 18:32:08 +02:00
then
2020-05-18 20:10:19 +02:00
echo -e "\e[31m code bash missing\e[0m"
echo $grepmot >> ~/.bashrc
echo "/etc/motds32/Stats32" >> ~/.bashrc
echo -e "\e[92m - Code bash \e[0madded.\n"
2020-04-19 18:32:08 +02:00
else
2020-05-18 20:10:19 +02:00
# 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"
2020-04-19 18:32:08 +02:00
fi
2020-04-19 16:57:38 +02:00
if [ -f "/usr/bin/motds32" ]
then
echo -e "\n\e[34m - Make file \e[0m>> update.\e[0m\n"
make install > /dev/null
2020-04-19 18:21:08 +02:00
motd -g
2020-04-19 16:57:38 +02:00
echo -e "\n\e[32;1m - Update binary done.\e[0m\n"
2020-04-19 17:00:58 +02:00
echo -e "\n\e[1;33m (Press any key.)\e[0m"
2020-04-19 16:57:38 +02:00
else
2020-04-19 17:00:58 +02:00
echo -e "\e[32;4m - Make install first !\e[0m\n"
echo -e "\n\e[1;33m (Press any key.)\e[0m"
2020-04-19 16:57:38 +02:00
fi
2020-05-18 20:10:19 +02:00
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
2020-04-19 18:32:08 +02:00
# generate new stat
# motd -g
/usr/bin/motds32 -g
2017-07-30 23:38:05 +02:00
2020-05-18 20:10:19 +02:00
}
# Motds32_update
Motds32_remove(){
echo -e "\n\e[34m Unistall of in progress... \e[0m\n"
## remove file and directory
# make uninstall
2017-07-30 23:38:05 +02:00
## remove cron
2020-05-18 20:10:19 +02:00
if crontab -l | grep -q '/usr/bin/motds32'
then
echo -e "\n \e[94m Cron localized\n"
crontab -l | grep -v $cronmotd| crontab -u root -
# crontab -l | grep -v "*/5 * * * * /usr/bin/motds32 -g >/dev/null 2>&1" | crontab -u root -
echo -e " \e[35m Cron removed\n"
2017-07-30 23:40:46 +02:00
else
2020-05-18 20:10:19 +02:00
echo -e "\n \e[35m Cron OK\n"
2017-07-30 23:40:46 +02:00
fi
2017-07-30 23:38:05 +02:00
2020-05-18 20:10:19 +02:00
if [ `grep -c motd ~/.bashrc` == 0 ]
2017-07-30 23:40:46 +02:00
then
2020-05-18 20:10:19 +02:00
echo -e " \e[35m Code bash removed"
2017-07-30 23:40:46 +02:00
else
2020-05-18 20:10:19 +02:00
echo -e " \e[34mCode bash found"
2020-03-30 22:46:19 +02:00
sed -i '/cat \/etc\/motd/d' ~/.bashrc
2020-05-18 20:10:19 +02:00
sed -i '\/etc\/motds32\/Stats32/d' ~/.bashrc
2020-03-30 23:19:17 +02:00
echo -e "\e[92m Code .bashrc removed.\e[0m"
2020-05-18 20:10:19 +02:00
grep -n '/etc/motd' ~/.bashrc
echo -e "\e[0m"
2017-07-30 23:40:46 +02:00
fi
2017-07-31 15:22:01 +02:00
2020-05-18 20:10:19 +02:00
make uninstall >/dev/null
if [ -d "/etc/motds32" ]
then
rm /etc/motds32/ -Rf
fi
if [ -f "/var/cache/motds32" ]
then
rm /usr/bin/motd /var/cache/motds32/ -Rf
fi
if [ -f "/etc/motd.orig" ]
then
mv /etc/motd.orig /etc/motd
fi
echo -e "\n\e[35m Motds32 Files... Removed, all good!"
# if test ! -e /etc/motd.orig; then mv /etc/motd.orig /etc/motd; fi
# if test ! -d /var/cache/motds32; then rm /usr/bin/motd /var/cache/motds32/ -Rf; fi
echo -e "\n\e[92m Script has been completly removed \e[0m"
printf "\n\n \e[1;33m (Press any key.)\e[0m"
}
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"
#check_depend
# Clear area beneath menu
tput cup 10 0
echo -n ${FG_GREEN}
tput ed
tput cup 11 0
case $selection in
1) Check_install_package
;;
2) Motds32_install
;;
3) Motds32_update
#echo -e "\n Installation \e[34mMOTDs32 terminated.\e[0m\n Help? Use: \n \033[1;30m /usr/bin/motds32\n"
;;
4) Motds32_remove
;;
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
2020-05-18 20:10:19 +02:00
echo -e " Installation \e[34mMOTDs32 terminated.\e[0m\n Help? Use: \n \033[1;30m /usr/bin/motds32\n"