Skip to content

Instantly share code, notes, and snippets.

@ajmasia
Last active April 11, 2021 14:45
Show Gist options
  • Save ajmasia/371ef33b575ccb1a5cb85197682d0bf9 to your computer and use it in GitHub Desktop.
Save ajmasia/371ef33b575ccb1a5cb85197682d0bf9 to your computer and use it in GitHub Desktop.
Install cc-tool script
#!/usr/bin/env bash
CC_TOOL_DIR="$HOME/cc-tool"
packages=("autoconf" "automake" "libusb" "boost" "pkgconfig" "libtool")
function innstall_packages() {
echo "πŸ‘‰ adding homebrew packages"
brew services stop --all
installed_packages=()
for i in "$@"; do
if brew ls --versions "$i" >/dev/null; then
continue
else
tput setaf 6
echo "πŸ‘‰ installing $i package"
tput sgr0
brew install "$i"
installed_packages+=("$i")
fi
done
if [ ${#installed_packages[@]} -eq 0 ]; then
tput setaf 6
echo "πŸ‘‰ no packages needed to be installed"
fi
}
function install_cc_tool {
tput setaf 2
echo "πŸ›  building cc-tool"
tput sgr0
cd "$CC_TOOL_DIR" && ./bootstrap && ./configure && make
}
function show_help {
tput setaf 2
echo "πŸ˜€ some help from https://www.zigbee2mqtt.io/information/flashing_the_cc2531.html"
tput setaf 6
echo "Connect devices: CC debugger --> Downloader cable CC2531 --> CC2531 USB sniffer"
echo "Connect BOTH the CC2531 USB sniffer and the CC debugger to your PC using USB"
echo "If the light on the CC debugger is RED, press the Reset button on the CC debugger. The light on the CC debugger should now turn GREEN"
echo "Download the firmware: https://github.com/Koenkk/Z-Stack-firmware/tree/master/coordinator/Z-Stack_Home_1.2/bin"
echo "Flash your firmware runing: sudo cc-tool -e -w <firmware-file.hex>"
echo "πŸ™‹β€β™‚οΈ Enjoy!!!"
tput sgr0
}
function ctrl_c() {
exit 1
}
trap ctrl_c INT
if [[ -d "$CC_TOOL_DIR" ]]; then
tput setaf 1
echo "⚠️ it seems cc-tool is installed in your user root directory"
exit 1
else
clear
tput setaf 2
echo "πŸš€ installing cc-tool app"
innstall_packages "${packages[@]}"
tput setaf 2
echo "πŸ‘‰ cloning into: '$CC_TOOL_DIR'"
tput sgr0
git clone https://github.com/dashesy/cc-tool.git "$CC_TOOL_DIR"
if install_cc_tool; then
tput setaf 2
echo "πŸŽ‰ cc-tool installation has been completed successfully"
echo "⚠️ add 'export PATH=$PATH:$HOME/cc-tool' to your .zshrc PATH"
tput sgr0
show_help
else
tput setaf 1
echo "πŸ’₯ an error occurred installing the app"
exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment