-
Notifications
You must be signed in to change notification settings - Fork 31
/
setupUbuntuSBC.sh
executable file
·674 lines (583 loc) · 27.6 KB
/
setupUbuntuSBC.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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
#!/bin/bash
# AstroPi3 Ubuntu SBC KStars/INDI Configuration Script
# Copyright (C) 2018 Robert Lancaster <[email protected]>
# This script 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 (at your option) any later version.
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
function display
{
echo ""
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "~ $*"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo ""
# This will display the message in the title bar (Note that the PS1 variable needs to be changed too--see below)
echo -en "\033]0;AstroPi3-SetupUbuntuSBC-$*\a"
}
display "Welcome to the AstroPi3 Ubuntu SBC KStars/INDI Configuration Script."
display "This will update, install and configure your Ubuntu System to work with INDI and KStars to be a hub for Astrophotography. Be sure to read the script first to see what it does and to customize it."
if [ "$(whoami)" != "root" ]; then
display "Please run this script with sudo due to the fact that it must do a number of sudo tasks. Exiting now."
exit 1
fi
read -p "Are you ready to proceed (y/n)? " proceed
if [ "$proceed" != "y" ]
then
exit
fi
export USERHOME=$(sudo -u $SUDO_USER -H bash -c 'echo $HOME')
# This changes the UserPrompt for the Setup Script (Necessary to make the messages display in the title bar)
PS1='AstroPi3-SetupUbuntuSBC~$ '
#########################################################
############# Updates
# This uninstalls the upgrades package because it prevents us from updating the system until it is done
# It seems like a good idea, but I wouldn't want it doing that when doing astrophotography and when
# I want to update or upgrade the system, I have to wait for it to stop in order to begin.
sudo apt -y remove unattended-upgrades
# Updates the computer to the latest packages.
display "Updating installed packages"
sudo apt update
sudo apt -y upgrade
sudo apt -y dist-upgrade
#########################################################
############# Configuration for Ease of Use/Access
# This will set your account to autologin. If you don't want this. then put a # on each line to comment it out.
display "Setting account: "$SUDO_USER" to auto login."
##################
sudo --preserve-env bash -c 'cat > /usr/share/lightdm/lightdm.conf.d/60-lightdm-gtk-greeter.conf' <<- EOF
[SeatDefaults]
greeter-session=lightdm-gtk-greeter
autologin-user=$SUDO_USER
EOF
##################
# This will prevent the SBC from turning on the lock-screen / screensaver which can be problematic when using VNC
gsettings set org.gnome.desktop.session idle-delay 0
gsettings set org.mate.screensaver lock-enabled false
# Installs Synaptic Package Manager for easy software install/removal
display "Installing Synaptic and apt-add-repository"
sudo apt -y install synaptic software-properties-common
# This will enable SSH which is apparently disabled on some SBCs by default.
display "Enabling SSH"
sudo apt -y install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh
# This will install and configure network manager and remove dhcpcd5 if installed because it has some issues
# Also the commands below that setup networking depend upon network manager.
display "Installing network manager"
sudo apt -y install network-manager network-manager-gnome
display "Making sure dhcpcd5 is not installed"
if [ -n "$(dpkg -l | grep dhcpcd5)" ]
then
sudo apt purge -y openresolv dhcpcd5
# This should remove the old manager panel from the taskbar
if [ -n "$(grep 'type=dhcpcdui' $USERHOME/.config/lxpanel/LXDE-$SUDO_USER/panels/panel)" ]
then
sed -i "s/type=dhcpcdui/type=space/g" $USERHOME/.config/lxpanel/LXDE-$SUDO_USER/panels/panel
fi
if [ -n "$(grep 'type=dhcpcdui' /etc/xdg/lxpanel/LXDE-$SUDO_USER/panels/panel)" ]
then
sed -i "s/type=dhcpcdui/type=space/g" /etc/xdg/lxpanel/LXDE-$SUDO_USER/panels/panel
fi
if [ -n "$(grep 'type=dhcpcdui' /etc/xdg/lxpanel/LXDE/panels/panel)" ]
then
sed -i "s/type=dhcpcdui/type=space/g" /etc/xdg/lxpanel/LXDE/panels/panel
fi
else
echo "dhcpcd5 is not installed"
fi
# This will set up your Pi to have access to internet with wifi, ethernet with DHCP, and ethernet with direct connection
display "Setting up Ethernet for both link-local and DHCP"
if [ -z "$(ls /etc/NetworkManager/system-connections/ | grep Link\ Local\ Ethernet)" ]
then
read -p "Do you want to give your pi a static ip address so that you can connect to it in the observing field with no router or wifi and just an ethernet cable (y/n)? " useStaticIP
if [ "$useStaticIP" == "y" ]
then
read -p "Please enter the IP address you would prefer. Please make sure that the first two numbers match your client computer's self assigned IP. For Example mine is: 169.254.0.5 ? " IP
if [[ "$IP" =~ ^(([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.){3}([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$ ]] # Note that this formula came from Jon in the thread: https://stackoverflow.com/questions/13777387/check-for-ip-validity
then
echo "IP Address is in correct format, proceeding"
# This will make sure that network manager can manage whether the ethernet connection is on or off and then you can change the connection in network maanager.
if [ -n "$(grep 'managed=false' /etc/NetworkManager/NetworkManager.conf)" ]
then
sed -i "s/managed=false/managed=true/g" /etc/NetworkManager/NetworkManager.conf
fi
# This section should add two connections, one for connecting to ethernet with a router and the other for connecting directly to a computer in the observing field with a Link Local IP
nmcli connection add type ethernet ifname eth0 con-name "Wired DHCP Ethernet" autoconnect yes
nmcli connection modify "Wired DHCP Ethernet" connection.autoconnect-priority 2 # Higher Priority because then it tries DHCP first and then switches to Link Local as a backup
nmcli connection modify "Wired DHCP Ethernet" ipv4.dhcp-timeout 5 # This sets the timeout for DHCP to a much shorter time so you don't have to wait forever for Link Local
nmcli connection modify "Wired DHCP Ethernet" ipv4.may-fail no # I'm not sure why this is needed, but without it, it doesn't seem to want to switch to link local
nmcli connection modify "Wired DHCP Ethernet" connection.autoconnect-retries 2 # These last two might not be necessary, but they might be needed if the global settings are to infinitely retry
nmcli connection modify "Wired DHCP Ethernet" connection.auth-retries 2
nmcli connection add type ethernet ifname eth0 con-name "Link Local Ethernet" autoconnect yes ip4 $IP/24
nmcli connection modify "Link Local Ethernet" connection.autoconnect-priority 1 # Lower priority because this is the backup for when in the observing field
# This will make sure /etc/network/interfaces does not interfere
##################
sudo --preserve-env bash -c 'cat > /etc/network/interfaces' <<- EOF
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
# The loopback network interface
auto lo
iface lo inet loopback
EOF
##################
else
echo "IP Address invalid, the static IP will not be set up. Please configure Network Manager later or run the script again."
fi
else
display "Leaving your IP address to be assigned only by dhcp. Note that you will always need either a router or wifi network to connect to your pi."
fi
else
display "This computer already has been assigned a static ip address. If you need to edit that, please edit the Link Local and Wired DHCP connections in Network Manager or delete them and run the script again."
fi
# This will promt you to install (1) x11vnc, (2) x2go, or (3) no remote access tool
read -p "Do you want to install (1) x11vnc, (2) x2go, or (3) no remote access tool? input (1/2/3)? " remoteAccessTool
if [ "$remoteAccessTool" == "1" ]
then
# Note: RealVNC does not work on non-Raspberry Pi ARM systems as far as I can tell.
# This will install x11vnc instead
sudo apt -y install x11vnc
# This will get the password for VNC
x11vnc -storepasswd /etc/x11vnc.pass
# This will store the service file.
######################
sudo --preserve-env bash -c 'cat > /lib/systemd/system/x11vnc.service' << EOF
[Unit]
Description=Start x11vnc at startup.
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /etc/x11vnc.pass -rfbport 5900 -shared
[Install]
WantedBy=multi-user.target
EOF
######################
# This enables the Service so it runs at startup
sudo systemctl enable x11vnc.service
sudo systemctl daemon-reload
elif [ "$remoteAccessTool" == "2" ]
then
# This will install x2go for Ubuntu
sudo add-apt-repository -y ppa:x2go/stable
sudo apt update
sudo apt install -y x2goserver x2goserver-xsession x2gomatebindings
else
display "No remote access tool will be installed!"
fi
display "Making Utilities Folder with script shortcuts for the Desktop"
# This will make a folder on the desktop with the right permissions for the launchers
if [ ! -d "$USERHOME/Desktop/utilities" ]
then
sudo --preserve-env -H -u $SUDO_USER bash -c 'mkdir -p $USERHOME/Desktop/utilities'
fi
# This will create a shortcut on the desktop in the utilities folder for creating udev rules for Serial Devices.
##################
sudo --preserve-env bash -c 'cat > $USERHOME/Desktop/utilities/SerialDevices.desktop' <<- EOF
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=true
Icon[en_US]=plip
Exec=sudo $(echo $DIR)/udevRuleScript.sh
Name[en_US]=Create Rule for Serial Device
Name=Create Rule for Serial Device
Icon=$(echo $DIR)/icons/plip.png
EOF
##################
sudo chmod +x $USERHOME/Desktop/utilities/SerialDevices.desktop
sudo chown $SUDO_USER:$SUDO_USER $USERHOME/Desktop/utilities/SerialDevices.desktop
# This will create a shortcut on the desktop in the utilities folder for Installing Astrometry Index Files.
##################
sudo --preserve-env bash -c 'cat > $USERHOME/Desktop/utilities/InstallAstrometryIndexFiles.desktop' <<- EOF
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=true
Icon[en_US]=mate-preferences-desktop-display
Exec=sudo $(echo $DIR)/astrometryIndexInstaller.sh
Name[en_US]=Install Astrometry Index Files
Name=Install Astrometry Index Files
Icon=$(echo $DIR)/icons/mate-preferences-desktop-display.svg
EOF
##################
sudo chmod +x $USERHOME/Desktop/utilities/InstallAstrometryIndexFiles.desktop
sudo chown $SUDO_USER:$SUDO_USER $USERHOME/Desktop/utilities/InstallAstrometryIndexFiles.desktop
# This will create a shortcut on the desktop in the utilities folder for Updating the System.
##################
sudo --preserve-env bash -c 'cat > $USERHOME/Desktop/utilities/systemUpdater.desktop' <<- EOF
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=true
Icon[en_US]=system-software-update
Exec=sudo $(echo $DIR)/systemUpdater.sh
Name[en_US]=Software Update
Name=Software Update
Icon=$(echo $DIR)/icons/system-software-update.svg
EOF
##################
sudo chmod +x $USERHOME/Desktop/utilities/systemUpdater.desktop
sudo chown $SUDO_USER:$SUDO_USER $USERHOME/Desktop/utilities/systemUpdater.desktop
# This will create a shortcut on the desktop in the utilities folder for Backing Up and Restoring the KStars/INDI Files.
##################
sudo --preserve-env bash -c 'cat > $USERHOME/Desktop/utilities/backupOrRestore.desktop' <<- EOF
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[en_US]=system-upgrade
Exec=mate-terminal -e '$(echo $DIR)/backupOrRestore.sh'
Name[en_US]=Backup or Restore
Name=Backup or Restore
Icon=$(echo $DIR)/icons/system-upgrade.svg
EOF
##################
sudo chmod +x $USERHOME/Desktop/utilities/backupOrRestore.desktop
sudo chown $SUDO_USER:$SUDO_USER $USERHOME/Desktop/utilities/backupOrRestore.desktop
#########################################################
############# Configuration for Hotspot Wifi for Connecting on the Observing Field
# This will fix a problem where AdHoc and Hotspot Networks Shut down very shortly after starting them
# Apparently it was due to power management of the wifi network by Network Manager.
# If Network Manager did not detect internet, it shut down the connections to save energy.
# If you want to leave wifi power management enabled, put #'s in front of this section
display "Preventing Wifi Power Management from shutting down AdHoc and Hotspot Networks"
##################
sudo --preserve-env bash -c 'cat > /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf' <<- EOF
[connection]
wifi.powersave = 2
EOF
##################
# This will create a NetworkManager Wifi Hotspot File.
# You can edit this file to match your settings now or after the script runs in Network Manager.
# If you prefer to set this up yourself, you can comment out this section with #'s.
# If you want the hotspot to start up by default you should set autoconnect to true.
display "Creating $(hostname -s)_FieldWifi, Hotspot Wifi for the observing field"
if [ -z "$(ls /etc/NetworkManager/system-connections/ | grep $(hostname -s)_FieldWifi)" ]
then
nmcli connection add type wifi ifname '*' con-name $(hostname -s)_FieldWifi autoconnect no ssid $(hostname -s)_FieldWifi
nmcli connection modify $(hostname -s)_FieldWifi 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
nmcli connection modify $(hostname -s)_FieldWifi 802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.psk $(hostname -s)_password
nmcli connection add type wifi ifname '*' con-name $(hostname -s)_FieldWifi_5G autoconnect no ssid $(hostname -s)_FieldWifi_5G
nmcli connection modify $(hostname -s)_FieldWifi_5G 802-11-wireless.mode ap 802-11-wireless.band a ipv4.method shared
nmcli connection modify $(hostname -s)_FieldWifi_5G 802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.psk $(hostname -s)_password
else
echo "$(hostname -s)_FieldWifi is already setup."
fi
# This section will set the new field wifi networks to autoconnect if the other networks don't connect.
display "Configuring Field wifi to autoconnect after wifi fails"
if [ -f /etc/NetworkManager/conf.d/wifi-enable-autohotspot.conf ]
then
echo "Field Wifi autoconnection is already configured, if you want to change it, edit network manager and /etc/NetworkManager/conf.d/wifi-enable-autohotspot.conf"
else
read -p "Do you wish to configure the field wifi hotspot to automatically come up after a certain time if there is no wifi network (y/n)? " autoWifi
if [ "$autoWifi" == "y" ]
then
read -p "What do you want the timeout to be? Mine is 30 seconds: " wifiTimeout
if ! [ "$wifiTimeout" -eq "$wifiTimeout" ] 2> /dev/null
then
echo "The timeout must be an integer number of seconds. Making it 30 instead. You can edit /etc/NetworkManager/conf.d/wifi-enable-autohotspot.conf to change it."
wifiTimeout=30
fi
# This sets both wifi networks to autoconnect with a priority to connect on 5G if available
nmcli connection modify $(hostname -s)_FieldWifi connection.autoconnect yes
nmcli connection modify $(hostname -s)_FieldWifi_5G connection.autoconnect yes
nmcli connection modify $(hostname -s)_FieldWifi connection.autoconnect-priority -10
nmcli connection modify $(hostname -s)_FieldWifi_5G connection.autoconnect-priority -5
# This configuration file will ensure that the wifi networks come up successfully in a reasonable time if the regular wifi fails.
##################
sudo --preserve-env bash -c ' cat > /etc/NetworkManager/conf.d/wifi-enable-autohotspot.conf' <<- EOF
[connection-wifi]
match-device=interface-name:wlan0
ipv4.dhcp-timeout=$wifiTimeout
ipv4.may-fail=no
connection.auth-retries=2
connection.autoconnect-retries=2
EOF
##################
fi
fi
# This will make a link to start the hotspot wifi on the Desktop
##################
sudo --preserve-env bash -c 'cat > $USERHOME/Desktop/utilities/StartFieldWifi.desktop' <<- EOF
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[en_US]=irda
Name[en_US]=Start $(hostname -s) Field Wifi
Exec=nmcli con up $(hostname -s)_FieldWifi
Name=Start $(hostname -s)_FieldWifi
Icon=$(echo $DIR)/icons/irda.png
EOF
##################
sudo chmod +x $USERHOME/Desktop/utilities/StartFieldWifi.desktop
sudo chown $SUDO_USER:$SUDO_USER $USERHOME/Desktop/utilities/StartFieldWifi.desktop
##################
sudo --preserve-env bash -c 'cat > $USERHOME/Desktop/utilities/StartFieldWifi_5G.desktop' <<- EOF
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[en_US]=irda
Name[en_US]=Start $(hostname -s) Field Wifi 5G
Exec=nmcli con up $(hostname -s)_FieldWifi_5G
Name=Start $(hostname -s)_FieldWifi_5G
Icon=$(echo $DIR)/icons/irda.png
EOF
##################
sudo chmod +x $USERHOME/Desktop/utilities/StartFieldWifi_5G.desktop
sudo chown $SUDO_USER:$SUDO_USER $USERHOME/Desktop/utilities/StartFieldWifi_5G.desktop
# This will make a link to restart Network Manager Service if there is a problem or to go back to regular wifi after using the adhoc connection
##################
sudo --preserve-env bash -c 'cat > $USERHOME/Desktop/utilities/StartNmService.desktop' <<- EOF
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[en_US]=preferences-system-network
Name[en_US]=Restart Network Manager Service
Exec=pkexec systemctl restart NetworkManager.service
Name=Restart Network Manager Service
Icon=$(echo $DIR)/icons/preferences-system-network.svg
EOF
##################
sudo chmod +x $USERHOME/Desktop/utilities/StartNmService.desktop
sudo chown $SUDO_USER:$SUDO_USER $USERHOME/Desktop/utilities/StartNmService.desktop
# This will make a link to restart nm-applet which sometimes crashes
##################
sudo --preserve-env bash -c 'cat > $USERHOME/Desktop/utilities/StartNmApplet.desktop' <<- EOF
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[en_US]=preferences-system-network
Name[en_US]=Restart Network Manager Applet
Exec=nm-applet
Name=Restart Network Manager
Icon=$(echo $DIR)/icons/preferences-system-network.svg
EOF
##################
sudo chmod +x $USERHOME/Desktop/utilities/StartNmApplet.desktop
sudo chown $SUDO_USER:$SUDO_USER $USERHOME/Desktop/utilities/StartNmApplet.desktop
# This will support the functions of the next two shortcuts.
display "Setting up Night Vision tools"
sudo apt -y install xcalib
# This will create a link that will turn the screen red to preserve night vision
##################
sudo --preserve-env bash -c 'cat > $USERHOME/Desktop/utilities/NightVisionMode.desktop' <<- EOF
[Desktop Entry]
Version=1.0
Type=Application
Terminal=true
Icon[en_US]=redeyes
Exec=xcalib -red 1 0 100 -green .1 0 1 -blue .1 0 1 -alter
Name[en_US]=Night Vision Mode
Name=Night Vision Mode
Icon=$(echo $DIR)/icons/redeyes.svg
EOF
##################
sudo chmod +x $USERHOME/Desktop/utilities/NightVisionMode.desktop
sudo chown $SUDO_USER:$SUDO_USER $USERHOME/Desktop/utilities/NightVisionMode.desktop
# This will create a link that will turn the screen back to normal
##################
sudo --preserve-env bash -c 'cat > $USERHOME/Desktop/utilities/NormalVisionMode.desktop' <<- EOF
[Desktop Entry]
Version=1.0
Type=Application
Terminal=true
Icon[en_US]=redeyes
Exec=xcalib -clear
Name[en_US]=Normal Vision Mode
Name=Normal Vision Mode
Icon=$(echo $DIR)/icons/blackeyes.svg
EOF
##################
sudo chmod +x $USERHOME/Desktop/utilities/NormalVisionMode.desktop
sudo chown $SUDO_USER:$SUDO_USER $USERHOME/Desktop/utilities/NormalVisionMode.desktop
#########################################################
############# File Sharing Configuration
display "Setting up File Sharing"
# Installs samba so that you can share files to your other computer(s).
sudo apt -y install samba
# Installs caja-share so that you can easily share the folders you want.
#sudo apt -y install caja-share
# Shares the entire user folder instead (much simpler to work with)
if [ ! -f /etc/samba/smb.conf ]
then
sudo mkdir -p /etc/samba/
##################
sudo --preserve-env bash -c 'cat > /etc/samba/smb.conf' <<- EOF
[global]
workgroup = ASTROGROUP
server string = Samba Server
server role = standalone server
log file = /var/log/samba/log.%m
max log size = 50
dns proxy = no
[homes]
comment = Home Directories
browseable = no
read only = no
writable = yes
valid users = $SUDO_USER
EOF
##################
fi
# Adds yourself to the user group of who can use samba, but checks first if you are already in the list
if [ -z "$(sudo pdbedit -L | grep $SUDO_USER)" ]
then
sudo smbpasswd -a $SUDO_USER
sudo adduser $SUDO_USER sambashare
fi
#########################################################
############# Very Important Configuration Items
# This will create a swap file for an increased 2 GB of artificial RAM. This is not needed on all systems, since different cameras download different size images, but if you are using a DSLR, it definitely is.
# This method is disabled in favor of the zram method below. If you prefer this method, you can re-enable it by taking out the #'s
#display "Creating SWAP Memory"
#wget https://raw.githubusercontent.com/Cretezy/Swap/master/swap.sh -O swap
#sh swap 2G
#rm swap
# This will create zram, basically a swap file saved in RAM. It will not read or write to the SD card, but instead, writes to compressed RAM.
# This is not needed on all systems, since different cameras download different size images, and different SBC's have different RAM capacities but
# if you are using a DSLR on a system with 1GB of RAM, it definitely is needed. If you don't want this, comment it out.
display "Installing zRAM for increased RAM capacity"
sudo apt -y install zram-config
# This should fix an issue where modemmanager could interfere with serial connections
display "Removing Modemmanger, which can interfere with serial connections."
sudo apt -y remove modemmanager
# This should fix an issue where you might not be able to use a serial mount connection because you are not in the "dialout" group
display "Enabling Serial Communication"
sudo usermod -a -G dialout $SUDO_USER
#########################################################
############# ASTRONOMY SOFTWARE
# Installs INDI, Kstars, and Ekos bleeding edge and debugging
display "Installing INDI and KStars"
sudo apt-add-repository ppa:mutlaqja/ppa -y
sudo apt update
sudo apt -y install indi-full
sudo apt -y install indi-full kstars-bleeding
sudo apt -y install kstars-bleeding-dbg indi-dbg
# Creates a config file for kde themes and icons which is missing on the Raspberry pi.
# Note: This is required for KStars to have the breeze icons.
display "Creating KDE config file so KStars can have breeze icons."
##################
sudo --preserve-env bash -c 'cat > $USERHOME/.config/kdeglobals' <<- EOF
[Icons]
Theme=breeze
EOF
##################
# Installs the GPS-Daemon (GPSD) and GPSD Clients
# This is necesarry if you have a local GPS dongle attached to your SBC,
# and want to use it to set the coordinates and systemm time.
# (If you don't need this, you can comment this line out with a #)
sudo apt -y install gpsd gpsd-clients
# Installs the General Star Catalog if you plan on using the simulators to test (If not, you can comment this line out with a #)
display "Installing GSC"
sudo apt -y install gsc
# Installs the Astrometry.net package for supporting offline plate solves. If you just want the online solver, comment this out with a #.
display "Installing Astrometry.net"
sudo apt -y install astrometry.net
# Installs PHD2 if you want it. If not, comment each line out with a #.
display "Installing PHD2"
sudo apt-add-repository ppa:pch/phd2 -y
sudo apt update
sudo apt -y install phd2
# Installs PHD2 Log viewer if you want it. If not, comment out with a #.
disdplay "Installing PHD2 Log Viewer"
sudo apt install phdlogview
# This will make a shortcut to PHD Log Viewer. If you aren't installing it, be sure to remove this too.
##################
sudo --preserve-env bash -c 'cat > $USERHOME/Desktop/utilities/PHDLogViewer.desktop' <<- EOF
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[en_US]=phd2
Name[en_US]=PHD Log Viewer
Exec=/usr/bin/phdlogview
Name=PHD Log Viewer
Icon=phd2
EOF
##################
sudo chmod +x $USERHOME/Desktop/utilities/PHDLogViewer.desktop
sudo chown $SUDO_USER $USERHOME/Desktop/utilities/PHDLogViewer.desktop
# This will copy the desktop shortcuts into place. If you don't want Desktop Shortcuts, of course you can comment this out.
display "Putting shortcuts on Desktop"
sudo cp /usr/share/applications/org.kde.kstars.desktop $USERHOME/Desktop/
sudo chmod +x $USERHOME/Desktop/org.kde.kstars.desktop
sudo chown $SUDO_USER:$SUDO_USER $USERHOME/Desktop/org.kde.kstars.desktop
sudo cp /usr/share/applications/phd2.desktop $USERHOME/Desktop/
sudo chmod +x $USERHOME/Desktop/phd2.desktop
sudo chown $SUDO_USER:$SUDO_USER $USERHOME/Desktop/phd2.desktop
#########################################################
############# INDI WEB MANAGER App
display "Installing INDI Web Manager App, indiweb, and python3"
# This will install pip3 and python along with their headers for the next steps
sudo apt -y install python3-pip
sudo apt -y install python3-dev
# Setuptools may be needed in order to install indiweb on some systems
sudo apt -y install python3-setuptools
sudo -H -u $SUDO_USER pip3 install setuptools --upgrade
# Wheel might not be installed on some systems
sudo -H -u $SUDO_USER pip3 install wheel
# This will install indiweb as the user
sudo -H -u $SUDO_USER pip3 install indiweb
#This will install the INDIWebManagerApp in the INDI PPA
sudo apt -y install indiwebmanagerapp
# This will make a link to start INDIWebManagerApp on the desktop
##################
sudo --preserve-env bash -c 'cat > $USERHOME/Desktop/INDIWebManagerApp.desktop' <<- EOF
[Desktop Entry]
Encoding=UTF-8
Name=INDI Web Manager App
Type=Application
Exec=INDIWebManagerApp %U
Icon=$(sudo -H -u $SUDO_USER python3 -m site --user-site)/indiweb/views/img/indi_logo.png
Comment=Program to start and configure INDI WebManager
EOF
##################
sudo chmod +x $USERHOME/Desktop/INDIWebManagerApp.desktop
sudo chown $SUDO_USER:$SUDO_USER $USERHOME/Desktop/INDIWebManagerApp.desktop
##################
#########################################################
############# Configuration for System Monitoring
# This will set you up with conky so that you can see how your system is doing at a moment's glance
# A big thank you to novaspirit who set up this theme https://github.com/novaspirit/rpi_conky
sudo apt -y install conky-all
cp "$DIR/conkyrc" $USERHOME/.conkyrc
sudo chown $SUDO_USER:$SUDO_USER $USERHOME/.conkyrc
#This should dynamically add lines to the conkyrc file based on the number of CPUs found
NUMEROFCPUS=$(grep -c ^processor /proc/cpuinfo)
for (( c=1; c<=$NUMEROFCPUS; c++ ))
do
CPULINE="CPU$c \${cpu cpu$c}% \${cpubar cpu$c}"
echo $CPULINE
sed -i "/\${cpugraph DimGray DarkSlateGray} \$color/i $CPULINE" $USERHOME/.conkyrc
done
# This will put a link into the autostart folder so it starts at login
mkdir -p $USERHOME/.config/autostart
##################
sudo --preserve-env bash -c 'cat > $USERHOME/.config/autostart/startConky.desktop' <<- EOF
[Desktop Entry]
Name=StartConky
Exec=conky -db -p 20
Terminal=false
Type=Application
EOF
##################
# Note that in order to work, this link needs to stay owned by root and not be executable
# This will run a script that should trust the desktop icons in Gnome
su - $SUDO_USER -c "$DIR/trustIconsGnome.sh"
#########################################################
# This will make the utility scripts in the folder executable in case the user wants to use them.
chmod +x "$DIR/udevRuleScript.sh"
chmod +x "$DIR/astrometryIndexInstaller.sh"
chmod +x "$DIR/systemUpdater.sh"
chmod +x "$DIR/backupOrRestore.sh"
display "Script Execution Complete. Your Ubuntu System should now be ready to use for Astrophotography. You should restart your computer."