From 6a86975f56f3b0caaab5ae6882ec7e6905883032 Mon Sep 17 00:00:00 2001 From: Erdal ALTIN Date: Sun, 22 Jan 2023 17:32:58 +0300 Subject: [PATCH] Create packagecheck.sh It checks if package is installed --- docker-compose.yml | 5 ++++- packagecheck.sh | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 packagecheck.sh diff --git a/docker-compose.yml b/docker-compose.yml index c7210a4..a50902b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,9 @@ services: - type: bind source: ./php-fpm/php-fpm.d/z-www.conf target: '${PHP_INI_DIR_PREFIX}/php-fpm.d/z-www.conf' + - type: bind + source: ./packagecheck.sh + target: '/tmp/packagecheck.sh' hostname: yii restart: unless-stopped ports: @@ -39,7 +42,7 @@ services: labels: - 'docker-volume-backup.stop-during-backup=true' command: > - bash -c "apt-get -y update && apt-get install -y zip unzip libicu-dev gettext-base && docker-php-ext-install intl && if pecl install -p -- redis; then pecl install -o -f redis && rm -rf /tmp/pear && docker-php-ext-enable redis; fi; curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer && + bash -c "apt-get -y update && sh /tmp/packagecheck.sh 'zip unzip gettext-base' && curl -sSL https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions -o - | sh -s intl && if pecl install -p -- redis; then pecl install -o -f redis && rm -rf /tmp/pear && docker-php-ext-enable redis; fi; curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer && if [ -f \"${WEBSERVER_DOC_ROOT}/web.php\" ]; then composer update --prefer-dist yiisoft/yii2-app-basic --working-dir=/app/basic; else composer create-project --prefer-dist yiisoft/yii2-app-basic basic; fi && composer require --prefer-dist "yiisoft/yii2-redis":~2.0.0 --working-dir=/app/basic; cp -R /app/basic/web/css ${WEBSERVER_DOC_ROOT}/; envsubst '$${DB_USER},$${DB_PASSWORD},$${DB_NAME}' < ${WEBSERVER_DOC_ROOT}/db.php.template > ${WEBSERVER_DOC_ROOT}/db.php && export RANDOM_VALUE=$(tr -dc '[:alnum:]' ${WEBSERVER_DOC_ROOT}/web.php && diff --git a/packagecheck.sh b/packagecheck.sh new file mode 100644 index 0000000..ac48cb2 --- /dev/null +++ b/packagecheck.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +PACKAGES=$1 + +notinstall_pkgs="" +install=false + +for pkg in $PACKAGES; do + status="$(dpkg-query -W --showformat='${db:Status-Status}' "$pkg" 2>&1)" + if [ ! $? = 0 ] || [ ! "$status" = installed ]; then + install=true + notinstall_pkgs=$pkg" "$notinstall_pkgs + else + installed_pkgs=$pkg" "$installed_pkgs + fi +done + +if "$install"; then + apt-get install -y --no-install-recommends $notinstall_pkgs && rm -rf /var/lib/apt/lists/* +else + echo "### WARNING ${installed_pkgs} Package[s] already installed. ###" +fi