diff --git a/ct/snipeit.sh b/ct/snipeit.sh index 2ec54d03e..644d15dc1 100644 --- a/ct/snipeit.sh +++ b/ct/snipeit.sh @@ -27,20 +27,24 @@ function update_script() { msg_error "No ${APP} Installation Found!" exit fi + RELEASE=$(curl -fsSL https://api.github.com/repos/snipe/snipe-it/releases/latest | grep '"tag_name"' | sed -E 's/.*"tag_name": "v([^"]+).*/\1/') - if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then + if [[ ! -f ~/.snipe-it ]] || [[ "${RELEASE}" != "$(cat ~/.snipe-it 2>/dev/null)" ]]; then msg_info "Stopping Services" systemctl stop nginx msg_ok "Services Stopped" + msg_info "Creating backup" + mv /opt/snipe-it /opt/snipe-it-backup + msg_ok "Backup created" + + fetch_and_deploy_gh_release "snipe-it" "snipe/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 + setup_composer + msg_info "Updating ${APP} to v${RELEASE}" $STD apt-get update $STD apt-get -y upgrade - mv /opt/snipe-it /opt/snipe-it-backup - temp_file=$(mktemp) - curl -fsSL "https://github.com/snipe/snipe-it/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file" - tar zxf "$temp_file" - mv "snipe-it-${RELEASE}" /opt/snipe-it cp /opt/snipe-it-backup/.env /opt/snipe-it/.env cp -r /opt/snipe-it-backup/public/uploads/ /opt/snipe-it/public/uploads/ cp -r /opt/snipe-it-backup/storage/private_uploads /opt/snipe-it/storage/private_uploads @@ -55,7 +59,6 @@ function update_script() { $STD php artisan view:clear chown -R www-data: /opt/snipe-it chmod -R 755 /opt/snipe-it - rm -rf "$temp_file" rm -rf /opt/snipe-it-backup msg_ok "Updated ${APP}" diff --git a/install/snipeit-install.sh b/install/snipeit-install.sh index 079893a72..b2d2bb41f 100644 --- a/install/snipeit-install.sh +++ b/install/snipeit-install.sh @@ -15,12 +15,13 @@ update_os msg_info "Installing Dependencies" $STD apt-get install -y \ - composer \ git \ - nginx \ - php8.2-{bcmath,common,ctype,ldap,curl,fileinfo,fpm,gd,iconv,intl,mbstring,mysql,soap,xml,xsl,zip,cli} + nginx msg_ok "Installed Dependencies" +PHP_VERSION="8.3" PHP_MODULE="common,ctype,ldap,fileinfo,iconv,mysql,soap,xsl" PHP_FPM="YES" setup_php +setup_composer +fetch_and_deploy_gh_release "snipe-it" "snipe/snipe-it" "tarball" setup_mariadb msg_info "Setting up database" @@ -38,12 +39,7 @@ $STD mariadb -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUS } >>~/snipeit.creds msg_ok "Set up database" -msg_info "Installing Snipe-IT" -temp_file=$(mktemp) -RELEASE=$(curl -fsSL https://api.github.com/repos/snipe/snipe-it/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') -curl -fsSL "https://github.com/snipe/snipe-it/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file" -tar zxf $temp_file -mv snipe-it-${RELEASE} /opt/snipe-it +msg_info "Configuring Snipe-IT" cd /opt/snipe-it cp .env.example .env IPADDRESS=$(hostname -I | awk '{print $1}') @@ -56,11 +52,9 @@ sed -i -e "s|^APP_URL=.*|APP_URL=http://$IPADDRESS|" \ chown -R www-data: /opt/snipe-it chmod -R 755 /opt/snipe-it export COMPOSER_ALLOW_SUPERUSER=1 -#$STD composer update --no-plugins --no-scripts $STD composer install --no-dev --optimize-autoloader --no-interaction $STD php artisan key:generate --force -echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt" -msg_ok "Installed SnipeIT" +msg_ok "Configured SnipeIT" msg_info "Creating Service" cat </etc/nginx/conf.d/snipeit.conf @@ -84,15 +78,13 @@ server { } } EOF - systemctl reload nginx -msg_ok "Configured Service" +msg_ok "Created Service" motd_ssh customize msg_info "Cleaning up" -rm -f $temp_file $STD apt-get -y autoremove $STD apt-get -y autoclean msg_ok "Cleaned"