bash functions and aliases
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

68 lines
3.1 KiB

#!/usr/bin/env bash
if [ "$(id -u)" != "0" ]; then
IS_SUDOERS=$(groups | grep sudo)
if [ -n "$(command -v sudo)" ] && [ -n "$IS_SUDOERS" ]; then
NEED_SUDO="$(command -v sudo)"
else
NEED_SUDO=""
fi
fi
MAINTENANCE_APT() {
# Colors
# Colors
CSI='\033['
CEND="${CSI}0m"
CGREEN="${CSI}1;32m"
if [ "$(id -u)" = "0" ] || [ -n "$IS_SUDOERS" ]; then
export DEBIAN_FRONTEND=noninteractive
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' APT UPDATE '
echo -e "${CGREEN}#############################################${CEND}"
if ! {
$NEED_SUDO apt-get update --allow-releaseinfo-change
}; then
$NEED_SUDO apt-get update
fi
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' APT FULL-UPGRADE '
echo -e "${CGREEN}#############################################${CEND}"
$NEED_SUDO apt-get --option=Dpkg::options::=--force-confmiss --option=Dpkg::options::=--force-confold --option=Dpkg::options::=--force-unsafe-io -y dist-upgrade
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' APT-GET AUTOREMOVE '
echo -e "${CGREEN}#############################################${CEND}"
$NEED_SUDO apt-get -o Dpkg::Options::="--force-confmiss" -o Dpkg::Options::="--force-confold" -y --purge autoremove
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' APT AUTOCLEAN '
echo -e "${CGREEN}#############################################${CEND}"
$NEED_SUDO apt-get -o Dpkg::Options::="--force-confmiss" -o Dpkg::Options::="--force-confold" -y autoclean
$NEED_SUDO apt-get -y clean
## clean packages in deinstall state
DEINSTALLED=$($NEED_SUDO dpkg --get-selections | grep deinstall | cut -f1)
if [ -n "$DEINSTALLED" ]; then
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' CLEAN DEINSTALLED PACKAGES '
echo -e "${CGREEN}#############################################${CEND}"
$NEED_SUDO dpkg --get-selections | grep deinstall | cut -f1 | xargs dpkg --purge
fi
OLD_LOGS=$($NEED_SUDO find /var/log/ -type f -mtime +30 -iname "*.gz")
if [ -n "$OLD_LOGS" ]; then
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' CLEANUP OLD LOGS '
echo -e "${CGREEN}#############################################${CEND}"
$NEED_SUDO find /var/log/ -type f -mtime +30 -iname "*.gz" -exec rm '{}' \;
fi
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' EE-BASHRC UPDATE '
echo -e "${CGREEN}#############################################${CEND}"
update_git_mybashrc
else
echo "you need to be root or sudoers to launch the maintenance"
fi
}
MAINTENANCE_APT