added cleanup on softwares

This commit is contained in:
Paul 2021-11-14 13:37:49 +01:00
parent 0fc13c478d
commit b24f1f849b
14 changed files with 110 additions and 20 deletions

View File

@ -0,0 +1,18 @@
#!/usr/bin/python3
import re
import os
def cleanup(name=None, path=None, version=None):
res = []
version = version.replace(".", "\.")
keep_pattern = f"^{name}-(?!{version}).*$"
regex = re.compile(keep_pattern)
for f in os.listdir(path):
if regex.match(f):
to_remove = f"{path}/{f}"
res.append(to_remove)
__salt__["file.remove"](to_remove)
if len(res) > 1:
return res
return None

View File

@ -0,0 +1,13 @@
#!/usr/bin/python3
def cleanup(name=None, path=None, version=None):
ret = {'name': name,
'changes': {},
'result': True,
'comment': 'No changes been made'}
res = __salt__['software.cleanup'](name, path, version)
if res is not None:
ret['changes']["folders"] = res
return ret

View File

@ -2,17 +2,23 @@
{%- from "golang/map.jinja" import golang with context %}
golang-archive-extract:
archive.extracted:
- name: {{ golang.release_dir }}/go{{ golang.version }}
- name: {{ golang.release_dir }}/go-{{ golang.version }}
- source: {{ golang.mirror }}/go{{ golang.version }}.{{ golang.os }}-{{ golang.arch }}.tar.gz
- skip_verify: true
- enforce_toplevel: false
- options: --transform 's/^go\///g'
- if_missing: {{ golang.release_dir }}/go{{ golang.version }}
- if_missing: {{ golang.release_dir }}/go-{{ golang.version }}
golang-binary-symlink:
file.symlink:
- name: {{ golang.install_dir }}/go
- target: {{ golang.release_dir }}/go{{ golang.version }}
- target: {{ golang.release_dir }}/go-{{ golang.version }}
- force: true
- require:
- archive: golang-archive-extract
golang-cleanup:
software.cleanup:
- name: go
- path: {{ golang.release_dir }}
- version: {{ golang.version }}

View File

@ -34,6 +34,12 @@ influxdb-archive-extract:
- watch_in:
- service: influxdb-service
influxdb-cleanup:
software.cleanup:
- name: influxdb
- path: {{ influxdb.release_dir }}
- version: {{ influxdb.version }}
influxdb-bin-symlink:
file.symlink:
- name: {{ influxdb.install_dir }}/influxdb

View File

@ -4,6 +4,6 @@ lego:
install_dir: /usr/local/apps
release_dir: /usr/local/apps/releases
mirror: https://github.com/go-acme/lego/releases/download
version: v4.0.1
version: 4.0.1
os: linux
arch: amd64

View File

@ -1,19 +1,23 @@
---
{%- from "lego/map.jinja" import lego with context %}
{%- if not salt['file.file_exists']( lego.install_dir +"/lego-" + lego.version) %}
lego-archive-extract:
archive.extracted:
- name: {{ lego.release_dir }}/lego-{{ lego.version }}-{{ lego.os }}-{{ lego.arch }}
- source: {{ lego.mirror }}/{{ lego.version }}/lego_{{ lego.version }}_{{ lego.os }}_{{ lego.arch }}.tar.gz
- name: {{ lego.release_dir }}/lego-{{ lego.version }}
- source: {{ lego.mirror }}/v{{ lego.version }}/lego_v{{ lego.version }}_{{ lego.os }}_{{ lego.arch }}.tar.gz
- skip_verify: true
- enforce_toplevel: false
- if_missing: {{ lego.release_dir }}/lego-{{ lego.version }}-{{ lego.os }}-{{ lego.arch }}
- if_missing: {{ lego.release_dir }}/lego-{{ lego.version }}
lego-binary-symlink:
file.symlink:
- name: /usr/local/bin/lego
- target: {{ lego.release_dir }}/lego-{{ lego.version }}-{{ lego.os }}-{{ lego.arch }}/lego
- target: {{ lego.release_dir }}/lego-{{ lego.version }}/lego
- force: true
- require:
- archive: lego-archive-extract
{%- endif %}
lego-cleanup:
software.cleanup:
- name: lego
- path: {{ lego.release_dir }}
- version: {{ lego.version }}

View File

@ -18,8 +18,14 @@ nextcloud-install-link:
- target: {{ nextcloud.release_dir }}/nextcloud-{{ nextcloud.version }}
- force: true
nextcloud-cleanup:
software.cleanup:
- name: nextcloud
- path: {{ nextcloud.release_dir }}
- version: {{ nextcloud.version }}
nextcloud-datadirectory:
file.directory:
- name: {{ nextcloud.config.datadirectory}}
- name: {{ nextcloud.config.datadirectory }}
- user: {{ nextcloud.user }}
- group: {{ nextcloud.group }}

View File

@ -17,6 +17,12 @@ pycharm-link:
- target: {{ pycharm.release_dir }}/pycharm-community-{{ pycharm.version }}
- force: true
pycharm-cleanup:
software.cleanup:
- name: pycharm-community
- path: {{ pycharm.release_dir }}
- version: {{ pycharm.version }}
pycharm-shortcut:
file.managed:
- name: /usr/share/applications/jetbrains-pycharm-ce.desktop

View File

@ -18,3 +18,9 @@ qrz-binary-symlink:
- archive: qrz-archive-extract
- watch_in:
- service: qrz-service
qrz-cleanup:
software.cleanup:
- name: qrz
- path: {{ qrz.release_dir }}
- version: {{ qrz.version }}

View File

@ -4,6 +4,6 @@ rclone:
install_dir: /usr/local/apps
release_dir: /usr/local/apps/releases
mirror: https://downloads.rclone.org
version: v1.50.2
version: 1.50.2
os: linux
arch: amd64

View File

@ -3,15 +3,21 @@
rclone-archive-extract:
archive.extracted:
- name: {{ rclone.release_dir }}
- source: {{ rclone.mirror }}/{{ rclone.version }}/rclone-{{ rclone.version }}-{{ rclone.os }}-{{ rclone.arch }}.zip
- source: {{ rclone.mirror }}/v{{ rclone.version }}/rclone-v{{ rclone.version }}-{{ rclone.os }}-{{ rclone.arch }}.zip
- skip_verify: true
- enforce_toplevel: false
- if_missing: {{ rclone.release_dir }}/rclone-{{ rclone.version }}-{{ rclone.os }}-{{ rclone.arch }}/rclone
- if_missing: {{ rclone.release_dir }}/rclone-v{{ rclone.version }}-{{ rclone.os }}-{{ rclone.arch }}/rclone
rclone-binary-symlink:
file.symlink:
- name: /usr/local/bin/rclone
- target: {{ rclone.release_dir }}/rclone-{{ rclone.version }}-{{ rclone.os }}-{{ rclone.arch }}/rclone
- target: {{ rclone.release_dir }}/rclone-v{{ rclone.version }}-{{ rclone.os }}-{{ rclone.arch }}/rclone
- force: true
- require:
- archive: rclone-archive-extract
rclone-cleanup:
software.cleanup:
- name: rclone
- path: {{ rclone.release_dir }}
- version: v{{ rclone.version }}

View File

@ -2,18 +2,25 @@
{%- from "syncthing/map.jinja" import syncthing with context %}
syncthing-archive-extract:
archive.extracted:
- name: {{ syncthing.release_dir }}
- name: {{ syncthing.release_dir }}/syncthing-{{ syncthing.version }}
- source: {{ syncthing.mirror }}/v{{ syncthing.version }}/syncthing-{{ syncthing.os }}-{{ syncthing.arch }}-v{{ syncthing.version }}.tar.gz
- enforce_toplevel: false
- skip_verify: true
- archive_format: tar
- if_missing: {{ syncthing.release_dir }}/syncthing-{{ syncthing.os }}-{{ syncthing.arch }}-v{{ syncthing.version }}
- options: --transform 's/syncthing-{{ syncthing.os }}-{{ syncthing.arch }}-v{{ syncthing.version }}/syncthing-{{ syncthing.version }}/g' --strip 1
- if_missing: {{ syncthing.release_dir }}/syncthing-{{ syncthing.version }}
- watch_in:
- service: syncthing-service
syncthing-bin-symlink:
file.symlink:
- name: {{ syncthing.install_dir }}/syncthing
- target: {{ syncthing.release_dir }}/syncthing-{{ syncthing.os }}-{{ syncthing.arch }}-v{{ syncthing.version }}
- target: {{ syncthing.release_dir }}/syncthing-{{ syncthing.version }}
- watch_in:
- service: syncthing-service
- service: syncthing-service
syncthing-cleanup:
software.cleanup:
- name: syncthing
- path: {{ syncthing.release_dir }}
- version: {{ syncthing.version }}

View File

@ -29,3 +29,9 @@ telegraf-defaults-file:
- template: jinja
- watch_in:
- service: telegraf-service
telegraf-cleanup:
software.cleanup:
- name: telegraf
- path: {{ telegraf.release_dir }}
- version: {{ telegraf.version }}

View File

@ -46,4 +46,10 @@ telegram-shortcut:
- mode: 644
- template: jinja
- require:
- archive: telegram-archive-extract
- archive: telegram-archive-extract
telegram-cleanup:
software.cleanup:
- name: telegram
- path: {{ telegram.release_dir }}
- version: {{ telegram.version }}