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.

69 lines
3.1 KiB

  1. #!/usr/bin/env bash
  2. if [ "$(id -u)" != "0" ]; then
  3. IS_SUDOERS=$(groups | grep sudo)
  4. if [ -n "$(command -v sudo)" ] && [ -n "$IS_SUDOERS" ]; then
  5. NEED_SUDO="$(command -v sudo)"
  6. else
  7. NEED_SUDO=""
  8. fi
  9. fi
  10. MAINTENANCE_APT() {
  11. # Colors
  12. # Colors
  13. CSI='\033['
  14. CEND="${CSI}0m"
  15. CGREEN="${CSI}1;32m"
  16. if [ "$(id -u)" = "0" ] || [ -n "$IS_SUDOERS" ]; then
  17. export DEBIAN_FRONTEND=noninteractive
  18. echo -e "${CGREEN}#############################################${CEND}"
  19. echo -e ' APT UPDATE '
  20. echo -e "${CGREEN}#############################################${CEND}"
  21. if ! {
  22. $NEED_SUDO apt-get update --allow-releaseinfo-change
  23. }; then
  24. $NEED_SUDO apt-get update
  25. fi
  26. echo -e "${CGREEN}#############################################${CEND}"
  27. echo -e ' APT FULL-UPGRADE '
  28. echo -e "${CGREEN}#############################################${CEND}"
  29. $NEED_SUDO apt-get --option=Dpkg::options::=--force-confmiss --option=Dpkg::options::=--force-confold --option=Dpkg::options::=--force-unsafe-io -y dist-upgrade
  30. echo -e "${CGREEN}#############################################${CEND}"
  31. echo -e ' APT-GET AUTOREMOVE '
  32. echo -e "${CGREEN}#############################################${CEND}"
  33. $NEED_SUDO apt-get -o Dpkg::Options::="--force-confmiss" -o Dpkg::Options::="--force-confold" -y --purge autoremove
  34. echo -e "${CGREEN}#############################################${CEND}"
  35. echo -e ' APT AUTOCLEAN '
  36. echo -e "${CGREEN}#############################################${CEND}"
  37. $NEED_SUDO apt-get -o Dpkg::Options::="--force-confmiss" -o Dpkg::Options::="--force-confold" -y autoclean
  38. $NEED_SUDO apt-get -y clean
  39. ## clean packages in deinstall state
  40. DEINSTALLED=$($NEED_SUDO dpkg --get-selections | grep deinstall | cut -f1)
  41. if [ -n "$DEINSTALLED" ]; then
  42. echo -e "${CGREEN}#############################################${CEND}"
  43. echo -e ' CLEAN DEINSTALLED PACKAGES '
  44. echo -e "${CGREEN}#############################################${CEND}"
  45. $NEED_SUDO dpkg --get-selections | grep deinstall | cut -f1 | xargs dpkg --purge
  46. fi
  47. OLD_LOGS=$($NEED_SUDO find /var/log/ -type f -mtime +30 -iname "*.gz")
  48. if [ -n "$OLD_LOGS" ]; then
  49. echo -e "${CGREEN}#############################################${CEND}"
  50. echo -e ' CLEANUP OLD LOGS '
  51. echo -e "${CGREEN}#############################################${CEND}"
  52. $NEED_SUDO find /var/log/ -type f -mtime +30 -iname "*.gz" -exec rm '{}' \;
  53. fi
  54. echo -e "${CGREEN}#############################################${CEND}"
  55. echo -e ' EE-BASHRC UPDATE '
  56. echo -e "${CGREEN}#############################################${CEND}"
  57. update_git_mybashrc
  58. else
  59. echo "you need to be root or sudoers to launch the maintenance"
  60. fi
  61. }
  62. MAINTENANCE_APT