Repository navigation
Expand file tree
/
Copy pathgravity-fwupdate
More file actions
executable file
·78 lines (64 loc) · 1.78 KB
/
Copy pathgravity-fwupdate
File metadata and controls
executable file
·78 lines (64 loc) · 1.78 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
# SPDX-License-Identifier: MIT
set -eu
unset PYTHON
[ -e /etc/default/gravity-fwupdate ] && . /etc/default/gravity-fwupdate
: "${GRAVITYFW:=}"
: "${VENDORFW:=}"
: "${VENDORFWTMP:=/run/.vendorfw-tmp}"
: "${PYTHON:=/usr/bin/python3}"
: "${FWEXTRACT:=gravity-fwextract}"
: "${GRAVITY_MACHINE:=}"
if [ -e "$(dirname "$0")"/functions.sh ]; then
. "$(dirname "$0")"/functions.sh
else
. /usr/share/gravity-scripts/functions.sh
fi
umount=false
cleanup() {
status=$?
rm -rf "$VENDORFWTMP" "$VENDORFW.new"
if "$umount"; then
umount /run/.system-efi || true
fi
return "$status"
}
trap cleanup EXIT
trap 'exit 1' HUP INT TERM
if [ -z "$GRAVITYFW" ] && [ -z "$VENDORFW" ]; then
mount_sys_esp /run/.system-efi
GRAVITYFW="/run/.system-efi/gravity/"
VENDORFW="/run/.system-efi/vendorfw"
umount=true
fi
if [ ! -e "${GRAVITYFW}/all_firmware.tar.gz" ]; then
echo "No firmware tarball found, skipping extraction"
exit 0
fi
if [ -z "$GRAVITY_MACHINE" ] && [ -r /proc/device-tree/compatible ]; then
if tr '\0' '\n' < /proc/device-tree/compatible | grep -qx 'apple,j773g'; then
GRAVITY_MACHINE=j773g
fi
fi
if [ -z "$GRAVITY_MACHINE" ]; then
echo "Unable to select a Gravity firmware machine profile" >&2
exit 1
fi
rm -rf "$VENDORFWTMP" "$VENDORFW.new"
mkdir -p "$VENDORFWTMP"
echo "Upgrading vendor firmware package"
"$FWEXTRACT" "$GRAVITYFW" "$VENDORFWTMP" \
--machine "$GRAVITY_MACHINE" --open-firmware /usr/lib/firmware
mv "${VENDORFWTMP}" "$VENDORFW".new
if [ -e "$VENDORFW" ]; then
rm -rf "$VENDORFW.old"
mv "$VENDORFW" "$VENDORFW.old"
fi
if mv "$VENDORFW.new" "$VENDORFW"; then
rm -rf "$VENDORFW.old"
else
[ ! -e "$VENDORFW.old" ] || mv "$VENDORFW.old" "$VENDORFW"
exit 1
fi
echo "Firmware upgraded"
true