Summer time …It’s time to keep my YunoHost server efficient,
I remove old kernels, orphaned packages, and leftover config files. This frees up disk space and helps maintain system stability and performance.
C’est l’été, j’ai profité de faire un bon nettoyage de l’ensemble de mon instance Yunohost. après plus de 12 ans d’usage et reinstalles complètes quelques anciens kernel et anciens parametres d’Apps… cela rend le système plus stable et tout frais.
Voici un script complet après diverses sources sur le net. ( Script passé sur IA)
#!/bin/bash
# === Colors ===
BLUE="\\033[1;34m"
YELLOW="\\033[1;33m"
GREEN="\\033[1;32m"
RED="\\033[1;31m"
RESET="\\033[0m"
echo -e "${BLUE}============================"
echo "YunoHost Summer Cleanup LOGS"
echo "Command yunohost tools basic-space-cleanup"
echo -e "============================${RESET}"
echo -e "${YELLOW}Running yunohost basic-space-cleanup...${RESET}"
yunohost tools basic-space-cleanup
echo -e "${BLUE}============================"
echo "Cleaning old Linux kernels"
echo -e "============================${RESET}"
CURRENT_KERNEL=$(uname -r)
echo -e "${YELLOW}Current kernel: $CURRENT_KERNEL${RESET}"
echo -e "${YELLOW}Removing obsolete kernels...${RESET}"
dpkg --list | grep 'linux-image-[0-9]' | awk '{print $2}' | grep -v "$CURRENT_KERNEL" | xargs sudo apt remove -y
echo -e "${BLUE}============================"
echo "Cleaning orphaned packages"
echo -e "============================${RESET}"
sudo apt autoremove --purge -y
sudo apt autoclean -y
sudo apt clean
echo -e "${BLUE}============================"
echo "Purging packages with residual config"
echo -e "============================${RESET}"
sudo dpkg -l | grep '^rc' | awk '{print $2}' | xargs sudo apt purge -y
echo -e "${BLUE}============================"
echo "Removing obsolete config files"
echo -e "============================${RESET}"
sudo find /etc -name "*.dpkg-old" -delete
sudo find /etc -name "*.dpkg-dist" -delete
sudo find /etc -name "*.ucf-old" -delete
echo -e "${BLUE}============================"
echo "Cleaning unused Node.js modules"
echo -e "============================${RESET}"
echo -e "${YELLOW}⚠️ This will delete ALL node_modules folders in /var/www.${RESET}"
echo -e "${YELLOW}✔️ Safe only if the apps are uninstalled or you're planning to reinstall their dependencies.${RESET}"
read -p "Do you want to proceed with deleting all node_modules? (y/N): " confirm_node
if [[ "$confirm_node" =~ ^[Yy]$ ]]; then
sudo find /var/www -type d -name "node_modules" -exec rm -rf {} +
echo -e "${GREEN}✅ Node.js modules deleted.${RESET}"
else
echo -e "${RED}⏩ Skipped deletion of node_modules.${RESET}"
fi
echo -e "${BLUE}============================"
echo "Disk space check"
echo -e "============================${RESET}"
df -h
echo -e "${GREEN}✅ Cleanup completed successfully.${RESET}"
How to use:
1/ Create the script file on your server:
nano yunohost-cleanup.sh
2/ Paste the code above, save and exit.
crtl O , Enter , crtl X
3/ Make it executable:
chmod +x yunohost-cleanup.sh
4/ Run the cleanup:
sudo ./yunohost-cleanup.sh
NB:
Use with caution:
This will delete all Node.js dependencies (node_modules directories) from every app located in /var/www.
Peertube, Nextcloud plugins, SearxNG, etc.
It is safe only if the apps have been uninstalled, or if you plan to reinstall or rebuild their dependencies.
