-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathastroarch_build.sh
More file actions
322 lines (256 loc) · 13.9 KB
/
astroarch_build.sh
File metadata and controls
322 lines (256 loc) · 13.9 KB
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
# Exit on the first error, if any
set -e
# Grab the OS architecture for further forked logic
ARCH=$(uname -m)
HAS_VIRT=$(command -v systemd-detect-virt >/dev/null 2>&1 && echo 1 || echo 0)
# Parallelize pacman download to 5 and use pacman as progress bar
if [ "$HAS_VIRT" -eq 0 ]; then
sed -i 's|#ParallelDownloads = 5|ParallelDownloads = 5|g' /etc/pacman.conf
sed -i 's|ParallelDownloads = 5|ParallelDownloads = 5\nILoveCandy|g' /etc/pacman.conf
sed -i 's|ParallelDownloads = 5|ParallelDownloads = 5\nDisableDownloadTimeout|g' /etc/pacman.conf
fi
# Add astroarch pacman repo to pacman.conf (it must go first)
if [ "$HAS_VIRT" -eq 0 ]; then
sed -i 's|\[core\]|\[astromatto\]\nSigLevel = Optional TrustAll\nServer = http://astroarch.astromatto.com:9000/$arch\n\n\[core\]|' /etc/pacman.conf
fi
# Bootstrap pacman-key
pacman-key --init && pacman-key --populate archlinuxarm
# Update all packages now
pacman -Syu --noconfirm
# Install just 2 packages for the next actions
# list of commented locales
pacman -S wget sudo git --noconfirm
# create user astro with home, add it to wheel
useradd -G wheel -m astronaut
echo "astronaut:astro" | chpasswd
# Pull the brain repo, this will be used for scripting out the final image
su astronaut -c "git clone https://github.com/devDucks/astroarch.git /home/astronaut/.astroarch"
# Uncomment en_US UTF8 and generate locale files
sed -i -e 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
locale-gen
# If we are on QEMU, packages have already been pulled in the docker phase - install only the pi kernel
if [ "$HAS_VIRT" -eq 1 ]; then
pacman -Syu linux-rpi linux-rpi-headers linux-firmware --noconfirm --ask 4
else
pacman -Syu base-devel pipewire-jack gnu-free-fonts wireplumber \
zsh plasma-desktop sddm networkmanager xf86-video-dummy \
network-manager-applet networkmanager-qt xorg konsole \
gpsd breeze-icons hicolor-icon-theme knewstuff tigervnc \
knotifyconfig kplotting qt6-datavis3d qt5-quickcontrols \
qt6-websockets qtkeychain stellarsolver xf86-video-fbdev \
xplanet plasma-nm dhcp dnsmasq kate plasma-systemmonitor \
dolphin uboot-tools usbutils cloud-guest-utils samba paru \
websockify novnc astrometry.net gsc kstars phd2 packagekit-qt6 \
indi-3rdparty-libs indi-3rdparty-drivers linux-rpi linux-rpi-headers \
i2c-tools indiserver-ui astro_dmx openssl-1.1 firefox chrony \
ksystemlog discover kwalletmanager kgpg qt6-serialbus \
qt6-serialport qt6ct udisks2 xorg-fonts-misc fuse2 \
fortune-mod cowsay pacman-contrib arandr neofetch \
astromonitor kscreen sddm-kcm flatpak plasma-x11-session \
kdialog jq astroarch-onboarding dhcpcd iw rsync --noconfirm --ask 4
fi
# Allow wheelers to sudo without password to install packages
sed -i 's/# %wheel ALL=(ALL:ALL) NOPASSWD: ALL/%wheel ALL=(ALL:ALL) NOPASSWD: ALL/g' /etc/sudoers
# Add astronaut to uucp for serial device ownership
usermod -aG uucp,sys,network,power,audio,input,lp,storage,video,users astronaut
# Add sddm user to video group
usermod -aG video sddm
# Allow x11 forwarding over SSH
sed -i 's/#AllowTcpForwarding yes/AllowTcpForwarding yes/g' /etc/ssh/sshd_config
sed -i 's/#X11DisplayOffset 10/X11DisplayOffset 10/g' /etc/ssh/sshd_config
sed -i 's/#X11UseLocalhost yes/X11UseLocalhost yes/g' /etc/ssh/sshd_config
# Install AUR packages
su astronaut -c "paru -Sy xrdp xorgxrdp --noconfirm"
# Make all necessary folders
mkdir /etc/sddm.conf.d
su astronaut -c "mkdir -p /home/astronaut/.config"
su astronaut -c "mkdir -p /home/astronaut/Pictures/wallpapers"
su astronaut -c "mkdir -p /home/astronaut/Desktop"
# install oh-my-zsh and set the default shell to zsh
chsh -s /usr/bin/zsh astronaut
rm /home/astronaut/.bash*
cd /home/astronaut
ZSH=/home/astronaut/.oh-my-zsh sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
chown -R astronaut:astronaut /home/astronaut/.oh-my-zsh/
# Set the samba pass
ln -s /home/astronaut/.astroarch/configs/smb.conf /etc/samba/smb.conf
systemctl start smb
(echo astro; echo astro) | smbpasswd -s -a astronaut
systemctl stop smb
# Link a zsh config for astronaut
ln -s /home/astronaut/.astroarch/configs/.zshrc /home/astronaut/.zshrc
# NetworkManager WiFi Power Saving
ln -s /home/astronaut/.astroarch/configs/default-wifi-powersave-off.conf /etc/NetworkManager/conf.d
# Start NetworkManager and sleep to create the hotspot
systemctl start NetworkManager
sleep 5
# Remove eventually existing systemd configs we are going to substitute
rm -f /usr/lib/systemd/system/novnc.service
# Synchronize the system time with the GPS if there is no Real Time Clock (RTC) or network connection to the Raspberry Pi
sed -i '$a\refclock SHM 0 offset 0.5 delay 0.2 refid NMEA' /etc/chrony.conf
sed -i '$a\driftfile /var/lib/chrony/drift' /etc/chrony.conf
# Disable systemd-timesyncd and enable chronyd
systemctl disable systemd-timesyncd
systemctl enable chronyd
# Symlink now files
ln -s /home/astronaut/.astroarch/configs/kde_settings.conf /etc/sddm.conf.d/kde_settings.conf
ln -s /home/astronaut/.astroarch/systemd/novnc.service /usr/lib/systemd/system/novnc.service
ln -s /home/astronaut/.astroarch/systemd/x0vncserver.service /etc/systemd/system/x0vncserver.service
ln -s /home/astronaut/.astroarch/systemd/resize_once.service /etc/systemd/system/resize_once.service
ln -s /home/astronaut/.astroarch/configs/.astroarch.version /home/astronaut/.astroarch.version
ln -s /home/astronaut/.astroarch/systemd/x0vncserver-xrdp.service /etc/systemd/user/x0vncserver-xrdp.service
# Copy xorg config
cp /home/astronaut/.astroarch/configs/xorg.conf /etc/X11/
# Copy v3d X config
cp /home/astronaut/.astroarch/configs/99-v3d.conf /etc/X11/xorg.conf.d
# Copy udev rule to disable wifi power saving
cp /home/astronaut/.astroarch/configs/81-wifi-powersave.rules /etc/udev/rules.d/81-wifi-powersave.rules
# Polkit rules go here
cp /home/astronaut/.astroarch/configs/99-polkit-power.rules /etc/polkit-1/rules.d/
cp /home/astronaut/.astroarch/configs/50-udiskie.rules /etc/polkit-1/rules.d/
cp /home/astronaut/.astroarch/configs/50-networkmanager.rules /etc/polkit-1/rules.d/
# Copy the systemd unit to create the AP the first boot
cp /home/astronaut/.astroarch/systemd/create_ap.service /etc/systemd/system/
# Enable vncserver
systemctl enable x0vncserver
# Enable xrdp
mv /etc/xrdp/startwm.sh /etc/xrdp/startwm.sh-old
ln -sfn /home/astronaut/.astroarch/configs/startwm.sh /etc/xrdp/startwm.sh
ln -sfn /home/astronaut/.astroarch/configs/Xwrapper.config /etc/xrdp/Xwrapper.config
# Add user xrdp
useradd xrdp -d / -c 'xrdp daemon' -s /usr/sbin/nologin
# Set user in xrdp.ini
sed -i '/#runtime_user=xrdp/s/^#//' /etc/xrdp/xrdp.ini
sed -i '/#runtime_group=xrdp/s/^#//' /etc/xrdp/xrdp.ini
sed -i 's/bitmap_cache=true/bitmap_cache=false/g' /etc/xrdp/xrdp.ini
# Set user in xrdp.sesman.ini
sed -i '/#SessionSockdirGroup=xrdp/s/^#//' /etc/xrdp/sesman.ini
sed -i '/TerminalServerUsers=tsusers/s/^/#/' /etc/xrdp/sesman.ini
# Set permissions
chown root:xrdp /etc/xrdp/rsakeys.ini
chmod u=rw,g=r /etc/xrdp/rsakeys.ini
chmod 755 /etc/xrdp/cert.pem
chmod 755 /etc/xrdp/key.pem
# Disables the display's power management features
sed -i 's/Option "DPMS"/& "false"/' /etc/X11/xrdp/xorg.conf
# Disabling compression can speed up local connections on low-power devices
sed -i 's|bitmap_compression=true|bitmap_compression=false|g' /etc/xrdp/xrdp.ini
sed -i 's|bulk_compression=true|bulk_compression=false|g' /etc/xrdp/xrdp.ini
# Improve xrdp & network
cp /home/astronaut/.astroarch/configs/99-sysctl.conf /etc/sysctl.d
#
su astronaut -c "cat <<EOF >/home/astronaut/.config/plasmanotifyrc
[DoNotDisturb]
WhenFullscreen=false
WhenScreensMirrored=false
EOF"
# Copy the config for kwinrc
su astronaut -c "cp /home/astronaut/.astroarch/configs/kwinrc /home/astronaut/.config"
# Create the folder (owned by astronaut) to store index files that requires no root access
su astronaut -c "mkdir -p /home/astronaut/.local/share/kstars/astrometry"
# Enable now all services
systemctl enable sddm.service \
novnc.service \
dhcpcd.service \
NetworkManager.service \
avahi-daemon.service \
nmb.service \
smb.service \
xrdp.service \
xrdp-sesman.service
# If we are on qemu, enable also the AP creation and resize scripts
if [ "$HAS_VIRT" -eq 1 ]; then
systemctl enable create_ap.service resize_once.service
fi
# Take sudoers to the original state
sed -i 's/%wheel ALL=(ALL:ALL) NOPASSWD: ALL/# %wheel ALL=(ALL:ALL) NOPASSWD: ALL/g' /etc/sudoers
sed -i 's/# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/g' /etc/sudoers
# Copy wallpapers
su astronaut -c "cp /home/astronaut/.astroarch/wallpapers/bubble.jpg /home/astronaut/Pictures/wallpapers"
su astronaut -c "cp /home/astronaut/.astroarch/wallpapers/south-milky.jpg /home/astronaut/Pictures/wallpapers"
su astronaut -c "cp /home/astronaut/.astroarch/wallpapers/pacman.jpg /home/astronaut/Pictures/wallpapers"
# Autostart AstroArch-onboarding
su astronaut -c "mkdir /home/astronaut/.config/autostart"
# Copy desktop icons
su astronaut -c "ln -snf /usr/share/applications/org.kde.konsole.desktop /home/astronaut/Desktop/Konsole"
su astronaut -c "ln -snf /usr/share/applications/org.kde.kstars.desktop /home/astronaut/Desktop/Kstars"
su astronaut -c "ln -snf /usr/share/applications/astrodmx_capture.desktop /home/astronaut/Desktop/AstroDMx_capture"
su astronaut -c "ln -snf /usr/share/applications/phd2.desktop /home/astronaut/Desktop/PHD2"
su astronaut -c "ln -snf /home/astronaut/.astroarch/desktop/update-astroarch.desktop /home/astronaut/Desktop/update-astroarch"
su astronaut -c "ln -snf /home/astronaut/.astroarch/desktop/astroarch-tweak-tool.desktop /home/astronaut/Desktop/AstroArch-Tweak-Tool"
su astronaut -c "ln -snf /usr/share/astroarch_onboarding/desktop/AstroArch-onboarding.desktop /home/astronaut/Desktop/AstroArch-onboarding"
su astronaut -c "cp /usr/share/astroarch_onboarding/desktop/AstroArch-onboarding-x11.desktop /home/astronaut/.config/autostart/AstroArch-onboarding-x11.desktop"
su astronaut -c "cp /usr/share/astroarch_onboarding/desktop/AstroArch-onboarding-xrdp.desktop /home/astronaut/.config/autostart/AstroArch-onboarding-xrdp.desktop"
# Make the icons executable so there will be no ! on the first boot
chmod +x /home/astronaut/Desktop/update-astroarch
chmod +x /home/astronaut/Desktop/AstroArch-onboarding
chmod +x /home/astronaut/Desktop/AstroArch-Tweak-Tool
# Remove actual novnc icons
rm -r /usr/share/webapps/novnc/app/images/icons/*
# Copy custom novnc icons folder
cp -r /home/astronaut/.astroarch/assets/icons/* /usr/share/webapps/novnc/app/images/icons
# config hostnames
echo "astroarch" > /etc/hostname
echo "127.0.0.1 localhost" >> /etc/hosts
echo "127.0.1.1 astroarch" >> /etc/hosts
# Copy the screensaver config, by default it is off
su astronaut -c "cp /home/astronaut/.astroarch/configs/kscreenlockerrc /home/astronaut/.config/kscreenlockerrc"
# Set a standard TZ to avoid breaking plasma clock widget
timedatectl set-timezone Europe/London
# If we are on a raspberry let's adjust /boot/config.txt
cp /home/astronaut/.astroarch/configs/config.txt /boot/config.txt
install -o root -g root -m 644 /home/astronaut/.astroarch/configs/kdeglobals /etc/xdg/
# Config plasma theme AstroArch
cp -r /home/astronaut/.astroarch/configs/look-and-feel/astroarch /usr/share/plasma/look-and-feel/
cp -r /home/astronaut/.astroarch/configs/layout-templates/astroarchPanel /usr/share/plasma/layout-templates/
# Add user astronaut-kiosk
useradd -G wheel -m astronaut-kiosk
echo "astronaut-kiosk:astro" | chpasswd
usermod -aG uucp,sys,network,power,audio,input,lp,storage,video,users,astronaut astronaut-kiosk
usermod -aG astronaut-kiosk astronaut
chmod -R 777 /home/astronaut-kiosk
su astronaut-kiosk -c "LC_ALL=C.UTF-8 xdg-user-dirs-update --force"
mkdir -p /home/astronaut-kiosk/.local/{bin,share,state}
## Add the kiosk session ##
# New Xrdp launcher for astronaut and astronaut-kiosk sessions
cp /home/astronaut/.astroarch/configs/kiosk/45-allow-shutdown-xrdp.rules /etc/polkit-1/rules.d/
cp /home/astronaut/.astroarch/configs/startwm.sh /home/astronaut-kiosk/
cp /home/astronaut/.astroarch/configs/kiosk/.xinitrc /home/astronaut-kiosk/
# Copy wallpapers
su astronaut-kiosk -c "mkdir -p /home/astronaut-kiosk/Pictures/wallpapers"
cp /home/astronaut/.astroarch/configs/kiosk/astroarch-kiosk.png /home/astronaut-kiosk/Pictures/wallpapers/
# Add menu
cp -r /home/astronaut/.astroarch/configs/kiosk/menus /home/astronaut-kiosk/.config/
# Copy kstars folders
cp -R /home/astronaut/.local/share/kstars /home/astronaut-kiosk/.local/share/
su astronaut-kiosk -c "cat <<EOF >/home/astronaut-kiosk/.config/plasmanotifyrc
[DoNotDisturb]
WhenFullscreen=false
WhenScreensMirrored=false
EOF"
# Copy the screensaver config, by default it is off
su astronaut-kiosk -c "cp /home/astronaut/.astroarch/configs/kscreenlockerrc /home/astronaut-kiosk/.config/kscreenlockerrc"
# Adjustment of user rights
chmod -R 777 /home/astronaut-kiosk
chown -R astronaut-kiosk:astronaut-kiosk /home/astronaut-kiosk
# Minimal desktop
ln -snf /home/astronaut/.astroarch/desktop/astroarch-config-kiosk.desktop /home/astronaut-kiosk/Desktop/Astroarch-config-Kiosk
ln -snf /home/astronaut/.astroarch/desktop/org.kde.konsole.desktop /home/astronaut-kiosk/Desktop/Konsole
# Allows access to the astronaut group
chmod -R 770 /home/astronaut
# Disable Kwallet by default
su astronaut -c "echo $'[Wallet]\nEnabled=false' > /home/astronaut/.config/kwalletrc"
# Increases the xrdp buffer
sed -i 's|#tcp_send_buffer_bytes=32768|tcp_send_buffer_bytes= 4194304|g' /etc/xrdp/xrdp.ini
# Modprobe brcmfmac
bash -c "echo \"options brcmfmac feature_disable=0x282000\" > /etc/modprobe.d/brcmfmac.conf"
# Override cmdline.txt (Only on QEMU)
if [ "$HAS_VIRT" -eq 1 ]; then
echo "root=UUID=$(blkid -s UUID -o value /dev/vda2) rw rootwait console=tty1 fsck.repair=yes video=HDMI-A-1:1920x1080M@60D" > /boot/cmdline.txt
fi
# Reboot and enjoy now, if QEMU stop and add indexes
if [ "$HAS_VIRT" -eq 0 ]; then
reboot
else
echo "Astroarchization achieved, now it's your turn"
fi