change is_this_installed() (#902)

This commit is contained in:
Daniel Hansson 2019-07-29 15:08:46 +02:00 committed by GitHub
parent cf5c831048
commit 4a2a7171fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 34 deletions

22
lib.sh
View File

@ -103,7 +103,6 @@ APACHE2=/etc/apache2/apache2.conf
# Full text Search
[ -n "$ES_INSTALL" ] && INDEX_USER=$(tr -dc '[:lower:]' < /dev/urandom | fold -w "$SHUF" | head -n 1)
[ -n "$ES_INSTALL" ] && ROREST=$(tr -dc "A-Za-z0-9" < /dev/urandom | fold -w "$SHUF" | head -n 1)
[ -n "$ES_INSTALL" ] && DOCKER_INS=$(dpkg -l | grep ^ii | awk '{print $2}' | grep docker)
[ -n "$ES_INSTALL" ] && nc_fts="ark74/nc_fts"
[ -n "$ES_INSTALL" ] && fts_es_name="fts_esror"
# Talk
@ -483,7 +482,7 @@ fi
restart_webserver() {
check_command systemctl restart apache2
if dpkg -l | grep "php$PHPVER-fpm" > /dev/null
if is_this_installed php"$PHPVER"-fpm
then
check_command systemctl restart php"$PHPVER"-fpm.service
fi
@ -567,15 +566,28 @@ msg_box "Ubuntu version $DISTRO must be between 18.04 - 18.04.4"
fi
}
# Check if program is installed (is_this_installed apache2)
is_this_installed() {
# Check if program is installed (stop_if_installed apache2)
stop_if_installed() {
if [ "$(dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep -c "ok installed")" == "1" ]
then
print_text_in_color "$Red" "${1} is installed, it must be a clean server."
print_text_in_color "$IRed" "${1} is installed, it must be a clean server."
exit 1
fi
}
# Check if program is installed (is_this_installed apache2)
is_this_installed() {
print_text_in_color "$ICyan" "Checking if ${1} is installed..."
if dpkg-query -W -f='${Status}' "${1}" | grep -q "ok installed"
then
print_text_in_color "$IGreen" "${1} is installed."
return 0
else
print_text_in_color "$IRed" "${1} is not installed."
return 1
fi
}
# Install_if_not program
install_if_not() {
if ! dpkg-query -W -f='${Status}' "${1}" | grep -q "ok installed"

View File

@ -232,7 +232,7 @@ debug_mode
lowest_compatible_nc 16
# Check that this run on the PostgreSQL VM
if ! which psql > /dev/null
if ! is_this_installed psql
then
print_text_in_color "$Red" "This script is intended to be run on then PostgreSQL VM but PostgreSQL is not installed."
print_text_in_color "$Red" "Aborting..."

View File

@ -107,15 +107,16 @@ msg_box "Nextcloud repo is not available, exiting..."
fi
# Check if it's a clean server
is_this_installed postgresql
is_this_installed apache2
is_this_installed php
is_this_installed php-fpm
is_this_installed php"$PHPVER"-fpm
is_this_installed php7.1-fpm
is_this_installed php7.0-fpm
is_this_installed mysql-common
is_this_installed mariadb-server
stop_if_installed postgresql
stop_if_installed apache2
stop_if_installed php
stop_if_installed php-fpm
stop_if_installed php"$PHPVER"-fpm
stop_if_installed php7.0-fpm
stop_if_installed php7.1-fpm
stop_if_installed php7.3-fpm
stop_if_installed mysql-common
stop_if_installed mariadb-server
# Create $SCRIPTS dir
if [ ! -d "$SCRIPTS" ]

View File

@ -37,7 +37,7 @@ https://shop.hanssonit.se/product/premium-support-per-30-minutes/"
fi
# System Upgrade
if which mysql > /dev/null
if is_this_installed mysql
then
apt-mark hold mariadb*
fi
@ -59,7 +59,7 @@ fi
apt update -q4 & spinner_loading
export DEBIAN_FRONTEND=noninteractive ; apt dist-upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
if which mysql > /dev/null
if is_this_installed mysql
then
apt-mark unhold mariadb*
echo
@ -84,15 +84,18 @@ print_text_in_color "$ICyan" "Trying to upgrade the Redis PECL extension..."
if version 18.04 "$DISTRO" 18.04.10; then
if ! pecl list | grep redis >/dev/null 2>&1
then
if dpkg -l | grep php"$PHPVER" > /dev/null 2>&1
if is_this_installed php"$PHPVER"-common
then
install_if_not php"$PHPVER"-dev
elif dpkg -l | grep php7.3 > /dev/null 2>&1
then
install_if_not php7.3-dev
elif dpkg -l | grep php7.0 > /dev/null 2>&1
elif is_this_installed php7.0-common
then
install_if_not php7.0-dev
elif is_this_installed php7.1-common
then
install_if_not php7.1-dev
elif is_this_installed php7.3-common
then
install_if_not php7.3-dev
fi
apt purge php-redis -y
apt autoremove -y
@ -116,15 +119,18 @@ if version 18.04 "$DISTRO" 18.04.10; then
restart_webserver
elif pecl list | grep redis >/dev/null 2>&1
then
if dpkg -l | grep php"$PHPVER" > /dev/null 2>&1
if is_this_installed php"$PHPVER"-common
then
install_if_not php"$PHPVER"-dev
elif dpkg -l | grep php7.3 > /dev/null 2>&1
then
install_if_not php7.3-dev
elif dpkg -l | grep php7.0 > /dev/null 2>&1
elif is_this_installed php7.0-common
then
install_if_not php7.0-dev
elif is_this_installed php7.1-common
then
install_if_not php7.1-dev
elif is_this_installed php7.3-common
then
install_if_not php7.3-dev
fi
pecl channel-update pecl.php.net
yes no | pecl upgrade redis
@ -207,7 +213,7 @@ update-grub
rm /var/lib/apt/lists/* -r
# Free some space (ZFS snapshots)
if dpkg -l | grep -q libzfs2linux
if is_this_installed libzfs2linux
then
if grep -rq ncdata /etc/mtab
then
@ -324,7 +330,7 @@ then
fi
# Backup PostgreSQL
if which psql > /dev/null
if is_this_installed psql
then
cd /tmp
if sudo -u postgres psql -c "SELECT 1 AS result FROM pg_database WHERE datname='$NCCONFIGDB'" | grep "1 row" > /dev/null
@ -379,7 +385,7 @@ fi
}
# Do the actual backup
if which mysql > /dev/null
if is_this_installed mysql
then
mariadb_backup
fi
@ -396,7 +402,7 @@ then
fi
# Do a backup of the ZFS mount
if dpkg -l | grep -q libzfs2linux
if is_this_installed libzfs2linux
then
if grep -rq ncdata /etc/mtab
then
@ -475,7 +481,7 @@ if [ "$(docker ps -a >/dev/null 2>&1 && echo yes || echo no)" == "yes" ]
then
if docker ps -a --format '{{.Names}}' | grep -Eq "bitwarden";
then
if [ "$(dpkg-query -W -f='${Status}' "apache2" 2>/dev/null | grep -c "ok installed")" == "1" ]
if is_this_installed apache2
then
if [ -d /root/bwdata ]
then

View File

@ -181,7 +181,7 @@ fi
format
# Do a backup of the ZFS mount
if dpkg -l | grep libzfs2linux
if is_this_installed libzfs2linux
then
if grep -r $LABEL_ /etc/mtab
then

View File

@ -153,7 +153,7 @@ fi
format
# Do a backup of the ZFS mount
if dpkg -l | grep libzfs2linux
if is_this_installed libzfs2linux
then
if grep -r $LABEL_ /etc/mtab
then