Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make door_daemon run again on openwrt based torwaechter #67

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
11 changes: 3 additions & 8 deletions ansible/files/torwaechter/update-keys-from-stdin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ set -eu

## this script takes keys on STDIN and programs teenstep eeprom

MONIT_STOP="/etc/init.d/monit stop"
MONIT_START="/etc/init.d/monit start"
TUERDAEMON_STOP="/etc/init.d/tuer_core stop"
TUERDAEMON_START="/etc/init.d/tuer_core start"
UPDATE_KEYS_TOOL="/flash/tuer/update-keys /dev/door"
TUERDAEMON_STOP="/etc/init.d/doord stop"
TUERDAEMON_START="/etc/init.d/doord start"
UPDATE_KEYS_TOOL="/usr/local/bin/update-keys /dev/door"

## stop monit. it monit not installed or error. don't start monit again later
${MONIT_STOP} || MONIT_START=""
## stop door daemon.
${TUERDAEMON_STOP}
## give daemons time to stop
Expand All @@ -19,5 +15,4 @@ sleep 1
${UPDATE_KEYS_TOOL}
## start daemon again
${TUERDAEMON_START}
${MONIT_START}

32 changes: 31 additions & 1 deletion ansible/host_vars/torwaechter/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---
ssh_users_tuergit: "{{ user_groups.noc | union(['fgenesis']) }}"

openwrt_variant: openwrt
openwrt_release: 18.06.4
openwrt_arch: x86
openwrt_target: geode
openwrt_output_image_suffixes:
- combined-ext4.img.gz
- combined-squashfs.img
- combined-squashfs.img.gz

openwrt_packages_extra:
- "-dropbear"
Expand All @@ -18,8 +20,15 @@ openwrt_packages_extra:
- screen
- sudo
- usbutils
- rsync
- lsblk

openwrt_mixin:
/home:
directory:
/run:
link: "/var/run"

# Go binaries
/usr/local/bin/door_client:
mode: '0755'
Expand All @@ -31,6 +40,26 @@ openwrt_mixin:
mode: '0755'
file: "{{ global_cache_dir }}/{{ inventory_hostname }}/door_and_sensors/update-keys/update-keys"

# door daemon init scripts and configs
/etc/init.d/doord:
mode: '0755'
file: "{{ global_cache_dir }}/{{ inventory_hostname }}/door_and_sensors/initscripts/doord.openwrt"
/etc/default/door:
mode: '0755'
file: "{{ global_cache_dir }}/{{ inventory_hostname }}/door_and_sensors/initscripts/door.default"
/etc/default/tuer:
link: "./door"
/etc/rc.d/S50doord:
link: "../init.d/doord"

# hotplug files
/etc/hotplug.d/tty/door.tty:
mode: '0755'
file: "{{ global_cache_dir }}/{{ inventory_hostname }}/door_and_sensors/scripts/door.tty"
/etc/hotplug.d/usb/door.usb:
mode: '0755'
file: "{{ global_cache_dir }}/{{ inventory_hostname }}/door_and_sensors/scripts/door.usb"

/usr/local/bin/authorized_keys.sh:
mode: '0755'
file: "{{ global_files_dir }}/{{ inventory_hostname }}/authorized_keys.sh"
Expand Down Expand Up @@ -109,6 +138,7 @@ openwrt_uci:
dns_search: realraum.at


# does not work, using symlink to /var/run instead for now
openwrt_mounts:
- path: /run
src: none
Expand Down
22 changes: 22 additions & 0 deletions ansible/roles/openwrt/image/filter_plugins/openwrt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible import errors


def openwrt_mixin_type(data, mixin_type):
try:
return [{'key': x, 'value': data[x]} for x in data if mixin_type in data[x]]

except Exception as e:
raise errors.AnsibleFilterError("openwrt_mixin_type(): %s" % str(e))


class FilterModule(object):

filter_map = {
'openwrt_mixin_type': openwrt_mixin_type,
}

def filters(self):
return self.filter_map
Binary file modified ansible/roles/openwrt/image/openwrt-keyring.gpg
Binary file not shown.
32 changes: 18 additions & 14 deletions ansible/roles/openwrt/image/tasks/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,50 @@
openwrt_imgbuilder_dir: "{{ tmpdir.path }}"
openwrt_imgbuilder_files: "{{ tmpdir.path }}/files"

- name: Create the download directory
file:
path: "{{ openwrt_download_dir }}/dl/{{ openwrt_arch }}"
state: directory
mode: '0755'

- name: Create the directories for mixins
file:
path: "{{ item }}"
state: directory
mode: '0755'
with_items:
- "{{ openwrt_download_dir }}/dl/{{ openwrt_arch }}"
- "{{ openwrt_imgbuilder_files }}/etc/config"
- "{{ openwrt_mixin | map('dirname') | map('regex_replace', '^', openwrt_imgbuilder_files) | unique | list }}"

loop: "{{ directories | flatten | unique | map('regex_replace', '^', openwrt_imgbuilder_files) | list }}"
vars:
directories:
- "/etc/config"
- "{{ openwrt_mixin | map('dirname') | list }}"
- "{{ openwrt_mixin | openwrt_mixin_type('directory') | map(attribute='key') | list }}"

- name: Copy mixins in place [1/3]
- name: Create symlinks
file:
dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
src: "{{ item.value.link }}"
force: yes
follow: no
state: link
with_dict: "{{ openwrt_mixin }}"
when: '"link" in item.value'
loop: "{{ openwrt_mixin | openwrt_mixin_type('link') }}"
loop_control:
label: "{{ item.key }}"

- name: Copy mixins in place [2/3]
- name: Copy mixins in place (from file)
copy:
src: "{{ item.value.file }}"
dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
mode: "{{ item.value.mode | default('0644') }}"
with_dict: "{{ openwrt_mixin }}"
when: '"file" in item.value'
loop: "{{ openwrt_mixin | openwrt_mixin_type('file') }}"
loop_control:
label: "{{ item.key }}"

- name: Copy mixins in place [3/3]
- name: Copy mixins in place (from content)
copy:
content: "{{ item.value.content }}"
dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
mode: "{{ item.value.mode | default('0644') }}"
with_dict: "{{ openwrt_mixin }}"
when: '"content" in item.value'
loop: "{{ openwrt_mixin | openwrt_mixin_type('content') }}"
loop_control:
label: "{{ item.key }}"

Expand Down