-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraspi-info-update
More file actions
61 lines (54 loc) · 2.49 KB
/
raspi-info-update
File metadata and controls
61 lines (54 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
#################################################################################
# _ _ __ #
# _ __ __ _ ___ _ __ (_) (_)_ __ / _| ___ #
# | '__/ _` / __| '_ \| |_____| | '_ \| |_ / _ \ #
# | | | (_| \__ \ |_) | |_____| | | | | _| (_) | #
# |_| \__,_|___/ .__/|_| |_|_| |_|_| \___/ #
# |_| #
# #
# #
# MIT License #
# Copyright (c) 2019-2026 Massimo Pissarello #
# #
#################################################################################
# Main Variables
RI="raspi-info"
UPVER=$(curl -sSfL "https://raw.githubusercontent.com/mapi68/$RI/master/version")
# Installation Function
install() {
echo -e "\e[1;33mInstalling latest version $UPVER of $RI...\e[0m"
temp_deb="/tmp/${RI}_latest.deb"
curl -sSfL "https://github.com/mapi68/$RI/raw/master/${RI}_latest.deb" -o "$temp_deb"
if [[ $? -eq 0 ]]; then
sudo apt install -qq -y "$temp_deb" && rm "$temp_deb"
if [[ $? -eq 0 ]]; then
echo -e "\e[1;32mInstallation successful!\e[0m" && echo
else
echo -e "\e[1;31mInstallation failed.\e[0m" && echo
return 1 # Signal an error
fi
else
echo -e "\e[1;31mFailed to download $RI.\e[0m" && echo
return 1 # Signal an error
fi
}
# Check if the program is installed
if ! command -v "$RI" &> /dev/null; then
echo -e "\e[1;33m$RI is not installed on your Raspberry Pi.\e[0m"
exit 1
fi
# Get the installed version
VER=$(dpkg -s "$RI" 2>/dev/null | awk '/^Version:/ {print $2}')
# Check if the installed version is newer or equal to the remote version
if [[ "$VER" == "$UPVER" ]]; then
echo -e "\e[1;32mYou have the latest version $UPVER of $RI: no update needed.\e[0m" && echo
exit 0
elif [[ "$VER" > "$UPVER" ]]; then
echo -e "\e[1;32mYou have a newer version $VER than the remote $UPVER: no update needed.\e[0m" && echo
exit 0
else
# Perform installation if the remote version is newer
install
exit $? # Propagate the exit code of the install function
fi