This repository has been archived by the owner on Apr 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-install.sh
613 lines (471 loc) · 15.4 KB
/
post-install.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
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
#!/usr/bin/pwsh
function setstatic {
$writeip = "N"
do {
Clear-Host
Write-Host "NETWORK SETUP"
Write-Host ""
Write-Host ""
Write-Host "Enter IP address in slash notation."
Write-Host "For example: 192.168.199.55/24"
Write-Host ""
$ipcidr = Read-Host
Clear-Host
Write-Host "NETWORK SETUP"
Write-Host ""
Write-Host ""
Write-Host "Enter the gateway address."
Write-Host "For example: 192.168.199.1"
Write-Host ""
$ipgate = Read-Host
Clear-Host
Write-Host "NETWORK SETUP"
Write-Host ""
Write-Host ""
Write-Host "Enter your DNS server address. If multiple, seperate with spaces."
Write-Host "For example: 1.1.1.1 8.8.8.8"
Write-Host ""
$ipdns = Read-Host
Clear-Host
Write-Host "NETWORK SETUP"
Write-Host ""
Write-Host ""
Write-Host "Does this look correct?"
Write-Host ""
Write-Host "IP Address: " $ipcidr
Write-Host "Gateway: " $ipgate
Write-Host "DNS Server(s): " $ipdns
Write-Host ""
Write-host "Write changes? If you're connected via SSH you'll need"
Write-Host "need to reconnect and restart setup (obviously skipping"
$writeip = Read-Host -Prompt "through the network setup you've already done). (Y/N)"
} while ( $writeip -eq "n")
if ($writeip -eq "y") {
mv /etc/dhcpcd.conf /etc/dhcpcd.conf.bak
echo "interface eth0" > /etc/dhcpcd.conf
$dhcpcdl1 = "static ip_address="+$ipcidr
echo $dhcpcdl1 >> /etc/dhcpcd.conf
$dhcpdcl2 = "static routers="+$ipgate
echo $dhcpdcl2 >> /etc/dhcpcd.conf
$dhcpcdl3 = "static domain_name_servers="+$ipdns
echo $dhcpcdl3 >> /etc/dhcpcd.conf
} else {}
}
function changehostname {
$hostnameapply = "n"
do {
Clear-Host
Write-Host "NETWORK SETUP"
Write-Host ""
Write-Host ""
Write-Host "Enter new hostname:"
Write-Host ""
$newhostname = Read-Host
Clear-Host
Write-Host "NETWORK SETUP"
Write-Host ""
Write-Host ""
Write-Host "Does this look correct?"
Write-Host ""
Write-Host "Hostname: " $newhostname
Write-Host ""
$hostnameapply = Read-Host -Prompt "Apply changes? They'll take effect at next reboot. (Y/N)"
} while ($hostnameapply -eq "n")
if ($hostnameapply = "y") {
#hostname file change
mv /etc/hostname /etc/hostname.bak
echo $newhostname > /etc/hostname
#hosts file change
$hostfilel1 = "127.0.0.1`tlocalhost"
$hostfilel2 = "127.0.0.1`t`t" + $newhostname
mv /etc/hosts /etc/hosts.bak
echo $hostfilel1 > /etc/hosts
echo $hostfilel2 >> /etc/hosts
}
else {}
}
function serialsetup {
$usbserialconnected = ls /dev/tty* | grep "USB"
do {
do {
$usbserialconnected = ls /dev/tty* | grep "USB"
if ($usbserialconnected -eq $NULL) {
$usbserialname = "NONE"
} else {
$usbserialname = $usbserialconnected
}
Clear-Host
Write-Host "SERIAL SETUP"
Write-Host ""
Write-Host ""
Write-Host "Detected device: $usbserialname"
Write-Host ""
$serialrescan = "Y"
$serialrescan = Read-Host -Prompt "Would you like to rescan? (Y)/N"
} while ($serialrescan -eq "Y")
if ($serialrescan -eq "n" -and $usbserialconnected -eq $NULL) {
Clear-Host
Write-Host "SERIAL SETUP"
Write-Host ""
Write-Host ""
Write-Host "Serial setup cancelled."
Pause
Break
}
} while ($usbserialconnected -eq $NULL)
if ($usbserialconnected -ne $NULL) {
Clear-Host
Write-Host "SERIAL SETUP"
Write-Host ""
Write-Host ""
Write-Host "Your serial adapter is:" $usbserialconnected " ..................... [x]"
usermod -a -G dialout pi
Write-Host "User `'pi`' added to dialout group .......................... [x]"
systemctl stop supervisor
pkill -f novnc
$confserline = "serialDevice=" + $usbserialconnected.Trim("/dev/")
$DDDConfig = "/.config/DomesdayDuplicator.ini"
(Get-Content $DDDConfig) -replace "serialDevice=", $confserline | Set-Content $DDDConfig
systemctl start supervisor
Write-Host "App preferences set ....................................... [x]"
Write-Host ""
}
}
function cifsclientsetup {
$cifsinstalled = apt-cache policy cifs-utils | grep 'none'
if ($cifsinstalled -ne $NULL) {
apt install cifs-utils
}
$cifsok = "N"
do {
Clear-Host
Write-Host "CIFS SETUP"
Write-Host ""
Write-Host ""
Write-Host "Enter the complete server and share path."
Write-Host "For example: //192.168.11.19/Data/DDDCaps"
Write-Host ""
$cifsserverpath = Read-Host
Clear-Host
Write-Host "CIFS SETUP"
Write-Host ""
Write-Host ""
Write-Host "Enter the username."
Write-Host ""
$cifsusername = Read-Host
Clear-Host
Write-Host "CIFS SETUP"
Write-Host ""
Write-Host ""
Write-Host "Enter the password."
Write-Host ""
$cifspass = Read-Host
Clear-Host
Write-Host "CIFS SETUP"
Write-Host ""
Write-Host ""
if (Test-Path /mnt/dddcifs) {}
else {
mkdir /mnt/dddcifs }
if (mount | grep "dddcifs") {
umount /mnt/dddcifs
}
try {
mount -t cifs -o username=$cifsusername,password=$cifspass $cifsserverpath /mnt/dddcifs
} catch {
Write-Host $Error
$cifsoof = "y"
}
if ($cifsoof -ne "y") {
Write-Host "Success!"
umount /mnt/dddcifs
$fstabexist = Select-String -Path /etc/fstab -Pattern "dddcifs"
if ($fstabexist -ne $NULL) {
(Get-Content /etc/fstab) -notmatch "dddcifs" | Set-Content /etc/fstab
}
$fstabline = $cifsserverpath + " /mnt/dddcifs cifs username=" + $cifsusername + ",password=" + $cifspass + " 0 0"
echo $fstabline >> /etc/fstab
mount -a
$cifsok = "y"
}
pause
} while ( $cifsok -eq "n")
}
function nfsclientsetup {
$nfsinstalled = apt-cache policy nfs-common | grep 'none'
if ($cifsinstalled -ne $NULL) {
apt install nfs-common
}
$nfsok = "N"
do {
Clear-Host
Write-Host "NFS SETUP"
Write-Host ""
Write-Host ""
Write-Host "Enter the complete server and share path."
Write-Host "For example: 192.168.11.19:/DDDCaps"
Write-Host ""
$nfsserverpath = Read-Host
Clear-Host
Write-Host "NFS SETUP"
Write-Host ""
Write-Host ""
Write-Host "Enter the protocol. Normally (and default) TCP."
Write-Host ""
$nfsprotoprompt = Read-Host -Prompt "1) TCP 2) UDP"
if ($nfsprotoprompt -eq "1") {
$nfsproto = "tcp"
}
elseif ($nfsprotoprompt -eq "2") {
$nfsproto = "udp"
}
else {
$nfsproto = "tcp"
}
Clear-Host
Write-Host "CIFS SETUP"
Write-Host ""
Write-Host ""
Write-Host "Enter the port. Typically 2049"
Write-Host ""
$nfsport = Read-Host
Clear-Host
Write-Host "CIFS SETUP"
Write-Host ""
Write-Host ""
if (Test-Path /mnt/dddnfs) {}
else {
mkdir /mnt/dddnfs }
if (mount | grep "dddnfs") {
umount /mnt/dddnfs
}
try {
mount -t nfs -o proto=$nfsproto,port=$nfsport $nfsserverpath /mnt/dddnfs
} catch {
Write-Host $Error
$nfsoof = "y"
}
if ($nfsoof -ne "y") {
Write-Host "Success!"
umount /mnt/dddnfs
$fstabexistnfs = Select-String -Path /etc/fstab -Pattern "dddnfs"
if ($fstabexistnfs -ne $NULL) {
(Get-Content /etc/fstab) -notmatch "dddnfs" | Set-Content /etc/fstab
}
$fstablinenfs = $nfsserverpath + " /mnt/dddnfs nfs proto=" + $nfsproto + ",port=" + $nfsport + " 0 0"
mount -a
echo $fstablinenfs >> /etc/fstab
$nfsok = "y"
}
pause
} while ( $nfsok -eq "n")
}
function localcapconfig {
if ((Test-Path /root/ddd) -eq $False){
mkdir /root/ddd
}
systemctl stop supervisor
pkill -f novnc
$DDDconfcapline = "captureDirectory=/root/ddd"
$DDDConfCap = "/.config/DomesdayDuplicator.ini"
$DDDconfcaplinerep = Get-Content $DDDConfCap | Select-String "captureDirectory=" | Select-Object -ExpandProperty Line
(Get-Content $DDDConfCap) | ForEach-Object {$_ -replace $DDDconfcaplinerep,$DDDconfcapline } | Set-Content $DDDConfCap
systemctl start supervisor
}
$smbconffile = "W2dsb2JhbF0KICAgbG9nIGZpbGUgPSAvdmFyL2xvZy9zYW1iYS9sb2cuJW0KICAgbWF4IGxvZyBzaXplID0gMTAwMAogICBsb2dnaW5nID0gZmlsZQogICBtYXAgdG8gZ3Vlc3QgPSBiYWQgdXNlcgoKW0RvbWVzZGF5IER1cGxpY2F0b3JdCnBhdGggPSAvcm9vdC9kZGQKd3JpdGVhYmxlPVllcwpjcmVhdGUgbWFzaz0wNzc3CmRpcmVjdG9yeSBtYXNrPTA3NzcKcHVibGljPXllcwpndWVzdCBvayA9IHllcwpmb3JjZSB1c2VyID0gcm9vdA=="
Clear-Host
Write-Host "**********************************"
Write-Host "** Thanks for installing DomePi **"
Write-Host "** **"
Write-Host "** This setup will help you **"
Write-Host "** configure DomePi for the **"
Write-Host "** first time. You can always **"
Write-Host "** re-run this script to make **"
Write-Host "** changes to your install. **"
Write-Host "**********************************"
Pause
$currentip = hostname -I
Clear-Host
Write-Host "NETWORK SETUP"
Write-Host ""
Write-Host ""
Write-Host "Current IP:" $currentip
Write-Host ""
Write-Host "Would you like to set a static IP?"
$staticip = Read-Host -Prompt 'Y/(N)'
if ($staticip -eq "y"){
setstatic
}
else {}
$currenthostname = hostname
Clear-Host
Write-Host "NETWORK SETUP"
Write-Host ""
Write-Host ""
Write-Host "Current hostname:" $currenthostname
Write-Host ""
Write-Host "Would you like to change the hostname?"
$changehostname = Read-Host -Prompt 'Y/(N)?'
if ($changehostname -eq "y"){
changehostname
}
else {}
Clear-Host
Write-Host "SERIAL SETUP"
Write-Host ""
Write-Host ""
Write-Host "If you have a USB serial adapter connected,"
Write-Host "DomePi can configure it to communicate with"
Write-Host "the Domesday Duplicator capture application"
Write-Host "and allow controlling your Laserdisc player."
Write-Host ""
$configserial = Read-Host -Prompt "Want to set up serial connectivity? Y/(N)"
if ($configserial -eq "Y") {
serialsetup
}
else {}
do {
$usbvidcapsetup = 0
Clear-Host
Write-Host "USB VIDEO SETUP"
Write-Host ""
Write-Host ""
Write-Host "DomePi can display video-in from your Laserdisc"
Write-Host "player if you have a supported USB capture"
Write-Host "device attached to the USB 2.0 ports."
Write-Host ""
$videoinchoice = Read-Host -Prompt "Want to set up video-in? Y/(N) "
if ($videoinchoice -eq "y"){
apt install mplayer ffmpeg pulseaudio golang
go get -v golang.org/x/net/websocket
"" >> /etc/supervisor/conf.d/supervisord.conf
"[program:pulseaudio]" >> /etc/supervisor/conf.d/supervisord.conf
"command=pulseaudio --start --exit-idle-time=-1" >> /etc/supervisor/conf.d/supervisord.conf
"" >> /etc/supervisor/conf.d/supervisord.conf
"[program:ffmpeg]" >> /etc/supervisor/conf.d/supervisord.conf
"command=ffmpeg -f alsa -i pulse -f mpegts -codec:a mp2 udp://localhost:1234" >> /etc/supervisor/conf.d/supervisord.conf
"" >> /etc/supervisor/conf.d/supervisord.conf
"[program:mplayer]" >> /etc/supervisor/conf.d/supervisord.conf
"command=mplayer tv:// -tv driver=v4l2 -vf scale=400:300 -zoom" >> /etc/supervisor/conf.d/supervisord.conf
<#
$replnovnc = Get-Content -Path "/etc/supervisor/conf.d/supervisord.conf"
$newnovnc = $replnovnc -replace '/usr/share/novnc/utils/launch.sh --vnc localhost:5900 --listen 8080', 'go run main.go --static ./static --vncAddress localhost:5900 --udpAddress :1234'
$newnovnc | Set-Content -Path "/etc/supervisor/conf.d/supervisord.conf"
#>
$usbvidcapsetup = 1
}
if ($videoinchoice -eq "n"){
$usbvidcapsetup = 1
}
}
until ($usbvidcapsetup = 1)
do {
Clear-Host
Write-Host "CAPTURE SETUP"
Write-Host ""
Write-Host ""
Write-Host "DomePi supports capturing to USB3 SSD storage"
Write-Host "and over 1Gb network via CIFS (SMB) and NFS."
Write-Host "If you chose to capture to local storage, you"
Write-Host "will have the option of setting up a network"
Write-Host "share for accessing the capture files."
Write-Host ""
Write-Host "Would you like to capture to local storage or"
$capturechoice = Read-Host -Prompt "over the network? 1) Local 2) Network "
if ($capturechoice -eq "1") {
$capturech = 1
}
elseif ($capturechoice -eq 2) {
$capturech = 2
} else {
$capturech = 3
}
} until ($capturech -eq 1 -or $capturech -eq 2)
if ($capturech -eq 1) {
#check if ssd is used
$sdacheck = blkid | grep "/dev/sda"
<# note, might need to check speed of attached disk if becomes issue:
time for i in `seq 1 1000`; do
dd bs=4k if=/dev/sda count=1 skip=$(( $RANDOM * 128 )) >/dev/null 2>&1;
done
#>
Clear-Host
Write-Host "CAPTURE SETUP"
Write-Host ""
Write-Host ""
if ($sdacheck -eq $NULL) {
Write-Host "You seem to be running DomePi from SD."
Write-Host "Either reflash to an SSD or re-run"
Write-Host "setup and choose Network capture."
exit
}
Write-Host "For local storage, captures will be"
Write-Host "written to the /root/ddd directory"
Write-Host "and then shared out via NFS or CIFS."
do {
Write-Host "Would you like to share via NFS or CIFS?"
$sharechoice = Read-Host -Prompt "1) NFS 2) CIFS "
if ($sharechoice -eq "1") {
$sharech = 1
}
elseif ($sharechoice -eq 2) {
$sharech = 2
} else {
$sharech = 3
}
} until ($sharech -eq 1 -or $sharech -eq 2)
if ($sharech -eq 1) {
localcapconfig
$nfsserverinstalled = apt-cache policy nfs-kernel-server | grep 'none'
if ($nfsserverinstalled -ne $NULL) {
apt install nfs-kernel-server
}
(Get-Content /etc/exports) -notmatch "/root/ddd" | Set-Content /etc/exports
echo "/root/ddd *(rw,all_squash,insecure,async,no_subtree_check,anonuid=0,anongid=0)" >> /etc/exports
exportfs -ra
systemctl restart nfs-kernel-server
Write-Host ""
Write-host "NFS share created."
$nfsservercurrip = hostname -I
$nfsservercurrip = $nfsservercurrip.TrimEnd()
$nfsserverconnstring = "Connection string: " + $nfsservercurrip + ":/root/ddd"
Write-Host $nfsserverconnstring
Write-Host "NFS Version: 3"
}
if ($sharech -eq 2) {
localcapconfig
$cifsserverinstalled = apt-cache policy samba-common-bin | grep 'none'
if ($cifsserverinstalled -ne $NULL) {
echo "samba-common samba-common/workgroup string WORKGROUP" | sudo debconf-set-selections
echo "samba-common samba-common/dhcp boolean true" | sudo debconf-set-selections
echo "samba-common samba-common/do_debconf boolean true" | sudo debconf-set-selections
apt install samba samba-common-bin -y
}
$smbconffiledec = [System.Convert]::FromBase64String($smbconffile)
Set-Content -Path /etc/samba/smb.conf -Value $smbconffiledec -AsByteStream
systemctl restart smbd
Write-Host ""
Write-Host "CIFS share created."
$cifsservercurrip = hostname -I
$cifsservercurrip = $cifsservercurrip.TrimEnd()
$cifsserversharepath = "Share path: \\" + $cifsservercurrip + "\Domesday Duplicator"
Write-Host $cifsserversharepath
}
}
if ($capturech -eq 2) {
do {
Clear-Host
Write-Host "CAPTURE SETUP"
Write-Host ""
Write-Host ""
Write-Host "Do you want to capture via NFS or CIFS (SMB)?"
$capdestchoice = Read-Host -Prompt "1) NFS 2) CIFS "
} until ($capdestchoice -eq "1" -or $capdestchoice -eq "2")
if ($capdestchoice -eq "1") {
nfsclientsetup
}
if ($capdestchoice -eq "2") {
cifsclientsetup
}
}
Remove-Item /etc/cron.d/ledblink