├── .github └── FUNDING.yml ├── README.md └── haa_downloader.sh /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: ['https://paypal.me/ravensystem'] 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Home Accessory Architect 2 | HAA firmware binary releases. 3 | 4 | [![Latest](https://img.shields.io/github/v/tag/RavenSystem/haa?color=red&label=last+release)](https://github.com/RavenSystem/haa/releases) 5 | 6 | Source code: https://github.com/RavenSystem/esp-homekit-devices 7 | -------------------------------------------------------------------------------- /haa_downloader.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # /-----------------------------------------------------------------------\ 3 | # | HAA Binary File Downloader, | 4 | # | Useful for downloading HAA Binary files for custom OTA update servers | 5 | # | Copyright (C) 2020 AJAX | 6 | # | | 7 | # | This program is free software: you can redistribute it and/or modify | 8 | # | it under the terms of the GNU General Public License as published by | 9 | # | the Free Software Foundation, either version 3 of the License, or | 10 | # | (at your option) any later version. | 11 | # | | 12 | # | This program is distributed in the hope that it will be useful, | 13 | # | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | # | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | # | GNU General Public License for more details. | 16 | # | | 17 | # | https://www.gnu.org/licenses/gpl-3.0.html | 18 | # \-----------------------------------------------------------------------/ 19 | # 20 | download_haa(){ 21 | echo "--------------------------------------------------------" 22 | echo 23 | version_meta=$(curl -s "https://api.github.com/repos/$owner/$repository/releases/tags/$version") 24 | validation=$(echo "$version_meta" | grep -Po '(?<="message": ")[^"]*') 25 | files=($(echo "$version_meta" | grep -Po '(?<="browser_download_url": ")[^"]*')) 26 | 27 | if [ -z "$validation" ] 28 | then 29 | if [ ! -d "$webroot/$repository/$version" ]; then 30 | mkdir "$webroot/$repository/$version" 31 | fi 32 | for i in "${files[@]}" 33 | do 34 | file_name="$(basename $i)" 35 | echo -n "Saving $webroot/$repository/$version/$file_name ... " 36 | curl -sLo "$webroot/$repository/$version/$file_name" "$i" 37 | if [ "$?" -ne 0 ] 38 | then 39 | echo "Failed to retrieve, check connection or user permissions" 40 | else 41 | echo "Done" 42 | fi 43 | done 44 | else 45 | echo "Incorrect Version?" 46 | fi 47 | } 48 | 49 | haa_downloader_config(){ 50 | echo 51 | echo "Setting up config for HAA Downloader" 52 | PS3='Please choose: ' 53 | echo 54 | wr_options=("/var/www/html (Apache, lighthttpd Default)" "/usr/share/nginx/html (Nginx Default" "Custom") 55 | select i in "${wr_options[@]}" 56 | do 57 | case "$i" in 58 | "/var/www/html (Apache, lighthttpd Default)") 59 | webroot="/var/www/html" 60 | if [ ! -d "$webroot" ] 61 | then 62 | echo "Folder doesn't exist, have you got this installed? Please try again..." 63 | echo 64 | continue 65 | fi 66 | ;; 67 | "/usr/share/nginx/html (Nginx Default") 68 | webroot="/usr/share/nginx/html" 69 | if [ ! -d "$webroot" ] 70 | then 71 | echo "Folder doesn't exist, have you got this installed? Please try again..." 72 | echo 73 | continue 74 | fi 75 | ;; 76 | "Custom") 77 | while [ ! -n "$webroot" ] || [ ! -d "$webroot" ] 78 | do 79 | echo -n "Please enter an absolute path to your webroot: " 80 | read webroot 81 | webroot="${webroot%/}" 82 | if [ ! -d "$webroot" ] 83 | then 84 | echo "Invalid Directory, try again..." 85 | echo 86 | fi 87 | done 88 | ;; 89 | *) echo "invalid option $REPLY" 90 | ;; 91 | esac 92 | echo '"web_root": "'"$webroot"'"' > haa_downloader.conf 93 | echo "Setting HAA Folder to: $webroot/$repository" 94 | echo 95 | break 96 | done 97 | } 98 | 99 | haa_downloader_help(){ 100 | echo 101 | echo 102 | echo "Downloading the latest version" 103 | echo "--------------------------------------------------------" 104 | echo 105 | echo " To download the latest version execute the script with no parameters" 106 | echo " 'sudo ./haa_downloader.sh'" 107 | echo " * Will download latest version (ie. 3.3.3) to /haa/3.3.3/" 108 | echo " * Will copy latest version to /haa/" 109 | echo 110 | echo " Example" 111 | echo " sudo ./haa_downloader.sh" 112 | echo 113 | echo 114 | echo "Downloading a specific version" 115 | echo "--------------------------------------------------------" 116 | echo 117 | echo " To download a specific version execute the script with the version flag -v followed by the desired version." 118 | echo " 'sudo ./haa_downloader.sh -v '" 119 | echo 120 | echo " * Will download the requested version (ie 3.3.3) to /haa/3.3.3/" 121 | echo " * Won't overwrite files in the main HAA Folder '/haa/' (Reserved for latest version)" 122 | echo 123 | echo " Example" 124 | echo " sudo ./haa_downloader.sh -v 3.3.3" 125 | echo 126 | echo 127 | echo "Downloading a beta version" 128 | echo "-------------------------------------------------------" 129 | echo 130 | echo " To download the latest beta version execute the script with the beta flag -b" 131 | echo " 'sudo ./haa_downloader.sh -b'" 132 | echo 133 | echo " This can be used in conjunction with the verions flag -v in order to download a custom beta version" 134 | echo " 'sudo ./haa_downloader.sh -bv " 135 | echo 136 | echo " Will download the requested beta version (ie 3.3.3) to /haabeta/3.3.3/" 137 | echo 138 | echo " Example" 139 | echo " sudo ./haa_downloader.sh -bv 3.3.3" 140 | echo 141 | echo 142 | echo "HAA Downloader Setup / Running for the first time" 143 | echo "--------------------------------------------------------" 144 | echo 145 | echo " To configure the folder of your web server you can use the -s flag to enter setup mode" 146 | echo 147 | echo " When running the script for the first time you will automatically enter setup to configure your web servers root file serving path (webroot)" 148 | echo " If you have installed Apache or lighthttpd with default settings you can simply select option 1 or you can set a custom path" 149 | echo 150 | echo " Example" 151 | echo " sudo ./haa_downloader.sh -s" 152 | echo 153 | echo 154 | } 155 | 156 | haa_downloader_usage(){ 157 | echo "sudo ./haa_downloader.sh <---Download Latest Version" 158 | echo "sudo ./haa_downloader.sh -b <---Download the Latest Beta Version" 159 | echo "sudo ./haa_downloader.sh -v <---Download Specific Version" 160 | echo "sudo ./haa_downloader.sh -s <---Run Setup Mode" 161 | echo "sudo ./haa_downloader.sh -h <---Help" 162 | echo 163 | } 164 | ########################################################################################################################################### 165 | echo 166 | echo "=============================================================" 167 | echo "HAA Binary Downloader Copyright (C) 2020 AJAX 168 | This program comes with ABSOLUTELY NO WARRANTY; 169 | This is free software, and you are welcome to redistribute it 170 | under certain conditions. 171 | See the GNU General Public License for more details." 172 | echo "=============================================================" 173 | echo 174 | owner="RavenSystem" 175 | repository="haa" 176 | script_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 177 | while getopts ":hsbv:" arg 178 | do 179 | case "${arg}" in 180 | h) 181 | haa_downloader_help 182 | exit 0 183 | ;; 184 | s) 185 | haa_downloader_config 186 | ;; 187 | b) 188 | repository="haabeta" 189 | ;; 190 | v) 191 | version="$OPTARG" 192 | ;; 193 | :) 194 | echo "$0: Must supply an argument to -$OPTARG." >&2 195 | echo 196 | haa_downloader_usage 197 | exit 1 198 | ;; 199 | ?) 200 | echo "Invalid option: -${OPTARG}." 201 | echo 202 | haa_downloader_usage 203 | exit 2 204 | ;; 205 | esac 206 | done 207 | webroot=$(cat -s "$script_path/haa_downloader.conf" | grep -Po '(?<="web_root": ")[^"]*') 208 | if [ -z "$webroot" ] 209 | then 210 | haa_downloader_config 211 | fi 212 | echo "check if repos exists?" 213 | if [ ! -d "$webroot"/"$repository" ] 214 | then 215 | echo "didn't exist" 216 | mkdir "$webroot/$repository" 217 | fi 218 | echo "done" 219 | if [ -n "$version" ] 220 | then 221 | echo "Attempting to download the specified verion: $version" 222 | download_haa 223 | else 224 | version=$(curl -s "https://api.github.com/repos/$owner/$repository/releases/latest" | grep -Po '(?<="tag_name": ")[^"]*') 225 | echo "Attempting to download the latest version: $version" 226 | download_haa 227 | echo 228 | echo -n "Copying latest files to: " 229 | pwd 230 | echo "--------------------------------------------------------" 231 | echo 232 | cp -v "$webroot"/"$repository"/"$version"/* "$webroot"/"$repository"/ 233 | fi 234 | echo 235 | rate_limit=$(curl -s "https://api.github.com/rate_limit" | grep -Pom 1 '(?<="limit": )[^,}]*') 236 | rate_status=$(curl -s "https://api.github.com/rate_limit" | grep -Pom 1 '(?<="remaining": )[^,}]*') 237 | echo "Github ratelimits unauthenticated request to $rate_limit per hour" 238 | echo "this script uses two calls per run and you have $rate_status remaining" 239 | echo 240 | echo "Complete, exiting" 241 | echo 242 | --------------------------------------------------------------------------------