-
Notifications
You must be signed in to change notification settings - Fork 4
/
brcr-update
executable file
·111 lines (109 loc) · 4.65 KB
/
brcr-update
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
#!/bin/bash
export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/opt/bin:/usr/local/bin"
nothing_new=0
trapcom() {
sudo rm -rf "$workdir"; exit 1
}
trap trapcom SIGTERM SIGINT
workdir="/usr/local/brcr_updater"
url="https://dl.google.com/dl/edgedl/chromeos/recovery/recovery.json"
github="https://api.github.com/repos/sebanc/brunch/releases"
#all=0; for num in $(lsblk -b --output FSAVAIL -z -P -n $(rootdev -d) | sed '/FSAVAIL=""/d' | cut -d '"' -f 2); do
#all=$(( num / 1000 / 1000 / 1000 + all )); done
#if (( "$all" < 5 )); then
# echo "WARNING: There is less than 5 gigabytes of free space left on your device. The installation may fail. Continue? (Enter for yes, Ctrl+C for no)"
# read -p "> "
#fi
[ -d "$workdir" ] || sudo mkdir -p "$workdir"
[ -n "$(uname -m | grep "i.*86")" ] && { echo "ERROR: your device CPU is x86. Latest brunch is incompatible with x86.)"; exit 1; }
cd $workdir
echo "===> Downloading recovery.json file"
sudo curl --progress-bar -S -L -o "$workdir"/recovery.json "$url" || exit 2
board="$(grep "CHROMEOS_RELEASE_DESCRIPTION=.*" "/etc/lsb-release" | rev | cut -d " " -f 1,2 | rev)"
board=$board
board="${board% *}"
echo "===> Downloading brunch releases information"
sudo curl --progress-bar -S -L -o "$workdir"/github "$github" || exit 2
echo "===> Parsing..."
string="$(grep -o '"url":.*/chromeos_.*_'${board}'_.*.bin\..*"' recovery.json | sort -V | tail -n 1)"
info_string="$(grep -A 6 --max-count 1 "$string" ./recovery.json)"
build_num="$(echo "$info_string" | grep --max-count 1 -o '"version":.*' | sed 's/^[[:blank:]]*//' | cut -d " " -f 2- | tr -d '",')"
build_url="$(echo "$string" | sed 's/^[[:blank:]]*//' | cut -d " " -f 2- | tr -d '",')"
cur_version="$(grep "CHROMEOS_RELEASE_VERSION=.*" "/etc/lsb-release" | cut -d "=" -f 2)"
cur_brunch="$(cut -d " " -f 2- /etc/brunch_version)"
cur_brunch="${cur_brunch// /-}"
cur_cros="$(grep "CHROMEOS_RELEASE_CHROME_MILESTONE=.*" "/etc/lsb-release" | cut -d "=" -f 2)"
cros="$(echo "$info_string" | grep --max-count 1 -o '"chrome_version":.*' | sed 's/^[[:blank:]]*//' | cut -d " " -f 2- | tr -d '",' | cut -d "." -f 1)"
_brunch="$(cat ./github | grep -A 45 '"tag_name":.*r'${cros}'-stable.*')"
if [ -z "$_brunch" ]; then
echo -e "\e[0;31mThe brunch update for r${cur_cros} version of Chrome OS has not yet been released\e[0m"
exit 0
fi
brunch="$(echo "$_brunch" | head -n 1 | sed 's/^[[:blank:]]*//' | cut -d " " -f 2- | tr -d '",')"
brunch_url="$(echo "$_brunch" | grep --max-count 1 -o '"browser_download_url":.*' | sed 's/^[[:blank:]]*//' | cut -d " " -f 2- | tr -d '",')"
if [[ -z "$brunch_url" || -z "$build_url" ]]; then
echo -e "\e[0;31mERROR: Failed to get url for brunch/recovery download. Check your internet connection, and if everything is fine, open an issue on GitHub\e[0m"
echo 'Debug output (attach this to issue)'
echo '----------'
cat <<EOF
brunch_url: "$brunch_url"
build_url: "$build_url"
cur_cros: "$cur_cros"
cros: "$cros"
string: "$string"
build_num: "$build_num"
board: "$board"
cur_brunch: "$cur_brunch"
brunch: "$brunch"
EOF
exit 1
fi
echo "Board name: "$board""
echo ''
echo "Latest ChromeOS build: "$build_num""
echo "Current ChromeOS build: "$cur_version""
echo "Latest ChromeOS version: "$cros""
echo "Current ChromeOS version: "$cur_cros""
echo ''
echo "Latest available brunch: "$brunch""
echo "Current brunch: "$cur_brunch""
echo ''
brunch_step1="${brunch%%-*}"
brunch_step2="${brunch##*-}"
brunch_compare="${cur_brunch##*-}"
brunch_step3="${brunch_step1}-${brunch_step2}"
if [[ "$build_num" != "$cur_version" ]] && (( ${cur_version//./} < ${build_num//./} )); then
echo -e "New version of \e[1;36mCh\e[1;31mr\e[1;33mo\e[1;32mme\e[0;36mOS\e[0m available!"
nothing_new=0
else
nothing_new=1
fi
if [[ "$brunch_step3" != "$cur_brunch" ]] && (( ${brunch_compare} < ${brunch_step2} )) ; then
echo -e "New version of \e[0;31mbrunch\e[0m available!"
nothing_new=0
else
nothing_new=1
fi
echo ""
if [ "$nothing_new" == 1 ]; then
echo -e "\e[1mNothing to update...\e[0m"
text="Ctrl+C"
text2="cancel"
else
text="Enter"
text2="continue"
fi
echo -e "Click \e[0;33m${text}\e[0m to ${text2}"
read -p "> "
echo "===> Downloading brunch $brunch"
sudo curl --progress-bar -S -L -o "$workdir/$(echo $brunch_url | grep -o "[^/]*$")" "$brunch_url"
echo "===> Downloading ChromeOS $build_num"
sudo curl --progress-bar -S -L -o "$workdir/chromeos.bin.zip" "$build_url"
echo "===> Unpacking ChromeOS .zip archive..."
sudo unzip "$workdir/chromeos.bin.zip" || exit 2
sudo mv "$workdir/chromeos_"* "$workdir/chromeos.bin" || exit 2
echo "===> Updating..."
sudo chromeos-update -f "$workdir/$(echo $brunch_url | grep -o "[^/]*$")" -r "$workdir/chromeos.bin"
echo "===> Done!"
echo "---> Cleaning up..."
sudo rm -rf "$workdir"