docker-GLPI/web-builder/service/glpi

86 lines
3.4 KiB
Plaintext
Raw Permalink Normal View History

2020-08-03 21:32:39 +02:00
#!/bin/sh
NORMAL=''
RED=''
GREEN=''
2020-08-03 21:32:39 +02:00
msglog() {
case "${1}" in
green)
TEXT_COLOR="${GREEN}"
;;
red)
TEXT_COLOR="${RED}"
;;
normal)
TEXT_COLOR="${NORMAL}"
;;
esac
DATE=$(date '+%Y %b %d %H:%M:%S')
echo ${DATE} ${TEXT_COLOR}${2}${NORMAL}
}
waiting_for_db() {
while ! mysqlshow -h db -uroot -p${MYSQL_ROOT_PASSWORD} 2>&1 | grep "^| ${MYSQL_DATABASE}" > /dev/null 2>&1 ; do
msglog red "Waiting for mysql database initilization..."
sleep 5
done
}
2024-03-28 18:20:48 +01:00
start_apache() {
rm -r /run/*
mkdir -p /run/apache2
2024-03-28 18:20:48 +01:00
msglog green "Starting Apache..."
exec /usr/sbin/httpd -D FOREGROUND
}
2024-03-28 18:20:48 +01:00
/etc/service/php
2020-08-06 18:26:12 +02:00
mkdir -p /var/www/glpi
if [ ! -e "/etc/glpi/config_db.php" ] ; then
waiting_for_db
msglog red "Initialazing ${GLPI_TARBALL}..."
2020-08-03 21:32:39 +02:00
cd /root
cp -r /root/glpi_template/etc/. /etc/glpi/.
cp -r /root/glpi_template/files/. /var/lib/glpi/.
mysql --host=db --user=root --password=${MYSQL_ROOT_PASSWORD} << EOF
use mysql;
GRANT SELECT ON time_zone_name TO '${MYSQL_USER}'@'%';
EOF
2020-08-06 18:26:12 +02:00
cd /var/www/glpi
2024-03-28 18:20:48 +01:00
php82 bin/console db:install --config-dir=${GLPI_CONFIG_DIR} -L fr_FR -H db -d ${MYSQL_DATABASE} -u ${MYSQL_USER} -p ${MYSQL_PASSWORD} -n
rm install/install.php
2020-08-06 18:26:12 +02:00
chown -R apache:apache /var/www/glpi /etc/glpi /var/lib/glpi /var/log/glpi
echo "${GLPI_VERSION}" > /etc/glpi/glpi_actual_version
echo "${FIELDS_VERSION}" > /etc/glpi/fields_actual_version
2024-03-28 18:20:48 +01:00
echo "${DATAINJECTION_VERSION}" > /etc/glpi/datainjection_actual_version
echo "${GLPIINVENTORY_VERSION}" > /etc/glpi/glpiinventory_actual_version
msglog green "Initialazing complete..."
2020-08-03 21:32:39 +02:00
else
msglog green "GLPI is already initialized"
2024-03-28 18:20:48 +01:00
GLPI_ACTUAL_VERSION=$(test -e /etc/glpi/glpi_actual_version && cat /etc/glpi/glpi_actual_version)
FIELDS_ACTUAL_VERSION=$(test -e /etc/glpi/fields_actual_version && cat /etc/glpi/fields_actual_version)
DATAINJECTION_ACTUAL_VERSION=$(test -e /etc/glpi/datainjection_actual_version && cat /etc/glpi/datainjection_actual_version)
GLPIINVENTORY_ACTUAL_VERSION=$(test -e /etc/glpi/glpiinventory_actual_version && cat /etc/glpi/glpiinventory_actual_version)
if [ "${GLPI_ACTUAL_VERSION}" = "${GLPI_VERSION}" -a "${FIELDS_ACTUAL_VERSION}" = "${FIELDS_VERSION}" -a "${DATAINJECTION_ACTUAL_VERSION}" = "${DATAINJECTION_VERSION}" -a "${GLPIINVENTORY_ACTUAL_VERSION}" = "${GLPIINVENTORY_VERSION}" ] ; then
chown -R apache:apache /var/www/glpi /etc/glpi /var/lib/glpi /var/log/glpi
[ -e "/var/www/glpi/install/install.php" ] && rm /var/www/glpi/install/install.php
msglog green "GLPI already up2date"
2024-03-28 18:20:48 +01:00
start_apache
fi
msglog red "Updating GLPI from ${GLPI_ACTUAL_VERSION} to ${GLPI_VERSION}"
waiting_for_db
cd /var/www/glpi
2024-03-28 18:20:48 +01:00
php82 bin/console glpi:maintenance:enable -n
php82 bin/console glpi:plugin:deactivate --all # -n
2020-08-06 18:26:12 +02:00
rm /var/www/glpi/install/install.php
2024-03-28 18:20:48 +01:00
php82 bin/console db:update --config-dir=${GLPI_CONFIG_DIR} -n && \
( echo "${GLPI_VERSION}" > /etc/glpi/glpi_actual_version ; \
echo "${FIELDS_VERSION}" > /etc/glpi/fields_actual_version ; \
2024-03-28 18:20:48 +01:00
echo "${DATAINJECTION_VERSION}" > /etc/glpi/datainjection_actual_version ; \
echo "${GLPIINVENTORY_VERSION}" > /etc/glpi/glpiinventory_actual_version )
php82 bin/console glpi:maintenance:disable -n
2020-08-06 18:26:12 +02:00
chown -R apache:apache /var/www/glpi /etc/glpi /var/lib/glpi /var/log/glpi
2020-08-03 21:32:39 +02:00
fi
2024-03-28 18:20:48 +01:00
start_apache