Skip to content

Commit a4efc89

Browse files
authored
Merge pull request #509 from OpenVoiceOS/fix/uninstall-remove-mark2-boot-artifacts
Clean Mark II boot artifacts on uninstall
2 parents e39ec5d + 20e946d commit a4efc89

4 files changed

Lines changed: 133 additions & 0 deletions

File tree

ansible/roles/ovos_hardware_mark2/defaults/main.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ ovos_hardware_mark2_sj201_flash_tool: xvf3510-flash
4545
ovos_hardware_mark2_sj201_firmware_image: app_xvf3510_int_spi_boot_v4_2_0.bin
4646
ovos_hardware_mark2_sj201_post_init_script: init_tas5806
4747
ovos_hardware_mark2_sj201_runtime_path: /usr/local/bin:/usr/sbin:/usr/bin:/bin
48+
ovos_hardware_mark2_enable_uart_line: "enable_uart=1"
4849
ovos_hardware_mark2_vocalfusion_dtbo_overlays:
4950
- sj201
5051
- sj201-buttons-overlay
@@ -54,6 +55,10 @@ ovos_hardware_mark2_pi5_model_match: "Raspberry Pi 5"
5455
ovos_hardware_mark2_modules_load_path: /etc/modules-load.d/vocalfusion.conf
5556
ovos_hardware_mark2_modules_load_content: |
5657
{{ ovos_hardware_mark2_vocalfusion_module_name }}
58+
ovos_hardware_mark2_user_runtime_dir: "/run/user/{{ ovos_installer_uid }}"
59+
ovos_hardware_mark2_user_bus_environment:
60+
XDG_RUNTIME_DIR: "{{ ovos_hardware_mark2_user_runtime_dir }}"
61+
DBUS_SESSION_BUS_ADDRESS: "unix:path={{ ovos_hardware_mark2_user_runtime_dir }}/bus"
5762
ovos_hardware_mark2_sj201_venv_path: "{{ ovos_installer_user_home }}/.venvs/sj201"
5863
ovos_hardware_mark2_sj201_venv_command: "{{ ansible_facts.python.executable }} -m venv"
5964
ovos_hardware_mark2_sj201_venv_packages:
@@ -89,5 +94,41 @@ ovos_hardware_mark2_backlight_overlay: "dtoverlay=rpi-backlight"
8994
ovos_hardware_mark2_touchscreen_overlays:
9095
- { overlay: "dtoverlay=vc4-kms-v3d", state: "absent" }
9196
- { overlay: "dtoverlay=vc4-fkms-v3d", state: "present" }
97+
ovos_hardware_mark2_touchscreen_present_overlays:
98+
- "dtoverlay=vc4-fkms-v3d"
99+
ovos_hardware_mark2_boot_config_cleanup_lines: >-
100+
{{
101+
[ovos_hardware_mark2_enable_uart_line, ovos_hardware_mark2_backlight_overlay]
102+
+ ovos_hardware_mark2_touchscreen_present_overlays
103+
+ (ovos_hardware_mark2_vocalfusion_dtbo_overlays | map('regex_replace', '^', 'dtoverlay=') | list)
104+
+ (
105+
ovos_hardware_mark2_vocalfusion_dtbo_overlays
106+
| map('regex_replace', '^', 'dtoverlay=')
107+
| map('regex_replace', '$', ovos_hardware_mark2_pi5_suffix)
108+
| list
109+
)
110+
}}
111+
ovos_hardware_mark2_overlay_cleanup_paths: >-
112+
{{
113+
(
114+
ovos_hardware_mark2_vocalfusion_dtbo_overlays
115+
| map('regex_replace', '$', '.dtbo')
116+
| list
117+
)
118+
+ (
119+
ovos_hardware_mark2_vocalfusion_dtbo_overlays
120+
| map('regex_replace', '$', ovos_hardware_mark2_pi5_suffix ~ '.dtbo')
121+
| list
122+
)
123+
| map('regex_replace', '^(.*)$', ovos_hardware_mark2_boot_overlays_dir ~ '/\\1')
124+
| list
125+
}}
126+
ovos_hardware_mark2_uninstall_paths:
127+
- "{{ ovos_hardware_mark2_working_dir }}"
128+
- "{{ ovos_hardware_mark2_sj201_venv_path }}"
129+
- "{{ ovos_hardware_mark2_sj201_unit_path }}"
130+
- "{{ ovos_hardware_mark2_wireplumber_conf_dir }}/{{ ovos_hardware_mark2_wireplumber_profile_conf_src }}"
131+
- "{{ ovos_hardware_mark2_modules_load_path }}"
132+
- "{{ ovos_hardware_mark2_vocalfusion_module_path }}"
92133
ovos_hardware_mark2_wireplumber_profile_conf_src: 90-sj201-profile.conf
93134
ovos_hardware_mark2_wireplumber_profile_conf_mode: "0644"

ansible/roles/ovos_hardware_mark2/tasks/uninstall.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,39 @@
3131
- ansible_facts.os_family == "Debian"
3232
- (ovos_installer_package_tracking_tracked_packages_to_remove | default([]) | length) == 0
3333
or ovos_hardware_mark2_kernel_headers_uninstall_result is not ansible.builtin.failed
34+
35+
- name: Stop and disable SJ201 systemd unit
36+
become: true
37+
become_user: "{{ ovos_installer_user }}"
38+
ansible.builtin.systemd_service:
39+
name: "{{ ovos_hardware_mark2_sj201_unit_name }}"
40+
enabled: false
41+
state: stopped
42+
scope: user
43+
daemon_reload: true
44+
environment: "{{ ovos_hardware_mark2_user_bus_environment }}"
45+
failed_when: false
46+
47+
- name: Remove Mark 2 boot config lines
48+
ansible.builtin.lineinfile:
49+
path: "{{ ovos_hardware_mark2_boot_config_path }}"
50+
regexp: "^{{ item | regex_escape() }}$"
51+
state: absent
52+
loop: "{{ ovos_hardware_mark2_boot_config_cleanup_lines }}"
53+
notify: Set Reboot
54+
55+
- name: Remove copied Mark 2 boot overlay files
56+
ansible.builtin.file:
57+
path: "{{ item }}"
58+
state: absent
59+
loop: "{{ ovos_hardware_mark2_overlay_cleanup_paths }}"
60+
notify: Set Reboot
61+
62+
- name: Remove Mark 2 runtime artifacts
63+
ansible.builtin.file:
64+
path: "{{ item }}"
65+
state: absent
66+
loop: "{{ ovos_hardware_mark2_uninstall_paths }}"
67+
notify:
68+
- Run Depmod
69+
- Set Reboot

ansible/roles/ovos_hardware_mark2/tasks/vocalfusion.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@
5454
loop: "{{ ovos_hardware_mark2_vocalfusion_dtbo_overlays | map('regex_replace', '^', 'dtoverlay=') | list }}"
5555
notify: Set Reboot
5656

57+
- name: Ensure UART is enabled for SJ201 initialization
58+
ansible.builtin.lineinfile:
59+
path: "{{ ovos_hardware_mark2_boot_config_path }}"
60+
regexp: "^enable_uart="
61+
line: "{{ ovos_hardware_mark2_enable_uart_line }}"
62+
notify: Set Reboot
63+
5764
- name: Build vocalfusion-soundcard.ko kernel module
5865
ansible.builtin.shell:
5966
cmd: "{{ ovos_hardware_mark2_vocalfusion_make_cmd }}"

tests/bats/code_quality.bats

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,15 @@ function setup() {
13041304

13051305
run bash -c "grep -A8 -F -- \"- name: Remove tracked kernel headers package\" \"$uninstall_file\" | grep -F -q -- \"autoremove: true\""
13061306
assert_success
1307+
1308+
run grep -F -q "Remove Mark 2 boot config lines" "$uninstall_file"
1309+
assert_success
1310+
1311+
run grep -F -q "Remove copied Mark 2 boot overlay files" "$uninstall_file"
1312+
assert_success
1313+
1314+
run grep -F -q "Remove Mark 2 runtime artifacts" "$uninstall_file"
1315+
assert_success
13071316
}
13081317

13091318
@test "uninstall_package_removals_request_dependency_cleanup_across_distros" {
@@ -1592,8 +1601,10 @@ function setup() {
15921601
}
15931602

15941603
@test "mark2_boot_config_changes_flag_reboot" {
1604+
local defaults_file="ansible/roles/ovos_hardware_mark2/defaults/main.yml"
15951605
local touchscreen_file="ansible/roles/ovos_hardware_mark2/tasks/touchscreen.yml"
15961606
local vocalfusion_file="ansible/roles/ovos_hardware_mark2/tasks/vocalfusion.yml"
1607+
local uninstall_file="ansible/roles/ovos_hardware_mark2/tasks/uninstall.yml"
15971608

15981609
run bash -c "grep -A5 -F -- \"- name: Add rpi-backlight DT overlay\" \"$touchscreen_file\" | grep -q -- \"notify: Set Reboot\""
15991610
assert_success
@@ -1607,8 +1618,46 @@ function setup() {
16071618
run bash -c "grep -A10 -F -- \"- name: Manage sj201, buttons and PWM overlays\" \"$vocalfusion_file\" | grep -q -- \"notify: Set Reboot\""
16081619
assert_success
16091620

1621+
run grep -F -q 'ovos_hardware_mark2_enable_uart_line: "enable_uart=1"' "$defaults_file"
1622+
assert_success
1623+
1624+
run bash -c "grep -A5 -F -- \"- name: Ensure UART is enabled for SJ201 initialization\" \"$vocalfusion_file\" | grep -q -- \"notify: Set Reboot\""
1625+
assert_success
1626+
16101627
run bash -c "grep -A8 -F -- \"- name: Create modules-load config for vocalfusion\" \"$vocalfusion_file\" | grep -q -- \"notify: Set Reboot\""
16111628
assert_success
1629+
1630+
run bash -c "grep -A8 -F -- \"- name: Remove Mark 2 boot config lines\" \"$uninstall_file\" | grep -q -- \"notify: Set Reboot\""
1631+
assert_success
1632+
1633+
run bash -c "grep -A8 -F -- \"- name: Remove copied Mark 2 boot overlay files\" \"$uninstall_file\" | grep -q -- \"notify: Set Reboot\""
1634+
assert_success
1635+
}
1636+
1637+
@test "mark2_uninstall_removes_boot_config_and_runtime_artifacts" {
1638+
local defaults_file="ansible/roles/ovos_hardware_mark2/defaults/main.yml"
1639+
local uninstall_file="ansible/roles/ovos_hardware_mark2/tasks/uninstall.yml"
1640+
1641+
run grep -F -q 'ovos_hardware_mark2_enable_uart_line: "enable_uart=1"' "$defaults_file"
1642+
assert_success
1643+
1644+
run grep -F -q 'dtoverlay=rpi-backlight' "$defaults_file"
1645+
assert_success
1646+
1647+
run grep -F -q 'dtoverlay=vc4-fkms-v3d' "$defaults_file"
1648+
assert_success
1649+
1650+
run bash -c "grep -A8 -F -- \"- name: Stop and disable SJ201 systemd unit\" \"$uninstall_file\" | grep -F -q -- 'scope: user'"
1651+
assert_success
1652+
1653+
run bash -c "grep -A10 -F -- \"- name: Remove Mark 2 boot config lines\" \"$uninstall_file\" | grep -F -q -- 'ovos_hardware_mark2_boot_config_cleanup_lines'"
1654+
assert_success
1655+
1656+
run bash -c "grep -A5 -F -- \"- name: Remove copied Mark 2 boot overlay files\" \"$uninstall_file\" | grep -F -q -- 'ovos_hardware_mark2_overlay_cleanup_paths'"
1657+
assert_success
1658+
1659+
run bash -c "grep -A10 -F -- \"- name: Remove Mark 2 runtime artifacts\" \"$uninstall_file\" | grep -F -q -- 'ovos_hardware_mark2_uninstall_paths'"
1660+
assert_success
16121661
}
16131662

16141663
@test "mark2_sj201_service_includes_sbin_in_runtime_path" {

0 commit comments

Comments
 (0)