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 header_info
check_container_storage check_container_storage
check_container_resources 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) }') 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 if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then
msg_info "Stopping Service"
msg_info "Stopping Apache2"
systemctl stop apache2 systemctl stop apache2
msg_ok "Stopped Apache2" msg_ok "Stopped Service"
msg_info "Updating $APP to v${RELEASE}" msg_info "Updating $APP to v${RELEASE}"
mv /var/www/partdb/ /opt/partdb-backup
cd /opt cd /opt
mv /opt/partdb/ /opt/partdb-backup
wget -q "https://github.com/Part-DB/Part-DB-server/archive/refs/tags/v${RELEASE}.zip" wget -q "https://github.com/Part-DB/Part-DB-server/archive/refs/tags/v${RELEASE}.zip"
unzip -q "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
chown -R www-data:www-data /var/www/partdb
cd /var/www/partdb/ cd /opt/partdb/
cp -r "/opt/partdb-backup/.env.local" /var/www/partdb/ cp -r "/opt/partdb-backup/.env.local" /opt/partdb/
cp -r "/opt/partdb-backup/public/media" /var/www/partdb/public/ cp -r "/opt/partdb-backup/public/media" /opt/partdb/public/
cp -r "/opt/partdb-backup/config/banner.md" /var/www/partdb/config/ 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 install &>/dev/null
yarn build &>/dev/null yarn build &>/dev/null
sudo -u www-data php bin/console cache:clear &>/dev/null php bin/console cache:clear &>/dev/null
sudo -u www-data php bin/console doctrine:migrations:migrate -n &>/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 echo "${RELEASE}" >/opt/${APP}_version.txt
msg_ok "Updated $APP to v${RELEASE}" msg_ok "Updated $APP to v${RELEASE}"
msg_info "Starting Apache2" msg_info "Starting Service"
systemctl start apache2 systemctl start apache2
msg_ok "Started Apache2" msg_ok "Started Service"
msg_info "Cleaning up" msg_info "Cleaning up"
rm -r "/opt/v${RELEASE}.zip" rm -r "/opt/v${RELEASE}.zip"

View File

@ -23,19 +23,8 @@ $STD apt-get install -y \
software-properties-common \ software-properties-common \
apt-transport-https \ apt-transport-https \
lsb-release \ lsb-release \
php \ php-{opcache,curl,gd,mbstring,xml,bcmath,intl,zip,xsl,pgsql} \
libapache2-mod-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 \ composer \
postgresql postgresql
msg_ok "Installed Dependencies" 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 ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';"
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0;" $STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0;"
{ {
echo "Part-DB Database Credentials" echo "Part-DB Credentials"
echo -e "Part-DB Database User: \e[32m$DB_USER\e[0m" echo "Part-DB Database User: $DB_USER"
echo -e "Part-DB Database Password: \e[32m$DB_PASS\e[0m" echo "Part-DB Database Password: $DB_PASS"
echo -e "Part-DB Database Name: \e[32m$DB_NAME\e[0m" echo "Part-DB Database Name: $DB_NAME"
echo ""
} >> ~/partdb.creds } >> ~/partdb.creds
msg_ok "Set up PostgreSQL" msg_ok "Set up PostgreSQL"
msg_info "Install yarn" msg_info "Setting up Node.js/Yarn"
curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor -o /usr/share/keyrings/yarnkey.gpg mkdir -p /etc/apt/keyrings
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" >/etc/apt/sources.list.d/yarn.list 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 update
$STD apt-get install -y yarn $STD apt-get install -y nodejs
msg_ok "Installed yarn" $STD npm install -g npm@latest
$STD npm install -g yarn
msg_ok "Installed Node.js/Yarn"
msg_info "Installing Part-DB (Patience)" msg_info "Installing Part-DB (Patience)"
cd /opt 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) }') 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" wget -q "https://github.com/Part-DB/Part-DB-server/archive/refs/tags/v${RELEASE}.zip"
unzip -q "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 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 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 export COMPOSER_ALLOW_SUPERUSER=1
$STD sudo -u www-data composer install --no-dev -o $STD composer install --no-dev -o --no-interaction
$STD yarn install $STD yarn install
$STD yarn build $STD yarn build
$STD sudo -u www-data php bin/console cache:clear $STD php bin/console cache:clear
sudo -u www-data php bin/console doctrine:migrations:migrate -n > ~/database-migration-output 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) ADMIN_PASS=$(grep -oP 'The initial password for the "admin" user is: \K\w+' ~/database-migration-output)
{ {
echo "Part-DB Admin Credentials" echo ""
echo -e "Part-DB Admin User: \e[32madmin\e[0m" echo "Part-DB Admin User: admin"
echo -e "Part-DB Admin User: \e[32m$ADMIN_PASS\e[0m" echo "Part-DB Admin Password: $ADMIN_PASS"
} >> ~/partdb.creds } >> ~/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 cat <<EOF >/etc/apache2/sites-available/partdb.conf
<VirtualHost *:80> <VirtualHost *:80>
ServerName partdb ServerName partdb
DocumentRoot /var/www/partdb/public DocumentRoot /opt/partdb/public
<Directory /var/www/partdb/public> <Directory /opt/partdb/public>
Options FollowSymLinks
AllowOverride All AllowOverride All
Order Allow,Deny Require all granted
Allow from All
</Directory> </Directory>
ErrorLog /var/log/apache2/partdb_error.log ErrorLog /var/log/apache2/partdb_error.log
@ -103,10 +97,9 @@ cat <<EOF >/etc/apache2/sites-available/partdb.conf
EOF EOF
$STD a2ensite partdb $STD a2ensite partdb
$STD a2enmod rewrite $STD a2enmod rewrite
rm /etc/apache2/sites-enabled/000-default.conf $STD a2dissite 000-default.conf
service apache2 restart $STD systemctl reload apache2
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt msg_ok "Created Service"
msg_ok "Installed Part-DB"
motd_ssh motd_ssh
customize customize