@dotpi/tools 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/DOC.md +66 -0
  2. package/LICENSE +28 -0
  3. package/NOTES.md +81 -0
  4. package/README.md +341 -0
  5. package/dotpi-tools.js +35 -0
  6. package/dotpi_root/bin/dotpi +66 -0
  7. package/dotpi_root/bin/dotpi_firstrun +193 -0
  8. package/dotpi_root/bin/dotpi_prepare_sd_card +616 -0
  9. package/dotpi_root/bin/dotpi_prepare_system +244 -0
  10. package/dotpi_root/etc/dotpi_environment_default.bash +69 -0
  11. package/dotpi_root/etc/dotpi_tarignore +3 -0
  12. package/dotpi_root/share/dotpi-install/update_to_v1.0.0_manager +39 -0
  13. package/dotpi_root/share/dotpi-install/update_to_v1.0.0_pi +39 -0
  14. package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_bluetooth.service +23 -0
  15. package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_bluetooth_command +134 -0
  16. package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_pipewire_relink +132 -0
  17. package/dotpi_root/share/dotpi_avahi_monitor/dotpi_avahi_monitor.service +22 -0
  18. package/dotpi_root/share/dotpi_avahi_monitor/dotpi_avahi_monitor_command +14 -0
  19. package/dotpi_root/share/dotpi_environment.bash +5 -0
  20. package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_bluetooth.bash +346 -0
  21. package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device.bash +504 -0
  22. package/dotpi_root/share/dotpi_functions/dotpi_functions_configuration.bash +435 -0
  23. package/dotpi_root/share/dotpi_functions/dotpi_functions_connection.bash +199 -0
  24. package/dotpi_root/share/dotpi_functions/dotpi_functions_dotpi.bash +36 -0
  25. package/dotpi_root/share/dotpi_functions/dotpi_functions_service.bash +111 -0
  26. package/dotpi_root/share/dotpi_functions/dotpi_functions_system.bash +175 -0
  27. package/dotpi_root/share/dotpi_functions/dotpi_functions_utils.bash +154 -0
  28. package/dotpi_root/share/dotpi_functions.bash +14 -0
  29. package/dotpi_root/share/dotpi_init.bash +18 -0
  30. package/dotpi_root/share/jackd/dotpi_jackd_bluetooth.bash +18 -0
  31. package/dotpi_root/share/jackd/dotpi_jackd_command +26 -0
  32. package/dotpi_root/share/jackd/dotpi_jackd_headphones.bash +21 -0
  33. package/dotpi_root/share/jackd/dotpi_jackd_hifiberry.bash +17 -0
  34. package/dotpi_root/share/jackd/jackd.service +22 -0
  35. package/dotpi_root/share/limits/zzz_dotpi_audio.conf +11 -0
  36. package/dotpi_root/share/wireplumber/bluetooth.lua.d/8zzz-dotpi-wireplumber-config.lua +4 -0
  37. package/examples/example-development/configuration/dotpi_project.bash +40 -0
  38. package/examples/example-headphones/configuration/dotpi_project.bash +18 -0
  39. package/examples/example-hifiberry/configuration/dotpi_instance_012.bash +4 -0
  40. package/examples/example-hifiberry/configuration/dotpi_project.bash +18 -0
  41. package/examples/example-network/configuration/dotpi_project.bash +21 -0
  42. package/package.json +35 -0
  43. package/src/configure-host.js +187 -0
  44. package/src/constants.js +30 -0
  45. package/src/create-project.js +438 -0
  46. package/src/install-rpi.js +173 -0
  47. package/src/templates/README.md +16 -0
  48. package/src/templates/ap.nmconnection +25 -0
  49. package/src/templates/dotpi_project.bash +31 -0
  50. package/src/templates/dotpi_secrets.bash +4 -0
  51. package/src/templates/infrastructure.nmconnection +29 -0
  52. package/src/templates/ssh_config +6 -0
  53. package/src/utils.js +175 -0
  54. package/test/constants.spec.js +37 -0
  55. package/test/create-project.test.js +57 -0
  56. package/test/install-rpi.test.js +8 -0
  57. package/test/utils.spec.js +48 -0
@@ -0,0 +1,193 @@
1
+ #!/bin/bash
2
+
3
+ set +e
4
+
5
+ local_file="$(readlink -f -- "$0")"
6
+ local_path="$(dirname -- "$local_file")"
7
+
8
+ log_file="${1:-${local_file}-$(date +"%Y%m%d-%H%M%S").log}"
9
+
10
+ # Self log
11
+ exec &> >(dotpi log "$log_file")
12
+
13
+ DOTPI_ROOT="${DOTPI_ROOT:-/opt/dotpi}"
14
+
15
+ # run imager firstrun before, to allow for over-rides
16
+ file_name="${local_path}/imager_firstrun.sh"
17
+ if [ -x "$file_name" ] ; then
18
+ echo "INFO: Run imager first run: ${file_name}"
19
+ # do not source to avoid exit
20
+ "$file_name"
21
+ else
22
+ echo "WARNING: Imager first run not found: ${file_name}"
23
+ fi
24
+
25
+ # install dotpi wrapper
26
+ ln -s "${DOTPI_ROOT}/bin/dotpi" /usr/bin
27
+
28
+ source "${DOTPI_ROOT}/share/dotpi_init.bash"
29
+
30
+ dotpi echo_info "Configure first user .bashrc"
31
+
32
+ FIRSTUSER="$(getent passwd 1000 | cut -d: -f1)"
33
+ FIRSTUSERHOME="$(getent passwd 1000 | cut -d: -f6)"
34
+
35
+ mkdir -p -- "$FIRSTUSERHOME"
36
+
37
+ IFS= read -r -d '' bashrc_append << EOF
38
+
39
+ ### dotpi
40
+
41
+ source "${DOTPI_ROOT}/share/dotpi_init.bash"
42
+
43
+ EOF
44
+
45
+ echo "$bashrc_append" >> "${FIRSTUSERHOME}/.bashrc"
46
+
47
+ # make sure .bashrc can be sourced when not in interactive mode
48
+ substitution="# dotpi: source even if non-interactive"
49
+ dotpi configuration_replace_region 'case $- in' 'esac' "$substitution" "${FIRSTUSERHOME}/.bashrc"
50
+
51
+ ####### hostname
52
+
53
+ dotpi echo_info "Set hostname to ${dotpi_instance_hostname}"
54
+
55
+ dotpi system_set_hostname "$dotpi_instance_hostname"
56
+
57
+ ####### ssh
58
+
59
+ dotpi echo_info "Configure SSH"
60
+
61
+ keys=()
62
+ for file in "${DOTPI_ROOT}/etc/ssh/"*.pub ; do
63
+ if [ -r "$file" ] ; then
64
+ keys+=( "$(cat "$file" )" )
65
+ fi
66
+ done
67
+
68
+ # install first key
69
+ key="${keys[0]}"
70
+ if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ] ; then
71
+ /usr/lib/raspberrypi-sys-mods/imager_custom enable_ssh -k "$key"
72
+ else
73
+ install -o "$FIRSTUSER" -m 700 -d "$FIRSTUSERHOME/.ssh"
74
+ install -o "$FIRSTUSER" -m 600 <(printf "$key") "$FIRSTUSERHOME/.ssh/authorized_keys"
75
+ systemctl enable ssh
76
+ fi
77
+
78
+ mkdir -p -- "${FIRSTUSERHOME}/.ssh"
79
+ # start from second element
80
+ for key in "${keys[@]: 1}" ; do
81
+ echo "key" >> "$FIRSTUSERHOME/.ssh/authorized_keys"
82
+ done
83
+
84
+ # delete if already set
85
+ sed -i -e '/^PasswordAuthentication/d' /etc/ssh/sshd_config
86
+
87
+ # allow for password authentication
88
+ # (after exclusive imager_custom enable_ssh -k)
89
+ echo "PasswordAuthentication ${dotpi_ssh_allow_password_authentication}" >>/etc/ssh/sshd_config
90
+
91
+ ####### user
92
+
93
+ dotpi echo_info "Configure first user login"
94
+
95
+ if [ -f /usr/lib/userconf-pi/userconf ] ; then
96
+ if [ -n "$dotpi_password_hash" ] ; then
97
+ dotpi echo_info "Set password with userconf-pi, using hash: ${dotpi_password_hash}"
98
+ /usr/lib/userconf-pi/userconf "$dotpi_user" "$dotpi_password_hash"
99
+ fi
100
+ else
101
+ if [ -n "$dotpi_password_hash" ] ; then
102
+ dotpi echo_info "Set password with chpasswd, using hash: ${dotpi_password_hash}"
103
+ echo "${FIRSTUSER}:${dotpi_password_hash}" | chpasswd -e
104
+ fi
105
+ if [ "$FIRSTUSER" != "$dotpi_user" ]; then
106
+ usermod -l "$dotpi_user" "$FIRSTUSER"
107
+ usermod -m -d "/home/${dotpi_user}" "$dotpi_user"
108
+ groupmod -n "$dotpi_user" "$FIRSTUSER"
109
+ if grep -q "^autologin-user=" /etc/lightdm/lightdm.conf ; then
110
+ sed /etc/lightdm/lightdm.conf -i -e "s/^autologin-user=.*/autologin-user=PI-USER/"
111
+ fi
112
+ if [ -f /etc/systemd/system/getty@tty1.service.d/autologin.conf ]; then
113
+ sed /etc/systemd/system/getty@tty1.service.d/autologin.conf -i -e "s/${FIRSTUSER}/${dotpi_user}/"
114
+ fi
115
+ if [ -f /etc/sudoers.d/010_pi-nopasswd ]; then
116
+ sed -i "s/^${FIRSTUSER} /${dotpi_user} /" /etc/sudoers.d/010_pi-nopasswd
117
+ fi
118
+ fi
119
+ fi
120
+
121
+ ####### wifi
122
+
123
+ dotpi echo_info "Configure wifi"
124
+
125
+ # Do *not* install wpa_supplicant
126
+ # - Bullseye: it should be sufficient in /boot
127
+ # - Bookworm: it breaks NetworkManager
128
+
129
+ source_path="${DOTPI_ROOT}/etc/network"
130
+ destination_path='/etc/NetworkManager/system-connections'
131
+ if [ -d "${source_path}" ] ; then
132
+ tar c -C "$source_path" '.' | tar xv -C "$destination_path"
133
+ fi
134
+ chmod 'u=rw,go=' "${destination_path}"/*
135
+
136
+ # unblock wifi in any case
137
+ #
138
+ # This is also done later by `dotpi_prepare_system` but doing this
139
+ # only in one place fail for some unknown reason
140
+ if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ] ; then
141
+ dotpi echo_info "Enable wifi with imager_custom"
142
+ /usr/lib/raspberrypi-sys-mods/imager_custom set_wlan_country "$dotpi_wifi_country_code"
143
+ else
144
+ raspi-config nonint do_wifi_country "$dotpi_wifi_country_code"
145
+ for file in /var/lib/systemd/rfkill/*:wlan ; do
146
+ echo 0 > "$file"
147
+ done
148
+ fi
149
+
150
+ nmcli radio wifi on
151
+ rfkill unblock wifi
152
+
153
+ ####### limits (real-time audio)
154
+
155
+ dotpi echo_info "Configure limits"
156
+
157
+ source_path="${DOTPI_ROOT}/share/limits"
158
+ destination_path='/etc/security/limits.d'
159
+ if [ -r "$source_path" ] ; then
160
+ mkdir -p "$destination_path"
161
+ tar c -C "$source_path" '.' | tar x -C "$destination_path"
162
+ fi
163
+
164
+ ###### keymap and timezone
165
+
166
+ dotpi echo_info "Configure keymap and timezone"
167
+
168
+ if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ]; then
169
+ /usr/lib/raspberrypi-sys-mods/imager_custom set_keymap "$dotpi_keymap"
170
+ /usr/lib/raspberrypi-sys-mods/imager_custom set_timezone "$dotpi_timezone"
171
+ else
172
+ rm -f /etc/localtime
173
+ echo "$dotpi_timezone" >/etc/timezone
174
+ dpkg-reconfigure -f noninteractive tzdata
175
+ cat >/etc/default/keyboard <<'KBEOF'
176
+ XKBMODEL="pc105"
177
+ XKBLAYOUT="$dotpi_keymap"
178
+ XKBVARIANT=""
179
+ XKBOPTIONS=""
180
+
181
+ KBEOF
182
+ dpkg-reconfigure -f noninteractive keyboard-configuration
183
+ fi
184
+
185
+ # read again as it may have changed
186
+ FIRSTUSER="$(getent passwd 1000 | cut -d: -f1)"
187
+
188
+ if [[ "$dotpi_prepare_system_automatic" == 'yes' ]] ; then
189
+ dotpi echo_info "Automatic: Run prepare system"
190
+
191
+ sudo dotpi system_execute_on_reboot "$FIRSTUSER" "${DOTPI_ROOT}/bin/dotpi_prepare_system"
192
+ fi
193
+