|
| 1 | + #!/bin/bash |
| 2 | +# Copyright (C) 2020, Raffaello Bonghi <[email protected]> |
| 3 | +# All rights reserved |
| 4 | +# Redistribution and use in source and binary forms, with or without |
| 5 | +# modification, are permitted provided that the following conditions are met: |
| 6 | +# 1. Redistributions of source code must retain the above copyright |
| 7 | +# notice, this list of conditions and the following disclaimer. |
| 8 | +# 2. Redistributions in binary form must reproduce the above copyright |
| 9 | +# notice, this list of conditions and the following disclaimer in the |
| 10 | +# documentation and/or other materials provided with the distribution. |
| 11 | +# 3. Neither the name of the copyright holder nor the names of its |
| 12 | +# contributors may be used to endorse or promote products derived |
| 13 | +# from this software without specific prior written permission. |
| 14 | +# |
| 15 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
| 16 | +# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, |
| 17 | +# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 19 | +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 24 | +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 25 | +# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | + |
| 27 | +red=`tput setaf 1` |
| 28 | +green=`tput setaf 2` |
| 29 | +reset=`tput sgr0` |
| 30 | + |
| 31 | +# Check if a path is included |
| 32 | +if [ -z $1 ] ; then |
| 33 | + echo "${red}Require to pass a path!${reset}" |
| 34 | + exit 1 |
| 35 | +fi |
| 36 | +# Get path |
| 37 | +LIBRARY_PATH="$1/libraries" |
| 38 | +# Library to download |
| 39 | +AUTHOR=$2 |
| 40 | +REPOSITORY=$3 |
| 41 | +# Get latest release from GitHub api, Get tag line |
| 42 | +echo "Find last version of $AUTHOR $REPOSITORY" |
| 43 | +TAG_VERSION=$(curl --silent "https://api.github.com/repos/$AUTHOR/$REPOSITORY/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') |
| 44 | +# Print version |
| 45 | +echo "Download $TAG_VERSION last version $REPOSITORY" |
| 46 | +# Download Adafruit library |
| 47 | +if [ ! -d "$LIBRARY_PATH" ] ; then |
| 48 | + echo "Make folder $LIBRARY_PATH" |
| 49 | + mkdir "$LIBRARY_PATH" |
| 50 | +fi |
| 51 | +# Download latest version |
| 52 | +wget --output-document "$LIBRARY_PATH/latest.tar.gz" "https://github.com/$AUTHOR/$REPOSITORY/archive/$TAG_VERSION.tar.gz" |
| 53 | +# Unzip file |
| 54 | +tar -xf "$LIBRARY_PATH/latest.tar.gz" -C "$LIBRARY_PATH" |
| 55 | +# Remove file |
| 56 | +rm "$LIBRARY_PATH/latest.tar.gz" |
| 57 | +# Rename folder |
| 58 | +mv "$LIBRARY_PATH/$REPOSITORY-$TAG_VERSION" "$LIBRARY_PATH/$REPOSITORY" |
| 59 | +# Download complete |
| 60 | +echo "${green}$REPOSITORY added in $LIBRARY_PATH ${reset}" |
| 61 | +# EOF |
0 commit comments