From 1afefd20e971fd78139b6e196674637c09a1ca6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slavi=C5=A1a=20Are=C5=BEina?= <58952836+tremor021@users.noreply.github.com> Date: Thu, 11 Dec 2025 12:08:16 +0100 Subject: [PATCH] Refactor (#9876) --- ct/snipeit.sh | 8 ++++---- install/snipeit-install.sh | 32 ++++++++------------------------ 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/ct/snipeit.sh b/ct/snipeit.sh index 54aa64706..471115f3b 100644 --- a/ct/snipeit.sh +++ b/ct/snipeit.sh @@ -36,16 +36,16 @@ function update_script() { systemctl stop nginx msg_ok "Services Stopped" - msg_info "Creating backup" + msg_info "Creating Backup" mv /opt/snipe-it /opt/snipe-it-backup - msg_ok "Backup created" + msg_ok "Created Backup" fetch_and_deploy_gh_release "snipe-it" "grokability/snipe-it" "tarball" [[ "$(php -v 2>/dev/null)" == PHP\ 8.2* ]] && PHP_VERSION="8.3" PHP_MODULE="common,ctype,ldap,fileinfo,iconv,mysql,soap,xsl" PHP_FPM="YES" setup_php sed -i 's/php8.2/php8.3/g' /etc/nginx/conf.d/snipeit.conf setup_composer - msg_info "Updating ${APP}" + msg_info "Updating Snipe-IT" $STD apt update $STD apt -y upgrade cp /opt/snipe-it-backup/.env /opt/snipe-it/.env @@ -63,7 +63,7 @@ function update_script() { chown -R www-data: /opt/snipe-it chmod -R 755 /opt/snipe-it rm -rf /opt/snipe-it-backup - msg_ok "Updated ${APP}" + msg_ok "Updated Snipe-IT" msg_info "Starting Service" systemctl start nginx diff --git a/install/snipeit-install.sh b/install/snipeit-install.sh index d368ff2c3..f824311f2 100644 --- a/install/snipeit-install.sh +++ b/install/snipeit-install.sh @@ -23,45 +23,29 @@ PHP_VERSION="8.3" PHP_MODULE="common,ctype,ldap,fileinfo,iconv,mysql,soap,xsl" P setup_composer fetch_and_deploy_gh_release "snipe-it" "grokability/snipe-it" "tarball" setup_mariadb - -msg_info "Setting up database" -DB_NAME=snipeit_db -DB_USER=snipeit -DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13) -$STD mariadb -u root -e "CREATE DATABASE $DB_NAME;" -$STD mariadb -u root -e "CREATE USER '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS';" -$STD mariadb -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUSH PRIVILEGES;" -{ - echo "SnipeIT-Credentials" - echo "SnipeIT Database User: $DB_USER" - echo "SnipeIT Database Password: $DB_PASS" - echo "SnipeIT Database Name: $DB_NAME" -} >>~/snipeit.creds -msg_ok "Set up database" +MARIADB_DB_NAME="snipeit_db" MARIADB_DB_USER="snipeit" setup_mariadb_db +import_local_ip msg_info "Configuring Snipe-IT" cd /opt/snipe-it cp .env.example .env -IPADDRESS=$(hostname -I | awk '{print $1}') - -sed -i -e "s|^APP_URL=.*|APP_URL=http://$IPADDRESS|" \ - -e "s|^DB_DATABASE=.*|DB_DATABASE=$DB_NAME|" \ - -e "s|^DB_USERNAME=.*|DB_USERNAME=$DB_USER|" \ - -e "s|^DB_PASSWORD=.*|DB_PASSWORD=$DB_PASS|" .env - +sed -i -e "s|^APP_URL=.*|APP_URL=http://$LOCAL_IP|" \ + -e "s|^DB_DATABASE=.*|DB_DATABASE=$MARIADB_DB_NAME|" \ + -e "s|^DB_USERNAME=.*|DB_USERNAME=$MARIADB_DB_USER|" \ + -e "s|^DB_PASSWORD=.*|DB_PASSWORD=$MARIADB_DB_PASS|" .env chown -R www-data: /opt/snipe-it chmod -R 755 /opt/snipe-it export COMPOSER_ALLOW_SUPERUSER=1 $STD composer install --no-dev --optimize-autoloader --no-interaction $STD php artisan key:generate --force -msg_ok "Configured SnipeIT" +msg_ok "Configured Snipe-IT" msg_info "Creating Service" cat </etc/nginx/conf.d/snipeit.conf server { listen 80; root /opt/snipe-it/public; - server_name $IPADDRESS; + server_name $LOCAL_IP; client_max_body_size 100M; index index.php;