|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2026 community-scripts ORG |
| 4 | +# Author: MickLesk (CanbiZ) |
| 5 | +# License: MIT | https://github.com/community-scripts/DevScripts/raw/main/LICENSE |
| 6 | +# Source: https://github.com/freescout-help-desk/freescout |
| 7 | + |
| 8 | +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" |
| 9 | +color |
| 10 | +verb_ip6 |
| 11 | +catch_errors |
| 12 | +setting_up_container |
| 13 | +network_check |
| 14 | +update_os |
| 15 | + |
| 16 | +var_admin_email="${var_admin_email:-admin@example.com}" |
| 17 | +if [[ ! "$var_admin_email" =~ ^[^@[:space:]]+@[^@[:space:]]+\.[^@[:space:]]+$ ]]; then |
| 18 | + msg_warn "Invalid admin email '${var_admin_email}', using admin@example.com" |
| 19 | + var_admin_email="admin@example.com" |
| 20 | +fi |
| 21 | +var_admin_pass="${var_admin_pass:-$(random_password 16)}" |
| 22 | + |
| 23 | +msg_info "Installing Dependencies" |
| 24 | +$STD apt install -y nginx |
| 25 | +msg_ok "Installed Dependencies" |
| 26 | + |
| 27 | +setup_mariadb |
| 28 | +MARIADB_DB_NAME="freescout" MARIADB_DB_USER="freescout" setup_mariadb_db |
| 29 | +PHP_VERSION="8.4" PHP_FPM="YES" setup_php |
| 30 | +fetch_and_deploy_gh_release "freescout" "freescout-help-desk/freescout" "tarball" |
| 31 | + |
| 32 | +msg_info "Configuring FreeScout" |
| 33 | +cd /opt/freescout |
| 34 | +cat <<EOF >/opt/freescout/.env |
| 35 | +APP_URL=http://${LOCAL_IP} |
| 36 | +DB_CONNECTION=mysql |
| 37 | +DB_HOST=localhost |
| 38 | +DB_PORT=3306 |
| 39 | +DB_DATABASE=freescout |
| 40 | +DB_USERNAME=freescout |
| 41 | +DB_PASSWORD=${MARIADB_DB_PASS} |
| 42 | +APP_KEY= |
| 43 | +EOF |
| 44 | +$STD php artisan key:generate --force |
| 45 | +$STD php artisan storage:link |
| 46 | +$STD php artisan migrate --force |
| 47 | +$STD php artisan freescout:create-user --role=admin --firstName=Admin --lastName=FreeScout --email="$var_admin_email" --password="$var_admin_pass" --no-interaction |
| 48 | +touch /opt/freescout/storage/.installed |
| 49 | +$STD php artisan freescout:clear-cache |
| 50 | +chown -R www-data:www-data /opt/freescout |
| 51 | +cat <<EOF >>~/freescout.creds |
| 52 | + |
| 53 | +FreeScout Admin |
| 54 | +Email: ${var_admin_email} |
| 55 | +Password: ${var_admin_pass} |
| 56 | +EOF |
| 57 | +chmod 600 ~/freescout.creds |
| 58 | +msg_ok "Configured FreeScout" |
| 59 | + |
| 60 | +msg_info "Configuring Nginx" |
| 61 | +sed -i 's/^;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/8.4/fpm/php.ini |
| 62 | +systemctl restart php8.4-fpm |
| 63 | +PHP_SOCK=$(get_php_fpm_socket) |
| 64 | +cat <<EOF >/etc/nginx/sites-available/freescout |
| 65 | +server { |
| 66 | + listen 80; |
| 67 | + listen [::]:80; |
| 68 | + server_name _; |
| 69 | + |
| 70 | + root /opt/freescout/public; |
| 71 | + index index.php index.html index.htm; |
| 72 | + |
| 73 | + client_max_body_size 128M; |
| 74 | + |
| 75 | + location / { |
| 76 | + try_files \$uri \$uri/ /index.php?\$query_string; |
| 77 | + } |
| 78 | + location ~ \.php\$ { |
| 79 | + fastcgi_split_path_info ^(.+\.php)(/.+)\$; |
| 80 | + fastcgi_pass unix:${PHP_SOCK}; |
| 81 | + fastcgi_index index.php; |
| 82 | + fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; |
| 83 | + include fastcgi_params; |
| 84 | + } |
| 85 | + location ~* ^/storage/attachment/ { |
| 86 | + expires 1M; |
| 87 | + access_log off; |
| 88 | + try_files \$uri \$uri/ /index.php?\$query_string; |
| 89 | + } |
| 90 | + location ~* ^/(?:css|js)/.*\.(?:css|js)\$ { |
| 91 | + expires 2d; |
| 92 | + access_log off; |
| 93 | + add_header Cache-Control "public, must-revalidate"; |
| 94 | + add_header X-Content-Type-Options "nosniff"; |
| 95 | + } |
| 96 | + location ~* ^/storage/.*\.((?!(jpg|jpeg|jfif|pjpeg|pjp|apng|bmp|gif|ico|cur|png|tif|tiff|webp|pdf|txt|diff|patch|json|mp3|wav|ogg|wma)).)*\$ { |
| 97 | + add_header Content-disposition "attachment; filename=\$2"; |
| 98 | + add_header X-Content-Type-Options "nosniff"; |
| 99 | + default_type application/octet-stream; |
| 100 | + } |
| 101 | + location ~* ^/(storage/|.*\.).*\$ { |
| 102 | + expires 1M; |
| 103 | + access_log off; |
| 104 | + add_header Cache-Control "public"; |
| 105 | + add_header X-Content-Type-Options "nosniff"; |
| 106 | + } |
| 107 | + location ~ /\. { |
| 108 | + deny all; |
| 109 | + } |
| 110 | +} |
| 111 | +EOF |
| 112 | +nginx_enable_site "freescout" |
| 113 | +msg_ok "Configured Nginx" |
| 114 | + |
| 115 | +msg_info "Setting up Cron" |
| 116 | +cat <<EOF >/etc/cron.d/freescout |
| 117 | +* * * * * www-data php /opt/freescout/artisan schedule:run >/dev/null 2>&1 |
| 118 | +EOF |
| 119 | +systemctl enable -q --now cron |
| 120 | +msg_ok "Set up Cron" |
| 121 | + |
| 122 | +motd_ssh |
| 123 | +customize |
| 124 | +cleanup_lxc |
0 commit comments