Skip to content

Instantly share code, notes, and snippets.

@jazz-it
Last active July 9, 2026 19:02
Show Gist options
  • Select an option

  • Save jazz-it/a32fd882491515a776c252a5bb096438 to your computer and use it in GitHub Desktop.

Select an option

Save jazz-it/a32fd882491515a776c252a5bb096438 to your computer and use it in GitHub Desktop.
LMDE Regular Maintenance Script (Croatian)
#!/usr/bin/env bash
set -euo pipefail
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
BLUE="\e[34m"
NC="\e[0m"
info() { echo -e "${BLUE}⧗ $1${NC}"; }
success() { echo -e "${GREEN}✔ $1${NC}"; }
warn() { echo -e "${YELLOW}⚠ $1${NC}"; }
error() { echo -e "${RED}✖ $1${NC}" 1>&2; }
require_root() {
if [[ ${EUID} -ne 0 ]]; then
error "Skripta mora biti pokrenuta s root ovlastima (sudo)."
exit 1
fi
}
check_lmde() {
if [[ -r /etc/os-release ]]; then
# shellcheck disable=SC1091
. /etc/os-release
if [[ "${ID:-}" != "linuxmint" ]] || [[ "${VARIANT_ID:-}" != "lmde" ]]; then
error "Ova skripta je namijenjena isključivo za LMDE (Debian-based)."
exit 1
fi
else
error "/etc/os-release nije dostupan. Ne mogu potvrditi LMDE."
exit 1
fi
}
measure_free_space() {
df --block-size=1 / | awk 'NR==2{print $4}'
}
print_space_delta() {
local initial_free final_free space_freed human_space
initial_free="$1"
final_free="$2"
space_freed=$(( final_free - initial_free ))
if (( space_freed > 0 )); then
human_space=$(numfmt --to=iec --format="%.1f" -- "${space_freed}")
info "Oslobođeno je: ${human_space} prostora na sistemskoj particiji."
elif (( space_freed == 0 )); then
info "Nema promjene zauzeća na sistemskoj particiji."
else
human_space=$(numfmt --to=iec --format="%.1f" -- "$(( -space_freed ))")
info "Zauzeto je dodatnih: ${human_space} prostora na sistemskoj particiji."
fi
}
apt_update_upgrade() {
info "Ažuriram APT pakete (update & upgrade)..."
apt-get update
apt-get -y upgrade
success "APT update & upgrade dovršeni."
}
apt_autoremove_clean() {
info "Uklanjam nepotrebne pakete (autoremove) i čistim APT cache..."
apt-get -y autoremove --purge
apt-get -y autoclean
apt-get -y clean
success "APT autoremove/autoclean/clean dovršeni."
}
kernel_cleanup() {
info "Čišćenje starih Debian kernel paketa..."
local running_kernel running_image keep_pattern
running_kernel="$(uname -r)"
running_image="linux-image-${running_kernel}"
# Zadrži trenutno pokrenuti kernel paket
keep_pattern="^${running_image}$"
mapfile -t kernels < <(dpkg-query -W -f='${Package}\n' 'linux-image-[0-9]*' 2>/dev/null || true)
if (( ${#kernels[@]} == 0 )); then
info "Nema instaliranih linux-image paketa za čišćenje."
return 0
fi
local to_remove=()
for pkg in "${kernels[@]}"; do
if [[ "${pkg}" =~ ${keep_pattern} ]]; then
continue
fi
to_remove+=("${pkg}")
done
if (( ${#to_remove[@]} == 0 )); then
info "Nema starih kernel paketa za uklanjanje."
return 0
fi
warn "Uklanjam sljedeće stare kernel pakete:"
printf ' %s\n' "${to_remove[@]}"
apt-get -y purge "${to_remove[@]}"
success "Stari kernel paketi uklonjeni."
}
journal_cleanup() {
if ! command -v journalctl >/dev/null 2>&1; then
info "systemd journal nije dostupan (journalctl). Preskačem."
return 0
fi
info "Čišćenje systemd journala (zadržavam zadnjih 30 dana)..."
journalctl --vacuum-time=30d
success "Systemd journal očišćen."
}
thumbnail_cleanup() {
info "Čišćenje thumbnail cache-a za sve korisnike..."
find /home -maxdepth 2 -type d -name ".cache" 2>/dev/null | while read -r cache_dir; do
thumb_dir="${cache_dir}/thumbnails"
if [[ -d "${thumb_dir}" ]]; then
rm -rf -- "${thumb_dir:?}/"*
success "Očišćen thumbnail cache: ${thumb_dir}"
fi
done
}
flatpak_cleanup() {
if ! command -v flatpak >/dev/null 2>&1; then
info "Flatpak nije instaliran. Preskačem Flatpak čišćenje."
return 0
fi
info "Čišćenje Flatpak cache-a..."
flatpak uninstall --unused -y || warn "Flatpak uninstall --unused nije uspio."
flatpak repair -y || warn "Flatpak repair nije uspio."
success "Flatpak čišćenje dovršeno (gdje je bilo moguće)."
}
dns_cache_flush() {
if command -v resolvectl >/dev/null 2>&1; then
info "Flushing DNS cache (resolvectl)..."
resolvectl flush-caches || warn "resolvectl flush-caches nije uspio."
success "DNS cache flush dovršen (resolvectl)."
elif command -v systemd-resolve >/dev/null 2>&1; then
info "Flushing DNS cache (systemd-resolve)..."
systemd-resolve --flush-caches || warn "systemd-resolve --flush-caches nije uspio."
success "DNS cache flush dovršen (systemd-resolve)."
else
info "Nema dostupnog alata za DNS cache flush (resolvectl/systemd-resolve). Preskačem."
fi
}
print_fs_summary() {
info "Sažetak zauzeća sistemske particije (/):"
local dash
dash=$(printf '─%.0s' {1..23})
df -h / | awk -v dashes="${dash}" 'NR==2 {
gsub(/%/, "", $5);
used=$3; avail=$4; total=$2; p_used=$5; p_avail=100 - p_used;
printf "%-12s %5s %4s\n", "Iskorišteno:", used, p_used"%";
printf "%-12s %5s %4s\n", "Slobodno:", avail, p_avail"%";
printf "%s\n", dashes;
printf "%-12s %5s %4s\n", "Ukupno:", total, "100%";
}'
}
main() {
require_root
check_lmde
info "Pokrećem LMDE maintenance skriptu..."
local initial_free final_free
initial_free="$(measure_free_space)"
apt_update_upgrade
apt_autoremove_clean
kernel_cleanup
journal_cleanup
thumbnail_cleanup
flatpak_cleanup
dns_cache_flush
final_free="$(measure_free_space)"
print_space_delta "${initial_free}" "${final_free}"
print_fs_summary
success "LMDE održavanje dovršeno."
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment