Update glpi-install.sh

This commit is contained in:
Nícolas Pastorello 2025-01-02 00:52:24 -03:00 committed by GitHub
parent be9765645a
commit 0831f8a21a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#Copyright (c) 2021-2025 community-scripts ORG # Copyright (c) 2021-2025 community-scripts ORG
# Author: Nícolas Pastorello (opastorello) # Author: kristocopani
# License: MIT # License: MIT
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
@ -16,135 +16,72 @@ update_os
msg_info "Installing Dependencies" msg_info "Installing Dependencies"
$STD apt-get install -y \ $STD apt-get install -y \
curl \ curl \
git \
sudo \
mc \ mc \
apache2 \ git \
php \ gpg \
php-{apcu,cli,common,curl,gd,imap,ldap,mysql,xmlrpc,xml,mbstring,bcmath,intl,zip,redis,bz2,soap,cas} \ sudo
libapache2-mod-php \
mariadb-server wget -qO- "https://keyserver.ubuntu.com/pks/lookup?fingerprint=on&op=get&search=0x6125E2A8C77F2818FB7BD15B93C4A3FD7BB9C367" | gpg --dearmour >/usr/share/keyrings/ansible-archive-keyring.gpg
cat <<EOF >/etc/apt/sources.list.d/ansible.list
deb [signed-by=/usr/share/keyrings/ansible-archive-keyring.gpg] http://ppa.launchpad.net/ansible/ansible/ubuntu jammy main
EOF
$STD apt update
$STD apt install -y ansible
msg_ok "Installed Dependencies" msg_ok "Installed Dependencies"
msg_info "Setting up database" msg_info "Setup Semaphore"
DB_NAME=glpi_db RELEASE=$(curl -s https://api.github.com/repos/semaphoreui/semaphore/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
DB_USER=glpi mkdir -p /opt/semaphore
DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13) cd /opt/semaphore
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql mysql wget -q https://github.com/semaphoreui/semaphore/releases/download/v${RELEASE}/semaphore_${RELEASE}_linux_amd64.deb
mysql -u root -e "CREATE DATABASE $DB_NAME;" $STD dpkg -i semaphore_${RELEASE}_linux_amd64.deb
mysql -u root -e "CREATE USER '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS';"
mysql -u root -e "GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'localhost';"
mysql -u root -e "GRANT SELECT ON \`mysql\`.\`time_zone_name\` TO '$DB_USER'@'localhost'; FLUSH PRIVILEGES;"
msg_ok "Set up database"
msg_info "Installing GLPi" SEM_HASH=$(openssl rand -base64 32)
cd /opt SEM_ENCRYPTION=$(openssl rand -base64 32)
RELEASE=$(curl -s https://api.github.com/repos/glpi-project/glpi/releases/latest | grep '"tag_name"' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/') SEM_KEY=$(openssl rand -base64 32)
echo "${RELEASE}" >"/opt/${APP}_version.txt" SEM_PW=$(openssl rand -base64 12)
wget -q "https://github.com/glpi-project/glpi/releases/download/${RELEASE}/glpi-${RELEASE}.tgz" cat <<EOF >/opt/semaphore/config.json
tar -xzvf glpi-${RELEASE}.tgz {
mv glpi /var/www/html/ "bolt": {
"host": "/opt/semaphore/semaphore_db.bolt"
cd /var/www/html/glpi },
php bin/console db:install --db-name=$DB_NAME --db-user=$DB_USER --db-password=$DB_PASS --no-interaction "tmp_path": "/opt/semaphore/tmp",
rm -rf /var/www/html/glpi/install "cookie_hash": "${SEM_HASH}",
msg_ok "Installed GLPi" "cookie_encryption": "${SEM_ENCRYPTION}",
"access_key_encryption": "${SEM_KEY}"
msg_info "Setting Downstream file"
cat <<EOF > /var/www/html/glpi/inc/downstream.php
<?php
define('GLPI_CONFIG_DIR', '/etc/glpi/');
if (file_exists(GLPI_CONFIG_DIR . '/local_define.php')) {
require_once GLPI_CONFIG_DIR . '/local_define.php';
} }
EOF EOF
mv /var/www/html/glpi/config /etc/glpi $STD semaphore user add --admin --login admin --email admin@helper-scripts.com --name Administrator --password ${SEM_PW} --config /opt/semaphore/config.json
mv /var/www/html/glpi/files /var/lib/glpi echo "${SEM_PW}" >~/semaphore.creds
mv /var/lib/glpi/_log /var/log/glpi echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt"
msg_ok "Setup Semaphore"
cat <<EOF > /etc/glpi/local_define.php msg_info "Creating Service"
<?php cat <<EOF >/etc/systemd/system/semaphore.service
define('GLPI_VAR_DIR', '/var/lib/glpi'); [Unit]
define('GLPI_DOC_DIR', GLPI_VAR_DIR); Description=Semaphore UI
define('GLPI_CRON_DIR', GLPI_VAR_DIR . '/_cron'); Documentation=https://docs.semaphoreui.com/
define('GLPI_DUMP_DIR', GLPI_VAR_DIR . '/_dumps'); Wants=network-online.target
define('GLPI_GRAPH_DIR', GLPI_VAR_DIR . '/_graphs'); After=network-online.target
define('GLPI_LOCK_DIR', GLPI_VAR_DIR . '/_lock');
define('GLPI_PICTURE_DIR', GLPI_VAR_DIR . '/_pictures');
define('GLPI_PLUGIN_DOC_DIR', GLPI_VAR_DIR . '/_plugins');
define('GLPI_RSS_DIR', GLPI_VAR_DIR . '/_rss');
define('GLPI_SESSION_DIR', GLPI_VAR_DIR . '/_sessions');
define('GLPI_TMP_DIR', GLPI_VAR_DIR . '/_tmp');
define('GLPI_UPLOAD_DIR', GLPI_VAR_DIR . '/_uploads');
define('GLPI_CACHE_DIR', GLPI_VAR_DIR . '/_cache');
define('GLPI_LOG_DIR', '/var/log/glpi');
EOF
msg_ok "Configured Downstream file"
msg_info "Setting Folder and File Permissions" [Service]
chown root:root /var/www/html/glpi/ -R ExecStart=/usr/bin/semaphore server --config /opt/semaphore/config.json
chown www-data:www-data /etc/glpi -R Restart=always
chown www-data:www-data /var/lib/glpi -R RestartSec=10s
chown www-data:www-data /var/log/glpi -R
chown www-data:www-data /var/www/html/glpi/marketplace -Rf
find /var/www/html/glpi/ -type f -exec chmod 0644 {} \;
find /var/www/html/glpi/ -type d -exec chmod 0755 {} \;
find /etc/glpi -type f -exec chmod 0644 {} \;
find /etc/glpi -type d -exec chmod 0755 {} \;
find /var/lib/glpi -type f -exec chmod 0644 {} \;
find /var/lib/glpi -type d -exec chmod 0755 {} \;
find /var/log/glpi -type f -exec chmod 0644 {} \;
find /var/log/glpi -type d -exec chmod 0755 {} \;
msg_ok "Configured Folder and File Permissions"
msg_info "Setting VirtualHost" [Install]
cat <<EOF >/etc/apache2/sites-available/glpi.conf WantedBy=multi-user.target
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/html/glpi/public
<Directory /var/www/html/glpi/public>
Require all granted
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</Directory>
ErrorLog \${APACHE_LOG_DIR}/glpi_error.log
CustomLog \${APACHE_LOG_DIR}/glpi_access.log combined
</VirtualHost>
EOF EOF
a2dissite 000-default.conf systemctl enable --now -q semaphore.service
a2enmod rewrite msg_ok "Created Service"
a2ensite glpi.conf
systemctl restart apache2
msg_ok "Configured VirtualHost"
msg_info "Setting Cron task"
echo "*/2 * * * * www-data /usr/bin/php /var/www/html/glpi/front/cron.php &>/dev/null" >> /etc/cron.d/glpi
msg_ok "Configured Cron task"
msg_info "Changing parameters in php.ini"
PHP_VERSION=$(ls /etc/php/ | grep -E '^[0-9]+\.[0-9]+$' | head -n 1)
PHP_INI="/etc/php/$PHP_VERSION/apache2/php.ini"
sed -i 's/^upload_max_filesize = .*/upload_max_filesize = 20M/' $PHP_INI
sed -i 's/^post_max_size = .*/post_max_size = 20M/' $PHP_INI
sed -i 's/^max_execution_time = .*/max_execution_time = 60/' $PHP_INI
sed -i 's/^max_input_vars = .*/max_input_vars = 5000/' $PHP_INI
sed -i 's/^memory_limit = .*/memory_limit = 256M/' $PHP_INI
sed -i 's/^;\?\s*session.cookie_httponly\s*=.*/session.cookie_httponly = On/' $PHP_INI
systemctl restart apache2
msg_ok "Changed parameters in php.ini"
motd_ssh motd_ssh
customize customize
msg_info "Cleaning up" msg_info "Cleaning up"
rm -rf /opt/glpi-${RELEASE}.tgz rm -rf semaphore_${RELEASE}_linux_amd64.deb
$STD apt-get -y autoremove $STD apt-get -y autoremove
$STD apt-get -y autoclean $STD apt-get -y autoclean
msg_ok "Cleaned" msg_ok "Cleaned"