|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2024 community-scripts ORG |
| 4 | +# Author: bvdberg01 |
| 5 | +# License: MIT |
| 6 | +# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 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 | +msg_info "Installing Dependencies" |
| 17 | +$STD apt-get install -y \ |
| 18 | + curl \ |
| 19 | + sudo \ |
| 20 | + mc \ |
| 21 | + zip \ |
| 22 | + ca-certificates \ |
| 23 | + software-properties-common \ |
| 24 | + apt-transport-https \ |
| 25 | + lsb-release \ |
| 26 | + php-{opcache,curl,gd,mbstring,xml,bcmath,intl,zip,xsl,pgsql} \ |
| 27 | + libapache2-mod-php \ |
| 28 | + composer \ |
| 29 | + postgresql |
| 30 | +msg_ok "Installed Dependencies" |
| 31 | + |
| 32 | +msg_info "Setting up PostgreSQL" |
| 33 | +DB_NAME=partdb |
| 34 | +DB_USER=partdb |
| 35 | +DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13) |
| 36 | +$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';" |
| 37 | +$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0;" |
| 38 | +{ |
| 39 | +echo "Part-DB Credentials" |
| 40 | +echo "Part-DB Database User: $DB_USER" |
| 41 | +echo "Part-DB Database Password: $DB_PASS" |
| 42 | +echo "Part-DB Database Name: $DB_NAME" |
| 43 | +} >> ~/partdb.creds |
| 44 | +msg_ok "Set up PostgreSQL" |
| 45 | + |
| 46 | +msg_info "Setting up Node.js/Yarn" |
| 47 | +mkdir -p /etc/apt/keyrings |
| 48 | +curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg |
| 49 | +echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" >/etc/apt/sources.list.d/nodesource.list |
| 50 | +$STD apt-get update |
| 51 | +$STD apt-get install -y nodejs |
| 52 | +$STD npm install -g npm@latest |
| 53 | +$STD npm install -g yarn |
| 54 | +msg_ok "Installed Node.js/Yarn" |
| 55 | + |
| 56 | +msg_info "Installing Part-DB (Patience)" |
| 57 | +cd /opt |
| 58 | +RELEASE=$(curl -s https://api.github.com/repos/Part-DB/Part-DB-server/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') |
| 59 | +wget -q "https://github.com/Part-DB/Part-DB-server/archive/refs/tags/v${RELEASE}.zip" |
| 60 | +unzip -q "v${RELEASE}.zip" |
| 61 | +mv /opt/Part-DB-server-${RELEASE}/ /opt/partdb |
| 62 | + |
| 63 | +cd /opt/partdb/ |
| 64 | +cp .env .env.local |
| 65 | +sed -i "s|DATABASE_URL=\"sqlite:///%kernel.project_dir%/var/app.db\"|DATABASE_URL=\"postgresql://${DB_USER}:${DB_PASS}@127.0.0.1:5432/${DB_NAME}?serverVersion=12.19&charset=utf8\"|" .env.local |
| 66 | + |
| 67 | +export COMPOSER_ALLOW_SUPERUSER=1 |
| 68 | +$STD composer install --no-dev -o --no-interaction |
| 69 | +$STD yarn install |
| 70 | +$STD yarn build |
| 71 | +$STD php bin/console cache:clear |
| 72 | +php bin/console doctrine:migrations:migrate -n > ~/database-migration-output |
| 73 | +chown -R www-data:www-data /opt/partdb |
| 74 | +ADMIN_PASS=$(grep -oP 'The initial password for the "admin" user is: \K\w+' ~/database-migration-output) |
| 75 | +{ |
| 76 | +echo "" |
| 77 | +echo "Part-DB Admin User: admin" |
| 78 | +echo "Part-DB Admin Password: $ADMIN_PASS" |
| 79 | +} >> ~/partdb.creds |
| 80 | +echo "${RELEASE}" >/opt/${APPLICATION}_version.txt |
| 81 | +msg_ok "Installed Part-DB" |
| 82 | + |
| 83 | +msg_info "Creating Service" |
| 84 | +cat <<EOF >/etc/apache2/sites-available/partdb.conf |
| 85 | +<VirtualHost *:80> |
| 86 | + ServerName partdb |
| 87 | + DocumentRoot /opt/partdb/public |
| 88 | + <Directory /opt/partdb/public> |
| 89 | + Options FollowSymLinks |
| 90 | + AllowOverride All |
| 91 | + Require all granted |
| 92 | + </Directory> |
| 93 | +
|
| 94 | + ErrorLog /var/log/apache2/partdb_error.log |
| 95 | + CustomLog /var/log/apache2/partdb_access.log combined |
| 96 | +</VirtualHost> |
| 97 | +EOF |
| 98 | +$STD a2ensite partdb |
| 99 | +$STD a2enmod rewrite |
| 100 | +$STD a2dissite 000-default.conf |
| 101 | +$STD systemctl reload apache2 |
| 102 | +msg_ok "Created Service" |
| 103 | + |
| 104 | +motd_ssh |
| 105 | +customize |
| 106 | + |
| 107 | +msg_info "Cleaning up" |
| 108 | +rm -rf ~/database-migration-output |
| 109 | +rm -rf "/opt/v${RELEASE}.zip" |
| 110 | +$STD apt-get -y autoremove |
| 111 | +$STD apt-get -y autoclean |
| 112 | +msg_ok "Cleaned" |
0 commit comments