forked from treehouses/builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autorunonce
209 lines (177 loc) · 6.45 KB
/
autorunonce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
# ----- BASIC CONFIGURATIONS: -----
# Sets hostname to a desirable name
# (default: treehouses)
hostname='treehouses'
# If "button", bluetooth is enabled unless GPIO 18 is pulled to ground
# If "normal", bluetooth is always on.
# If "off", bluetooth is always off
# (Default: button)
bluetooth="button"
# If true, this allows trusted treehouses team members to log on to the system without a password
# It will search for key pairs or authorized_key files directly in /boot folder to incorporate in the ssh server
# (default: true)
treehousesteamsshkeys="true"
addauthorizedkey=""
# ----- INTERNET CONFIGURATIONS: -----
# Options for connectiontype:
# "ethernet" connects to ethernet only
# "wifi" connects to an existing router
# "apinternet" turns the raspberry pi into a hotspot with internet connection
# "aplocal" turns the raspberry pi into a hotspot without internet connection
# "bridge" connects to an existing router, creates a raspberry pi hotspot and bridges these two connections.
connectiontype="apinternet"
# Change this value to true if you are using a hidden network
# (default: false)
hidden="false"
# wifiname: Insert the name (SSID) of your wifi router
# wifipassword: Insert the password of your wifi router. Leave field empty for open networks
# (Edit if "connectiontype" is "wifi" or "bridge")
wifiname=''
wifipassword=''
# for Enterprise only, please leave it blank if you are not using WPA2-Enterprise
identity=''
# hotspotname: Change to the name you want your hotspot to have, raspberry pi will be a hotspot with this name as SSID
# hotspotpassword:
# Insert the password you want your Raspberry Pi hotspot to have. Can be blank for no password (open network)
# Passwords must be 8 characters or more. If your password has less, it will be configured as open network
# (Edit if "connectiontype" is "apinternet", "aplocal" or "bridge")
hotspotname='treehouses'
hotspotpassword=''
# ----- OTHER CONFIGURATION: -----
# startvnc: If true, it starts vnc and gui (default: false)
startvnc="false"
# starttor: If true, it starts a tor hidden service (default: false)
# starttornotice: If true, publishes these addresses to treehouses gitter or "tornoticeurl" (default: false)
starttor="false"
starttornotice="false"
tornoticeapiurl=""
# startplanet: If true, this starts the docker service (default: true)
# updateplanet: If true, this updates the planet to the latest revision (default: false)
startplanet="true"
updateplanet="false"
# enablecoralboard: If true, this enables the use of the Coral Enviro board. (default: false)
# startcoralenvirodemo: If true, this starts the demo on Coral Enviro board. (default: false)
enablecoralenviroboard="false"
startcoralenvirodemo="false"
# No need to edit below this line
#----------------------------------------------------------------------------------------------------#
# sets the desired hostname for your raspberry pi
treehouses rename $hostname
# expands the filesystem
treehouses expandfs
# configures the wifi antenna of the raspberry pi
if [ ! $(treehouses detect wifi) ]; then connectiontype="ethernet"; fi; # default network when no wifi
if [ ${#hotspotpassword} -lt 8 ]; then hotspotpassword=''; fi; # no password if the password is < 8 characters long
case $connectiontype in
"ethernet")
;;
"wifi")
if [ "$hidden" == "false" ]; then
if [ -z $identity ]; then
treehouses wifi $wifiname $wifipassword
else
treehouses wifi $wifiname $wifipassword $identity
fi
else
if [ -z $identity ]; then
treehouses wifihidden $wifiname $wifipassword
else
treehouses wifihidden $wifiname $wifipassword $identity
fi
fi;;
"apinternet")
if [ "$hidden" == "false" ]; then
treehouses ap internet $hotspotname $hotspotpassword
else
treehouses aphidden internet $hotspotname $hotspotpassword
fi;;
"aplocal")
if [ "$hidden" == "false" ]; then
treehouses ap local $hotspotname $hotspotpassword
else
treehouses aphidden local $hotspotname $hotspotpassword
fi;;
"bridge")
treehouses bridge $wifiname $hotspotname $wifipassword $hotspotpassword;;
*)
echo "Unsupported configuration. Switching to default ap internet config";
treehouses ap internet treehouses;;
esac
# disables button for bluetooth if Coral Env board is present, or constant bluetooth is selected
if [ $bluetooth != "off" ] && [ $(treehouses detect bluetooth) ]; then
if [ $bluetooth = "button" ] && [ $enablecoralenviroboard = "false" ]; then
treehouses button bluetooth
else
treehouses bluetooth on
fi
fi
# starts vnc and gui services
if [ $startvnc = "true" ]; then
treehouses vnc on
fi
# starts tor service
if [ $starttor = "true" ]; then
treehouses tor add 22
if [ $startplanet = "true" ]; then
treehouses tor add 80
treehouses tor add 2200
fi
sleep 10
sync
if [ $starttornotice = "true" ]; then
if [ ${#tornoticeapiurl} -ge 0 ]; then
treehouses tor notice delete
treehouses tor notice add $tornoticeapiurl
fi
treehouses tor notice on
fi
sync
sleep 10
fi
# updates planet if there is an internet connection
if [ $updateplanet = "true" ] && [ "$(treehouses internet)" ]; then
docker pull treehouses/planet:latest
docker pull treehouses/planet:db-init
docker tag treehouses/planet:latest treehouses/planet:local
docker tag treehouses/planet:db-init treehouses/planet:db-init-local
fi
# removes treehouses team members sshkeys and places keys to .ssh folder
if [ $treehousesteamsshkeys = "false" ]; then
treehouses sshkey deleteall
fi
if [[ ! -z $addauthorizedkey ]]; then
treehouses sshkey add $addauthorizedkey
fi
# starts planet
if [ $startplanet = "true" ]; then
{
echo "#!/bin/sh"
echo
echo "if [ \"$(treehouses container)\" = \"balena\" ]; then"
echo " export DOCKER_HOST=localhost:2375"
echo "fi"
echo "sleep 1"
echo
echo "planet_autorun=true"
echo
echo "if [ \"\$planet_autorun\" = true ]; then"
echo " treehouses services planet up"
echo "fi"
} > /boot/autorun
mv /srv/tenalp /srv/planet
sync;sync;sync
treehouses services planet up
fi
# starts coral environmental board demo
if [ "$startcoralenvirodemo" = "true" ] && [ -e /sys/bus/iio/devices/iio:device0 ]; then
treehouses coralenv demo-always-on
fi
# boots to console if RPiZero or RPi3A+ (not enough RAM?)
case "$(treehouses detect rpi)" in
RPIZW|RPI3A+)
treehouses bootoption console;;
esac
if [ "$(treehouses rebootneeded)" = "true" ]; then
reboot
fi