Skip to content

Commit 23f65d0

Browse files
authored
Refactor: Snipe-IT (#7081)
* Refactor * Update snipeit.sh * Update
1 parent aece852 commit 23f65d0

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

ct/snipeit.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,24 @@ function update_script() {
2727
msg_error "No ${APP} Installation Found!"
2828
exit
2929
fi
30+
3031
RELEASE=$(curl -fsSL https://api.github.com/repos/snipe/snipe-it/releases/latest | grep '"tag_name"' | sed -E 's/.*"tag_name": "v([^"]+).*/\1/')
31-
if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then
32+
if [[ ! -f ~/.snipe-it ]] || [[ "${RELEASE}" != "$(cat ~/.snipe-it 2>/dev/null)" ]]; then
3233
msg_info "Stopping Services"
3334
systemctl stop nginx
3435
msg_ok "Services Stopped"
3536

37+
msg_info "Creating backup"
38+
mv /opt/snipe-it /opt/snipe-it-backup
39+
msg_ok "Backup created"
40+
41+
fetch_and_deploy_gh_release "snipe-it" "snipe/snipe-it" "tarball"
42+
[[ "$(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
43+
setup_composer
44+
3645
msg_info "Updating ${APP} to v${RELEASE}"
3746
$STD apt-get update
3847
$STD apt-get -y upgrade
39-
mv /opt/snipe-it /opt/snipe-it-backup
40-
temp_file=$(mktemp)
41-
curl -fsSL "https://github.com/snipe/snipe-it/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file"
42-
tar zxf "$temp_file"
43-
mv "snipe-it-${RELEASE}" /opt/snipe-it
4448
cp /opt/snipe-it-backup/.env /opt/snipe-it/.env
4549
cp -r /opt/snipe-it-backup/public/uploads/ /opt/snipe-it/public/uploads/
4650
cp -r /opt/snipe-it-backup/storage/private_uploads /opt/snipe-it/storage/private_uploads
@@ -55,7 +59,6 @@ function update_script() {
5559
$STD php artisan view:clear
5660
chown -R www-data: /opt/snipe-it
5761
chmod -R 755 /opt/snipe-it
58-
rm -rf "$temp_file"
5962
rm -rf /opt/snipe-it-backup
6063
msg_ok "Updated ${APP}"
6164

install/snipeit-install.sh

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ update_os
1515

1616
msg_info "Installing Dependencies"
1717
$STD apt-get install -y \
18-
composer \
1918
git \
20-
nginx \
21-
php8.2-{bcmath,common,ctype,ldap,curl,fileinfo,fpm,gd,iconv,intl,mbstring,mysql,soap,xml,xsl,zip,cli}
19+
nginx
2220
msg_ok "Installed Dependencies"
2321

22+
PHP_VERSION="8.3" PHP_MODULE="common,ctype,ldap,fileinfo,iconv,mysql,soap,xsl" PHP_FPM="YES" setup_php
23+
setup_composer
24+
fetch_and_deploy_gh_release "snipe-it" "snipe/snipe-it" "tarball"
2425
setup_mariadb
2526

2627
msg_info "Setting up database"
@@ -38,12 +39,7 @@ $STD mariadb -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUS
3839
} >>~/snipeit.creds
3940
msg_ok "Set up database"
4041

41-
msg_info "Installing Snipe-IT"
42-
temp_file=$(mktemp)
43-
RELEASE=$(curl -fsSL https://api.github.com/repos/snipe/snipe-it/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
44-
curl -fsSL "https://github.com/snipe/snipe-it/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file"
45-
tar zxf $temp_file
46-
mv snipe-it-${RELEASE} /opt/snipe-it
42+
msg_info "Configuring Snipe-IT"
4743
cd /opt/snipe-it
4844
cp .env.example .env
4945
IPADDRESS=$(hostname -I | awk '{print $1}')
@@ -56,11 +52,9 @@ sed -i -e "s|^APP_URL=.*|APP_URL=http://$IPADDRESS|" \
5652
chown -R www-data: /opt/snipe-it
5753
chmod -R 755 /opt/snipe-it
5854
export COMPOSER_ALLOW_SUPERUSER=1
59-
#$STD composer update --no-plugins --no-scripts
6055
$STD composer install --no-dev --optimize-autoloader --no-interaction
6156
$STD php artisan key:generate --force
62-
echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt"
63-
msg_ok "Installed SnipeIT"
57+
msg_ok "Configured SnipeIT"
6458

6559
msg_info "Creating Service"
6660
cat <<EOF >/etc/nginx/conf.d/snipeit.conf
@@ -84,15 +78,13 @@ server {
8478
}
8579
}
8680
EOF
87-
8881
systemctl reload nginx
89-
msg_ok "Configured Service"
82+
msg_ok "Created Service"
9083

9184
motd_ssh
9285
customize
9386

9487
msg_info "Cleaning up"
95-
rm -f $temp_file
9688
$STD apt-get -y autoremove
9789
$STD apt-get -y autoclean
9890
msg_ok "Cleaned"

0 commit comments

Comments
 (0)