#!/bin/bash OS=`uname` arch=$(uname -i) archarchlinux=$(uname -m) if [ $# -lt 1 ] then echo "Not enough arguments - exiting" exit 1 fi if [ ${1} != "install-deps" ] && [ ${1} != "build-package" ] && [ ${1} != "update-repo" ] && [ ${1} != "clone-repo" ] then echo "Invalid mode - exiting" exit 1 fi if [[ $arch == unknown ]]; then if [[ $archarchlinux == x86_64* ]]; then echo "X64 Architecture detected" elif [[ $archarchlinux == i*86 ]]; then echo "X32 Architecture detected" elif [[ $archarchlinux == armhf ]]; then echo "ARM Architecture detected" elif [[ $archarchlinux == aarch64 ]]; then echo "64 bit ARM Architecture detected" else if [[ $arch == x86_64* ]]; then echo "X64 Architecture detected" elif [[ $arch == i*86 ]]; then echo "X32 Architecture detected" elif [[ $arch == armhf ]]; then echo "ARM Architecture detected" elif [[ $arch == aarch64 ]]; then echo "64 bit ARM Architecture detected" else echo "Unsupported architecture" exit 1 fi fi fi if [ ${1} = "install-deps" ] ;then #debian echo "Running on Debian" echo "Installing dependencies" codename=$(lsb_release -a | grep Codename | cut -c 11-) echo "Checking if depenencies are installed" # Get the installed Node.js version export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion node_version=$(node -v 2>/dev/null) # Check if Node.js is installed if [ $? -ne 0 ]; then echo "Node.js is not installed, installing latest 20 LTS version" curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion echo "restart your shell and rerun the script" exit 0 fi nvm install 20 nvm use 20 sudo apt update && sudo apt install pkg-config make gcc g++ build-essential libx11-dev libxkbfile-dev libsecret-1-dev git python3 -y || exit 1 if ! type yarn &>/dev/null; then npm install yarn --global || exit 1 fi if ! type go &>/dev/null || ! [ "$(go version | grep -o ' go.* ' | awk -F'.' '{print $2}')" -gt 20 ] ;then filename="go1.23.3.linux-arm64.tar.gz" wget "https://go.dev/dl/$filename" -O "/tmp/$filename" sudo tar -C /usr/local -xzf "/tmp/$filename" rm -f "/tmp/$filename" export PATH=$PATH:/usr/local/go/bin fi fi if [ ${1} = "build-package" ];then cd $HOME/arduino-ide export PATH=$PATH:/usr/local/go/bin export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm node --version nvm use 20 || exit 1 if ! type yarn &>/dev/null; then npm install yarn --global || exit 1 fi echo "building package" # Abort early on error set -eE trap '(\ echo;\ echo \!\!\! An error happened during script execution;\ echo \!\!\! Please check console output for bad sync,;\ echo \!\!\! failed patch application, OOM killer messages, etc.;\ echo\ )' ERR #see https://github.com/arduino/arduino-ide/blob/main/.github/workflows/build.yml#L389 #yarn install #yarn --cwd electron-app rebuild #yarn build npx node-gyp install yarn install --immutable yarn --cwd arduino-ide-extension build yarn --cwd arduino-ide-extension lint yarn --cwd electron-app rebuild yarn --cwd electron-app build yarn --cwd electron-app package #appimage saved to /home/pi/arduino-ide/electron-app/dist/arduino-ide_2.3.4-snapshot-63e9dfd_Linux_arm64.AppImage sudo rm -rf '/opt/Arduino IDE' sudo mv electron-app/dist/linux-arm64-unpacked '/opt/Arduino IDE' fi if [ ${1} = "clone-repo" ] then echo "cloning repo of arduino-ide" cd $HOME git clone --depth 1 https://github.com/arduino/arduino-ide $HOME/arduino-ide cd $HOME/arduino-ide echo "from now on copy the script to the root of the arduino-ide source code to build it" exit 0 fi if [ ${1} = "update-repo" ] then echo "updating repo of arduino-ide" cd $HOME/arduino-ide git pull git merge fi