1
0
Fork 0

add command exist, do not purge docker by default

This commit is contained in:
VirtuBox 2019-09-02 13:43:21 +02:00
parent abeb6ab779
commit 8faa37486a
Signed by: virtubox
GPG Key ID: 22EB296C97BAD476
1 changed files with 28 additions and 22 deletions

View File

@ -13,6 +13,10 @@ if [ "$(id -u)" != "0" ]; then
fi
fi
command_exists() {
command -v "$@" > /dev/null 2>&1
}
transfer_vtbox_net() {
{ curl --progress-bar --upload-file "$1" https://transfer.vtbox.net/$(basename "$1") && echo ""; } | tee -a $HOME/.transfer.log && echo ""
}
@ -123,7 +127,7 @@ _find_duplicates() {
echo "duplicate-find <path> [--force]"
echo "use --force to delete files"
else
if [ -z "$(command -v rdfind)" ]; then
if ! command_exists rdfind; then
apt-get install rdfind -y
fi
if [ "$2" = "--force" ]; then
@ -169,20 +173,22 @@ MAINTENANCE_APT() {
echo -e "${CGREEN}#############################################${CEND}"
$NEED_SUDO dpkg --get-selections | grep deinstall | cut -f1 | xargs dpkg --purge
fi
if [ -x /usr/bin/docker ]; then
list_images=$(docker images --filter "dangling=true" -q --no-trunc)
list_volumes=$(docker volume ls -qf dangling=true)
if [ -n "$list_images" ]; then
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' DOCKER IMAGES CLEANUP '
echo -e "${CGREEN}#############################################${CEND}"
docker rmi "$list_images"
fi
if [ -n "$list_volumes" ]; then
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' DOCKER VOLUMES CLEANUP '
echo -e "${CGREEN}#############################################${CEND}"
docker volume rm "$list_volumes"
if [ "$1" = "--docker" ]; then
if command_exists docker; then
list_images=$(docker images --filter "dangling=true" -q --no-trunc)
list_volumes=$(docker volume ls -qf dangling=true)
if [ -n "$list_images" ]; then
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' DOCKER IMAGES CLEANUP '
echo -e "${CGREEN}#############################################${CEND}"
docker rmi "$list_images"
fi
if [ -n "$list_volumes" ]; then
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' DOCKER VOLUMES CLEANUP '
echo -e "${CGREEN}#############################################${CEND}"
docker volume rm "$list_volumes"
fi
fi
fi
OLD_LOGS=$($NEED_SUDO find /var/log/ -type f -mtime +30 -iname "*.gz")
@ -214,10 +220,10 @@ EE_NGINX_COMPILE() {
EE_SHOW_LOG() {
{ [ -x /usr/bin/ccze ] && {
tail -n 500 "$1" | ccze -A
tail -n 500 "$1" | ccze -A -p syslog -C
}; } || {
apt install ccze -y
tail -n 500 "$1" | ccze -A
tail -n 500 "$1" | ccze -A -p syslog -C
}
}
@ -377,9 +383,9 @@ _PPA_INSTALL() {
shift
done
if [ -n "$PPA" ]; then
for UPPA in $PPA; do
$NEED_SUDO add-apt-repository "$UPPA" -y
done
for UPPA in $PPA; do
$NEED_SUDO add-apt-repository "$UPPA" -y
done
fi
fi
}
@ -431,7 +437,7 @@ _SITESPEED() {
echo "Usage : sitespeed <url>"
else
curl -s -w \
'\nLookup time:\t\t%{time_namelookup}\nConnect time:\t\t%{time_connect}\nSSL handshake time:\t%{time_appconnect}\nPre-Transfer time:\t%{time_pretransfer}\nRedirect time:\t\t%{time_redirect}\nStart transfer time:\t%{time_starttransfer}\n\nTotal time:\t\t%{time_total}\n' -o /dev/null "$@"
'\nLookup time:\t\t%{time_namelookup}\nConnect time:\t\t%{time_connect}\nSSL handshake time:\t%{time_appconnect}\nPre-Transfer time:\t%{time_pretransfer}\nRedirect time:\t\t%{time_redirect}\nStart transfer time:\t%{time_starttransfer}\n\nTotal time:\t\t%{time_total}\n' -o /dev/null "$@"
fi
}
@ -600,4 +606,4 @@ alias apt-bionic-kernel=_APT_BIONIC_KERNEL
alias ufw-minimal=_UFW_MINIMAL
alias ssh-secure=_SSH_SECURE
alias passwdgen=_PWGEN
alias pip='python3 -m pip'
alias pip='python3 -m pip'