Browse Source

add maintenance.sh

master
VirtuBox 11 months ago
parent
commit
e569b6c1a8
Signed by: virtubox GPG Key ID: 22EB296C97BAD476
1 changed files with 68 additions and 0 deletions
  1. +68
    -0
      maintenance.sh

+ 68
- 0
maintenance.sh View File

@@ -0,0 +1,68 @@
#!/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

Loading…
Cancel
Save