@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.
- package/DOC.md +66 -0
- package/LICENSE +28 -0
- package/NOTES.md +81 -0
- package/README.md +341 -0
- package/dotpi-tools.js +35 -0
- package/dotpi_root/bin/dotpi +66 -0
- package/dotpi_root/bin/dotpi_firstrun +193 -0
- package/dotpi_root/bin/dotpi_prepare_sd_card +616 -0
- package/dotpi_root/bin/dotpi_prepare_system +244 -0
- package/dotpi_root/etc/dotpi_environment_default.bash +69 -0
- package/dotpi_root/etc/dotpi_tarignore +3 -0
- package/dotpi_root/share/dotpi-install/update_to_v1.0.0_manager +39 -0
- package/dotpi_root/share/dotpi-install/update_to_v1.0.0_pi +39 -0
- package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_bluetooth.service +23 -0
- package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_bluetooth_command +134 -0
- package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_pipewire_relink +132 -0
- package/dotpi_root/share/dotpi_avahi_monitor/dotpi_avahi_monitor.service +22 -0
- package/dotpi_root/share/dotpi_avahi_monitor/dotpi_avahi_monitor_command +14 -0
- package/dotpi_root/share/dotpi_environment.bash +5 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_bluetooth.bash +346 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device.bash +504 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_configuration.bash +435 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_connection.bash +199 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_dotpi.bash +36 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_service.bash +111 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_system.bash +175 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_utils.bash +154 -0
- package/dotpi_root/share/dotpi_functions.bash +14 -0
- package/dotpi_root/share/dotpi_init.bash +18 -0
- package/dotpi_root/share/jackd/dotpi_jackd_bluetooth.bash +18 -0
- package/dotpi_root/share/jackd/dotpi_jackd_command +26 -0
- package/dotpi_root/share/jackd/dotpi_jackd_headphones.bash +21 -0
- package/dotpi_root/share/jackd/dotpi_jackd_hifiberry.bash +17 -0
- package/dotpi_root/share/jackd/jackd.service +22 -0
- package/dotpi_root/share/limits/zzz_dotpi_audio.conf +11 -0
- package/dotpi_root/share/wireplumber/bluetooth.lua.d/8zzz-dotpi-wireplumber-config.lua +4 -0
- package/examples/example-development/configuration/dotpi_project.bash +40 -0
- package/examples/example-headphones/configuration/dotpi_project.bash +18 -0
- package/examples/example-hifiberry/configuration/dotpi_instance_012.bash +4 -0
- package/examples/example-hifiberry/configuration/dotpi_project.bash +18 -0
- package/examples/example-network/configuration/dotpi_project.bash +21 -0
- package/package.json +35 -0
- package/src/configure-host.js +187 -0
- package/src/constants.js +30 -0
- package/src/create-project.js +438 -0
- package/src/install-rpi.js +173 -0
- package/src/templates/README.md +16 -0
- package/src/templates/ap.nmconnection +25 -0
- package/src/templates/dotpi_project.bash +31 -0
- package/src/templates/dotpi_secrets.bash +4 -0
- package/src/templates/infrastructure.nmconnection +29 -0
- package/src/templates/ssh_config +6 -0
- package/src/utils.js +175 -0
- package/test/constants.spec.js +37 -0
- package/test/create-project.test.js +57 -0
- package/test/install-rpi.test.js +8 -0
- package/test/utils.spec.js +48 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Usage: dotpi_service_install [--user] <service_file>
|
|
4
|
+
# note: <service_file> is a path
|
|
5
|
+
dotpi_service_install() (
|
|
6
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
7
|
+
|
|
8
|
+
if (( $# < 1 )); then
|
|
9
|
+
dotpi_echo_info "Usage: ${_dotpi_command} [--user] <service_file>"
|
|
10
|
+
return 1
|
|
11
|
+
fi
|
|
12
|
+
|
|
13
|
+
if [[ "$USER" != "root" ]]; then
|
|
14
|
+
dotpi_echo_error "This command must be run as root"
|
|
15
|
+
return 1
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
arguments=("$@")
|
|
19
|
+
|
|
20
|
+
# last argument is service file
|
|
21
|
+
service_file="${arguments[-1]}"
|
|
22
|
+
|
|
23
|
+
# other arguments are options for systemctl
|
|
24
|
+
# user --user for user services
|
|
25
|
+
command_options=("${arguments[@]}")
|
|
26
|
+
unset "command_options[-1]"
|
|
27
|
+
|
|
28
|
+
user_service=0
|
|
29
|
+
for option in "${command_options[@]}"; do
|
|
30
|
+
if [[ "${option}" == "--user" ]]; then
|
|
31
|
+
user_service=1
|
|
32
|
+
break
|
|
33
|
+
fi
|
|
34
|
+
done
|
|
35
|
+
|
|
36
|
+
service_name=$(basename -- "${service_file}")
|
|
37
|
+
|
|
38
|
+
if (( user_service )); then
|
|
39
|
+
service_destination="/etc/systemd/user"
|
|
40
|
+
else
|
|
41
|
+
service_destination="/etc/systemd/system"
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
ln -s -f "$(dotpi readlink_follow "${service_file}")" "${service_destination}"
|
|
45
|
+
|
|
46
|
+
if (( user_service )); then
|
|
47
|
+
# drop sudo, with a proper session, including XDG_RUNTIME_DIR and DBUS_SESSION_BUS_ADDRESS
|
|
48
|
+
command_prefix=(systemctl --machine="${SUDO_USER}@")
|
|
49
|
+
else
|
|
50
|
+
command_prefix=(systemctl)
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
"${command_prefix[@]}" "${command_options[@]}" daemon-reload
|
|
54
|
+
|
|
55
|
+
# be sure to stop as default or previous version might be running
|
|
56
|
+
"${command_prefix[@]}" "${command_options[@]}" stop "${service_name}"
|
|
57
|
+
"${command_prefix[@]}" "${command_options[@]}" enable "${service_name}"
|
|
58
|
+
"${command_prefix[@]}" "${command_options[@]}" start "${service_name}"
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
# Usage: dotpi_service_uninstall [--user] <service_name>
|
|
62
|
+
dotpi_service_uninstall() (
|
|
63
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
64
|
+
|
|
65
|
+
if (( $# < 1 )); then
|
|
66
|
+
dotpi_echo_info "Usage: ${_dotpi_command} [--user] <service_name>"
|
|
67
|
+
return 1
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
if [[ "$USER" != "root" ]]; then
|
|
71
|
+
dotpi_echo_error "This command must be run as root"
|
|
72
|
+
return 1
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
arguments=("$@")
|
|
76
|
+
|
|
77
|
+
# last argument is service file
|
|
78
|
+
service_name="${arguments[-1]}"
|
|
79
|
+
|
|
80
|
+
# other arguments are options for systemctl
|
|
81
|
+
# user --user for user services
|
|
82
|
+
command_options=("${arguments[@]}")
|
|
83
|
+
unset "command_options[-1]"
|
|
84
|
+
|
|
85
|
+
user_service=0
|
|
86
|
+
for option in "${command_options[@]}"; do
|
|
87
|
+
if [[ "${option}" == "--user" ]]; then
|
|
88
|
+
user_service=1
|
|
89
|
+
break
|
|
90
|
+
fi
|
|
91
|
+
done
|
|
92
|
+
|
|
93
|
+
if (( user_service )); then
|
|
94
|
+
service_destination="/etc/systemd/user"
|
|
95
|
+
else
|
|
96
|
+
service_destination="/etc/systemd/system"
|
|
97
|
+
fi
|
|
98
|
+
|
|
99
|
+
rm -f "${service_destination}/${service_name}"
|
|
100
|
+
|
|
101
|
+
if (( user_service )); then
|
|
102
|
+
# drop sudo, with a proper session, including XDG_RUNTIME_DIR and DBUS_SESSION_BUS_ADDRESS
|
|
103
|
+
command_prefix=(systemctl --machine="${SUDO_USER}@")
|
|
104
|
+
else
|
|
105
|
+
command_prefix=(systemctl)
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
"${command_prefix[@]}" "${command_options[@]}" stop "${service_name}"
|
|
109
|
+
"${command_prefix[@]}" "${command_options[@]}" disable "${service_name}"
|
|
110
|
+
"${command_prefix[@]}" "${command_options[@]}" daemon-reload
|
|
111
|
+
)
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# echo 'raspberry' or 'other'
|
|
4
|
+
dotpi_system_is_raspberry_pi() (
|
|
5
|
+
model='other'
|
|
6
|
+
|
|
7
|
+
if [ -r /proc/device-tree/model ] ; then
|
|
8
|
+
model="$( (set -o pipefail ; \
|
|
9
|
+
cat /proc/device-tree/model \
|
|
10
|
+
| perl -ne '
|
|
11
|
+
if ( m/raspberry/i ) {
|
|
12
|
+
print "raspberry\n"
|
|
13
|
+
} else {
|
|
14
|
+
print "other\n"
|
|
15
|
+
}
|
|
16
|
+
' ) || echo 'other')"
|
|
17
|
+
|
|
18
|
+
fi
|
|
19
|
+
|
|
20
|
+
if [[ "$model" == "raspberry" ]] ; then
|
|
21
|
+
return 0
|
|
22
|
+
else
|
|
23
|
+
return 1
|
|
24
|
+
fi
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
dotpi_system_get_bootfs_path() (
|
|
28
|
+
# since Raspberry Pi OS Bookworm
|
|
29
|
+
local_path='/boot/firmware'
|
|
30
|
+
|
|
31
|
+
if ! [ -d "$local_path" ] ; then
|
|
32
|
+
# for Raspberry Pi OS Bullseye
|
|
33
|
+
local_path='/boot'
|
|
34
|
+
|
|
35
|
+
if ! [ -d "$local_path" ] ; then
|
|
36
|
+
dotpi_echo_error "Boot file-system not found"
|
|
37
|
+
echo ""
|
|
38
|
+
return 1
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
echo "$local_path"
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# usage: sudo dotpi system_set_hostname <new_hostname>
|
|
47
|
+
dotpi_system_set_hostname() (
|
|
48
|
+
if [ -z "$DOTPI_ROOT" ] ; then
|
|
49
|
+
echo "DOTPI_ROOT undefined" >&2
|
|
50
|
+
return 1
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
if ! dotpi_system_is_raspberry_pi ; then
|
|
54
|
+
dotpi_echo_error "System is not a Raspberry Pi. Not changing hostname"
|
|
55
|
+
return 1
|
|
56
|
+
fi
|
|
57
|
+
|
|
58
|
+
if [ -z "$1" ] ; then
|
|
59
|
+
dotpi_echo_error "New hostname argument is required"
|
|
60
|
+
return 1
|
|
61
|
+
fi
|
|
62
|
+
dotpi_instance_hostname="$1"
|
|
63
|
+
|
|
64
|
+
destination_file="${DOTPI_ROOT}/etc/dotpi_environment_instance.bash"
|
|
65
|
+
dotpi_configuration_write --file "$destination_file" --key 'dotpi_instance_hostname' --value "$dotpi_instance_hostname"
|
|
66
|
+
|
|
67
|
+
hostname_current="$(cat /etc/hostname | tr -d " \t\n\r")"
|
|
68
|
+
if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ]; then
|
|
69
|
+
/usr/lib/raspberrypi-sys-mods/imager_custom set_hostname "${dotpi_instance_hostname}"
|
|
70
|
+
else
|
|
71
|
+
echo "${dotpi_instance_hostname}" >/etc/hostname
|
|
72
|
+
sed -i "s/127.0.1.1.*${hostname_current}/127.0.1.1\t${dotpi_instance_hostname}/g" /etc/hosts
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
# explicitly update hostnamectl for immediate effect
|
|
76
|
+
hostnamectl hostname "$dotpi_instance_hostname" || {
|
|
77
|
+
dotpi_echo_warning "hostnamectl unable to change hostname to ${dotpi_instance_hostname}"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
# update services to use the new hostname
|
|
81
|
+
services=(
|
|
82
|
+
'NetworkManager'
|
|
83
|
+
'avahi-daemon.service' # Bonjour / zeroconf / mDNS
|
|
84
|
+
)
|
|
85
|
+
for service in "${services[@]}" ; do
|
|
86
|
+
# restart service only if active (avoid early start on first boot)
|
|
87
|
+
if systemctl is-active "$service" > /dev/null 2>&1 ; then
|
|
88
|
+
systemctl restart "$service" || {
|
|
89
|
+
dotpi_echo_warning "systemctl unable to restart service ${service}"
|
|
90
|
+
}
|
|
91
|
+
fi
|
|
92
|
+
done
|
|
93
|
+
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
dotpi_system_execute_on_reboot() (
|
|
97
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
98
|
+
_dotpi_usage() {
|
|
99
|
+
echo "Usage: ${_dotpi_command} <user> <executable>"
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
user="$1"
|
|
103
|
+
if [[ -z "$user" ]] ; then
|
|
104
|
+
dotpi_echo_error "Missing user argument."
|
|
105
|
+
_dotpi_usage
|
|
106
|
+
exit 1
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
executable="$2"
|
|
110
|
+
if [[ -z "$executable" ]] ; then
|
|
111
|
+
dotpi_echo_error "Missing executable argument."
|
|
112
|
+
_dotpi_usage
|
|
113
|
+
exit 1
|
|
114
|
+
fi
|
|
115
|
+
|
|
116
|
+
if ! [[ -d /etc/cron.d ]] ; then
|
|
117
|
+
dotpi_echo_error "System without cron.d support."
|
|
118
|
+
dotpi_echo_error "$1 will NOT execute on next boot."
|
|
119
|
+
return 1
|
|
120
|
+
fi
|
|
121
|
+
|
|
122
|
+
executable_name="$(basename "$executable")"
|
|
123
|
+
executable_file="$(dotpi_readlink_follow "$executable")"
|
|
124
|
+
|
|
125
|
+
date_string="$(date '+%Y%m%d_%H%M%S')"
|
|
126
|
+
|
|
127
|
+
# Cf. https://manpages.debian.org/bookworm/cron/cron.8.en.html
|
|
128
|
+
|
|
129
|
+
# As described above, the files under these directories have to pass some
|
|
130
|
+
# sanity checks including the following: be executable, be owned by root, not
|
|
131
|
+
# be writable by group or other and, if symlinks, point to files owned by
|
|
132
|
+
# root. Additionally, the file names must conform to the filename requirements
|
|
133
|
+
# of run-parts: they must be entirely made up of letters, digits and can only
|
|
134
|
+
# contain the special signs underscores ('_') and hyphens ('-'). Any file that
|
|
135
|
+
# does not conform to these requirements will not be executed by
|
|
136
|
+
# run-parts. For example, any file containing dots will be ignored. This is
|
|
137
|
+
# done to prevent cron from running any of the files that are left by the
|
|
138
|
+
# Debian package management system when handling files in /etc/cron.d/ as
|
|
139
|
+
# configuration files (i.e. files ending in .dpkg-dist, .dpkg-orig, .dpkg-old,
|
|
140
|
+
# and .dpkg-new).
|
|
141
|
+
|
|
142
|
+
cron_file="/etc/cron.d/zzz_dotpi_${date_string}_$(echo -n "${executable_name}" \
|
|
143
|
+
| dotpi_sed 's/[^a-zA-Z0-9_-]/_/g')"
|
|
144
|
+
|
|
145
|
+
log_path="${DOTPI_ROOT}/var/log"
|
|
146
|
+
mkdir -p "$log_path"
|
|
147
|
+
|
|
148
|
+
log_name="${executable_name}_${date_string}.log"
|
|
149
|
+
log_file="${log_path}/${log_name}"
|
|
150
|
+
|
|
151
|
+
cat >> "$cron_file" << EOF
|
|
152
|
+
|
|
153
|
+
SHELL=/bin/bash
|
|
154
|
+
|
|
155
|
+
@reboot ${user} "${executable_file}" 2>&1 | sudo dotpi log "$log_file"
|
|
156
|
+
@reboot root rm "$cron_file"
|
|
157
|
+
|
|
158
|
+
EOF
|
|
159
|
+
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
# Usage: sudo dotpi system_update
|
|
163
|
+
# equivalent of apt-get update and apt-get dist-upgrade
|
|
164
|
+
|
|
165
|
+
dotpi_system_update() {
|
|
166
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
167
|
+
log_file="${DOTPI_ROOT}/var/log/${_dotpi_command}_$(date +"%Y%m%d-%H%M%S").log"
|
|
168
|
+
exec &> >(dotpi log "$log_file")
|
|
169
|
+
|
|
170
|
+
dotpi_echo_info "Log of dotpi-manager update: ${log_file}"
|
|
171
|
+
|
|
172
|
+
dotpi_echo_info "Update and dist-upgrade"
|
|
173
|
+
dotpi_apt_get update
|
|
174
|
+
dotpi_apt_get dist-upgrade
|
|
175
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
dotpi_apt_get() {
|
|
4
|
+
# fully automated, with default choices (yes to any questions)
|
|
5
|
+
# keep installation explicit, do not install recommended
|
|
6
|
+
|
|
7
|
+
# wait for other apt-get processes (first or daily updates)
|
|
8
|
+
# -1 is unlimited
|
|
9
|
+
# DPkg::Lock::Timeout=-1
|
|
10
|
+
|
|
11
|
+
# wait for distant resources (internet)
|
|
12
|
+
# -1 is unlimited
|
|
13
|
+
# Acquire::Retries=-1
|
|
14
|
+
|
|
15
|
+
DEBIAN_FRONTEND=noninteractive \
|
|
16
|
+
apt-get \
|
|
17
|
+
-o APT::Get::Assume-Yes=true \
|
|
18
|
+
-o APT::Install-Recommends=false \
|
|
19
|
+
-o APT::Install-Suggests=false \
|
|
20
|
+
-o DPkg::Lock::Timeout=-1 \
|
|
21
|
+
-o Acquire::Retries=-1 \
|
|
22
|
+
-o Acquire::Check-Valid-Until=false \
|
|
23
|
+
-o Acquire::Check-Date=false \
|
|
24
|
+
"${@}"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
dotpi_source_if_available() {
|
|
28
|
+
if [ -f "$1" ] && [ -r "$1" ] ; then
|
|
29
|
+
source "$1"
|
|
30
|
+
return 0
|
|
31
|
+
else
|
|
32
|
+
return 1
|
|
33
|
+
fi
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# `readlink -f` is not available for MacOS
|
|
37
|
+
# https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
|
|
38
|
+
dotpi_readlink_follow() (
|
|
39
|
+
target_file="$1"
|
|
40
|
+
|
|
41
|
+
cd -- "$(dirname -- "$target_file")" || {
|
|
42
|
+
echo ''
|
|
43
|
+
return 1
|
|
44
|
+
}
|
|
45
|
+
target_file="$(basename -- "$target_file")"
|
|
46
|
+
|
|
47
|
+
# Iterate down a (possible) chain of symlinks
|
|
48
|
+
while [[ -L "$target_file" ]] ; do
|
|
49
|
+
target_file="$(readlink -- "$target_file")"
|
|
50
|
+
cd -- "$(dirname -- "$target_file")" || {
|
|
51
|
+
echo ''
|
|
52
|
+
return 1
|
|
53
|
+
}
|
|
54
|
+
target_file="$(basename -- "$target_file")"
|
|
55
|
+
done
|
|
56
|
+
|
|
57
|
+
# Compute the canonicalized name by finding the physical path
|
|
58
|
+
# for the directory we're in and appending the target file.
|
|
59
|
+
target_path="$(pwd -P)"
|
|
60
|
+
result="${target_path}/${target_file}"
|
|
61
|
+
echo "$result"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# Black 0;30 Dark Gray 1;30
|
|
65
|
+
# Red 0;31 Light Red 1;31
|
|
66
|
+
# Green 0;32 Light Green 1;32
|
|
67
|
+
# Brown/Orange 0;33 Yellow 1;33
|
|
68
|
+
# Blue 0;34 Light Blue 1;34
|
|
69
|
+
# Purple 0;35 Light Purple 1;35
|
|
70
|
+
# Cyan 0;36 Light Cyan 1;36
|
|
71
|
+
# Light Gray 0;37 White 1;37
|
|
72
|
+
|
|
73
|
+
dotpi_color_none='\e[0m'
|
|
74
|
+
dotpi_color_red='\e[0;31m'
|
|
75
|
+
dotpi_color_orange='\e[0;33m'
|
|
76
|
+
dotpi_color_green='\e[0;32m'
|
|
77
|
+
|
|
78
|
+
dotpi_echo_error() {
|
|
79
|
+
printf "${dotpi_color_red}ERROR: ${dotpi_color_none}${*}\n" >&2
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
dotpi_echo_warning() {
|
|
83
|
+
printf "${dotpi_color_orange}WARNING: ${dotpi_color_none}${*}\n" >&2
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
dotpi_echo_info() {
|
|
87
|
+
printf "${dotpi_color_green}INFO: ${dotpi_color_none}${*}\n" >&2
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# remove colour and other control sequences
|
|
92
|
+
# Cf. https://superuser.com/questions/380772/removing-ansi-color-codes-from-text-stream
|
|
93
|
+
dotpi_colour_remove() {
|
|
94
|
+
dotpi_sed 's/\e\[[0-9;]*[mGKH]//g'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
dotpi_log() (
|
|
98
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
99
|
+
_dotpi_usage() {
|
|
100
|
+
echo "Usage: <command> 2>&1 | ${_dotpi_command} <log_file>" >&2
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
log_file="$1"
|
|
104
|
+
if [[ -z "$log_file" ]] ; then
|
|
105
|
+
dotpi_echo_error "missing output filename"
|
|
106
|
+
_dotpi_usage
|
|
107
|
+
return 1
|
|
108
|
+
fi
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
tee -i >(while IFS= read -r line; do
|
|
112
|
+
echo "$line" \
|
|
113
|
+
| dotpi_colour_remove \
|
|
114
|
+
| dotpi_sed "s/^/$(date '+%Y-%m-%d %H:%M:%S') /" \
|
|
115
|
+
>> "$log_file"
|
|
116
|
+
done)
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
dotpi_sed() {
|
|
120
|
+
# sed is not portable
|
|
121
|
+
perl -pe "$@"
|
|
122
|
+
return $?
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
# dotpi_uuidgen
|
|
126
|
+
if $( command -v uuidgen > /dev/null ) ; then
|
|
127
|
+
dotpi_uuidgen() {
|
|
128
|
+
uuidgen | tr '[:upper:]' '[:lower:]'
|
|
129
|
+
}
|
|
130
|
+
elif [ -r /proc/sys/kernel/random/uuid ] ; then
|
|
131
|
+
dotpi_uuidgen() {
|
|
132
|
+
cat /proc/sys/kernel/random/uuid
|
|
133
|
+
}
|
|
134
|
+
else
|
|
135
|
+
dotpi_uuidgen() {
|
|
136
|
+
printf '%08x-%04x-%04x-%012x\n' $(( (RANDOM << 16 + RANDOM) % 0xffffffff )) $(( RANDOM )) $(( RANDOM )) $(( ( (RANDOM << 16 + RANDOM) << 16) + RANDOM % 0xffffffffffff ))
|
|
137
|
+
}
|
|
138
|
+
fi
|
|
139
|
+
|
|
140
|
+
dotpi_file_word_size() {
|
|
141
|
+
if [[ $# != 1 ]] ; then
|
|
142
|
+
dotpi_echo_error 'First argument is file to read'
|
|
143
|
+
dotpi_echo_error "Usage: ${FUNCNAME[0]} <file_to_read>"
|
|
144
|
+
return 1
|
|
145
|
+
fi
|
|
146
|
+
|
|
147
|
+
echo "$(file "$1" | perl -pe 's/.*(32|64)-bit.*/$1/' )"
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
# requires ts form moretuils
|
|
151
|
+
dotpi_timestamp() {
|
|
152
|
+
# [now (time_from_start)]
|
|
153
|
+
ts -s '(%H:%M:%.S)]' | ts '[%Y-%m-%d %H:%M:%S'
|
|
154
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
#### default functions
|
|
4
|
+
|
|
5
|
+
for file in "${DOTPI_ROOT}/share/dotpi_functions/"* ; do
|
|
6
|
+
# continue on error
|
|
7
|
+
source "$file" || true
|
|
8
|
+
done
|
|
9
|
+
|
|
10
|
+
#### dotpi-manager
|
|
11
|
+
|
|
12
|
+
# continue on error
|
|
13
|
+
dotpi_source_if_available "${DOTPI_ROOT}/share/dotpi-manager/dotpi-manager.bash" || true
|
|
14
|
+
dotpi_source_if_available "${DOTPI_ROOT}/share/dotpi-led/dotpi-led.bash" || true
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# when sourced, the shell might not be bash
|
|
4
|
+
if [ -n "$ZSH_VERSION" ] ; then
|
|
5
|
+
_local_file="${0:a}"
|
|
6
|
+
elif [ -n "$BASH_VERSION" ] ; then
|
|
7
|
+
_local_file="${BASH_SOURCE[0]}"
|
|
8
|
+
else
|
|
9
|
+
_local_file="$0"
|
|
10
|
+
fi
|
|
11
|
+
_local_path="$(cd -- "$(dirname -- "${_local_file}")" && pwd)"
|
|
12
|
+
|
|
13
|
+
DOTPI_ROOT="$(cd -- "${_local_path}/.." && pwd)"
|
|
14
|
+
export DOTPI_ROOT
|
|
15
|
+
|
|
16
|
+
source "${DOTPI_ROOT}/share/dotpi_functions.bash"
|
|
17
|
+
|
|
18
|
+
source "${DOTPI_ROOT}/share/dotpi_environment.bash"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# keep this
|
|
2
|
+
DOTPI_JACKD_ENVIRONMENT=(
|
|
3
|
+
JACK_NO_AUDIO_RESERVATION=1
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
# warning: long option for -d (--driver) seems broken
|
|
7
|
+
|
|
8
|
+
# explicit outchannels (default is 0)
|
|
9
|
+
|
|
10
|
+
DOTPI_JACKD_ARGUMENTS=(
|
|
11
|
+
--realtime
|
|
12
|
+
--realtime-priority 95
|
|
13
|
+
-d alsa
|
|
14
|
+
--device -d bluealsa
|
|
15
|
+
--period 1024
|
|
16
|
+
--nperiods 2
|
|
17
|
+
--rate 48000
|
|
18
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
local_file="$(dotpi readlink_follow "$0")"
|
|
4
|
+
local_path="$(dirname -- "$local_file")"
|
|
5
|
+
|
|
6
|
+
source "${local_path}/dotpi_jackd.bash"
|
|
7
|
+
|
|
8
|
+
echo "dotpi_jackd_command"
|
|
9
|
+
|
|
10
|
+
echo "ENV: ${DOTPI_JACKD_ENVIRONMENT[@]}"
|
|
11
|
+
echo "ARGS: ${DOTPI_JACKD_ARGUMENTS[@]}"
|
|
12
|
+
|
|
13
|
+
for e in "${DOTPI_JACKD_ENVIRONMENT[@]}" ; do
|
|
14
|
+
export "$e"
|
|
15
|
+
done
|
|
16
|
+
|
|
17
|
+
while IFS= read -r output ; do
|
|
18
|
+
jackd_pid="$!"
|
|
19
|
+
# forward output
|
|
20
|
+
echo "$output"
|
|
21
|
+
if [[ "$output" =~ JackAudioDriver.*stopping ]] ; then
|
|
22
|
+
dotpi echo_error "jackd stopped, it will be killed."
|
|
23
|
+
kill "$jackd_pid"
|
|
24
|
+
fi
|
|
25
|
+
done < <( jackd "${DOTPI_JACKD_ARGUMENTS[@]}" 2>&1)
|
|
26
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# keep this
|
|
2
|
+
DOTPI_JACKD_ENVIRONMENT=(
|
|
3
|
+
JACK_NO_AUDIO_RESERVATION=1
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
# warning: long option for -d (--driver) seems broken
|
|
7
|
+
|
|
8
|
+
# explicit outchannels (default is 0)
|
|
9
|
+
|
|
10
|
+
DOTPI_JACKD_ARGUMENTS=(
|
|
11
|
+
--realtime
|
|
12
|
+
--realtime-priority 95
|
|
13
|
+
-d alsa
|
|
14
|
+
--device hw:0
|
|
15
|
+
--playback
|
|
16
|
+
--period 1024
|
|
17
|
+
--nperiods 2
|
|
18
|
+
--rate 48000
|
|
19
|
+
--inchannels 0
|
|
20
|
+
--outchannels 2
|
|
21
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# keep this
|
|
2
|
+
DOTPI_JACKD_ENVIRONMENT=(
|
|
3
|
+
JACK_NO_AUDIO_RESERVATION=1
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
# warning: long option for -d (--driver) seems broken
|
|
7
|
+
|
|
8
|
+
DOTPI_JACKD_ARGUMENTS=(
|
|
9
|
+
--realtime
|
|
10
|
+
--realtime-priority 95
|
|
11
|
+
-d alsa
|
|
12
|
+
--device hw:0,0
|
|
13
|
+
--duplex
|
|
14
|
+
--period 128
|
|
15
|
+
--nperiods 2
|
|
16
|
+
--rate 48000
|
|
17
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=Jack service
|
|
3
|
+
After=sound.target
|
|
4
|
+
|
|
5
|
+
[Service]
|
|
6
|
+
Type=exec
|
|
7
|
+
LimitRTPRIO=infinity
|
|
8
|
+
LimitMEMLOCK=infinity
|
|
9
|
+
User=pi
|
|
10
|
+
Group=audio
|
|
11
|
+
ExecStart=/opt/dotpi/share/jackd/dotpi_jackd_command
|
|
12
|
+
Restart=always
|
|
13
|
+
|
|
14
|
+
# wait before restarting
|
|
15
|
+
RestartSec=1s
|
|
16
|
+
|
|
17
|
+
# Do not stop to try restarting service
|
|
18
|
+
StartLimitBurst=0
|
|
19
|
+
|
|
20
|
+
[Install]
|
|
21
|
+
WantedBy=multi-user.target
|
|
22
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Provided by the jackd package.
|
|
2
|
+
#
|
|
3
|
+
# Changes to this file will be preserved.
|
|
4
|
+
#
|
|
5
|
+
# If you want to enable/disable realtime permissions, run
|
|
6
|
+
#
|
|
7
|
+
# dpkg-reconfigure -p high jackd2
|
|
8
|
+
|
|
9
|
+
@audio - rtprio 95
|
|
10
|
+
@audio - memlock unlimited
|
|
11
|
+
#@audio - nice -19
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
dotpi_project_name='example'
|
|
4
|
+
|
|
5
|
+
# default to "yes" (password and/or ssh keys must be defined in "secrets")
|
|
6
|
+
dotpi_ssh_allow_password_authentication='yes'
|
|
7
|
+
|
|
8
|
+
# define soundcard
|
|
9
|
+
dotpi_audio_device='HiFiBerry DAC+ ADC Pro'
|
|
10
|
+
|
|
11
|
+
# define node.js version (defaults to lts)
|
|
12
|
+
dotpi_node_version='lts'
|
|
13
|
+
|
|
14
|
+
# add packages (make sure to keep the parentheses, even for a single line)
|
|
15
|
+
dotpi_apt_install+=(
|
|
16
|
+
#### utilities ####
|
|
17
|
+
# 'locate' # find files
|
|
18
|
+
'screen' # detach sessions
|
|
19
|
+
|
|
20
|
+
#### compilation ####
|
|
21
|
+
'cmake'
|
|
22
|
+
'make'
|
|
23
|
+
'scons'
|
|
24
|
+
|
|
25
|
+
#### network ####
|
|
26
|
+
'dnsutils' # dig
|
|
27
|
+
'nmap' # test clients in network
|
|
28
|
+
|
|
29
|
+
#### audio ####
|
|
30
|
+
'jackmeter' # monitor sound activity in console
|
|
31
|
+
# 'mpv' # play soundfiles via jackd
|
|
32
|
+
# 'sox' # manipulate soundfile
|
|
33
|
+
# 'vlc' # play soundfiles via jackd
|
|
34
|
+
|
|
35
|
+
#### bluetooth ####
|
|
36
|
+
# 'bluez'
|
|
37
|
+
# 'bluez-alsa'
|
|
38
|
+
# 'bluez-alsa-utils' # bluealsa-aplay to get sound from Bluetooth
|
|
39
|
+
# 'bluez-tools'
|
|
40
|
+
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
dotpi_project_name='example'
|
|
4
|
+
|
|
5
|
+
dotpi_ssh_allow_password_authentication='yes'
|
|
6
|
+
|
|
7
|
+
dotpi_audio_device='Headphones'
|
|
8
|
+
|
|
9
|
+
# add packages
|
|
10
|
+
# be sure to keep the parentheses, even for a single line
|
|
11
|
+
dotpi_apt_install+=(
|
|
12
|
+
# 'dnsutils' # dig
|
|
13
|
+
'jackmeter' # monitor sound activity in console
|
|
14
|
+
# 'locate'
|
|
15
|
+
# 'nmap' # test clients in network
|
|
16
|
+
'screen' # detach sessions
|
|
17
|
+
# 'mpv' # play soundfiles via jackd
|
|
18
|
+
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
dotpi_project_name='example'
|
|
4
|
+
|
|
5
|
+
dotpi_ssh_allow_password_authentication='yes'
|
|
6
|
+
|
|
7
|
+
dotpi_audio_device='HiFiBerry DAC+ ADC Pro'
|
|
8
|
+
|
|
9
|
+
# add packages
|
|
10
|
+
# be sure to keep the parentheses, even for a single line
|
|
11
|
+
dotpi_apt_install+=(
|
|
12
|
+
# 'dnsutils' # dig
|
|
13
|
+
'jackmeter' # monitor sound activity in console
|
|
14
|
+
# 'locate'
|
|
15
|
+
# 'nmap' # test clients in network
|
|
16
|
+
'screen' # detach sessions
|
|
17
|
+
# 'mpv' # play soundfiles via jackd
|
|
18
|
+
)
|