1
0
Fork 0
This commit is contained in:
virtubox 2019-01-31 15:34:19 +01:00
commit a06254fcd0
1 changed files with 37 additions and 11 deletions

View File

@ -1,5 +1,17 @@
# FUNCTIONS
if [ "$(id -u)" != "0" ]; then
IS_SUDOERS=$(groups | grep sudo)
if [ -x /usr/bin/sudo ] && [ -n "$IS_SUDOERS" ]; then
NEED_SUDO="/usr/bin/sudo"
else
NEED_SUDO=""
fi
fi
transfer_vtbox_net() {
{ curl --progress-bar --upload-file "$1" https://transfer.vtbox.net/$(basename $1) && echo ""; } | tee -a $HOME/.transfer.log && echo ""
}
@ -18,8 +30,13 @@ update_git_mybashrc() {
}
EE_MYSQL_OPTIMIZATION() {
if [ -f $HOME/.my.cnf ]; then
mysqlcheck -Aos --auto-repair
/usr/bin/mysqlcheck -Aos --auto-repair
elif [ -f /etc/psa/.psa.shadow ]; then
MYSQL_PWD="$(cat /etc/psa/.psa.shadow)" /usr/bin/mysqlcheck -Aos -uadmin --auto-repair
else
echo "$HOME/.my.cnf or /etc/psa/.psa.shadow doesn't exist"
fi
}
@ -82,30 +99,32 @@ MAINTENANCE_APT() {
CRED="${CSI}1;31m"
CGREEN="${CSI}1;32m"
if [ "$(id -u)" = "0" ] || [ -n "$IS_SUDOERS" ]; then
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' APT UPDATE '
echo -e "${CGREEN}#############################################${CEND}"
sudo apt update
$NEED_SUDO apt update
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' APT FULL-UPGRADE '
echo -e "${CGREEN}#############################################${CEND}"
sudo apt full-upgrade -y
$NEED_SUDO apt full-upgrade -y
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' APT-GET AUTOREMOVE '
echo -e "${CGREEN}#############################################${CEND}"
sudo apt-get -y --purge autoremove
$NEED_SUDO apt-get -y --purge autoremove
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' APT AUTOCLEAN '
echo -e "${CGREEN}#############################################${CEND}"
sudo apt-get -y autoclean
sudo apt-get -y clean
$NEED_SUDO apt-get -y autoclean
$NEED_SUDO apt-get -y clean
## clean packages in deinstall state
DEINSTALLED=$(sudo dpkg --get-selections | grep deinstall | cut -f1)
DEINSTALLED=$($NEED_SUDO dpkg --get-selections | grep deinstall | cut -f1)
if [ ! -z "$DEINSTALLED" ]; then
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' CLEAN DEINSTALL PACKAGES '
echo -e "${CGREEN}#############################################${CEND}"
sudo dpkg --get-selections | grep deinstall | cut -f1 | xargs dpkg --purge
$NEED_SUDO dpkg --get-selections | grep deinstall | cut -f1 | xargs dpkg --purge
fi
if [ -x /usr/bin/docker ]; then
echo -e "${CGREEN}#############################################${CEND}"
@ -120,17 +139,20 @@ MAINTENANCE_APT() {
docker volume rm "$list_volumes"
fi
fi
OLD_LOGS=$(sudo find /var/log/ -type f -mtime +30 -iname "*.gz")
OLD_LOGS=$($NEED_SUDO find /var/log/ -type f -mtime +30 -iname "*.gz")
if [ ! -z "$OLD_LOGS" ]; then
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' CLEANUP OLD LOGS '
echo -e "${CGREEN}#############################################${CEND}"
sudo find /var/log/ -type f -mtime +30 -iname "*.gz" -exec rm '{}' \;
$NEED_SUDO find /var/log/ -type f -mtime +30 -iname "*.gz" -exec rm '{}' \;
fi
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' EE-BASHRC UPDATE '
echo -e "${CGREEN}#############################################${CEND}"
update_git_mybashrc
else
echo "you need to be root or sudoers to launch the maintenance"
fi
}
@ -145,7 +167,11 @@ EE_NGINX_COMPILE() {
EE_SHOW_LOG() {
{ [ -x /usr/bin/ccze ] && {
tail -n 500 "$1" | ccze -A
} } || { apt install ccze -y; tail -n 500 "$1" | ccze -A
}
}
@ -170,7 +196,7 @@ EE_SHOW_FPM() {
alias transfer=transfer_vtbox_net
alias cheat=CHEAT_CHECK
alias wp='wp --allow-root'
#alias wp='/usr/bin/wp --allow-root'
alias gpigz=compress_pigz
alias gunpigz=decompress_pigz