Last active
September 6, 2019 03:47
-
-
Save ThinGuy/a1967d38898ef4b0e9f3946deca28a17 to your computer and use it in GitHub Desktop.
Remove unused snap revisions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cleanup-snaps() { | |
for SNAP in $(sudo find 2>/dev/null /snap -maxdepth 2 -type l -name current |awk -F/ '{print $3}');do | |
local -a OLD_REVS=($(sudo find 2>/dev/null /snap/${SNAP} -maxdepth 1 ! -name "$(readlink /snap/${SNAP}/current)" ! -name ${SNAP} -type d -exec basename {} \;)) | |
[[ ${#OLD_REVS[@]} -ge 1 ]] && { printf '%s %s\n' ${SNAP} ${OLD_REVS[@]}|\ | |
xargs -rn2 -P1 bash -c 'sudo snap remove $0 --revision=$1|\ | |
sed -r "s/^.*\(|\)//g;s/removed/of snap $0 &/g;s/^.*$/"$(printf "\e[1m&\e[0m")"/g;s/revision/Revision/g"' | |
[[ $? -eq 0 ]] && { printf "\e[1A\e[60G\e[38;2;0;230;0mOK\e[0m\n"; } || { printf "\e[58G\e[38;2;240;0;0mFAILED\e[0m\n";} ; } | |
[[ ${#OLD_REVS[@]} -lt 1 ]] && printf "\e[38;2;150;150;150msnap \"${SNAP}\" only has a single revision\e[60GOK\e[0m\n" || true | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment