Skip to content

Commit 29e34f2

Browse files
committed
adding arduino-linux-setup.sh script
1 parent c6bac06 commit 29e34f2

File tree

2 files changed

+195
-0
lines changed

2 files changed

+195
-0
lines changed

Diff for: build/build.xml

+1
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@
629629

630630
<copy todir="linux/work" file="linux/dist/arduino" />
631631
<copy todir="linux/work" file="linux/dist/install.sh" />
632+
<copy todir="linux/work" file="linux/dist/arduino-linux-setup.sh" />
632633
<copy todir="linux/work" file="linux/dist/uninstall.sh" />
633634

634635
<chmod perm="ugo+x">

Diff for: build/linux/dist/arduino-linux-setup.sh

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# arduino-linux-setup.sh : A simple Arduino setup script for Linux systems
2+
# Copyright (C) 2015 Arduino Srl
3+
#
4+
# Author : Arturo Rinaldi
5+
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+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
#
21+
# Release v6 changelog :
22+
#
23+
# + removing sudocheck function and control
24+
#
25+
# Release v5 changelog :
26+
#
27+
# + adding UDEV rule for stm32 DFU mode
28+
#
29+
# Release v4 changelog :
30+
#
31+
# + The rules are generated in a temporary folder
32+
#
33+
# + the user should run it without sudo while having its permissions
34+
#
35+
# Release v3 changelog :
36+
#
37+
# + The most common linux distros are now fully supported
38+
#
39+
# + now the script checks for SUDO permissions
40+
#
41+
42+
#! /bin/bash
43+
44+
# if [[ $EUID != 0 ]] ; then
45+
# echo This must be run as root!
46+
# exit 1
47+
# fi
48+
49+
refreshudev () {
50+
51+
echo ""
52+
echo "Restarting udev"
53+
echo ""
54+
55+
sudo service udev restart
56+
sudo udevadm control --reload-rules
57+
sudo udevadm trigger
58+
59+
}
60+
61+
groupsfunc () {
62+
63+
echo ""
64+
echo "******* Add User to dialout,tty, uucp, plugdev groups *******"
65+
echo ""
66+
67+
sudo usermod -a -G tty $1
68+
sudo usermod -a -G dialout $1
69+
sudo usermod -a -G uucp $1
70+
sudo groupadd plugdev
71+
sudo usermod -a -G plugdev $1
72+
73+
}
74+
75+
acmrules () {
76+
77+
echo ""
78+
echo "Setting serial port rules"
79+
echo ""
80+
81+
cat <<EOF
82+
"KERNEL="ttyUSB[0-9]*", TAG+="udev-acl", TAG+="uaccess", OWNER="$1"
83+
"KERNEL="ttyACM[0-9]*", TAG+="udev-acl", TAG+="uaccess", OWNER="$1"
84+
EOF
85+
86+
}
87+
88+
openocdrules () {
89+
90+
echo ""
91+
echo "Adding Arduino M0/M0 Pro Rules"
92+
echo ""
93+
94+
cat <<EOF
95+
ACTION!="add|change", GOTO="openocd_rules_end"
96+
SUBSYSTEM!="usb|tty|hidraw", GOTO="openocd_rules_end"
97+
98+
#Please keep this list sorted by VID:PID
99+
100+
#CMSIS-DAP compatible adapters
101+
ATTRS{product}=="*CMSIS-DAP*", MODE="664", GROUP="plugdev"
102+
103+
LABEL="openocd_rules_end"
104+
EOF
105+
106+
}
107+
108+
avrisprules () {
109+
110+
cat <<EOF
111+
SUBSYSTEM!="usb_device", ACTION!="add", GOTO="avrisp_end"
112+
# Atmel Corp. JTAG ICE mkII
113+
ATTR{idVendor}=="03eb", ATTRS{idProduct}=="2103", MODE="660", GROUP="dialout"
114+
# Atmel Corp. AVRISP mkII
115+
ATTR{idVendor}=="03eb", ATTRS{idProduct}=="2104", MODE="660", GROUP="dialout"
116+
# Atmel Corp. Dragon
117+
ATTR{idVendor}=="03eb", ATTRS{idProduct}=="2107", MODE="660", GROUP="dialout"
118+
119+
LABEL="avrisp_end"
120+
EOF
121+
122+
}
123+
124+
dfustm32rules () {
125+
126+
cat <<EOF
127+
# Example udev rules (usually placed in /etc/udev/rules.d)
128+
# Makes STM32 DfuSe device writeable for the "plugdev" group
129+
130+
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE="664", GROUP="plugdev", TAG+="uaccess"
131+
EOF
132+
133+
}
134+
135+
removemm () {
136+
137+
echo ""
138+
echo "******* Removing modem manager *******"
139+
echo ""
140+
141+
if [ -f /etc/lsb-release -a ! -f /etc/SuSE-release ] || [ -f /etc/debian_version ] || [ -f /etc/linuxmint/info ]
142+
then
143+
#Only for Ubuntu/Mint/Debian
144+
sudo apt-get remove modemmanager
145+
elif [ -f /etc/SuSE-release ]
146+
then
147+
#Only for Suse
148+
sudo zypper remove modemmanager
149+
elif [ -f /etc/fedora-release ] || [ -f /etc/redhat-release ]
150+
then
151+
#Only for Red Hat/Fedora/CentOS
152+
sudo yum remove modemmanager
153+
else
154+
echo ""
155+
echo "Your system is not supported, please take care of it with your package manager"
156+
echo ""
157+
fi
158+
159+
}
160+
161+
162+
if [ "$1" = "" ]
163+
then
164+
echo ""
165+
echo "Run the script with command ./arduino-linux-setup.sh \$USER"
166+
echo ""
167+
else
168+
169+
[ `whoami` != $1 ] && echo "" && echo "The user name is not the right one, please double-check it !" && echo "" && exit 1
170+
171+
groupsfunc $1
172+
173+
removemm
174+
175+
mkdir -p $PWD/rulesgen
176+
177+
acmrules $1 > $PWD/rulesgen/90-extraacl.rules
178+
179+
openocdrules > $PWD/rulesgen/98-openocd.rules
180+
181+
avrisprules > $PWD/rulesgen/avrisp.rules
182+
183+
dfustm32rules > $PWD/rulesgen/40-dfuse.rules
184+
185+
sudo mv $PWD/rulesgen/*.rules /etc/udev/rules.d/
186+
187+
rm -rf $PWD/rulesgen
188+
189+
refreshudev
190+
191+
echo ""
192+
echo "*********** Please Reboot your system ************"
193+
echo ""
194+
fi

0 commit comments

Comments
 (0)