From f191d2beadb24f6a48c2ccb5f2887100c289f640 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Fri, 24 Nov 2023 19:34:47 +0100 Subject: [PATCH] updated kopia state --- states/kopia/config.sls | 21 ++++++++++++++++++++ states/kopia/defaults.yaml | 9 +++++++++ states/kopia/init.sls | 4 ++++ states/kopia/install.sls | 38 +++++++++++++++++++++++++++++++++++++ states/kopia/kernelmap.yaml | 3 +++ states/kopia/map.jinja | 14 ++++++++++++++ states/kopia/osarchmap.yaml | 24 +++++++++++++++++++++++ 7 files changed, 113 insertions(+) create mode 100644 states/kopia/config.sls create mode 100644 states/kopia/defaults.yaml create mode 100644 states/kopia/init.sls create mode 100644 states/kopia/install.sls create mode 100644 states/kopia/kernelmap.yaml create mode 100644 states/kopia/map.jinja create mode 100644 states/kopia/osarchmap.yaml diff --git a/states/kopia/config.sls b/states/kopia/config.sls new file mode 100644 index 0000000..c2fe004 --- /dev/null +++ b/states/kopia/config.sls @@ -0,0 +1,21 @@ +--- +{%- from "kopia/map.jinja" import kopia with context %} +kopia-config-dir: + file.directory: + - name: /etc/kopia + - user: root + - group: root + - mode: 700 + - watch_in: + - service: kopia-service + +kopia-config-file: + file.managed: + - name: /etc/kopia/kopia.conf + - source: salt://kopia/templates/kopia.conf.j2 + - user: root + - group: root + - mode: 600 + - template: jinja + - watch_in: + - service: kopia-service diff --git a/states/kopia/defaults.yaml b/states/kopia/defaults.yaml new file mode 100644 index 0000000..3a20f77 --- /dev/null +++ b/states/kopia/defaults.yaml @@ -0,0 +1,9 @@ +--- +kopia: + enabled: true + release_dir: /usr/local/apps/releases + install_dir: /usr/local/apps + mirror: https://github.com/kopia/kopia/releases/download + version: 0.15.0 + os: linux + arch: x64 diff --git a/states/kopia/init.sls b/states/kopia/init.sls new file mode 100644 index 0000000..d507940 --- /dev/null +++ b/states/kopia/init.sls @@ -0,0 +1,4 @@ +--- +include: + - .install + - .config diff --git a/states/kopia/install.sls b/states/kopia/install.sls new file mode 100644 index 0000000..7024286 --- /dev/null +++ b/states/kopia/install.sls @@ -0,0 +1,38 @@ +--- +{%- from "kopia/map.jinja" import kopia with context %} +{% set archive_exclude_dir = './kopia-' + kopia.version + '-' + kopia.os + '-' + kopia.arch %} +kopia-archive-extract: + archive.extracted: + - name: {{ kopia.release_dir }}/kopia-{{ kopia.version }} + - source: {{ kopia.mirror }}/v{{ kopia.version }}/kopia-{{ kopia.version }}-{{ kopia.os }}-{{ kopia.arch }}.tar.gz + - enforce_toplevel: false + - options: > + --transform 's|^\{{ archive_exclude_dir }}|/|g' + --transform 's|LICENSE||g' + --transform 's|README.md||g' + --strip 1 + - skip_verify: true + - archive_format: tar + - if_missing: {{ kopia.release_dir }}/kopia-{{ kopia.version }}/kopia + +kopia-bin-perm: + file.managed: + - name: {{ kopia.release_dir }}/kopia-{{ kopia.version }}/kopia + - user: root + - group: root + - require: + - archive: kopia-archive-extract + +kopia-bin-symlink: + file.symlink: + - name: /usr/local/bin/kopia + - target: {{ kopia.release_dir }}/kopia-{{ kopia.version }}/kopia + - force: true + - require: + - archive: kopia-archive-extract + +kopia-cleanup: + software.cleanup: + - name: kopia + - path: {{ kopia.release_dir }} + - version: "{{ kopia.version }}" diff --git a/states/kopia/kernelmap.yaml b/states/kopia/kernelmap.yaml new file mode 100644 index 0000000..40943f2 --- /dev/null +++ b/states/kopia/kernelmap.yaml @@ -0,0 +1,3 @@ +--- +Linux: + os: "linux" diff --git a/states/kopia/map.jinja b/states/kopia/map.jinja new file mode 100644 index 0000000..c1f0417 --- /dev/null +++ b/states/kopia/map.jinja @@ -0,0 +1,14 @@ +{%- import_yaml "kopia/defaults.yaml" as default_settings -%} + +{%- import_yaml "kopia/kernelmap.yaml" as kernelmap -%} +{%- import_yaml "kopia/osarchmap.yaml" as osarchmap -%} + +{%- set defaults = salt['grains.filter_by'](default_settings, + default='kopia', + merge=salt['grains.filter_by'](osarchmap, grain='osarch', + merge=salt['grains.filter_by'](kernelmap, grain='kernel') + ) + ) +-%} + +{%- set kopia = salt['pillar.get']('kopia', default=defaults, merge=True) -%} diff --git a/states/kopia/osarchmap.yaml b/states/kopia/osarchmap.yaml new file mode 100644 index 0000000..826e231 --- /dev/null +++ b/states/kopia/osarchmap.yaml @@ -0,0 +1,24 @@ +--- +amd64: + arch: "x64" + +x86_64: + arch: "x64" + +386: + arch: "386" + +arm64: + arch: "arm64" + +aarch64: + arch: "arm64" + +armv6l: + arch: "arm" + +armv7l: + arch: "arm" + +armhf: + arch: "arm"