Skip to content

Commit 1de7e42

Browse files
authored
Rework SnipeIT: Tarball & Tempfile (#2963)
* SnipeIT: Change Release to tarball * Update snipeit.sh * Update snipeit-install.sh * Update snipeit.sh
1 parent 60994b6 commit 1de7e42

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

ct/snipeit.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/m
66
# Source: https://snipeitapp.com/
77

88
APP="SnipeIT"
9-
var_tags="assat-management;foss"
9+
var_tags="asset-management;foss"
1010
var_cpu="2"
1111
var_ram="2048"
1212
var_disk="4"
@@ -27,13 +27,20 @@ function update_script() {
2727
msg_error "No ${APP} Installation Found!"
2828
exit
2929
fi
30-
RELEASE=$(curl -s https://api.github.com/repos/snipe/snipe-it/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
30+
RELEASE=$(curl -s https://api.github.com/repos/snipe/snipe-it/releases/latest | grep '"tag_name"' | sed -E 's/.*"tag_name": "v([^"]+).*/\1/')
3131
if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then
32+
msg_info "Stopping Services"
33+
systemctl stop nginx
34+
msg_ok "Services Stopped"
35+
3236
msg_info "Updating ${APP} to v${RELEASE}"
3337
$STD apt-get update
3438
$STD apt-get -y upgrade
3539
mv /opt/snipe-it /opt/snipe-it-backup
36-
cd /opt
40+
temp_file=$(mktemp)
41+
wget -q "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
3744
$STD wget -q "https://github.com/snipe/snipe-it/archive/refs/tags/v${RELEASE}.zip"
3845
unzip -q v${RELEASE}.zip
3946
mv snipe-it-${RELEASE} /opt/snipe-it
@@ -53,9 +60,13 @@ function update_script() {
5360
chmod -R 755 /opt/snipe-it
5461
rm -rf /opt/v${RELEASE}.zip
5562
rm -rf /opt/snipe-it-backup
56-
msg_ok "Updated ${APP} LXC"
63+
msg_ok "Updated ${APP}"
64+
65+
msg_info "Starting Service"
66+
systemctl start nginx
67+
msg_ok "Started Service"
5768
else
58-
msg_ok "No update required. ${APP} is already at v${RELEASE}."
69+
msg_ok "No update required. ${APP} is already at v${RELEASE}"
5970
fi
6071
exit
6172
}
@@ -67,4 +78,4 @@ description
6778
msg_ok "Completed Successfully!\n"
6879
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
6980
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
70-
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}${CL}"
81+
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}${CL}"

install/snipeit-install.sh

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ mysql -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUSH PRIVI
4141
msg_ok "Set up database"
4242

4343
msg_info "Installing Snipe-IT"
44-
cd /opt
45-
RELEASE=$(curl -s https://api.github.com/repos/snipe/snipe-it/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
46-
echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt"
47-
wget -q "https://github.com/snipe/snipe-it/archive/refs/tags/v${RELEASE}.zip"
48-
unzip -q v${RELEASE}.zip
44+
temp_file=$(mktemp)
45+
RELEASE=$(curl -s https://api.github.com/repos/snipe/snipe-it/releases/latest | grep '"tag_name"' | sed -E 's/.*"tag_name": "v([^"]+).*/\1/')
46+
wget -q "https://github.com/snipe/snipe-it/archive/refs/tags/v${RELEASE}.tar.gz" -O $temp_file
47+
tar zxf $temp_file
4948
mv snipe-it-${RELEASE} /opt/snipe-it
50-
5149
cd /opt/snipe-it
5250
cp .env.example .env
5351
IPADDRESS=$(hostname -I | awk '{print $1}')
@@ -59,17 +57,14 @@ sed -i -e "s|^APP_URL=.*|APP_URL=http://$IPADDRESS|" \
5957

6058
chown -R www-data: /opt/snipe-it
6159
chmod -R 755 /opt/snipe-it
62-
63-
6460
export COMPOSER_ALLOW_SUPERUSER=1
6561
$STD composer update --no-plugins --no-scripts
6662
$STD composer install --no-dev --prefer-source --no-plugins --no-scripts
67-
6863
$STD php artisan key:generate --force
64+
echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt"
6965
msg_ok "Installed SnipeIT"
7066

7167
msg_info "Creating Service"
72-
7368
cat <<EOF >/etc/nginx/conf.d/snipeit.conf
7469
server {
7570
listen 80;
@@ -100,7 +95,7 @@ motd_ssh
10095
customize
10196

10297
msg_info "Cleaning up"
103-
rm -rf /opt/v${RELEASE}.zip
98+
rm -f $temp_file
10499
$STD apt-get -y autoremove
105100
$STD apt-get -y autoclean
106101
msg_ok "Cleaned"

0 commit comments

Comments
 (0)