Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New tool: xpurge #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions xpurge
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

SIZE=0
FILES=()
CACHE=/var/cache/xbps
TMPFILE=$(mktemp)

xbps-query -l | awk '{ print $2 }' > ${TMPFILE}

for file in $(ls ${CACHE} | grep -v "\.sig$"); do
name=$(echo "$file"|sed -e "s;\.noarch\.xbps.*;;" -e"s;\.x86_64\.xbps.*;;")
if [ ! $(grep ${name} ${TMPFILE}) ]; then
file_size_kb=`du -k "$CACHE/$file" | cut -f1`
echo "${CACHE}/${file} - $file_size_kb Kb"
FILES+=("${CACHE}/${file}")
SIZE=$((SIZE+$file_size_kb))
fi
done

if [[ ${#FILES[@]} -gt 0 ]]; then
echo
echo " Total size: $SIZE Kb"
echo

read -p "Do you want to delete old these files? (y/n) " answer
if [[ $answer == [Yy]* ]]; then
for i in "${FILES[@]}"; do rm -vf ${i}*; done
fi
fi

rm -f $TMPFILE