From 52989599dda1ade00bf46683a3c2e48c863da84c Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 16 Jul 2022 11:45:29 -0500 Subject: [PATCH 01/33] move iiab-internet-on|off - introduce netwarn --- roles/network/tasks/enable_services.yml | 11 ----------- roles/network/tasks/install.yml | 20 ++++++++++++++++++++ scripts/netwarn.sh | 8 ++++++++ 3 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 scripts/netwarn.sh diff --git a/roles/network/tasks/enable_services.yml b/roles/network/tasks/enable_services.yml index 2991a0c58..4566c00bb 100644 --- a/roles/network/tasks/enable_services.yml +++ b/roles/network/tasks/enable_services.yml @@ -202,17 +202,6 @@ # group: root mode: 0755 -- name: Install /usr/bin/iiab-internet-on|off from template (root:root by default) - template: - src: "{{ item }}" - dest: /usr/bin/ - # owner: root - # group: root - mode: 0755 - with_items: - - gateway/iiab-internet-on - - gateway/iiab-internet-off - - name: Add 'squid' variable values to {{ iiab_ini_file }} - if squid_installed is defined ini_file: diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index 08ddb9113..2a76b10c2 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -76,6 +76,26 @@ include_tasks: roles/network/tasks/squid.yml when: squid_install and squid_installed is undefined +- name: Link /usr/local/sbin/netwarn to {{ iiab_dir }}/scripts/netwarn + file: + src: "{{ iiab_dir }}/scripts/netwarn.sh" + dest: /usr/local/sbin/netwarn + mode: '0755' + state: link + +- name: Install /usr/bin/iiab-internet-on|off from template (root:root by default) + template: + src: "{{ item }}" + dest: /usr/bin/ + # owner: root + # group: root + mode: 0755 + with_items: + - gateway/iiab-internet-on + - gateway/iiab-internet-off + +# mate desktop detection based on 'register: nd_dir' + - name: "Set 'network_installed: True'" set_fact: diff --git a/scripts/netwarn.sh b/scripts/netwarn.sh new file mode 100644 index 000000000..8524c22f8 --- /dev/null +++ b/scripts/netwarn.sh @@ -0,0 +1,8 @@ +if ! [ -f /etc/iiab/install-flags/iiab-network-complete ]; then + zenity --question --text="You need to provision the network. Ensure you have your upstream internet active first if needed. You will be prompted for your password. You should REBOOT afterwards, do you want to Proceed?" + rc=$? + if [ $rc == "1" ]; then + exit 1 + fi + x-terminal-emulator -e /usr/local/bin/iiab-network +fi From 8d42038ad2c0dc80121ee429c097ee91640cdd08 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 16 Jul 2022 12:16:09 -0500 Subject: [PATCH 02/33] introduce netwarn-iiab-network.desktop --- roles/network/tasks/install.yml | 21 ++++++++++++++++++++- scripts/netwarn-iiab-network.desktop | 10 ++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 scripts/netwarn-iiab-network.desktop diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index 2a76b10c2..301b3ddc0 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -94,8 +94,27 @@ - gateway/iiab-internet-on - gateway/iiab-internet-off -# mate desktop detection based on 'register: nd_dir' +# mate desktop detection based on 'register: nd_dir' in enable_services +- name: Check if /usr/share/mate/autostart/ exists + stat: + path: /usr/share/mate/autostart/ + register: mate_dir +- name: Link /usr/share/mate/autostart/netwarn-iiab-network.desktop to {{ iiab_dir }}/scripts/netwarn-iiab-network.desktop + file: + src: "{{ iiab_dir }}/scripts/netwarn" + dest: /usr/share/mate/autostart/netwarn-iiab-network.desktop + mode: '0755' + state: link + when: mate_dir.stat.exists and mate_dir.stat.isdir + +# RpiOS detection based on register: lx in pwd-warnings.yml +- name: Is /etc/xdg/lxsession/LXDE-pi a directory? + stat: + path: /etc/xdg/lxsession/LXDE-pi + register: lx + +# clairify usage - name: "Set 'network_installed: True'" set_fact: diff --git a/scripts/netwarn-iiab-network.desktop b/scripts/netwarn-iiab-network.desktop new file mode 100644 index 000000000..35547ee41 --- /dev/null +++ b/scripts/netwarn-iiab-network.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name[en_US]=iiab-network +Comment[en_US]=iiab-network +Name[en_CA]=iiab-network +Comment[en_CA]=iiab-network +Type=Application +Exec=/usr/local/sbin/netwarn +Hidden=false +Name=iiab-network +Comment=iiab-network From a3de7b389d3f6add35d748a13a63bddf85492dbe Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 16 Jul 2022 12:47:30 -0500 Subject: [PATCH 03/33] also allow ICO to set the complete flag --- roles/network/tasks/main.yml | 6 ++++++ scripts/iiab-network | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index 8e225eb40..1fce28475 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -101,3 +101,9 @@ include_tasks: restart.yml # end block when: network_installed is defined and network_enabled + +- name: Create {{ iiab_etc_path }}/install-flags/iiab-network-complete on second pass of network role. + file: + path: "{{ iiab_etc_path }}/install-flags/iiab-network-complete" + state: touch + when: iiab_stage|int == 9 diff --git a/scripts/iiab-network b/scripts/iiab-network index 9e56350eb..c2d12056f 100644 --- a/scripts/iiab-network +++ b/scripts/iiab-network @@ -1,7 +1,3 @@ #!/bin/bash -e cd /opt/iiab/iiab sudo ./iiab-network -rc=$? -if [[ $rc == "0" ]]; then - sudo touch /etc/iiab/install-flags/iiab-network-complete -fi From e6155e6a864c9cc8d5710d889b008b57b0a706ee Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 17 Jul 2022 15:15:56 -0500 Subject: [PATCH 04/33] netwarn - with reboot question --- roles/network/tasks/install.yml | 2 +- scripts/netwarn.sh | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index 301b3ddc0..592c1612c 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -80,7 +80,7 @@ file: src: "{{ iiab_dir }}/scripts/netwarn.sh" dest: /usr/local/sbin/netwarn - mode: '0755' + mode: 0755 state: link - name: Install /usr/bin/iiab-internet-on|off from template (root:root by default) diff --git a/scripts/netwarn.sh b/scripts/netwarn.sh index 8524c22f8..641d5ba81 100644 --- a/scripts/netwarn.sh +++ b/scripts/netwarn.sh @@ -1,8 +1,20 @@ +#!/bin/bash if ! [ -f /etc/iiab/install-flags/iiab-network-complete ]; then - zenity --question --text="You need to provision the network. Ensure you have your upstream internet active first if needed. You will be prompted for your password. You should REBOOT afterwards, do you want to Proceed?" + zenity --question --width=200 --text="You need to provision the network. Ensure you have your upstream internet active first. You might be prompted for your password. Should you not want to provision the network at this time just click NO" rc=$? if [ $rc == "1" ]; then - exit 1 + exit 0 fi x-terminal-emulator -e /usr/local/bin/iiab-network + rc=$? + if [ $rc == "1" ]; then + zenity --question --width=200 --text="Network exited with error, please review /opt/iiab/iiab/iiab-network.log" + exit 1 + fi + zenity --question --width=200 --text="A REBOOT is recommended, would you like to REBOOT now?" + rc=$? + if [ $rc == "1" ]; then + exit 0 + fi + x-terminal-emulator -e /usr/sbin/reboot fi From 700cdc9a07d421eda9390267ebc6bf646f98e678 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 18 Jul 2022 20:33:08 -0500 Subject: [PATCH 05/33] switch to using dash via sh --- scripts/netwarn.sh | 47 +++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/scripts/netwarn.sh b/scripts/netwarn.sh index 641d5ba81..457152b37 100644 --- a/scripts/netwarn.sh +++ b/scripts/netwarn.sh @@ -1,20 +1,29 @@ -#!/bin/bash -if ! [ -f /etc/iiab/install-flags/iiab-network-complete ]; then - zenity --question --width=200 --text="You need to provision the network. Ensure you have your upstream internet active first. You might be prompted for your password. Should you not want to provision the network at this time just click NO" - rc=$? - if [ $rc == "1" ]; then - exit 0 - fi - x-terminal-emulator -e /usr/local/bin/iiab-network - rc=$? - if [ $rc == "1" ]; then - zenity --question --width=200 --text="Network exited with error, please review /opt/iiab/iiab/iiab-network.log" - exit 1 - fi - zenity --question --width=200 --text="A REBOOT is recommended, would you like to REBOOT now?" - rc=$? - if [ $rc == "1" ]; then - exit 0 - fi - x-terminal-emulator -e /usr/sbin/reboot +#!/bin/sh +if [ -f /etc/iiab/install-flags/iiab-network-complete ]; then + exit +fi + +zenity --question --width=350 --text="IIAB needs to configure networking:\n\n► Internet must be live before you begin.\n►You might be prompted for your password.\n\nContinue?" +case $? in + -1|5) + exit 1 + ;; + + 1) + exit 0 + ;; + + 0) + x-terminal-emulator -e /usr/local/bin/iiab-network + ;; +esac + +if [ "$?" = "1" ]; then + zenity --warning --width=350 --text="iiab-network exited with error.\n\nPlease review /opt/iiab/iiab/iiab-network.log" + exit 1 +fi + +zenity --question --width=350 --text="iiab-network complete.\n\nWould you like to REBOOT now? (Recommended)" +if [ "$?" = "0" ]; then + x-terminal-emulator -e "sudo reboot" fi From a5c8dcc904e1c9c1426f5d8580e5560479d2e421 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 18 Jul 2022 22:53:41 -0500 Subject: [PATCH 06/33] rework --- roles/network/tasks/install.yml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index 592c1612c..20c6f279b 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -76,13 +76,7 @@ include_tasks: roles/network/tasks/squid.yml when: squid_install and squid_installed is undefined -- name: Link /usr/local/sbin/netwarn to {{ iiab_dir }}/scripts/netwarn - file: - src: "{{ iiab_dir }}/scripts/netwarn.sh" - dest: /usr/local/sbin/netwarn - mode: 0755 - state: link - +# all installs - name: Install /usr/bin/iiab-internet-on|off from template (root:root by default) template: src: "{{ item }}" @@ -100,11 +94,21 @@ path: /usr/share/mate/autostart/ register: mate_dir +# contents work with mate as of 'switch to using dash via sh' +# 'text' is up for debate other structural changes I do not recommend JV +# if need be cut a second version for RasPiOS + +- name: Link /usr/local/sbin/netwarn to {{ iiab_dir }}/scripts/netwarn + file: + src: "{{ iiab_dir }}/scripts/netwarn.sh" + dest: /usr/local/sbin/netwarn + state: link + when: mate_dir.stat.exists and mate_dir.stat.isdir + - name: Link /usr/share/mate/autostart/netwarn-iiab-network.desktop to {{ iiab_dir }}/scripts/netwarn-iiab-network.desktop file: - src: "{{ iiab_dir }}/scripts/netwarn" + src: "{{ iiab_dir }}/scripts/netwarn-iiab-network.desktop" dest: /usr/share/mate/autostart/netwarn-iiab-network.desktop - mode: '0755' state: link when: mate_dir.stat.exists and mate_dir.stat.isdir From ad3d4f2ea913b27f184833ae203be4ba5a606e8d Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 18 Jul 2022 23:22:11 -0500 Subject: [PATCH 07/33] speedup - ssh ports are not changing --- roles/network/tasks/install.yml | 7 +++++-- roles/network/tasks/main.yml | 2 -- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index 20c6f279b..330d6bd38 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -61,12 +61,12 @@ #- { name: 'net.ipv6.conf.lo.disable_ipv6', value: '1' } # BY ABOVE -# UNMAINTAINED +# UNUSED #- name: Install named / BIND # include_tasks: roles/network/tasks/named.yml # when: named_install is defined and named_install -# UNMAINTAINED +# UNUSED #- name: Install dhcpd # include_tasks: roles/network/tasks/dhcpd.yml # when: dhcpd_install is defined and dhcpd_install @@ -88,6 +88,9 @@ - gateway/iiab-internet-on - gateway/iiab-internet-off +- name: avahi + include_tasks: avahi.yml + # mate desktop detection based on 'register: nd_dir' in enable_services - name: Check if /usr/share/mate/autostart/ exists stat: diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index 1fce28475..aecbc5d7e 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -65,8 +65,6 @@ when: is_ubuntu and not is_ubuntu_16 #### Start services - - name: avahi - include_tasks: avahi.yml - name: hostapd include_tasks: hostapd.yml - name: computed_services From 9bc9f3aeee0c95b92cd0bf890d88409e229f961b Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 18 Jul 2022 23:49:25 -0500 Subject: [PATCH 08/33] fedora files --- .../templates/network/{ifcfg-WAN.j2 => ifcfg-WAN.j2.unsued} | 0 .../templates/network/{ifcfg-slave.j2 => ifcfg-slave.j2.unused} | 0 roles/network/templates/network/{ifcfg.j2 => ifcfg.j2.usused} | 0 .../network/{sysconfig.network.j2 => sysconfig.network.j2.unused} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename roles/network/templates/network/{ifcfg-WAN.j2 => ifcfg-WAN.j2.unsued} (100%) rename roles/network/templates/network/{ifcfg-slave.j2 => ifcfg-slave.j2.unused} (100%) rename roles/network/templates/network/{ifcfg.j2 => ifcfg.j2.usused} (100%) rename roles/network/templates/network/{sysconfig.network.j2 => sysconfig.network.j2.unused} (100%) diff --git a/roles/network/templates/network/ifcfg-WAN.j2 b/roles/network/templates/network/ifcfg-WAN.j2.unsued similarity index 100% rename from roles/network/templates/network/ifcfg-WAN.j2 rename to roles/network/templates/network/ifcfg-WAN.j2.unsued diff --git a/roles/network/templates/network/ifcfg-slave.j2 b/roles/network/templates/network/ifcfg-slave.j2.unused similarity index 100% rename from roles/network/templates/network/ifcfg-slave.j2 rename to roles/network/templates/network/ifcfg-slave.j2.unused diff --git a/roles/network/templates/network/ifcfg.j2 b/roles/network/templates/network/ifcfg.j2.usused similarity index 100% rename from roles/network/templates/network/ifcfg.j2 rename to roles/network/templates/network/ifcfg.j2.usused diff --git a/roles/network/templates/network/sysconfig.network.j2 b/roles/network/templates/network/sysconfig.network.j2.unused similarity index 100% rename from roles/network/templates/network/sysconfig.network.j2 rename to roles/network/templates/network/sysconfig.network.j2.unused From ce25ac3cdc3232c24905240b79bee71693b64757 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 18 Jul 2022 23:44:19 -0500 Subject: [PATCH 09/33] netplan setup is one time and may not even be needed --- roles/network/tasks/install.yml | 10 +++++++--- roles/network/tasks/main.yml | 5 ----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index 330d6bd38..15ec9331c 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -45,6 +45,8 @@ # dest: /etc/network/if-pre-up.d/iptables # mode: '0755' +- name: avahi + include_tasks: avahi.yml # Ongoing rework (e.g. PR #2652) arising from ansible.posix collection changes: - name: "4 network settings in /etc/sysctl.conf -- e.g. disabling IPv6 (this might be overkill, as IPv6 should really only be disabled on the LAN side, i.e. br0)" @@ -76,6 +78,11 @@ include_tasks: roles/network/tasks/squid.yml when: squid_install and squid_installed is undefined + #preprep for backends +- name: Netplan in use on Ubuntu 18.04+ + include_tasks: netplan.yml + when: is_ubuntu + # all installs - name: Install /usr/bin/iiab-internet-on|off from template (root:root by default) template: @@ -88,9 +95,6 @@ - gateway/iiab-internet-on - gateway/iiab-internet-off -- name: avahi - include_tasks: avahi.yml - # mate desktop detection based on 'register: nd_dir' in enable_services - name: Check if /usr/share/mate/autostart/ exists stat: diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index aecbc5d7e..579bf64e9 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -59,11 +59,6 @@ # include_tasks: squid.yml # when: squid_install and FQDN_changed and iiab_stage|int == 9 - #preprep for backends - - name: Netplan in use on Ubuntu 18.04+ - include_tasks: netplan.yml - when: is_ubuntu and not is_ubuntu_16 - #### Start services - name: hostapd include_tasks: hostapd.yml From 85a5f8fd985d000ec1ddea47b0538e29d40cddd8 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 19 Jul 2022 00:05:34 -0500 Subject: [PATCH 10/33] unmask hostapd once --- roles/network/tasks/hostapd.yml | 3 +-- roles/network/tasks/install.yml | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/roles/network/tasks/hostapd.yml b/roles/network/tasks/hostapd.yml index 0bae7b20f..520567a66 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -1,8 +1,7 @@ -- name: Unmask the Access Point 'hostapd' service +- name: Disable the Access Point 'hostapd' service systemd: name: hostapd enabled: no - masked: no - name: Disable hostapd when not using ap0 and wifi gateway present, or no WiFi hardware present or support not detected set_fact: diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index 15ec9331c..4272cd627 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -45,6 +45,12 @@ # dest: /etc/network/if-pre-up.d/iptables # mode: '0755' +-- name: Unmask the Access Point 'hostapd' service + systemd: + name: hostapd + enabled: no + masked: no + - name: avahi include_tasks: avahi.yml From 861652f141282ef212022e62a177aaabd4a4378e Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 19 Jul 2022 00:49:28 -0500 Subject: [PATCH 11/33] hostapd refinement --- roles/network/tasks/hostapd.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/roles/network/tasks/hostapd.yml b/roles/network/tasks/hostapd.yml index 520567a66..99fb6cf41 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -1,13 +1,14 @@ -- name: Disable the Access Point 'hostapd' service - systemd: - name: hostapd - enabled: no - - name: Disable hostapd when not using ap0 and wifi gateway present, or no WiFi hardware present or support not detected set_fact: hostapd_enabled: False when: (not wifi_up_down and discovered_wireless_iface == iiab_wan_iface) or discovered_wireless_iface == "none" or not can_be_ap +- name: Disable the Access Point 'hostapd' service + systemd: + name: hostapd + enabled: no + when: not hostapd_enabled + - name: Detect current Wifi channel shell: iw {{ discovered_wireless_iface }} info | grep channel | cut -d' ' -f2 register: current_client_channel @@ -21,10 +22,12 @@ - name: Generate new random mac address for ap0 shell: tr -dc A-F0-9 < /dev/urandom | head -c 10 | sed -r 's/(..)/\1:/g;s/:$//;s/^/02:/' register: ap0_mac + when: can_be_ap - name: Setting ap0 mac address for use in hostapd service file set_fact: ap0_mac_addr: "{{ ap0_mac.stdout }}" + when: can_be_ap - name: "Use custom 'hostapd' systemd service unit file using ap0 -- install from template: /etc/systemd/system/hostapd.service, /etc/systemd/system/iiab-clone-wifi.service, /etc/systemd/system/iiab-wifi-test.service, /usr/sbin/iiab-test-wifi" template: From 4f05d638fb39c700bd2208406c96df0777715877 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 21 Jul 2022 14:02:14 -0400 Subject: [PATCH 12/33] scripts/netwarn.sh: Cleaner pop-ups & #!/bin/sh in-line explanation --- scripts/netwarn.sh | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/scripts/netwarn.sh b/scripts/netwarn.sh index 457152b37..59a0cc20a 100644 --- a/scripts/netwarn.sh +++ b/scripts/netwarn.sh @@ -1,29 +1,32 @@ #!/bin/sh + +# Some OS's like Ubuntu with LightDM *IGNORE* the above shebang line when this +# script is invcked from /usr/share/mate/autostart/netwarn-iiab-network.desktop +# +# WHAT HAPPENS: sh (dash) NOT BASH will always be run! As confirmed by: +# +# ps -p $$ # Whereas 'echo $SHELL' DOES NOT show the actual running shell! +# +# RECAP: We hard-code the above '#!/bin/sh' for uniformity across all distros. + if [ -f /etc/iiab/install-flags/iiab-network-complete ]; then exit fi -zenity --question --width=350 --text="IIAB needs to configure networking:\n\n► Internet must be live before you begin.\n►You might be prompted for your password.\n\nContinue?" -case $? in - -1|5) - exit 1 - ;; - - 1) - exit 0 - ;; - - 0) - x-terminal-emulator -e /usr/local/bin/iiab-network - ;; -esac - -if [ "$?" = "1" ]; then - zenity --warning --width=350 --text="iiab-network exited with error.\n\nPlease review /opt/iiab/iiab/iiab-network.log" - exit 1 +zenity --question --width=360 --text="IIAB needs to configure networking:\n\n► Internet must be live before you begin.\n►You might be prompted for your password.\n\nContinue? (This can take 2-3 minutes)" +rc=$? +if [ "$rc" != "0" ]; then + exit $rc fi -zenity --question --width=350 --text="iiab-network complete.\n\nWould you like to REBOOT now? (Recommended)" +x-terminal-emulator -e /usr/local/bin/iiab-network +rc=$? +if [ "$rc" != "0" ]; then + zenity --warning --width=360 --text="iiab-network exited with error: $rc\n\nPlease review /opt/iiab/iiab/iiab-network.log" + exit $rc +fi + +zenity --question --width=360 --text="iiab-network complete.\n\nWould you like to REBOOT now? (Recommended)" if [ "$?" = "0" ]; then x-terminal-emulator -e "sudo reboot" fi From a5610dd7d50760073e2406b5aa49dd57cd2df71d Mon Sep 17 00:00:00 2001 From: root Date: Thu, 21 Jul 2022 14:45:37 -0400 Subject: [PATCH 13/33] Add /usr/local/sbin/netwarn to /etc/xdg/lxsession/LXDE-pi/autostart --- roles/network/tasks/install.yml | 21 +++++++++++++++------ roles/www_options/tasks/main.yml | 18 +++++++++--------- scripts/{netwarn.sh => netwarn} | 0 3 files changed, 24 insertions(+), 15 deletions(-) rename scripts/{netwarn.sh => netwarn} (100%) diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index 4272cd627..8188446d4 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -113,7 +113,7 @@ - name: Link /usr/local/sbin/netwarn to {{ iiab_dir }}/scripts/netwarn file: - src: "{{ iiab_dir }}/scripts/netwarn.sh" + src: "{{ iiab_dir }}/scripts/netwarn" dest: /usr/local/sbin/netwarn state: link when: mate_dir.stat.exists and mate_dir.stat.isdir @@ -125,13 +125,22 @@ state: link when: mate_dir.stat.exists and mate_dir.stat.isdir -# RpiOS detection based on register: lx in pwd-warnings.yml -- name: Is /etc/xdg/lxsession/LXDE-pi a directory? +- name: Does /etc/xdg/lxsession/LXDE-pi/autostart exist? stat: - path: /etc/xdg/lxsession/LXDE-pi - register: lx + path: /etc/xdg/lxsession/LXDE-pi/autostart + register: lxde_pi_autostart_present -# clairify usage +- name: If so, add /usr/local/sbin/netwarn to /etc/xdg/lxsession/LXDE-pi/autostart + lineinfile: + path: /etc/xdg/lxsession/LXDE-pi/autostart + regexp: '^/usr/local/sbin/netwarn$' + line: '/usr/local/sbin/netwarn' + when: lxde_pi_autostart_present.stat.exists + +# Add logic for Mint & stock Ubuntu here? (in addition to Mate & LXDE-pi) + + +# RECORD Network AS INSTALLED - name: "Set 'network_installed: True'" set_fact: diff --git a/roles/www_options/tasks/main.yml b/roles/www_options/tasks/main.yml index 445ee5e0e..ec25d97ef 100644 --- a/roles/www_options/tasks/main.yml +++ b/roles/www_options/tasks/main.yml @@ -23,29 +23,29 @@ when: nginx_installed is defined #when: nginx_install -- name: Make home page autostart on localhost (the server's console) if session manager is LXDE (rpi) +- name: Does /etc/xdg/lxsession/LXDE-pi/autostart exist? (if so, auto-launch browser on boot, displaying http://box.lan IIAB home page) stat: path: /etc/xdg/lxsession/LXDE-pi/autostart - register: lxde_present + register: lxde_pi_autostart_present -- name: Check for Chromium name change +- name: Does /usr/bin/chromium exist? (check for browser filename change) stat: path: /usr/bin/chromium register: chromium_present -- name: Add chromium-browser to /etc/xdg/lxsession/LXDE-pi/autostart if session manager is LXDE +- name: Add chromium-browser to /etc/xdg/lxsession/LXDE-pi/autostart lineinfile: path: /etc/xdg/lxsession/LXDE-pi/autostart regexp: '^/usr/bin/chromium-browser' - line: '/usr/bin/chromium-browser --disable-restore-session-state http://box/home' - when: lxde_present.stat.exists and not chromium_present.stat.exists + line: '/usr/bin/chromium-browser --disable-restore-session-state http://box/home' + when: lxde_pi_autostart_present.stat.exists and not chromium_present.stat.exists -- name: Add chromium to /etc/xdg/lxsession/LXDE-pi/autostart if session manager is LXDE +- name: Add chromium to /etc/xdg/lxsession/LXDE-pi/autostart lineinfile: path: /etc/xdg/lxsession/LXDE-pi/autostart regexp: '^/usr/bin/chromium' - line: '/usr/bin/chromium --disable-restore-session-state http://box/home' - when: lxde_present.stat.exists and chromium_present.stat.exists + line: '/usr/bin/chromium --disable-restore-session-state http://box/home' + when: lxde_pi_autostart_present.stat.exists and chromium_present.stat.exists - debug: diff --git a/scripts/netwarn.sh b/scripts/netwarn similarity index 100% rename from scripts/netwarn.sh rename to scripts/netwarn From a442bd7b26cf4adaa9187bfa1aec2f92541d540a Mon Sep 17 00:00:00 2001 From: root Date: Thu, 21 Jul 2022 15:14:09 -0400 Subject: [PATCH 14/33] Move scripts/netwarn* to roles/network/templates/netwarn/ --- roles/network/tasks/install.yml | 43 ++----------------- roles/network/tasks/netwarn.yml | 37 ++++++++++++++++ .../network/templates/netwarn}/netwarn | 0 .../netwarn}/netwarn-iiab-network.desktop | 0 4 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 roles/network/tasks/netwarn.yml rename {scripts => roles/network/templates/netwarn}/netwarn (100%) mode change 100644 => 100755 rename {scripts => roles/network/templates/netwarn}/netwarn-iiab-network.desktop (100%) diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index 8188446d4..c84ec9a23 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -1,7 +1,7 @@ # 2022-03-16: 'apt show | grep Size' revealed download sizes, on 64-bit RasPiOS with desktop. - name: Install dnsmasq -- configure LATER in 'network', after Stage 9 - include_tasks: roles/network/tasks/dnsmasq.yml + include_tasks: dnsmasq.yml - name: Install package networkd-dispatcher (OS's other than RasPiOS) package: @@ -94,50 +94,13 @@ template: src: "{{ item }}" dest: /usr/bin/ - # owner: root - # group: root mode: 0755 with_items: - gateway/iiab-internet-on - gateway/iiab-internet-off -# mate desktop detection based on 'register: nd_dir' in enable_services -- name: Check if /usr/share/mate/autostart/ exists - stat: - path: /usr/share/mate/autostart/ - register: mate_dir - -# contents work with mate as of 'switch to using dash via sh' -# 'text' is up for debate other structural changes I do not recommend JV -# if need be cut a second version for RasPiOS - -- name: Link /usr/local/sbin/netwarn to {{ iiab_dir }}/scripts/netwarn - file: - src: "{{ iiab_dir }}/scripts/netwarn" - dest: /usr/local/sbin/netwarn - state: link - when: mate_dir.stat.exists and mate_dir.stat.isdir - -- name: Link /usr/share/mate/autostart/netwarn-iiab-network.desktop to {{ iiab_dir }}/scripts/netwarn-iiab-network.desktop - file: - src: "{{ iiab_dir }}/scripts/netwarn-iiab-network.desktop" - dest: /usr/share/mate/autostart/netwarn-iiab-network.desktop - state: link - when: mate_dir.stat.exists and mate_dir.stat.isdir - -- name: Does /etc/xdg/lxsession/LXDE-pi/autostart exist? - stat: - path: /etc/xdg/lxsession/LXDE-pi/autostart - register: lxde_pi_autostart_present - -- name: If so, add /usr/local/sbin/netwarn to /etc/xdg/lxsession/LXDE-pi/autostart - lineinfile: - path: /etc/xdg/lxsession/LXDE-pi/autostart - regexp: '^/usr/local/sbin/netwarn$' - line: '/usr/local/sbin/netwarn' - when: lxde_pi_autostart_present.stat.exists - -# Add logic for Mint & stock Ubuntu here? (in addition to Mate & LXDE-pi) +- name: 'Install /usr/local/sbin/netwarn for pop-ups on boot, if iiab-network should be run' + include_tasks: netwarn.yml # RECORD Network AS INSTALLED diff --git a/roles/network/tasks/netwarn.yml b/roles/network/tasks/netwarn.yml new file mode 100644 index 000000000..098a5c49e --- /dev/null +++ b/roles/network/tasks/netwarn.yml @@ -0,0 +1,37 @@ +# mate desktop detection based on 'register: nd_dir' in enable_services +- name: Does /usr/share/mate/autostart/ exist? + stat: + path: /usr/share/mate/autostart/ + register: mate_dir + +# contents work with mate as of 'switch to using dash via sh' +# 'text' is up for debate other structural changes I do not recommend JV + +- name: 'Install from template: /usr/local/sbin/netwarn' + file: + src: netwarn/netwarn + dest: /usr/local/sbin/ + mode: 0755 + when: mate_dir.stat.exists and mate_dir.stat.isdir + +- name: 'Install from template: /usr/share/mate/autostart/netwarn-iiab-network.desktop' + file: + src: netwarn/netwarn-iiab-network.desktop + dest: /usr/share/mate/autostart/ + when: mate_dir.stat.exists and mate_dir.stat.isdir + + +- name: Does /etc/xdg/lxsession/LXDE-pi/autostart exist? + stat: + path: /etc/xdg/lxsession/LXDE-pi/autostart + register: lxde_pi_autostart_present + +- name: If so, add /usr/local/sbin/netwarn to /etc/xdg/lxsession/LXDE-pi/autostart + lineinfile: + path: /etc/xdg/lxsession/LXDE-pi/autostart + regexp: '^/usr/local/sbin/netwarn$' + line: '/usr/local/sbin/netwarn' + when: lxde_pi_autostart_present.stat.exists + + +# 2022-07-21: Is autostart pop-up logic for Mint & stock Ubuntu much the same? diff --git a/scripts/netwarn b/roles/network/templates/netwarn/netwarn old mode 100644 new mode 100755 similarity index 100% rename from scripts/netwarn rename to roles/network/templates/netwarn/netwarn diff --git a/scripts/netwarn-iiab-network.desktop b/roles/network/templates/netwarn/netwarn-iiab-network.desktop similarity index 100% rename from scripts/netwarn-iiab-network.desktop rename to roles/network/templates/netwarn/netwarn-iiab-network.desktop From 42b5b766c45399748cdee28f0d1f53036298e316 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 21 Jul 2022 15:30:44 -0400 Subject: [PATCH 15/33] network/tasks/install.yml: hostapd syntax errors 85a5f8fd (3 days ago) --- roles/network/tasks/install.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index c84ec9a23..3cc89148a 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -45,11 +45,11 @@ # dest: /etc/network/if-pre-up.d/iptables # mode: '0755' --- name: Unmask the Access Point 'hostapd' service - systemd: - name: hostapd - enabled: no - masked: no +- name: Unmask the Access Point 'hostapd' service + systemd: + name: hostapd + enabled: no + masked: no - name: avahi include_tasks: avahi.yml From 44af07638b9395207c6b72d604c93e4553be4f1a Mon Sep 17 00:00:00 2001 From: root Date: Thu, 21 Jul 2022 19:53:37 +0000 Subject: [PATCH 16/33] Clean up roles/network/tasks/netwarn.yml --- roles/network/tasks/netwarn.yml | 49 +++++++++++++++++---------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/roles/network/tasks/netwarn.yml b/roles/network/tasks/netwarn.yml index 098a5c49e..91c66c14f 100644 --- a/roles/network/tasks/netwarn.yml +++ b/roles/network/tasks/netwarn.yml @@ -1,26 +1,3 @@ -# mate desktop detection based on 'register: nd_dir' in enable_services -- name: Does /usr/share/mate/autostart/ exist? - stat: - path: /usr/share/mate/autostart/ - register: mate_dir - -# contents work with mate as of 'switch to using dash via sh' -# 'text' is up for debate other structural changes I do not recommend JV - -- name: 'Install from template: /usr/local/sbin/netwarn' - file: - src: netwarn/netwarn - dest: /usr/local/sbin/ - mode: 0755 - when: mate_dir.stat.exists and mate_dir.stat.isdir - -- name: 'Install from template: /usr/share/mate/autostart/netwarn-iiab-network.desktop' - file: - src: netwarn/netwarn-iiab-network.desktop - dest: /usr/share/mate/autostart/ - when: mate_dir.stat.exists and mate_dir.stat.isdir - - - name: Does /etc/xdg/lxsession/LXDE-pi/autostart exist? stat: path: /etc/xdg/lxsession/LXDE-pi/autostart @@ -34,4 +11,30 @@ when: lxde_pi_autostart_present.stat.exists +# mate desktop detection based on 'register: nd_dir' in enable_services +- name: Does /usr/share/mate/autostart/ exist? + stat: + path: /usr/share/mate/autostart/ + register: mate_dir + +# contents work with mate as of 'switch to using dash via sh' +# 'text' is up for debate other structural changes I do not recommend JV + +- name: 'Install from template: /usr/share/mate/autostart/netwarn-iiab-network.desktop' + template: + src: netwarn/netwarn-iiab-network.desktop + dest: /usr/share/mate/autostart/ + when: mate_dir.stat.exists and mate_dir.stat.isdir + + # 2022-07-21: Is autostart pop-up logic for Mint & stock Ubuntu much the same? + +# (Let's insert those here if so, and refine the 'when:' line below.) + + +- name: 'If a supported graphical OS is detected, install from template: /usr/local/sbin/netwarn' + template: + src: netwarn/netwarn + dest: /usr/local/sbin/ + mode: 0755 + when: lxde_pi_autostart_present or (mate_dir.stat.exists and mate_dir.stat.isdir) From 2530b779fc5afff5efb4c703610f66c77329b679 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 21 Jul 2022 19:05:58 -0400 Subject: [PATCH 17/33] Bypass dysfunctional error-checking if mate-terminal detected --- roles/network/templates/netwarn/netwarn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/templates/netwarn/netwarn b/roles/network/templates/netwarn/netwarn index 59a0cc20a..146c41725 100755 --- a/roles/network/templates/netwarn/netwarn +++ b/roles/network/templates/netwarn/netwarn @@ -21,7 +21,7 @@ fi x-terminal-emulator -e /usr/local/bin/iiab-network rc=$? -if [ "$rc" != "0" ]; then +if [ "$rc" != "0" ] && [ ! -f /usr/bin/mate-terminal ]; then zenity --warning --width=360 --text="iiab-network exited with error: $rc\n\nPlease review /opt/iiab/iiab/iiab-network.log" exit $rc fi From 78e65f44ddffa68f951c3e48e99911fc0d4685fd Mon Sep 17 00:00:00 2001 From: root Date: Thu, 21 Jul 2022 21:45:22 -0400 Subject: [PATCH 18/33] Intercept mate-terminal RC + tee iiab-network errors to iiab-network.log --- iiab-network | 35 ++++++++++++------------- roles/network/templates/netwarn/netwarn | 22 +++++----------- 2 files changed, 24 insertions(+), 33 deletions(-) diff --git a/iiab-network b/iiab-network index 9ac41f986..54e781a66 100755 --- a/iiab-network +++ b/iiab-network @@ -4,11 +4,15 @@ CWD=`pwd` export ANSIBLE_LOG_PATH="$CWD/iiab-network.log" -if [ ! -f iiab-network.yml ]; then - echo "iiab-network.yml not found in current directory." - echo "Please rerun this command from the top level of the git repo." - echo "Exiting." +exit_error() { + echo -e "\nEXITING: "$@ | tee -a /opt/iiab/iiab/iiab-network.log exit 1 +} + +if [ ! -f iiab-network.yml ]; then + exit_error "iiab-network.yml not found in current directory." \ + "Please rerun this command from the top level of the git repo." \ + "Exiting." fi OS="unknown" # will be overridden below, if /etc/iiab/iiab.env is legit @@ -19,26 +23,21 @@ if [ -f /etc/iiab/iiab.env ]; then if grep -q STAGE= /etc/iiab/iiab.env ; then echo -e "\nExtracted STAGE=$STAGE (counter) from /etc/iiab/iiab.env" if ! [ "$STAGE" -eq "$STAGE" ] 2> /dev/null; then - echo -e "\nEXITING: STAGE (counter) value == ""$STAGE"" is non-integer" - exit 1 + exit_error "STAGE (counter) value == ""$STAGE"" is non-integer" elif [ "$STAGE" -lt 0 ] || [ "$STAGE" -gt 9 ]; then - echo -e "\nEXITING: STAGE (counter) value == ""$STAGE"" is out-of-range" - exit 1 + exit_error "STAGE (counter) value == ""$STAGE"" is out-of-range" elif [ "$STAGE" -lt 3 ]; then - echo -e "\nEXITING: STAGE (counter) value == ""$STAGE" - echo -e "\nIIAB Stage 3 not complete." - echo -e "\nPlease run: ./iiab-install" - exit 1 + exit_error "STAGE (counter) value == ""$STAGE" \ + "\nIIAB Stage 3 not complete." \ + "\nPlease run: ./iiab-install" fi else - echo -e "\nEXITING: STAGE (counter) not found" - echo -e "\nIIAB not installed." - echo -e "\nPlease run: ./iiab-install" - exit 1 + exit_error "STAGE (counter) not found" \ + "\nIIAB not installed." \ + "\nPlease run: ./iiab-install" fi else - echo -e "\nEXITING: /etc/iiab/iiab.env not found" - exit 1 + exit_error "/etc/iiab/iiab.env not found" fi echo "Ansible will now run iiab-network.yml -- log file is iiab-network.log" diff --git a/roles/network/templates/netwarn/netwarn b/roles/network/templates/netwarn/netwarn index 146c41725..fc4c8f4bb 100755 --- a/roles/network/templates/netwarn/netwarn +++ b/roles/network/templates/netwarn/netwarn @@ -1,13 +1,4 @@ -#!/bin/sh - -# Some OS's like Ubuntu with LightDM *IGNORE* the above shebang line when this -# script is invcked from /usr/share/mate/autostart/netwarn-iiab-network.desktop -# -# WHAT HAPPENS: sh (dash) NOT BASH will always be run! As confirmed by: -# -# ps -p $$ # Whereas 'echo $SHELL' DOES NOT show the actual running shell! -# -# RECAP: We hard-code the above '#!/bin/sh' for uniformity across all distros. +#!/bin/bash if [ -f /etc/iiab/install-flags/iiab-network-complete ]; then exit @@ -15,18 +6,19 @@ fi zenity --question --width=360 --text="IIAB needs to configure networking:\n\n► Internet must be live before you begin.\n►You might be prompted for your password.\n\nContinue? (This can take 2-3 minutes)" rc=$? -if [ "$rc" != "0" ]; then +if [[ $rc != "0" ]]; then exit $rc fi -x-terminal-emulator -e /usr/local/bin/iiab-network -rc=$? -if [ "$rc" != "0" ] && [ ! -f /usr/bin/mate-terminal ]; then +# mate-terminal always returns 255 w/ autostart, so intercept/record return code +x-terminal-emulator -e "bash -c '/usr/local/bin/iiab-network; echo \"\$?\" > /tmp/iiab-network.rc'" +rc=$(cat /tmp/iiab-network.rc) +if [[ $rc != "0" ]]; then zenity --warning --width=360 --text="iiab-network exited with error: $rc\n\nPlease review /opt/iiab/iiab/iiab-network.log" exit $rc fi zenity --question --width=360 --text="iiab-network complete.\n\nWould you like to REBOOT now? (Recommended)" -if [ "$?" = "0" ]; then +if [[ $? == "0" ]]; then x-terminal-emulator -e "sudo reboot" fi From 0763d56fa986eeb6a183332b565dd196a42c11fc Mon Sep 17 00:00:00 2001 From: A Holt Date: Thu, 21 Jul 2022 23:21:53 -0400 Subject: [PATCH 19/33] iiab-network: Lint intendation --- iiab-network | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iiab-network b/iiab-network index 54e781a66..6d286c2a0 100755 --- a/iiab-network +++ b/iiab-network @@ -28,8 +28,8 @@ if [ -f /etc/iiab/iiab.env ]; then exit_error "STAGE (counter) value == ""$STAGE"" is out-of-range" elif [ "$STAGE" -lt 3 ]; then exit_error "STAGE (counter) value == ""$STAGE" \ - "\nIIAB Stage 3 not complete." \ - "\nPlease run: ./iiab-install" + "\nIIAB Stage 3 not complete." \ + "\nPlease run: ./iiab-install" fi else exit_error "STAGE (counter) not found" \ From e221c0a91cba9139bc905058cab21a4cac852c62 Mon Sep 17 00:00:00 2001 From: A Holt Date: Thu, 21 Jul 2022 23:26:14 -0400 Subject: [PATCH 20/33] iiab-network: Remove repetitive output --- iiab-network | 1 - 1 file changed, 1 deletion(-) diff --git a/iiab-network b/iiab-network index 6d286c2a0..5e3d5ba20 100755 --- a/iiab-network +++ b/iiab-network @@ -12,7 +12,6 @@ exit_error() { if [ ! -f iiab-network.yml ]; then exit_error "iiab-network.yml not found in current directory." \ "Please rerun this command from the top level of the git repo." \ - "Exiting." fi OS="unknown" # will be overridden below, if /etc/iiab/iiab.env is legit From 71351c18b1363c33c13ce1f6da8854f4a7e7511b Mon Sep 17 00:00:00 2001 From: A Holt Date: Thu, 21 Jul 2022 23:38:47 -0400 Subject: [PATCH 21/33] Rename ifcfg-WAN.j2.unsued to ifcfg-WAN.j2.unused --- .../network/{ifcfg-WAN.j2.unsued => ifcfg-WAN.j2.unused} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename roles/network/templates/network/{ifcfg-WAN.j2.unsued => ifcfg-WAN.j2.unused} (100%) diff --git a/roles/network/templates/network/ifcfg-WAN.j2.unsued b/roles/network/templates/network/ifcfg-WAN.j2.unused similarity index 100% rename from roles/network/templates/network/ifcfg-WAN.j2.unsued rename to roles/network/templates/network/ifcfg-WAN.j2.unused From f1ba6d82cc13427d062be77c8b68de191531b79d Mon Sep 17 00:00:00 2001 From: A Holt Date: Thu, 21 Jul 2022 23:39:18 -0400 Subject: [PATCH 22/33] Rename ifcfg.j2.usused to ifcfg.j2.unused --- .../templates/network/{ifcfg.j2.usused => ifcfg.j2.unused} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename roles/network/templates/network/{ifcfg.j2.usused => ifcfg.j2.unused} (100%) diff --git a/roles/network/templates/network/ifcfg.j2.usused b/roles/network/templates/network/ifcfg.j2.unused similarity index 100% rename from roles/network/templates/network/ifcfg.j2.usused rename to roles/network/templates/network/ifcfg.j2.unused From f8cb292828785d5c51aa8db26e1bcdb156baac74 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 Jul 2022 09:14:26 -0400 Subject: [PATCH 23/33] FULL/PATH/dnsmasq.yml in network/tasks/install.yml for 1-prep --- roles/network/tasks/install.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index 3cc89148a..dcb17feb4 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -1,7 +1,7 @@ # 2022-03-16: 'apt show | grep Size' revealed download sizes, on 64-bit RasPiOS with desktop. - name: Install dnsmasq -- configure LATER in 'network', after Stage 9 - include_tasks: dnsmasq.yml + include_tasks: roles/network/tasks/dnsmasq.yml # Invoked by 1-prep (so full path needed) - name: Install package networkd-dispatcher (OS's other than RasPiOS) package: From a450db1f1a5fafba73aa6b1c48e59ef4a3c91916 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 Jul 2022 09:27:31 -0400 Subject: [PATCH 24/33] FULL/PATH to Avahi stuff in roles/network for 1-prep --- roles/network/tasks/avahi.yml | 2 +- roles/network/tasks/install.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/network/tasks/avahi.yml b/roles/network/tasks/avahi.yml index 15a62de8e..8fe5f7159 100644 --- a/roles/network/tasks/avahi.yml +++ b/roles/network/tasks/avahi.yml @@ -7,7 +7,7 @@ - name: Install avahi announce config file /etc/avahi/services/schoolserver.service template: - src: avahi/schoolserver.service + src: roles/network/templates/avahi/schoolserver.service # Invoked by 1-prep (so full path needed) dest: /etc/avahi/services/schoolserver.service owner: avahi group: avahi diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index dcb17feb4..d375f8b5d 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -51,8 +51,8 @@ enabled: no masked: no -- name: avahi - include_tasks: avahi.yml +- name: Install Avahi (mDNS, Zeroconf/Bonjour) + include_tasks: roles/network/tasks/avahi.yml # Invoked by 1-prep (so full path needed) # Ongoing rework (e.g. PR #2652) arising from ansible.posix collection changes: - name: "4 network settings in /etc/sysctl.conf -- e.g. disabling IPv6 (this might be overkill, as IPv6 should really only be disabled on the LAN side, i.e. br0)" From 7d0bf6c1ef0bd0daf35f873fa60fc6d8ce763578 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 Jul 2022 09:51:53 -0400 Subject: [PATCH 25/33] FULL/PATH to netplan.yml & netwarn.yml for 1-prep --- roles/network/tasks/install.yml | 6 +++--- roles/network/tasks/main.yml | 30 +++++++++++++++++------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index d375f8b5d..088aac902 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -81,12 +81,12 @@ # LESS MAINTAINED - name: Install Squid - include_tasks: roles/network/tasks/squid.yml + include_tasks: roles/network/tasks/squid.yml # Invoked by 1-prep (so full path needed) when: squid_install and squid_installed is undefined #preprep for backends - name: Netplan in use on Ubuntu 18.04+ - include_tasks: netplan.yml + include_tasks: roles/network/tasks/netplan.yml # Invoked by 1-prep (so full path needed) when: is_ubuntu # all installs @@ -100,7 +100,7 @@ - gateway/iiab-internet-off - name: 'Install /usr/local/sbin/netwarn for pop-ups on boot, if iiab-network should be run' - include_tasks: netwarn.yml + include_tasks: roles/network/tasks/netwarn.yml # Invoked by 1-prep (so full path needed) # RECORD Network AS INSTALLED diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index 579bf64e9..36359edb1 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -43,21 +43,24 @@ - name: Configuring Network if enabled block: - # - name: Configure wondershaper - # include_tasks: wondershaper.yml - # when: wondershaper_install or wondershaper_installed is defined -# - name: (Re)Install named -# include_tasks: named.yml -# when: named_install and FQDN_changed and iiab_stage|int == 9 + # DEPRECATED + #- name: Configure wondershaper + # include_tasks: wondershaper.yml + # when: wondershaper_install or wondershaper_installed is defined + # + #- name: (Re)Install named + # include_tasks: named.yml + # when: named_install and FQDN_changed and iiab_stage|int == 9 + # + #- name: (Re)Install dhcpd + # include_tasks: dhcpd.yml + # when: dhcpd_install and FQDN_changed and iiab_stage|int == 9 -# - name: (Re)Install dhcpd -# include_tasks: dhcpd.yml -# when: dhcpd_install and FQDN_changed and iiab_stage|int == 9 - -# - name: (Re)Install Squid -# include_tasks: squid.yml -# when: squid_install and FQDN_changed and iiab_stage|int == 9 + # 2022-07-22: Is './runrole --reinstall network' the new way to make this run? + #- name: (Re)Install Squid + # include_tasks: squid.yml + # when: squid_install and FQDN_changed and iiab_stage|int == 9 #### Start services - name: hostapd @@ -92,6 +95,7 @@ - name: Restart services include_tasks: restart.yml + # end block when: network_installed is defined and network_enabled From 556db4bfb643298460dd089d981b2ac92a5567e3 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 Jul 2022 10:53:24 -0400 Subject: [PATCH 26/33] 2 vars in detected_network.yml to netplan.yml; FULL/PATHS for 1-prep --- roles/network/tasks/detected_network.yml | 21 +++++++--------- roles/network/tasks/install.yml | 4 +-- roles/network/tasks/main.yml | 32 +++++++++++++----------- roles/network/tasks/netplan.yml | 13 ++++++++++ roles/network/tasks/netwarn.yml | 4 +-- 5 files changed, 43 insertions(+), 31 deletions(-) diff --git a/roles/network/tasks/detected_network.yml b/roles/network/tasks/detected_network.yml index 01ff42e18..9acffaab6 100644 --- a/roles/network/tasks/detected_network.yml +++ b/roles/network/tasks/detected_network.yml @@ -36,25 +36,22 @@ device_gw: "{{ discovered_wan_iface }}" when: ansible_default_ipv4.gateway is defined -- name: Figure out netplan file name - shell: ls /etc/netplan - register: netplan - ignore_errors: True # pre 17.10 doesn't use netplan - when: is_ubuntu +# 2022-07-22: Moved to netplan.yml +# - name: Figure out netplan file name +# shell: ls /etc/netplan +# register: netplan +# ignore_errors: True # pre 17.10 doesn't use netplan +# when: is_ubuntu - name: Setting dhcpcd_test results set_fact: dhcpcd_result: "{{ ansible_local.local_facts.dhcpcd }}" -- name: Setting systemd_networkd results +# 2022-07-22: Copied to netplan.yml (REMOVE DUPLICATE CODE LATER?!) +- name: "Set 'systemd_networkd_active: True' if local_facts.systemd_networkd confirms" set_fact: systemd_networkd_active: True - when: 'ansible_local.local_facts.systemd_networkd == "enabled"' - -- name: Setting systemd_networkd-2 results - set_fact: - systemd_networkd_active: True - when: 'ansible_local.local_facts.systemd_networkd == "enabled-runtime"' + when: ansible_local.local_facts.systemd_networkd == "enabled" or ansible_local.local_facts.systemd_networkd == "enabled-runtime" - name: Setting network_manager results set_fact: diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index 088aac902..4ce34c3c1 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -96,8 +96,8 @@ dest: /usr/bin/ mode: 0755 with_items: - - gateway/iiab-internet-on - - gateway/iiab-internet-off + - roles/network/templates/gateway/iiab-internet-on # Invoked by 1-prep (so full path needed) + - roles/network/templates/gateway/iiab-internet-off # Invoked by 1-prep (so full path needed) - name: 'Install /usr/local/sbin/netwarn for pop-ups on boot, if iiab-network should be run' include_tasks: roles/network/tasks/netwarn.yml # Invoked by 1-prep (so full path needed) diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index 36359edb1..efea4cf3f 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -25,21 +25,23 @@ include_tasks: install.yml when: network_install and network_installed is undefined -- name: Create /usr/bin/iiab-hotspot-on from template - template: - src: hostapd/iiab-hotspot-on - dest: /usr/bin/iiab-hotspot-on - owner: root - group: root - mode: 0755 - -- name: Create /usr/bin/iiab-hotspot-off from template - template: - src: hostapd/iiab-hotspot-off - dest: /usr/bin/iiab-hotspot-off - owner: root - group: root - mode: 0755 +# 2022-07-22: Should be done in install.yml above (avoid duplication if poss?) +# +# - name: Create /usr/bin/iiab-hotspot-on from template +# template: +# src: hostapd/iiab-hotspot-on +# dest: /usr/bin/iiab-hotspot-on +# owner: root +# group: root +# mode: 0755 +# +# - name: Create /usr/bin/iiab-hotspot-off from template +# template: +# src: hostapd/iiab-hotspot-off +# dest: /usr/bin/iiab-hotspot-off +# owner: root +# group: root +# mode: 0755 - name: Configuring Network if enabled block: diff --git a/roles/network/tasks/netplan.yml b/roles/network/tasks/netplan.yml index 43865d437..2e685be3e 100644 --- a/roles/network/tasks/netplan.yml +++ b/roles/network/tasks/netplan.yml @@ -1,3 +1,16 @@ +# 2022-07-22: Moved from detected_network.yml +- name: Figure out netplan file name + shell: ls /etc/netplan + register: netplan + #ignore_errors: True # pre 17.10 doesn't use netplan + +# 2022-07-22: Copied from detected_network.yml (REMOVE DUPLICATE CODE LATER?!) +- name: "Set 'systemd_networkd_active: True' if local_facts.systemd_networkd confirms" + set_fact: + systemd_networkd_active: True + when: ansible_local.local_facts.systemd_networkd == "enabled" or ansible_local.local_facts.systemd_networkd == "enabled-runtime" + + - name: Disable cloud-init the easy way shell: touch /etc/cloud/cloud-init.disabled when: item|trim == "50-cloud-init.yaml" diff --git a/roles/network/tasks/netwarn.yml b/roles/network/tasks/netwarn.yml index 91c66c14f..d31b262d7 100644 --- a/roles/network/tasks/netwarn.yml +++ b/roles/network/tasks/netwarn.yml @@ -22,7 +22,7 @@ - name: 'Install from template: /usr/share/mate/autostart/netwarn-iiab-network.desktop' template: - src: netwarn/netwarn-iiab-network.desktop + src: roles/network/templates/netwarn/netwarn-iiab-network.desktop # Invoked by 1-prep (so full path needed) dest: /usr/share/mate/autostart/ when: mate_dir.stat.exists and mate_dir.stat.isdir @@ -34,7 +34,7 @@ - name: 'If a supported graphical OS is detected, install from template: /usr/local/sbin/netwarn' template: - src: netwarn/netwarn + src: roles/network/templates/netwarn/netwarn # Invoked by 1-prep (so full path needed) dest: /usr/local/sbin/ mode: 0755 when: lxde_pi_autostart_present or (mate_dir.stat.exists and mate_dir.stat.isdir) From 79d6bd8bc66778b319e52d358627840b5ebb601d Mon Sep 17 00:00:00 2001 From: A Holt Date: Fri, 22 Jul 2022 11:15:38 -0400 Subject: [PATCH 27/33] iiab-network: Line ending typo / syntax error --- iiab-network | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iiab-network b/iiab-network index 5e3d5ba20..5dc831b8e 100755 --- a/iiab-network +++ b/iiab-network @@ -11,7 +11,7 @@ exit_error() { if [ ! -f iiab-network.yml ]; then exit_error "iiab-network.yml not found in current directory." \ - "Please rerun this command from the top level of the git repo." \ + "Please rerun this command from the top level of the git repo." fi OS="unknown" # will be overridden below, if /etc/iiab/iiab.env is legit From f33e15ecd2eb5adacf3770ab1dd48dad24d6804f Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 Jul 2022 11:25:47 -0400 Subject: [PATCH 28/33] network/tasks/restart.yml also needed netplan var. Dup code for now :/ --- roles/network/tasks/detected_network.yml | 2 +- roles/network/tasks/main.yml | 2 ++ roles/network/tasks/netplan.yml | 2 +- roles/network/tasks/restart.yml | 8 ++++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/roles/network/tasks/detected_network.yml b/roles/network/tasks/detected_network.yml index 9acffaab6..8a5dd3a5d 100644 --- a/roles/network/tasks/detected_network.yml +++ b/roles/network/tasks/detected_network.yml @@ -36,7 +36,7 @@ device_gw: "{{ discovered_wan_iface }}" when: ansible_default_ipv4.gateway is defined -# 2022-07-22: Moved to netplan.yml +# 2022-07-22: Moved to netplan.yml AND restart.yml (REMOVE DUPLICATE CODE LATER?!) # - name: Figure out netplan file name # shell: ls /etc/netplan # register: netplan diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index efea4cf3f..5a000f13b 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -43,6 +43,7 @@ # group: root # mode: 0755 + - name: Configuring Network if enabled block: @@ -101,6 +102,7 @@ # end block when: network_installed is defined and network_enabled + - name: Create {{ iiab_etc_path }}/install-flags/iiab-network-complete on second pass of network role. file: path: "{{ iiab_etc_path }}/install-flags/iiab-network-complete" diff --git a/roles/network/tasks/netplan.yml b/roles/network/tasks/netplan.yml index 2e685be3e..8a772d214 100644 --- a/roles/network/tasks/netplan.yml +++ b/roles/network/tasks/netplan.yml @@ -1,4 +1,4 @@ -# 2022-07-22: Moved from detected_network.yml +# 2022-07-22: Moved from detected_network.yml to netplan.yml AND restart.yml (REMOVE DUPLICATE CODE LATER?!) - name: Figure out netplan file name shell: ls /etc/netplan register: netplan diff --git a/roles/network/tasks/restart.yml b/roles/network/tasks/restart.yml index de930332f..e5a825dee 100644 --- a/roles/network/tasks/restart.yml +++ b/roles/network/tasks/restart.yml @@ -1,3 +1,11 @@ +# 2022-07-22: Moved from detected_network.yml to netplan.yml AND restart.yml (REMOVE DUPLICATE CODE LATER?!) +- name: Figure out netplan file name + shell: ls /etc/netplan + register: netplan + #ignore_errors: True # pre 17.10 doesn't use netplan + when: is_ubuntu + + - name: Restart wpa_supplicant service systemd: name: "{{ item }}" From 60579c6c008e7b12c5a463087ca5f3d602deab49 Mon Sep 17 00:00:00 2001 From: A Holt Date: Fri, 22 Jul 2022 12:18:58 -0400 Subject: [PATCH 29/33] network/tasks/install.yml: Spacing around "all installs" header --- roles/network/tasks/install.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/network/tasks/install.yml b/roles/network/tasks/install.yml index 4ce34c3c1..ebdf5a080 100644 --- a/roles/network/tasks/install.yml +++ b/roles/network/tasks/install.yml @@ -90,6 +90,7 @@ when: is_ubuntu # all installs + - name: Install /usr/bin/iiab-internet-on|off from template (root:root by default) template: src: "{{ item }}" From e71efff7e2481c42d1132fd692836d2ec4415e06 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 Jul 2022 14:43:39 -0400 Subject: [PATCH 30/33] network/tasks/main.yml: Restore iiab-hotspot-on|off --- roles/network/tasks/main.yml | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index 5a000f13b..9187eeb48 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -25,23 +25,14 @@ include_tasks: install.yml when: network_install and network_installed is undefined -# 2022-07-22: Should be done in install.yml above (avoid duplication if poss?) -# -# - name: Create /usr/bin/iiab-hotspot-on from template -# template: -# src: hostapd/iiab-hotspot-on -# dest: /usr/bin/iiab-hotspot-on -# owner: root -# group: root -# mode: 0755 -# -# - name: Create /usr/bin/iiab-hotspot-off from template -# template: -# src: hostapd/iiab-hotspot-off -# dest: /usr/bin/iiab-hotspot-off -# owner: root -# group: root -# mode: 0755 +- name: Install /usr/bin/iiab-hotspot-on|off from template (root:root by default) + template: + src: "{{ item }}" + dest: /usr/bin/ + mode: 0755 + with_items: + - hostapd/iiab-hotspot-on + - hostapd/iiab-hotspot-off - name: Configuring Network if enabled From 69aba8eec3ef4121d98fc9a8f7c1de2b9412504c Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 Jul 2022 15:14:40 -0400 Subject: [PATCH 31/33] network/tasks/main.yml: Swap order of iiab-hotspot-on|off & install.yml on @jvonau's request --- roles/network/tasks/main.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index 9187eeb48..6a2ba3a7a 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -21,10 +21,10 @@ - name: computed_network include_tasks: computed_network.yml -- name: Install network packages (including many WiFi tools, and also iptables-persistent for firewall) - include_tasks: install.yml - when: network_install and network_installed is undefined - +# 2022-07-22: @jvonau asks for this to be (1) AFTER computed_network.yml [what +# goes into the 'hotspot' depends on what can_be_ap and wifi_up_down are set to] +# AND (2) BEFORE install.yml -- FYI Admin Console reads iiab_network_mode from +# /etc/iiab/iiab.ini and uses /usr/bin/iiab-hotspot-on|off. - name: Install /usr/bin/iiab-hotspot-on|off from template (root:root by default) template: src: "{{ item }}" @@ -34,6 +34,10 @@ - hostapd/iiab-hotspot-on - hostapd/iiab-hotspot-off +- name: Install network packages (including many WiFi tools, and also iptables-persistent for firewall) + include_tasks: install.yml + when: network_install and network_installed is undefined + - name: Configuring Network if enabled block: From dbeaf024824738ae766c181caedd38dae9e3630f Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 Jul 2022 15:35:05 -0400 Subject: [PATCH 32/33] Try to explain ordering of iiab-hotspot-on|off & install.yml (in network/tasks/main.yml) --- roles/network/tasks/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index 6a2ba3a7a..67f9d28e7 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -21,10 +21,10 @@ - name: computed_network include_tasks: computed_network.yml -# 2022-07-22: @jvonau asks for this to be (1) AFTER computed_network.yml [what -# goes into the 'hotspot' depends on what can_be_ap and wifi_up_down are set to] -# AND (2) BEFORE install.yml -- FYI Admin Console reads iiab_network_mode from -# /etc/iiab/iiab.ini and uses /usr/bin/iiab-hotspot-on|off. +# 2022-07-22: @jvonau asks for this to be (1) BELOW computed_network.yml +# (what goes into iiab-hotspot-on|off depends on can_be_ap and wifi_up_down) +# AND (2) ABOVE install.yml for some reason? REQUIREMENT: Admin Console reads +# iiab_network_mode from /etc/iiab/iiab.ini + uses /usr/bin/iiab-hotspot-on|off - name: Install /usr/bin/iiab-hotspot-on|off from template (root:root by default) template: src: "{{ item }}" From 9f5032d74fa3566f2becfe1f9e5a80e81332bc9b Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 Jul 2022 15:59:10 -0400 Subject: [PATCH 33/33] Comment out 'netplan apply' from restart.yml (trim netplan.yml later?) --- roles/network/tasks/restart.yml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/roles/network/tasks/restart.yml b/roles/network/tasks/restart.yml index e5a825dee..1576a2af3 100644 --- a/roles/network/tasks/restart.yml +++ b/roles/network/tasks/restart.yml @@ -1,9 +1,9 @@ # 2022-07-22: Moved from detected_network.yml to netplan.yml AND restart.yml (REMOVE DUPLICATE CODE LATER?!) -- name: Figure out netplan file name - shell: ls /etc/netplan - register: netplan - #ignore_errors: True # pre 17.10 doesn't use netplan - when: is_ubuntu +# - name: Figure out netplan file name +# shell: ls /etc/netplan +# register: netplan +# #ignore_errors: True # pre 17.10 doesn't use netplan +# when: is_ubuntu - name: Restart wpa_supplicant service @@ -33,9 +33,13 @@ daemon_reload: yes when: hostapd_enabled and (wifi_up_down or not no_net_restart) -- name: Reload netplan for Wifi gateway on Ubuntu 18+ - shell: netplan apply - when: wifi_up_down and is_ubuntu and netplan.stdout.find("yaml") != -1 +# 2022-07-22: @jvonau suggests commenting this out as: "we really don't touch +# any of the config files... netplan.yml renames one file if it's a container +# build like on MATE, could possibly skip netplan.yml in future or toss that in +# the mix now and see what shakes up" [ok, but keep netplan.yml as is for now] +# - name: Reload netplan for Wifi gateway on Ubuntu 18+ +# shell: netplan apply +# when: wifi_up_down and is_ubuntu and netplan.stdout.find("yaml") != -1 #- name: Start named service # systemd: