Skip to content

Commit d0f2c71

Browse files
bvdberg01MickLesk
andauthored
New script: Part-DB LXC (#591)
* New script: Part-DB LXC * Improved based on PR feedback MickLesk * Migrate header & footer to latest version * formatting and remove old header * formatting * fix json --------- Co-authored-by: CanbiZ <47820557+MickLesk@users.noreply.github.com>
1 parent 22c0757 commit d0f2c71

File tree

3 files changed

+236
-0
lines changed

3 files changed

+236
-0
lines changed

ct/part-db.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env bash
2+
source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
3+
# Copyright (c) 2021-2024 community-scripts ORG
4+
# Author: bvdberg01
5+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
6+
# Source: https://docs.part-db.de/
7+
8+
# App Default Values
9+
APP="Part-DB"
10+
var_tags="inventory;parts"
11+
var_cpu="2"
12+
var_ram="1024"
13+
var_disk="8"
14+
var_os="debian"
15+
var_version="12"
16+
var_unprivileged="1"
17+
18+
# App Output & Base Settings
19+
header_info "$APP"
20+
base_settings
21+
22+
# Core
23+
variables
24+
color
25+
catch_errors
26+
27+
function update_script() {
28+
header_info
29+
check_container_storage
30+
check_container_resources
31+
if [[ ! -d /opt/partdb ]]; then
32+
msg_error "No ${APP} Installation Found!"
33+
exit
34+
fi
35+
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) }')
36+
if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then
37+
msg_info "Stopping Service"
38+
systemctl stop apache2
39+
msg_ok "Stopped Service"
40+
41+
msg_info "Updating $APP to v${RELEASE}"
42+
cd /opt
43+
mv /opt/partdb/ /opt/partdb-backup
44+
wget -q "https://github.com/Part-DB/Part-DB-server/archive/refs/tags/v${RELEASE}.zip"
45+
unzip -q "v${RELEASE}.zip"
46+
mv /opt/Part-DB-server-${RELEASE}/ /opt/partdb
47+
48+
cd /opt/partdb/
49+
cp -r "/opt/partdb-backup/.env.local" /opt/partdb/
50+
cp -r "/opt/partdb-backup/public/media" /opt/partdb/public/
51+
cp -r "/opt/partdb-backup/config/banner.md" /opt/partdb/config/
52+
53+
export COMPOSER_ALLOW_SUPERUSER=1
54+
composer install --no-dev -o --no-interaction &>/dev/null
55+
yarn install &>/dev/null
56+
yarn build &>/dev/null
57+
php bin/console cache:clear &>/dev/null
58+
php bin/console doctrine:migrations:migrate -n &>/dev/null
59+
chown -R www-data:www-data /opt/partdb
60+
echo "${RELEASE}" >/opt/${APP}_version.txt
61+
msg_ok "Updated $APP to v${RELEASE}"
62+
63+
msg_info "Starting Service"
64+
systemctl start apache2
65+
msg_ok "Started Service"
66+
67+
msg_info "Cleaning up"
68+
rm -r "/opt/v${RELEASE}.zip"
69+
rm -r /opt/partdb-backup
70+
msg_ok "Cleaned"
71+
msg_ok "Updated Successfully"
72+
else
73+
msg_ok "No update required. ${APP} is already at v${RELEASE}"
74+
fi
75+
exit
76+
}
77+
78+
start
79+
build_container
80+
description
81+
82+
msg_ok "Completed Successfully!\n"
83+
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
84+
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
85+
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}${CL}"

install/part-db-install.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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"

json/part-db.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "Part-DB",
3+
"slug": "part-db",
4+
"categories": [
5+
0
6+
],
7+
"date_created": "2024-12-18",
8+
"type": "ct",
9+
"updateable": true,
10+
"privileged": false,
11+
"interface_port": 80,
12+
"documentation": "https://docs.part-db.de/",
13+
"website": "https://github.com/Part-DB/Part-DB-server",
14+
"logo": "https://avatars.githubusercontent.com/u/36010898?s=48&v=4",
15+
"description": "Part-DB is an Open source inventory management system for your electronic components",
16+
"install_methods": [
17+
{
18+
"type": "default",
19+
"script": "ct/part-db.sh",
20+
"resources": {
21+
"cpu": 2,
22+
"ram": 1024,
23+
"hdd": 8,
24+
"os": "debian",
25+
"version": "12"
26+
}
27+
}
28+
],
29+
"default_credentials": {
30+
"username": null,
31+
"password": null
32+
},
33+
"notes": [
34+
{
35+
"text": "Show login and database credentials: `cat part-db.creds`",
36+
"type": "info"
37+
}
38+
]
39+
}

0 commit comments

Comments
 (0)