|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2025 community-scripts ORG |
| 4 | +# Author: Nícolas Pastorello (opastorello) |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 6 | + |
| 7 | +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" |
| 8 | +color |
| 9 | +verb_ip6 |
| 10 | +catch_errors |
| 11 | +setting_up_container |
| 12 | +network_check |
| 13 | +update_os |
| 14 | + |
| 15 | +msg_info "Installing Dependencies" |
| 16 | +$STD apt-get install -y \ |
| 17 | + curl \ |
| 18 | + git \ |
| 19 | + sudo \ |
| 20 | + mc \ |
| 21 | + apache2 \ |
| 22 | + php8.2-{apcu,cli,common,curl,gd,imap,ldap,mysql,xmlrpc,xml,mbstring,bcmath,intl,zip,redis,bz2,soap} \ |
| 23 | + php-cas \ |
| 24 | + libapache2-mod-php \ |
| 25 | + mariadb-server |
| 26 | +msg_ok "Installed Dependencies" |
| 27 | + |
| 28 | +msg_info "Setting up database" |
| 29 | +DB_NAME=glpi_db |
| 30 | +DB_USER=glpi |
| 31 | +DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13) |
| 32 | +mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql mysql |
| 33 | +mysql -u root -e "CREATE DATABASE $DB_NAME;" |
| 34 | +mysql -u root -e "CREATE USER '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS';" |
| 35 | +mysql -u root -e "GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'localhost';" |
| 36 | +mysql -u root -e "GRANT SELECT ON \`mysql\`.\`time_zone_name\` TO '$DB_USER'@'localhost'; FLUSH PRIVILEGES;" |
| 37 | +{ |
| 38 | + echo "GLPI Database Credentials" |
| 39 | + echo "Database: $DB_NAME" |
| 40 | + echo "Username: $DB_USER" |
| 41 | + echo "Password: $DB_PASS" |
| 42 | +} >> ~/glpi_db.creds |
| 43 | +msg_ok "Set up database" |
| 44 | + |
| 45 | +msg_info "Installing GLPi" |
| 46 | +cd /opt |
| 47 | +RELEASE=$(curl -s https://api.github.com/repos/glpi-project/glpi/releases/latest | grep '"tag_name"' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/') |
| 48 | +wget -q "https://github.com/glpi-project/glpi/releases/download/${RELEASE}/glpi-${RELEASE}.tgz" |
| 49 | +tar -xzvf glpi-${RELEASE}.tgz |
| 50 | +cd /opt/glpi |
| 51 | +$STD php bin/console db:install --db-name=$DB_NAME --db-user=$DB_USER --db-password=$DB_PASS --no-interaction |
| 52 | +echo "${RELEASE}" >"/opt/${APP}_version.txt" |
| 53 | +msg_ok "Installed GLPi" |
| 54 | + |
| 55 | +msg_info "Setting Downstream file" |
| 56 | +cat <<EOF > /opt/glpi/inc/downstream.php |
| 57 | +<?php |
| 58 | +define('GLPI_CONFIG_DIR', '/etc/glpi/'); |
| 59 | +if (file_exists(GLPI_CONFIG_DIR . '/local_define.php')) { |
| 60 | + require_once GLPI_CONFIG_DIR . '/local_define.php'; |
| 61 | +} |
| 62 | +EOF |
| 63 | + |
| 64 | +mv /opt/glpi/config /etc/glpi |
| 65 | +mv /opt/glpi/files /var/lib/glpi |
| 66 | +mv /var/lib/glpi/_log /var/log/glpi |
| 67 | + |
| 68 | +cat <<EOF > /etc/glpi/local_define.php |
| 69 | +<?php |
| 70 | +define('GLPI_VAR_DIR', '/var/lib/glpi'); |
| 71 | +define('GLPI_DOC_DIR', GLPI_VAR_DIR); |
| 72 | +define('GLPI_CRON_DIR', GLPI_VAR_DIR . '/_cron'); |
| 73 | +define('GLPI_DUMP_DIR', GLPI_VAR_DIR . '/_dumps'); |
| 74 | +define('GLPI_GRAPH_DIR', GLPI_VAR_DIR . '/_graphs'); |
| 75 | +define('GLPI_LOCK_DIR', GLPI_VAR_DIR . '/_lock'); |
| 76 | +define('GLPI_PICTURE_DIR', GLPI_VAR_DIR . '/_pictures'); |
| 77 | +define('GLPI_PLUGIN_DOC_DIR', GLPI_VAR_DIR . '/_plugins'); |
| 78 | +define('GLPI_RSS_DIR', GLPI_VAR_DIR . '/_rss'); |
| 79 | +define('GLPI_SESSION_DIR', GLPI_VAR_DIR . '/_sessions'); |
| 80 | +define('GLPI_TMP_DIR', GLPI_VAR_DIR . '/_tmp'); |
| 81 | +define('GLPI_UPLOAD_DIR', GLPI_VAR_DIR . '/_uploads'); |
| 82 | +define('GLPI_CACHE_DIR', GLPI_VAR_DIR . '/_cache'); |
| 83 | +define('GLPI_LOG_DIR', '/var/log/glpi'); |
| 84 | +EOF |
| 85 | +msg_ok "Configured Downstream file" |
| 86 | + |
| 87 | +msg_info "Setting Folder and File Permissions" |
| 88 | +chown root:root /opt/glpi/ -R |
| 89 | +chown www-data:www-data /etc/glpi -R |
| 90 | +chown www-data:www-data /var/lib/glpi -R |
| 91 | +chown www-data:www-data /var/log/glpi -R |
| 92 | +chown www-data:www-data /opt/glpi/marketplace -Rf |
| 93 | +find /opt/glpi/ -type f -exec chmod 0644 {} \; |
| 94 | +find /opt/glpi/ -type d -exec chmod 0755 {} \; |
| 95 | +find /etc/glpi -type f -exec chmod 0644 {} \; |
| 96 | +find /etc/glpi -type d -exec chmod 0755 {} \; |
| 97 | +find /var/lib/glpi -type f -exec chmod 0644 {} \; |
| 98 | +find /var/lib/glpi -type d -exec chmod 0755 {} \; |
| 99 | +find /var/log/glpi -type f -exec chmod 0644 {} \; |
| 100 | +find /var/log/glpi -type d -exec chmod 0755 {} \; |
| 101 | +msg_ok "Configured Folder and File Permissions" |
| 102 | + |
| 103 | +msg_info "Setup Service" |
| 104 | +cat <<EOF >/etc/apache2/sites-available/glpi.conf |
| 105 | +<VirtualHost *:80> |
| 106 | + ServerName localhost |
| 107 | + DocumentRoot /opt/glpi/public |
| 108 | +
|
| 109 | + <Directory /opt/glpi/public> |
| 110 | + Require all granted |
| 111 | + RewriteEngine On |
| 112 | + RewriteCond %{HTTP:Authorization} ^(.+)$ |
| 113 | + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] |
| 114 | + RewriteCond %{REQUEST_FILENAME} !-f |
| 115 | + RewriteRule ^(.*)$ index.php [QSA,L] |
| 116 | + </Directory> |
| 117 | +
|
| 118 | + ErrorLog \${APACHE_LOG_DIR}/glpi_error.log |
| 119 | + CustomLog \${APACHE_LOG_DIR}/glpi_access.log combined |
| 120 | +</VirtualHost> |
| 121 | +EOF |
| 122 | +$STD a2dissite 000-default.conf |
| 123 | +$STD a2enmod rewrite |
| 124 | +$STD a2ensite glpi.conf |
| 125 | +msg_ok "Setup Service" |
| 126 | + |
| 127 | +msg_info "Setup Cronjob" |
| 128 | +(crontab -l 2>/dev/null; echo "* * * * * php /opt/glpi/front/cron.php") | crontab - |
| 129 | +msg_ok "Setup Cronjob" |
| 130 | + |
| 131 | +msg_info "Update PHP Params" |
| 132 | +PHP_VERSION=$(ls /etc/php/ | grep -E '^[0-9]+\.[0-9]+$' | head -n 1) |
| 133 | +PHP_INI="/etc/php/$PHP_VERSION/apache2/php.ini" |
| 134 | +sed -i 's/^upload_max_filesize = .*/upload_max_filesize = 20M/' $PHP_INI |
| 135 | +sed -i 's/^post_max_size = .*/post_max_size = 20M/' $PHP_INI |
| 136 | +sed -i 's/^max_execution_time = .*/max_execution_time = 60/' $PHP_INI |
| 137 | +sed -i 's/^max_input_vars = .*/max_input_vars = 5000/' $PHP_INI |
| 138 | +sed -i 's/^memory_limit = .*/memory_limit = 256M/' $PHP_INI |
| 139 | +sed -i 's/^;\?\s*session.cookie_httponly\s*=.*/session.cookie_httponly = On/' $PHP_INI |
| 140 | +systemctl restart apache2 |
| 141 | +msg_ok "Update PHP Params" |
| 142 | + |
| 143 | +motd_ssh |
| 144 | +customize |
| 145 | + |
| 146 | +msg_info "Cleaning up" |
| 147 | +rm -rf /opt/glpi/install |
| 148 | +rm -rf /opt/glpi-${RELEASE}.tgz |
| 149 | +$STD apt-get -y autoremove |
| 150 | +$STD apt-get -y autoclean |
| 151 | +msg_ok "Cleaned" |
0 commit comments