|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2025 community-scripts ORG |
| 4 | +# Author: bvdberg01 | CanbiZ |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 6 | +# Source: https://github.com/karlomikus/bar-assistant |
| 7 | +# Source: https://github.com/karlomikus/vue-salt-rim |
| 8 | +# Source: https://www.meilisearch.com/ |
| 9 | + |
| 10 | +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" |
| 11 | +color |
| 12 | +verb_ip6 |
| 13 | +catch_errors |
| 14 | +setting_up_container |
| 15 | +network_check |
| 16 | +update_os |
| 17 | + |
| 18 | +msg_info "Installing Dependencies" |
| 19 | +$STD apt-get install -y \ |
| 20 | + redis-server \ |
| 21 | + nginx \ |
| 22 | + lsb-release \ |
| 23 | + libvips |
| 24 | +#php-{ffi,opcache,redis,zip,pdo-sqlite,bcmath,pdo,curl,dom,fpm} |
| 25 | +msg_ok "Installed Dependencies" |
| 26 | + |
| 27 | +PHP_VERSION="8.3" PHP_FPM=YES PHP_MODULE="ffi,opcache,redis,zip,pdo-sqlite,bcmath,pdo,curl,dom,fpm" setup_php |
| 28 | +setup_composer |
| 29 | +NODE_VERSION="22" setup_nodejs |
| 30 | +fetch_and_deploy_gh_release "meilisearch" "meilisearch/meilisearch" "binary" |
| 31 | +fetch_and_deploy_gh_release "bar-assistant" "karlomikus/bar-assistant" "tarball" "latest" "/opt/bar-assistant" |
| 32 | +fetch_and_deploy_gh_release "vue-salt-rim" "karlomikus/vue-salt-rim" "tarball" "latest" "/opt/vue-salt-rim" |
| 33 | + |
| 34 | +msg_info "Configuring PHP" |
| 35 | +PHPVER=$(php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION . "\n";') |
| 36 | +sed -i.bak -E 's/^\s*;?\s*ffi\.enable\s*=.*/ffi.enable=true/' /etc/php/${PHPVER}/fpm/php.ini |
| 37 | +$STD systemctl reload php${PHPVER}-fpm |
| 38 | +msg_info "configured PHP" |
| 39 | + |
| 40 | +msg_info "Configure MeiliSearch" |
| 41 | +curl -fsSL https://raw.githubusercontent.com/meilisearch/meilisearch/latest/config.toml -o /etc/meilisearch.toml |
| 42 | +MASTER_KEY=$(openssl rand -base64 12) |
| 43 | +sed -i \ |
| 44 | + -e 's|^env =.*|env = "production"|' \ |
| 45 | + -e "s|^# master_key =.*|master_key = \"$MASTER_KEY\"|" \ |
| 46 | + -e 's|^db_path =.*|db_path = "/var/lib/meilisearch/data"|' \ |
| 47 | + -e 's|^dump_dir =.*|dump_dir = "/var/lib/meilisearch/dumps"|' \ |
| 48 | + -e 's|^snapshot_dir =.*|snapshot_dir = "/var/lib/meilisearch/snapshots"|' \ |
| 49 | + -e 's|^# no_analytics = true|no_analytics = true|' \ |
| 50 | + -e 's|^http_addr =.*|http_addr = "127.0.0.1:7700"|' \ |
| 51 | + /etc/meilisearch.toml |
| 52 | +msg_ok "Configured MeiliSearch" |
| 53 | + |
| 54 | +msg_info "Creating MeiliSearch service" |
| 55 | +cat <<EOF >/etc/systemd/system/meilisearch.service |
| 56 | +[Unit] |
| 57 | +Description=Meilisearch |
| 58 | +After=network.target |
| 59 | +
|
| 60 | +[Service] |
| 61 | +ExecStart=/usr/bin/meilisearch --config-file-path /etc/meilisearch.toml |
| 62 | +Restart=always |
| 63 | +
|
| 64 | +[Install] |
| 65 | +WantedBy=multi-user.target |
| 66 | +EOF |
| 67 | +systemctl enable -q --now meilisearch |
| 68 | +sleep 5 |
| 69 | +msg_ok "Created Service MeiliSearch" |
| 70 | + |
| 71 | +msg_info "Installing Bar Assistant" |
| 72 | +cd /opt/bar-assistant |
| 73 | +cp /opt/bar-assistant/.env.dist /opt/bar-assistant/.env |
| 74 | +MeiliSearch_API_KEY=$(curl -s -X GET 'http://127.0.0.1:7700/keys' -H "Authorization: Bearer $MASTER_KEY" | grep -o '"key":"[^"]*"' | head -n 1 | sed 's/"key":"//;s/"//') |
| 75 | +MeiliSearch_API_KEY_UID=$(curl -s -X GET 'http://127.0.0.1:7700/keys' -H "Authorization: Bearer $MASTER_KEY" | grep -o '"uid":"[^"]*"' | head -n 1 | sed 's/"uid":"//;s/"//') |
| 76 | +LOCAL_IP=$(hostname -I | awk '{print $1}') |
| 77 | +sed -i -e "s|^APP_URL=|APP_URL=http://${LOCAL_IP}/bar/|" \ |
| 78 | + -e "s|^MEILISEARCH_HOST=|MEILISEARCH_HOST=http://127.0.0.1:7700|" \ |
| 79 | + -e "s|^MEILISEARCH_KEY=|MEILISEARCH_KEY=${MASTER_KEY}|" \ |
| 80 | + -e "s|^MEILISEARCH_API_KEY=|MEILISEARCH_API_KEY=${MeiliSearch_API_KEY}|" \ |
| 81 | + -e "s|^MEILISEARCH_API_KEY_UID=|MEILISEARCH_API_KEY_UID=${MeiliSearch_API_KEY_UID}|" \ |
| 82 | + /opt/bar-assistant/.env |
| 83 | +$STD composer install --no-interaction |
| 84 | +$STD php artisan key:generate |
| 85 | +touch storage/bar-assistant/database.ba3.sqlite |
| 86 | +$STD php artisan migrate --force |
| 87 | +$STD php artisan storage:link |
| 88 | +$STD php artisan bar:setup-meilisearch |
| 89 | +$STD php artisan scout:sync-index-settings |
| 90 | +$STD php artisan config:cache |
| 91 | +$STD php artisan route:cache |
| 92 | +$STD php artisan event:cache |
| 93 | +mkdir /opt/bar-assistant/storage/bar-assistant/uploads/temp |
| 94 | +chown -R www-data:www-data /opt/bar-assistant |
| 95 | +msg_ok "Installed Bar Assistant" |
| 96 | + |
| 97 | +msg_info "Installing Salt Rim" |
| 98 | +cd /opt/vue-salt-rim |
| 99 | +cat <<EOF >/opt/vue-salt-rim/public/config.js |
| 100 | +window.srConfig = {} |
| 101 | +window.srConfig.API_URL = "http://${LOCAL_IP}/bar" |
| 102 | +window.srConfig.MEILISEARCH_URL = "http://${LOCAL_IP}/search" |
| 103 | +EOF |
| 104 | +$STD npm install |
| 105 | +$STD npm run build |
| 106 | +msg_ok "Installed Salt Rim" |
| 107 | + |
| 108 | +msg_info "Creating Service" |
| 109 | +cat <<EOF >/etc/nginx/sites-available/barassistant.conf |
| 110 | +server { |
| 111 | + listen 80 default_server; |
| 112 | + listen [::]:80 default_server; |
| 113 | + server_name _; |
| 114 | +
|
| 115 | + location = /favicon.ico { access_log off; log_not_found off; } |
| 116 | + location = /robots.txt { access_log off; log_not_found off; } |
| 117 | +
|
| 118 | + client_max_body_size 100M; |
| 119 | +
|
| 120 | + location /bar/ { |
| 121 | + proxy_pass http://127.0.0.1:8080/; |
| 122 | + proxy_set_header Host \$host; |
| 123 | + proxy_set_header X-Real-IP \$remote_addr; |
| 124 | + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; |
| 125 | + proxy_set_header X-Forwarded-Proto \$scheme; |
| 126 | + } |
| 127 | +
|
| 128 | + location /search/ { |
| 129 | + proxy_pass http://127.0.0.1:7700/; |
| 130 | + } |
| 131 | +
|
| 132 | + location / { |
| 133 | + proxy_pass http://127.0.0.1:8081/; |
| 134 | + proxy_set_header Host \$host; |
| 135 | + proxy_set_header X-Real-IP \$remote_addr; |
| 136 | + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; |
| 137 | + proxy_set_header X-Forwarded-Proto \$scheme; |
| 138 | + } |
| 139 | +} |
| 140 | +
|
| 141 | +server { |
| 142 | + listen 127.0.0.1:8080; |
| 143 | + server_name example.com; |
| 144 | + root /opt/bar-assistant/public; |
| 145 | +
|
| 146 | + add_header X-Frame-Options "SAMEORIGIN"; |
| 147 | + add_header X-Content-Type-Options "nosniff"; |
| 148 | +
|
| 149 | + index index.php; |
| 150 | + charset utf-8; |
| 151 | +
|
| 152 | + location / { |
| 153 | + try_files \$uri \$uri/ /index.php?\$query_string; |
| 154 | + } |
| 155 | +
|
| 156 | + location = /favicon.ico { access_log off; log_not_found off; } |
| 157 | + location = /robots.txt { access_log off; log_not_found off; } |
| 158 | +
|
| 159 | + error_page 404 /index.php; |
| 160 | +
|
| 161 | + location ~ ^/index\.php(/|$) { |
| 162 | + fastcgi_pass unix:/var/run/php/php$PHPVER-fpm.sock; |
| 163 | + fastcgi_param SCRIPT_FILENAME \$realpath_root\$fastcgi_script_name; |
| 164 | + include fastcgi_params; |
| 165 | + fastcgi_hide_header X-Powered-By; |
| 166 | + } |
| 167 | +
|
| 168 | + location ~ /\.(?!well-known).* { |
| 169 | + deny all; |
| 170 | + } |
| 171 | +} |
| 172 | +
|
| 173 | +server { |
| 174 | + listen 127.0.0.1:8081; |
| 175 | + server_name _; |
| 176 | + root /opt/vue-salt-rim/dist; |
| 177 | +
|
| 178 | + location / { |
| 179 | + try_files \$uri \$uri/ /index.html; |
| 180 | + } |
| 181 | +} |
| 182 | +EOF |
| 183 | + |
| 184 | +ln -s /etc/nginx/sites-available/barassistant.conf /etc/nginx/sites-enabled/ |
| 185 | +rm -f /etc/nginx/sites-enabled/default |
| 186 | +$STD systemctl reload nginx |
| 187 | +msg_ok "Created Service" |
| 188 | + |
| 189 | +motd_ssh |
| 190 | +customize |
| 191 | + |
| 192 | +msg_info "Cleaning up" |
| 193 | +$STD apt-get -y autoremove |
| 194 | +$STD apt-get -y autoclean |
| 195 | +msg_ok "Cleaned" |
0 commit comments