From: LuaTenshi Date: Thu, 5 Mar 2015 23:47:33 +0000 (-0500) Subject: Confirm dialogue added, updated cleanup command X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c692f7435e03a7a6576499670f95ad94c59f89de;p=discourse_docker.git Confirm dialogue added, updated cleanup command Added a confirm dialogue to the Cleanup Command, and the ability to show how much space was cleared after running the cleanup command. --- diff --git a/launcher b/launcher index 1786a75..58b0efe 100755 --- a/launcher +++ b/launcher @@ -300,12 +300,28 @@ RUBY } [ $command == "cleanup" ] && { - echo "Starting Cleanup" - docker inspect -f '{{.Id}},{{.State.Running}},{{.State.FinishedAt}}' $(docker ps -qa) | \ - awk -F, 'BEGIN { TIME=strftime("%FT%T.000000000Z",systime()-60*60*24); } $2=="false" && $3 < TIME {print $1;}' | \ - xargs --no-run-if-empty docker rm >/dev/null 2>/dev/null - docker images --no-trunc| grep none | awk '{print $3}' | xargs -r docker rmi - echo "Ending Cleanup" + echo + echo "The following command will" + echo "- Delete all docker images for old containers" + echo "- Delete all stopped and orphan containers" + echo + read -p "Are you sure (Y/n): " -n 1 -r && echo + if [[ $REPLY =~ ^[Yy]$ || ! $REPLY ]] + then + GetSpace=$(du -sk | awk '{print $1}'); + echo "Starting Cleanup" + docker inspect -f '{{.Id}},{{.State.Running}},{{.State.FinishedAt}}' $(docker ps -qa) | \ + awk -F, 'BEGIN { TIME=strftime("%FT%T.000000000Z",systime()-60*60*24); } $2=="false" && $3 < TIME {print $1;}' | \ + xargs --no-run-if-empty docker rm >/dev/null 2>/dev/null + docker images --no-trunc| grep none | awk '{print $3}' | xargs -r docker rmi + let SpaceFreed=$GetSpace-$(du -sk | awk '{print $1}') + Output="$SpaceFreed" | awk '{sum=$1;hum[1024**3]="GB"; hum[1024**2]="MB"; hum[1024]="KB"; for (x=1024**3;x>=1024; x/=1024){ if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x];break }}}' + [ -z "$Output" ] && { + [[ $SpaceFreed > 0 ]] && { echo "./launcher cleanup cleared up $SpaceFreed Bytes of disk space."; } || { echo "./launcher cleanup has finished, no files were removed."; } + } || { echo "./launcher cleanup cleared up $Output of disk space."; } + else + echo "Aborting..." + fi exit 0 }