-
Notifications
You must be signed in to change notification settings - Fork 3
/
firmware
executable file
·149 lines (137 loc) · 3.79 KB
/
firmware
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
# Define some color variables
YELLOW='\033[1m\033[38;5;226m'
PEACH='\e[1;38;2;255;204;153m'
GREEN='\033[1m\033[38;2;0;255;0m'
RED='\033[1m\033[38;5;196m'
NC='\033[0m' # No Color
# Function to check if fwupdmgr is available
check_fwupdmgr() {
if command -v fwupdmgr >/dev/null; then
return 0
else
echo -e "${RED}Error: fwupdmgr is not installed.${NC}"
read -rp "Do you want to install fwupdmgr? (Y/n): " install_choice
case $install_choice in
[yY]*)
install_fwupdmgr
;;
*)
chmod +x manager
./manager
;;
esac
fi
}
# Function to install fwupdmgr
install_fwupdmgr() {
echo -e "${GREEN}Installing fwupdmgr...${NC}"
sleep 1
# Add installation commands based on the package manager used by the system
if command -v apt >/dev/null; then
sudo apt update && sudo apt install fwupd -y
elif command -v dnf >/dev/null; then
sudo dnf install fwupd -y
elif command -v yum >/dev/null; then
sudo yum install fwupd -y
elif command -v zypper >/dev/null; then
sudo zypper install fwupd
elif command -v pacman >/dev/null; then
sudo pacman -S fwupd
else
echo -e "${RED}Sorry, I don't know how to install fwupdmgr on your system.${NC}"
sleep 3
chmod +x manager
./manager
fi
}
# Function to display a menu with options
display_menu() {
clear
echo ""
COLUMNS=$(tput cols)
t1="====================="
t2="Firmware Manager"
printf "${YELLOW}%*s\n${NC}" $(((${#t1} + $COLUMNS) / 2)) "$t1"
printf "${YELLOW}%*s\n${NC}" $(((${#t2} + $COLUMNS) / 2)) "$t2"
printf "${YELLOW}%*s\n${NC}" $(((${#t1} + $COLUMNS) / 2)) "$t1"
echo ""
echo -e "${PEACH}Select Your Choice:${NC}"
echo " 1. Check for Firmware Updates"
echo " 2. Download and Install Firmware Updates"
echo " 3. Show More Info about Firmware Updates"
echo " 4. Refresh Metadata"
echo " 5. Rollback Firmware"
echo " 6. Go Back To Main Menu"
echo ""
echo -n "Enter your choice: "
}
# Function to check for firmware updates
check_firmware_updates() {
check_fwupdmgr
echo ""
echo -e "${GREEN}Checking for Firmware Updates...${NC}"
sleep 1
fwupdmgr get-devices
sleep 1
read -rp "Press Enter to continue..."
}
# Function to download and install firmware updates
install_firmware_updates() {
check_fwupdmgr
echo ""
echo -e "${GREEN}Downloading and Installing Firmware Updates...${NC}"
sleep 1
sudo fwupdmgr update
sleep 1
read -rp "Press Enter to continue..."
}
# Function to show more information about firmware updates
show_more_info() {
check_fwupdmgr
echo ""
echo -e "${GREEN}Showing More Information about Firmware Updates...${NC}"
sleep 1
sudo fwupdmgr get-updates
sleep 1
read -rp "Press Enter to continue..."
}
# Function to refresh metadata
refresh_metadata() {
check_fwupdmgr
echo ""
echo -e "${GREEN}Refreshing Firmware Metadata...${NC}"
sleep 1
sudo fwupdmgr refresh --force
sleep 1
read -rp "Press Enter to continue..."
}
# Function to perform a firmware rollback
perform_rollback() {
check_fwupdmgr
echo ""
echo -e "${GREEN}Performing Firmware Rollback...${NC}"
sleep 1
sudo fwupdmgr downgrade
sleep 1
read -rp "Press Enter to continue..."
}
# Go back to main menu
main_menu() {
chmod +x manager
./manager
}
# Main loop
while true; do
display_menu
read -r choice
case $choice in
1) check_firmware_updates ;;
2) install_firmware_updates ;;
3) show_more_info ;;
4) refresh_metadata ;;
5) perform_rollback ;;
6) main_menu ;;
*) echo "" && echo -e "${RED}Invalid choice. Please try again.${NC}" && sleep 3 ;;
esac
done