Skip to content

Instantly share code, notes, and snippets.

@artynet
Last active January 9, 2016 00:38
Show Gist options
  • Save artynet/77c76cab3a45725b3b9e to your computer and use it in GitHub Desktop.
Save artynet/77c76cab3a45725b3b9e to your computer and use it in GitHub Desktop.
#
# The MIT License (MIT)
#
# Copyright (c) 2015 - Arduino Srl (http://www.arduino.org/) support@arduino.org
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Author : Arturo Rinaldi
# e-mail : arturo@arduino.org
#
# Changelog
#
# v22 : + perfecting overall build mechanism
#
# v17 : + disabling entries for mac64
#
# v16 : + mostly buxfixing; the extension folder is now named ArduinoStudioExt
#
# v15 : + adding mac64 build by previously exporting the enviroment variable OST to mac64
# + cleaning of malicious .DS_Store files
#
# v14 : + check for existing tools dir cointaning all the necessary toolchains and binaries
#
#!/bin/bash
clean () {
[ -d node/node_modules ] && rm -rf node/node_modules 2> /dev/null
[ -d hardware/tools ] && rm -rf hardware/tools 2> /dev/null
}
detectversion () {
[ ! -e package.json ] && exit 0
version=`cat package.json | grep version | awk {'print $2'} | sed s/\"//g | sed s/,//g`
echo ""
echo "version is : "$version
echo ""
sleep 2
}
detectos () {
OS=`uname -s`
if [[ x$OS == xDarwin ]]
then
# OSX
avr="avr-toolchain-mac32-3.4.5-1.zip"
arm="gcc-arm-none-eabi-4.8.3-2014q1-mac.tar.gz"
openocd="OpenOCD-0.9.0-arduino.org-x86_64-apple-darwin13.4.0.tar.bz2"
OS="mac32"
elif [[ x$OS == xMINGW32_NT-6.1 ]] || [[ x$OS == xCYGWIN_NT-6.1 ]] || [[ x$OS == xCYGWIN_NT-6.1-WOW ]] || [[ x$OS == xCYGWIN_NT-6.3-WOW ]]
then
# Windows
avr="avr-toolchain-win32-3.4.5-1.zip"
arm="gcc-arm-none-eabi-4.8.3-2014q1-windows.tar.gz"
openocd="OpenOCD-0.9.0-arduino.org-win32.tar.bz2"
bossac"bossac.exe"
OS="win32"
elif [[ x$OS == xLinux ]]
then
# Detects 32 or 64 bit Linux system
MACHINE=`uname -m`
if [[ $MACHINE == "i686" ]]
then
# Linux 32
avr="avr-toolchain-linux32-3.4.5-1.zip"
arm="gcc-arm-none-eabi-4.8.3-2014q1-linux32.tar.gz"
openocd="OpenOCD-0.9.0-arduino.org-i686-linux-gnu.tar.bz2"
bossac="bossac"
OS=linux32
elif [[ $MACHINE == "x86_64" ]]
then
#Linux 64
avr="avr-toolchain-linux64-3.4.5-1.zip"
arm="gcc-arm-none-eabi-4.8.3-2014q1-linux64.tar.gz"
openocd="OpenOCD-0.9.0-arduino.org-x86_64-linux-gnu.tar.bz2"
bossac="bossac"
OS=linux64
fi
fi
cmsis="CMSIS.zip"
}
nodemodules () {
if [ ! -d node/node_modules ]
then
cd node/
if [[ $OS == "mac32" ]]
then
npm install --build-from-source
elif [[ $OS == "win32" ]]
then
npm install
else
npm install --build-from-source
fi
cd ../
else
echo ""
echo "skipping node modules build"
fi
}
downloadtc () {
mkdir -p hardware/tools
cd hardware/tools
for i in $openocd $arm $avr $cmsis
do
if [ ! -e $1/$i ]
then
wget http://download.arduino.org/tools/"$i" -O $1/$i
fi
cp $1/$i .
if [ ! -e "$1"/"$i".sha1 ]
then
wget http://download.arduino.org/studio/tools/sha1/"$i".sha1 -O "$1"/"$i".sha1
fi
cp $1/$i.sha1 .
if [ $? -eq 1 ]
then
echo ""
echo "Can't find sha1 file !"
echo ""
clean
exit 0
fi
shasum -c "$i".sha1
echo ""
[ $? -eq 1 ] && echo "error sha" && exit 0
done
tar xf $openocd
mkdir -p avr/
unzip -q $avr -d avr
mkdir -p samd/
tar xf $arm -C samd/ --strip-components=1
mkdir -p CMSIS/
unzip -q $cmsis -d CMSIS
rm *.zip *tar.bz2 *.tar.gz *.sha1 2> /dev/null
cd ../../../
echo ""
echo $PWD
}
finalize () {
DIR="ArduinoStudioExt"
chmod -R 755 brackets-arduino/
mv brackets-arduino/ $DIR
find $DIR -name .DS_Store | xargs rm 2> /dev/null
zip -q -r $DIR-$version-$OS.zip $DIR/* -x *.git* *.gitignore* *.DS_Store*
mv $DIR brackets-arduino
cd brackets-arduino/
clean
git reset --hard HEAD
}
if [ ! -d tools/ ]
then
mkdir -p tools/
fi
cd tools/
TOOLS_BIN_PATH=`pwd`
cd -
if [ ! -d brackets-arduino/ ]
then
echo ""
echo -e "Clone the brackets-arduino repo with this command :\n \ngit clone https://github.com/arduino-org/brackets-arduino.git\n\nand then restart the script !"
echo ""
exit 0
else
cd brackets-arduino/
find . -name .DS_Store | xargs rm 2> /dev/null
fi
clean
detectversion
detectos
nodemodules
downloadtc $TOOLS_BIN_PATH
finalize
echo ""
echo "finished"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment