Last active
January 6, 2025 13:29
-
-
Save kosuke14/6a129119de350d6e93b5d4e1a70e7efd to your computer and use it in GitHub Desktop.
a suggestion for murkmod's future ChromeOS updater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
lsbval() { | |
local key="$1" | |
local lsbfile="${2:-/etc/lsb-release}" | |
if ! echo "${key}" | grep -Eq '^[a-zA-Z0-9_]+$'; then | |
return 1 | |
fi | |
sed -E -n -e \ | |
"/^[[:space:]]*${key}[[:space:]]*=/{ | |
s:^[^=]+=[[:space:]]*:: | |
s:[[:space:]]+$:: | |
p | |
}" "${lsbfile}" | |
} # from rainestorme/murkmod (MIT License) | |
check_chromeos_update() { | |
local appid=$(lsbval CHROMEOS_RELEASE_APPID) | |
local version=$(lsbval CHROMEOS_RELEASE_VERSION) | |
local arch=$(uname -m) | |
local track=$(lsbval CHROMEOS_RELEASE_TRACK) # "stable-channel" | |
local board=$(lsbval CHROMEOS_RELEASE_BOARD) | |
local hardware_class=$(crossystem hwid) | |
local OMAHA_URL="https://tools.google.com/service/update2" | |
local REQUEST_DATA=$(cat <<EOF | |
<?xml version="1.0" encoding="UTF-8"?> | |
<request protocol="3.0" version="ChromeOSUpdate-1.0" updaterversion="0.1.0.0" installsource="ondemandupdate" ismachine="1"> | |
<os platform="ChromeOS" version="$version" sp="$version_$arch" /> | |
<app appid="$appid" version="$version" board="$board" track="$track" hardware_class="$hardware_class"> | |
<updatecheck /> | |
</app> | |
</request> | |
EOF | |
) | |
local response=$(curl -s -X POST -H "Content-Type: application/xml" --data "$REQUEST_DATA" "$OMAHA_URL") | |
local binary_url=$(echo "$response" | grep -o 'codebase="[^"]*"' | sed -e 's/codebase="//' -e 's/"//' | head -n 1) | |
local binary_path=$(echo "$response" | grep 'event="update"' | grep -o 'run="[^"]*"' | sed -e 's/run="//' -e 's/"//' | head -n 1) | |
if [ -z "$binary_path" ]; then | |
return | |
fi | |
echo "$binary_url$binary_path" | |
} | |
check_chromeos_update |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment