Skip to content

Commit

Permalink
New script: Part-DB LXC
Browse files Browse the repository at this point in the history
  • Loading branch information
bvdberg01 committed Nov 29, 2024
1 parent 78948b0 commit e36b13f
Show file tree
Hide file tree
Showing 3 changed files with 268 additions and 0 deletions.
110 changes: 110 additions & 0 deletions ct/part-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env bash
source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
# Copyright (c) 2021-2024 community-scripts ORG
# Author: bvdberg01
# License: MIT
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE

function header_info {
clear
cat <<"EOF"
____ __ ____ ____
/ __ \____ ______/ /_ / __ \/ __ )
/ /_/ / __ `/ ___/ __/_____/ / / / __ |
/ ____/ /_/ / / / /_/_____/ /_/ / /_/ /
/_/ \__,_/_/ \__/ /_____/_____/
EOF
}
header_info
echo -e "Loading..."
APP="Part-DB"
var_disk="8"
var_cpu="2"
var_ram="1024"
var_os="debian"
var_version="12"
variables
color
catch_errors

function default_settings() {
CT_TYPE="1"
PW=""
CT_ID=$NEXTID
HN=$NSAPP
DISK_SIZE="$var_disk"
CORE_COUNT="$var_cpu"
RAM_SIZE="$var_ram"
BRG="vmbr0"
NET="dhcp"
GATE=""
APT_CACHER=""
APT_CACHER_IP=""
DISABLEIP6="no"
MTU=""
SD=""
NS=""
MAC=""
VLAN=""
SSH="no"
VERB="no"
echo_default
}

function update_script() {
header_info
check_container_storage
check_container_resources
if [[ ! -d /var/www/partdb ]]; then msg_error "No ${APP} Installation Found!"; exit; fi

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) }')
if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then

msg_info "Stopping Apache2"
systemctl stop apache2
msg_ok "Stopped Apache2"

msg_info "Updating $APP to v${RELEASE}"
mv /var/www/partdb/ /opt/partdb-backup
cd /opt
wget -q "https://github.com/Part-DB/Part-DB-server/archive/refs/tags/v${RELEASE}.zip"
unzip -q "v${RELEASE}.zip"
mv /opt/Part-DB-server-${RELEASE}/ /var/www/partdb
chown -R www-data:www-data /var/www/partdb

cd /var/www/partdb/
cp -r "/opt/partdb-backup/.env.local" /var/www/partdb/
cp -r "/opt/partdb-backup/public/media" /var/www/partdb/public/
cp -r "/opt/partdb-backup/config/banner.md" /var/www/partdb/config/

sudo -u www-data composer install --no-dev -o &>/dev/null
yarn install &>/dev/null
yarn build &>/dev/null
sudo -u www-data php bin/console cache:clear &>/dev/null
sudo -u www-data php bin/console doctrine:migrations:migrate -n &>/dev/null
echo "${RELEASE}" >/opt/${APP}_version.txt
msg_ok "Updated $APP to v${RELEASE}"

msg_info "Starting Apache2"
systemctl start apache2
msg_ok "Started Apache2"

msg_info "Cleaning up"
rm -r "/opt/v${RELEASE}.zip"
rm -r /opt/partdb-backup
msg_ok "Cleaned"
msg_ok "Updated Successfully"
else
msg_ok "No update required. ${APP} is already at v${RELEASE}"
fi
exit
}

start
build_container
description

msg_ok "Completed Successfully!\n"
echo -e "${APP} should be reachable by going to the following URL.
${BL}http://${IP}${CL} \n"
119 changes: 119 additions & 0 deletions install/part-db-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env bash

# Copyright (c) 2021-2024 community-scripts ORG
# Author: bvdberg01
# License: MIT
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE

source /dev/stdin <<< "$FUNCTIONS_FILE_PATH"
color
verb_ip6
catch_errors
setting_up_container
network_check
update_os

msg_info "Installing Dependencies"
$STD apt-get install -y \
curl \
sudo \
mc \
zip \
ca-certificates \
software-properties-common \
apt-transport-https \
lsb-release \
php \
libapache2-mod-php \
php-opcache \
php-curl \
php-gd \
php-mbstring \
php-xml \
php-bcmath \
php-intl \
php-zip \
php-xsl \
php-pgsql \
nodejs \
composer \
postgresql
msg_ok "Installed Dependencies"

msg_info "Setting up PostgreSQL"
DB_NAME=partdb
DB_USER=partdb
DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13)
$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';"
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0;"
{
echo "Part-DB Database Credentials"
echo -e "Part-DB Database User: \e[32m$DB_USER\e[0m"
echo -e "Part-DB Database Password: \e[32m$DB_PASS\e[0m"
echo -e "Part-DB Database Name: \e[32m$DB_NAME\e[0m"
echo ""
} >> ~/partdb.creds
msg_ok "Set up PostgreSQL"

msg_info "Install yarn"
curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor -o /usr/share/keyrings/yarnkey.gpg
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" >/etc/apt/sources.list.d/yarn.list
$STD apt-get update
$STD apt-get install -y yarn
msg_ok "Installed yarn"

msg_info "Installing Part-DB (Patience)"
cd /opt
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) }')
wget -q "https://github.com/Part-DB/Part-DB-server/archive/refs/tags/v${RELEASE}.zip"
unzip -q "v${RELEASE}.zip"
mv /opt/Part-DB-server-${RELEASE}/ /var/www/partdb

cd /var/www/partdb/
cp .env .env.local
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

chown -R www-data:www-data /var/www/partdb
$STD sudo -u www-data composer install --no-dev -o
$STD yarn install
$STD yarn build
$STD sudo -u www-data php bin/console cache:clear
sudo -u www-data php bin/console doctrine:migrations:migrate -n > ~/database-migration-output

ADMIN_PASS=$(grep -oP 'The initial password for the "admin" user is: \K\w+' ~/database-migration-output)
{
echo "Part-DB Admin Credentials"
echo -e "Part-DB Admin User: \e[32madmin\e[0m"
echo -e "Part-DB Admin User: \e[32m$ADMIN_PASS\e[0m"
} >> ~/partdb.creds

cat <<EOF >/etc/apache2/sites-available/partdb.conf
<VirtualHost *:80>
ServerName partdb
DocumentRoot /var/www/partdb/public
<Directory /var/www/partdb/public>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog /var/log/apache2/partdb_error.log
CustomLog /var/log/apache2/partdb_access.log combined
</VirtualHost>
EOF
$STD a2ensite partdb
$STD a2enmod rewrite
rm /etc/apache2/sites-enabled/000-default.conf
service apache2 restart
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
msg_ok "Installed Part-DB"

motd_ssh
customize

msg_info "Cleaning up"
rm -rf ~/database-migration-output
rm -rf "/opt/v${RELEASE}.zip"
$STD apt-get -y autoremove
$STD apt-get -y autoclean
msg_ok "Cleaned"
39 changes: 39 additions & 0 deletions json/part-db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "Part-DB",
"slug": "part-db",
"categories": [
0
],
"date_created": "2024-11-29",
"type": "ct",
"updateable": true,
"privileged": false,
"interface_port": "80",
"documentation": "https://docs.part-db.de/",
"website": "https://github.com/Part-DB/Part-DB-server",
"logo": "https://avatars.githubusercontent.com/u/36010898?s=48&v=4",
"description": "Part-DB is an Open source inventory management system for your electronic components",
"install_methods": [
{
"type": "default",
"script": "ct/part-db.sh",
"resources": {
"cpu": "2",
"ram": "1024",
"hdd": "8",
"os": "debian",
"version": "12"
}
}
],
"default_credentials": {
"username": null,
"password": null
},
"notes": [
{
"text": "Show login and database credentials: `cat part-db.creds`",
"type": "info"
}
]
}

0 comments on commit e36b13f

Please sign in to comment.