Skip to content

Commit

Permalink
Create packagecheck.sh
Browse files Browse the repository at this point in the history
It checks if package is installed
  • Loading branch information
damalis committed Jan 22, 2023
1 parent 03b75ab commit 6a86975
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:]' </dev/urandom | head -c 32) && envsubst '$$RANDOM_VALUE' < ${WEBSERVER_DOC_ROOT}/web.php.template > ${WEBSERVER_DOC_ROOT}/web.php &&
Expand Down
22 changes: 22 additions & 0 deletions packagecheck.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6a86975

Please sign in to comment.