Improved based on PR feedback MickLesk

This commit is contained in:
bvdberg01 2024-12-04 00:18:24 +01:00
parent e36b13f15b
commit 326b63f1b0
2 changed files with 50 additions and 58 deletions

View File

@ -56,39 +56,38 @@ 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
if [[ ! -d /opt/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"
msg_info "Stopping Service"
systemctl stop apache2
msg_ok "Stopped Apache2"
msg_ok "Stopped Service"
msg_info "Updating $APP to v${RELEASE}"
mv /var/www/partdb/ /opt/partdb-backup
cd /opt
mv /opt/partdb/ /opt/partdb-backup
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
mv /opt/Part-DB-server-${RELEASE}/ /opt/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/
cd /opt/partdb/
cp -r "/opt/partdb-backup/.env.local" /opt/partdb/
cp -r "/opt/partdb-backup/public/media" /opt/partdb/public/
cp -r "/opt/partdb-backup/config/banner.md" /opt/partdb/config/
sudo -u www-data composer install --no-dev -o &>/dev/null
export COMPOSER_ALLOW_SUPERUSER=1
composer install --no-dev -o --no-interaction &>/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
php bin/console cache:clear &>/dev/null
php bin/console doctrine:migrations:migrate -n &>/dev/null
chown -R www-data:www-data /opt/partdb
echo "${RELEASE}" >/opt/${APP}_version.txt
msg_ok "Updated $APP to v${RELEASE}"
msg_info "Starting Apache2"
msg_info "Starting Service"
systemctl start apache2
msg_ok "Started Apache2"
msg_ok "Started Service"
msg_info "Cleaning up"
rm -r "/opt/v${RELEASE}.zip"

View File

@ -23,19 +23,8 @@ $STD apt-get install -y \
software-properties-common \
apt-transport-https \
lsb-release \
php \
php-{opcache,curl,gd,mbstring,xml,bcmath,intl,zip,xsl,pgsql} \
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"
@ -47,54 +36,59 @@ 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 ""
echo "Part-DB Credentials"
echo "Part-DB Database User: $DB_USER"
echo "Part-DB Database Password: $DB_PASS"
echo "Part-DB Database Name: $DB_NAME"
} >> ~/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
msg_info "Setting up Node.js/Yarn"
mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
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
$STD apt-get update
$STD apt-get install -y yarn
msg_ok "Installed yarn"
$STD apt-get install -y nodejs
$STD npm install -g npm@latest
$STD npm install -g yarn
msg_ok "Installed Node.js/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
mv /opt/Part-DB-server-${RELEASE}/ /opt/partdb
cd /var/www/partdb/
cd /opt/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
export COMPOSER_ALLOW_SUPERUSER=1
$STD composer install --no-dev -o --no-interaction
$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
$STD php bin/console cache:clear
php bin/console doctrine:migrations:migrate -n > ~/database-migration-output
chown -R www-data:www-data /opt/partdb
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"
echo ""
echo "Part-DB Admin User: admin"
echo "Part-DB Admin Password: $ADMIN_PASS"
} >> ~/partdb.creds
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
msg_ok "Installed Part-DB"
msg_info "Creating Service"
cat <<EOF >/etc/apache2/sites-available/partdb.conf
<VirtualHost *:80>
ServerName partdb
DocumentRoot /var/www/partdb/public
<Directory /var/www/partdb/public>
DocumentRoot /opt/partdb/public
<Directory /opt/partdb/public>
Options FollowSymLinks
AllowOverride All
Order Allow,Deny
Allow from All
Require all granted
</Directory>
ErrorLog /var/log/apache2/partdb_error.log
@ -103,10 +97,9 @@ cat <<EOF >/etc/apache2/sites-available/partdb.conf
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"
$STD a2dissite 000-default.conf
$STD systemctl reload apache2
msg_ok "Created Service"
motd_ssh
customize