forked from JohnForecast/RaspbianDECnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildAndInstall.sh
575 lines (506 loc) · 15.1 KB
/
BuildAndInstall.sh
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
#!/bin/sh
#******************************************************************************
# (C) John Forecast [email protected]
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#******************************************************************************
# Shell script to download and build DECnet on Raspbian and piOS.
#
# This file should be placed in, an initially empty, directory which will
# be used to hold the source files for the Linux kernel and DECnet. If it
# finds the Linux or the DECnet source tree present, it will ask if it
# should down load a new version.
#
# When invoking this script it is possible to override certain features
# by setting environment variables:
#
# branch=xxx ./BuildAndInstall.sh
#
# The following overrides are available:
#
# branch=name Use the specified branch when downloading the
# Linux kernel source tree
#
# forcekernel=name Force the build to generate the specified kernel
# This is only valid when running on a 32-bit kernel
# and "name" can be one of the following:
#
# kernel - Original Pi, Zero and Compute Module
# kernel7 - Pi 2, Pi 3 and Compute Module 3
# kernel7l - Pi 4 and Compute Module 4
APTGET=/usr/bin/apt-get
CAT=/bin/cat
CHMOD=/bin/chmod
CP=/bin/cp
CUT=/usr/bin/cut
DATE=/bin/date
DPKG=/usr/bin/dpkg
EXPR=/usr/bin/expr
GIT=/usr/bin/git
GREP=/bin/grep
MAKE=/usr/bin/make
MV=/bin/mv
PRINTF=/usr/bin/printf
PWD=/bin/pwd
RM=/bin/rm
SED=/bin/sed
SUDO=/usr/bin/sudo
TRUE=/bin/true
Here=`$PWD`
Log=$Here/Log
NoRPI=1
Model=
Revision=
RealModel=
Arch=`uname -m`
ArchDir=arm
ArchSw=
CPUSw=-j1
Kernel=
BootKernel=
Config=
LinuxDownload=1
DECnetDownload=1
DECnetConfig=1
Pause=1
Name=
Addr=
Area=0
Node=0
Interface=
BranchSw=
#
# Useful functions
#
check_addr() {
if [ ! -z "$1" ]; then
if [ `$EXPR $1 : '[0-9]*\.[0-9]*'` -ne "`$EXPR length $1`" ]; then
echo "Node address must be in the format area.node"
return 0
fi
AreaNo=`echo $1 | $CUT -d. -f1`
NodeNo=`echo $1 | $CUT -d. -f2`
if [ "$AreaNo" -le 0 -o "$AreaNo" -ge 64 ]; then
echo "Area must be between 1 and 63 inclusive"
return 0
fi
if [ "$NodeNo" -le 0 -o "$NodeNo" -ge 1024 ]; then
echo "Node must be between 1 and 1023 inclusive"
return 0
fi
return 1
fi
return 0
}
check_name() {
if [ "`$EXPR length $1`" -le 6 ]; then
if [ `$EXPR $1 : '[0-9a-zA-Z]*'` -ne "`$EXPR length $1`" ]; then
echo "DECnet node names may be up to 6 alphanumeric characters"
return 0
fi
return 1
fi
return 0
}
check_interface() {
$GREP -q "$1:" /proc/net/dev
if [ $? -ne 0 ]; then
echo "Can't find device $1 on your system. Choose one of the following:"
awk '/.*:/ { print substr($1,0,index($1, ":")) }' < /proc/net/dev
return 0
fi
return 1
}
DOCMD() {
echo "$1" >> $Log
$1 >> $Log 2>&1
return $?
}
if [ -e /sys/firmware/devicetree/base/model ]; then
$GREP -q "^Raspberry Pi" /sys/firmware/devicetree/base/model
NoRPI=$?
fi
if [ $NoRPI -ne 0 ]; then
echo "This script is not running on a Raspberry Pi"
exit 1
fi
#
# Handle some command-line overrides
#
if [ ! -z "$branch" ]; then
BranchSw="--branch=$branch"
fi
#
# Make sure all the packages we will need are installed
#
echo "Checking required packages are installed"
for pkg in git bc bison flex libssl-dev make libncurses-dev
do
$SUDO $DPKG -s $pkg >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -n "Installing $pkg .... "
$SUDO $APTGET install -y $pkg >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to install package '" $pkg "'"
exit 1
fi
echo
fi
done
#
# Determine which model/revision we're running on
#
temp=`$CUT -d " " -f 3- /sys/firmware/devicetree/base/model`
echo $temp | $GREP -q "Rev"
if [ $? -eq 0 ]; then
Model=`echo $temp | awk '{ sub(" Rev .*$", "", $0); print $0 }'`
Revision=`echo $temp | awk '{ sub("^.* Rev ", "", $0); print $0 }'`
else
Model=$temp
fi
RealModel=$Model
if [ ! -z "$forcekernel" ]; then
Model=$forcekernel
fi
#
# Determine which kernel we need to build
#
if [ "$Arch" != "aarch64" ]; then
Kernel=zImage
case $Model in
"Model A"*|"Model B"*|"Zero"*|"Compute Module"|kernel)
case $RealModel in
"Model A"*|"Model B"*|"Zero"*|"Compute Module")
;;
*)
CPUSw=-j4
;;
esac
BootKernel=kernel
Config=bcmrpi_defconfig
;;
"2 Model"*|"3 Model"*|"Compute Module 3"*|kernel7)
CPUSw=-j4
BootKernel=kernel7
Config=bcm2709_defconfig
;;
"4 Model"*|"Compute Module 4"*|kernel7l)
CPUSw=-j4
BootKernel=kernel7l
Config=bcm2711_defconfig
;;
*)
echo "Unknown Raspberry Pi model - '" $temp "'"
echo "This script may need updating"
exit 1
esac
else
Kernel=Image
BootKernel=kernel8
Config=bcm2711_defconfig
ArchDir=arm64
ArchSw="ARCH=arm64"
CPUSw=-j4
fi
## Temp for debug
#echo "Model: " $RealModel
#echo "Revision: " $Revision
#if [ ! -z "$forcekernel" ]; then
# echo "Forcekernel: " $forcekernel
#fi
#echo "Kernel: " $Kernel
#echo "BootKernel: " $BootKernel
#echo "Config: " $Config
#echo "Build switches: " $ArchSw " " $CPUSw
##
if [ -d ./linux ]; then
while $TRUE ; do
echo "There appears to be an existing linux source tree present"
echo "Do you want to:"
echo " 1 - Delete existing tree, download a new one and build"
echo " 2 - Clean and rebuild using the existing tree"
echo " 3 - Rebuild using the existing tree"
echo " 4 - Install the kernel/modules/dtbs already built in the existing tree"
echo " 5 - Don't bother to build or install the kernel/modules/dtbs"
echo
read -p "Enter code (1 - 5): " LinuxDownload Junk
if [ "$Junk" = "" ]; then
case $LinuxDownload in
1|2|3|4|5)
break
;;
esac
fi
echo "Invalid Response"
echo
done
fi
if [ -d ./RaspbianDECnet ]; then
while $TRUE ; do
echo
echo "There appears to be an existing DECnet source tree present"
echo "Do you want to:"
echo " 1 - Delete existing tree, download a new one and build"
echo " 2 - Clean and rebuild using the existing tree"
echo " 3 - Rebuild using the existing tree"
echo " 4 - Install the DECnet utilties already built in the existing tree"
echo " 5 - Don't bother to build or install the DECnet utilities"
echo
read -p "Enter code (1 - 5): " DECnetDownload Junk
if [ "$Junk" = "" ]; then
case $DECnetDownload in
1|2|3|4|5)
break
;;
esac
fi
echo "Invalid Response"
echo
done
fi
if [ -z "$forcekernel" ]; then
if [ -e /etc/decnet.conf ]; then
while $TRUE ; do
echo
echo "There appears to to an existing DECnet configuration present"
echo "Do you want to:"
echo " 1 - Delete the existing configuration files and create new ones"
echo " 2 - Use the existing configuration files"
echo
read -p "Enter code (1 - 2): " DECnetConfig Junk
if [ "$Junk" = "" ]; then
case $DECnetConfig in
1|2)
break
;;
esac
fi
echo "Invalid Response"
echo
done
fi
else
DECnetConfig=3
fi
if [ -z "$forcekernel" ]; then
echo
while $TRUE; do
echo "When the build completes, do you want to:"
echo " 1 - Install the new kernel and DECnet on this system"
echo " 2 - Pause before installing the new kernel and DECnet on this system"
echo " 3 - Terminate this script"
read -p "Enter code (1 - 3): " PostBuild Junk
if [ "$Junk" = "" ]; then
case $PostBuild in
1|2|3)
break
;;
esac
fi
echo "Invalid Response"
echo
done
else
PostBuild=3
fi
DefaultName=`hostname -s | cut -b1-6`
DefaultAddr="1.1"
DefaultInterface="eth0"
if [ $PostBuild -ne 3 -a $DECnetConfig -eq 1 ]; then
echo
while $TRUE; do
read -p "Enter your DECnet node address [$DefaultAddr] : " Addr
if [ -z "$Addr" ]; then
Addr=$DefaultAddr
fi
check_addr $Addr
if [ $? -eq 1 ]; then break; fi
done
Area=$AreaNo
Node=$NodeNo
while $TRUE; do
read -p "Enter your DECnet node name [$DefaultName] : " Name
if [ -z "$Name" ]; then
Name=$DefaultName
fi
check_name $Name
if [ $? -eq 1 ]; then break; fi
done
while $TRUE; do
read -p "Enter your Ethernet/Wireless interface name [$DefaultInterface] : " Interface
if [ -z "$Interface" ]; then
Interface=$DefaultInterface
fi
check_interface $Interface
if [ $? -eq 1 ]; then break; fi
done
$CP /dev/null /tmp/nodes$$
echo
echo "You may now set up some other DECnet nodes on your network. When you"
echo "have finished, press [ENTER] when prompted for the node address."
echo
while $TRUE; do
echo
while $TRUE; do
read -p "Enter the node's address: area.node (e.g. 1.1) : " remaddr
if [ -z "$remaddr" ]; then
break 2
fi
check_addr $remaddr
if [ $? -eq 1 ]; then break; fi
done
while $TRUE; do
read -p "Enter its node name : " remname
check_name $remname
if [ $? -eq 1 ]; then break; fi
done
printf >>/tmp/nodes$$ "node %-7s name %-6s\n" $remaddr $remname
done
fi
echo
echo "All questions have been answered"
if [ $LinuxDownload -ne 5 -a $DECnetDownload -ne 5 ]; then
echo "The download/build log will be in $Log"
fi
start=`$DATE`
echo "Kernel/DECnet build started at $start\n" > $Log
if [ $LinuxDownload -eq 1 ]; then
DOCMD "$RM -rf linux"
DOCMD "$GIT clone --depth=1 $BranchSw https://github.com/raspberrypi/linux"
if [ $? -ne 0 ]; then
echo "git failed to clone linux repository"
exit 1
fi
DOCMD "cd $Here/linux"
DOCMD "$MAKE $ArchSw $Config"
if [ $? -ne 0 ]; then
echo "Failed to make default configuration"
exit 1
fi
$SED '
/CONFIG_DECNET is not set/ c\
CONFIG_DECNET=m\
# CONFIG_DECNET_ROUTER is not set\
# CONFIG_DECNET_NF_GRABULATOR is not set
' <.config >.config.new
$MV .config .config.old
$MV .config.new .config
fi
if [ $DECnetDownload -eq 1 ]; then
DOCMD "cd $Here"
DOCMD "$RM -rf RaspbianDECnet"
DOCMD "$GIT clone https://github.com/JohnForecast/RaspbianDECnet"
if [ $? -ne 0 ]; then
echo "git failed to clone RaspbianDECnet repository"
exit 1
fi
fi
if [ $LinuxDownload -le 3 ]; then
DOCMD "cd $Here"
DOCMD "$CP ./RaspbianDECnet/kernel/include/net/*.h ./linux/include/net"
DOCMD "$RM -rf ./linux/net/decnet"
DOCMD "$CP -r ./RaspbianDECnet/kernel/net/decnet ./linux/net"
DOCMD "cd $Here/linux"
if [ $LinuxDownload -le 2 ]; then
DOCMD "$MAKE clean"
fi
DOCMD "$MAKE $CPUSw $ArchSw $Kernel modules dtbs"
if [ $? -ne 0 ]; then
echo "Kernel make failed"
exit 1
fi
fi
if [ $DECnetDownload -le 3 ]; then
DOCMD "cd $Here/RaspbianDECnet/dnprogs"
if [ $DECnetDownload -le 2 ]; then
DOCMD "$MAKE clean"
fi
DOCMD "$MAKE $CPUSw all"
if [ $? -ne 0 ]; then
echo "DECnet Utilities make failed"
exit 1
fi
if [ "$Arch" != "aarch64" ]; then
for a in armv6l armv7 armv7l; do
if [ "$Arch" != "$a" ]; then
ln -sf $Arch libvaxdata/linux/$a
fi
done
fi
ln -sf $Arch libvaxdatalin
fi
echo "Kernel and/or DECnet Utilities build complete"
case $PostBuild in
1)
;;
2)
read -p "Press [ENTER] when ready" Junk
;;
3)
exit 0
;;
esac
if [ $LinuxDownload -le 4 ]; then
DOCMD "cd $Here/linux"
DOCMD "$SUDO $MAKE modules_install"
if [ $? -ne 0 ]; then
echo "Kernel modules install failed"
exit 1
fi
if [ "$Arch" = "aarch64" ]; then
DOCMD "$SUDO $CP arch/$ArchDir/boot/dts/broadcom/*.dtb /boot"
else
DOCMD "$SUDO $CP arch/$ArchDir/boot/dts/*.dtb /boot"
fi
DOCMD "$SUDO $CP arch/$ArchDir/boot/dts/overlays/*.dtb* /boot/overlays"
DOCMD "$SUDO $CP arch/$ArchDir/boot/dts/overlays/README /boot/overlays"
DOCMD "$SUDO $CP arch/$ArchDir/boot/$Kernel /boot/$BootKernel.img"
fi
if [ $DECnetDownload -le 4 ]; then
DOCMD "cd $Here/RaspbianDECnet/dnprogs"
DOCMD "$SUDO $MAKE install"
if [ $? -ne 0 ]; then
echo "DECnet Utilities install failed"
exit 1
fi
fi
if [ $DECnetConfig -eq 1 ]; then
NodeAddr=`expr \( $Area \* 1024 \) + $Node`
byte4=`$EXPR $NodeAddr % 256`
byte5=`$EXPR $NodeAddr / 256`
$PRINTF >/tmp/$$.link "[Match]\n"
$PRINTF >>/tmp/$$.link "OriginalName=%s\n\n" $Interface
$PRINTF >>/tmp/$$.link "[Link]\n"
$PRINTF >>/tmp/$$.link "MACAddress=aa:00:04:00:%02x:%02x\n" $byte4 $byte5
$PRINTF >>/tmp/$$.link "NamePolicy=kernel database onboard slot path\n"
$SUDO $MV /tmp/$$.link /etc/systemd/network/00-mac.link
$CAT >/tmp/$$.conf <<EOF
#V001.0
# DECnet hosts file
#
#Node Node Name Node Line Line
#Type Address Tag Name Tag Device
#----- ------- ----- ----- ----- ------
EOF
printf >>/tmp/$$.conf "executor %-7s name %-6s line %s\n" $Addr $Name $Interface
$CAT /tmp/nodes$$ >>/tmp/$$.conf
$RM /tmp/nodes$$
$SUDO $MV /tmp/$$.conf /etc/decnet.conf
$SUDO $CHMOD 644 /etc/decnet.conf
fi
echo
echo "Kernel and/or DECnet Utilities successfully installed"
echo
echo "You may still need to decide how to start up DECnet - see section 6 of"
echo "README.Raspbian in $Here/RaspbianDECnet"
echo "A reboot is required to change MAC addresses and clear out any"
echo "currently loaded DECnet module"
echo