Skip to content

Instantly share code, notes, and snippets.

@Fail-Safe
Last active May 16, 2024 15:31
Show Gist options
  • Save Fail-Safe/2b33040fcf56e148744cfb43e82ce589 to your computer and use it in GitHub Desktop.
Save Fail-Safe/2b33040fcf56e148744cfb43e82ce589 to your computer and use it in GitHub Desktop.
Downloads the mt7986 firmware files from a given mtk-openwrt-feeds commit hash
#!/bin/sh
if [ $# -eq 0 ]; then
printf "No arguments supplied. Please provide the commit hash for the firmware release you wish to download."
exit 1
fi
# $1 will be the incoming commit hash
fw_url="https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/+archive/${1}/autobuild_mac80211_release/package/kernel/mt76/src/firmware.tar.gz"
orig_pwd="$(pwd)"
fw_path="$orig_pwd/mt7986-firmware"
fw_tmp_path="$fw_path/tmp"
fw_src_file="$fw_tmp_path/fw.tar.gz"
os_name="$(uname)"
cleanup() {
printf " > Cleaning up...\n\n"
rm -r "$fw_tmp_path"
}
printf "> This is a $os_name system\n\n"
printf " > Creating firmware directory...\n\n"
mkdir -p "$fw_tmp_path"
printf " > Pulling requested firmware source at commit: %s...\n\n" "$1"
curl -o "$fw_src_file" "$fw_url"
printf "\n"
printf " > Expanding firmware source...\n\n"
tar -C "$fw_tmp_path" -xzvf "$fw_src_file"
printf "\n"
printf " > Moving mt7986 firmware binaries to %s...\n\n" "$fw_path"
if [ "$os_name" = "Darwin" ]; then
find -E "$fw_tmp_path/" -type f -regex ".*mt7986_(r|w).+\.bin" -exec mv {} "$fw_path/" \;
elif [ "$os_name" = "Linux" ]; then
find "$fw_tmp_path/" -type f -regex ".*mt7986_\(r\|w\).+\.bin" -exec mv {} "$fw_path/" \;
else
printf "Unsupported OS. This can be fixed, but I need more details from you.\n\n"
cleanup
exit 1
fi
cleanup
cd "$orig_pwd" || exit 1
printf "> Done!\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment