mirror of
https://github.com/saltstack-formulas/packages-formula.git
synced 2025-04-17 10:10:27 +00:00
Merge pull request #26 from noelmcloughlin/archive_v1
Support for 'archive file' format
This commit is contained in:
commit
72f6a0603a
6 changed files with 150 additions and 4 deletions
|
@ -13,7 +13,7 @@ platforms:
|
|||
run_command: /lib/systemd/systemd
|
||||
provision_command:
|
||||
- apt-get install udev -y
|
||||
- name: ubuntu-17.10
|
||||
- name: ubuntu-18.04
|
||||
driver_config:
|
||||
run_command: /lib/systemd/systemd
|
||||
provision_command:
|
||||
|
@ -64,7 +64,7 @@ suites:
|
|||
- name: fedora
|
||||
excludes:
|
||||
- debian-9
|
||||
- ubuntu-17.10
|
||||
- ubuntu-18.04
|
||||
- centos-7
|
||||
provisioner:
|
||||
pillars-from-files:
|
||||
|
@ -73,7 +73,7 @@ suites:
|
|||
- name: centos
|
||||
excludes:
|
||||
- debian-9
|
||||
- ubuntu-17.10
|
||||
- ubuntu-18.04
|
||||
- fedora-27
|
||||
provisioner:
|
||||
dependencies:
|
||||
|
|
14
README.rst
14
README.rst
|
@ -127,6 +127,18 @@ You can specify:
|
|||
* ``required states`` on which any of the ``wanted`` packages depend for their
|
||||
correct installation (ie, ``epel`` for RedHat families).
|
||||
|
||||
``packages.archives``
|
||||
-------------------
|
||||
|
||||
'Archive file` handler for common 'download' and 'checksum' states; extraction state based on `format` value.
|
||||
|
||||
* ``wanted`` archive package software, which will be installed by extraction.
|
||||
* ``unwanted`` archive package software, which are uninstalled by directory removal.
|
||||
* ``required archive packages`` on which any of the ``wanted`` items depend on. Optional.
|
||||
|
||||
.. note:: Supports `tar` formats that `salt.states.archive.extracted` understands (tar, rar, zip, etc). The `packages.archives` state can be extended.
|
||||
|
||||
|
||||
``packages.snaps``
|
||||
-----------------
|
||||
|
||||
|
@ -164,5 +176,5 @@ Tested on
|
|||
* Debian/9
|
||||
* Centos/7
|
||||
* Fedora/27
|
||||
* Ubuntu/17.10
|
||||
* Ubuntu/18.04
|
||||
|
||||
|
|
106
packages/archives.sls
Normal file
106
packages/archives.sls
Normal file
|
@ -0,0 +1,106 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=sls
|
||||
{% from "packages/map.jinja" import packages with context %}
|
||||
|
||||
{% set req_packages = packages.pkgs.required.pkgs + ['curl', 'tar', 'bzip2', 'gzip',] %}
|
||||
include:
|
||||
- packages.pkgs
|
||||
|
||||
extend:
|
||||
pkg_req_pkgs:
|
||||
pkg.installed:
|
||||
- pkgs: {{ req_packages }}
|
||||
|
||||
{% set wanted_archives = packages.archives.required.archives %}
|
||||
{% do wanted_archives.update( packages.archives.wanted ) %}
|
||||
{% set unwanted_archives = packages.archives.unwanted %}
|
||||
|
||||
# unwanted 'archive' software
|
||||
{% for file_or_directory in unwanted_archives %}
|
||||
packages-archive-unwanted-{{ file_or_directory }}:
|
||||
file.absent:
|
||||
- name: {{ file_or_directory }}
|
||||
{% endfor %}
|
||||
|
||||
# wanted 'archive' software
|
||||
{% for package, archive in wanted_archives.items() %}
|
||||
|
||||
packages-archive-wanted-remove-prev-{{ package }}:
|
||||
file.absent:
|
||||
- name: {{ packages.tmpdir }}/{{ package }}
|
||||
- require_in:
|
||||
- packages-archive-wanted-extract-{{ package }}-directory
|
||||
|
||||
packages-archive-wanted-extract-{{ package }}-directory:
|
||||
file.directory:
|
||||
- names:
|
||||
- {{ packages.tmpdir }}/tmp
|
||||
- {{ archive.dest }}
|
||||
- user: {{ 'root' if "user" not in archive else archive.user }}
|
||||
- mode: {{ '0755' if "mode" not in archive else archive.mode }}
|
||||
- makedirs: True
|
||||
- require_in:
|
||||
- cmd: packages-archive-wanted-download-{{ package }}
|
||||
|
||||
packages-archive-wanted-download-{{ package }}:
|
||||
cmd.run:
|
||||
- name: curl -s -L -o {{ packages.tmpdir }}/{{ package }} {{ archive.dl.source }}
|
||||
- unless: test -f {{ packages.tmpdir }}/{{ package }}
|
||||
|
||||
{%- if "hashsum" in archive.dl and archive.dl.hashsum %}
|
||||
{# refer to https://github.com/saltstack/salt/pull/41914 #}
|
||||
|
||||
packages-archive-wanted-{{ package }}-check-hashsum:
|
||||
module.run:
|
||||
- name: file.check_hash
|
||||
- path: {{ packages.tmpdir }}/{{ package }}
|
||||
- file_hash: {{ archive.dl.hashsum }}
|
||||
- require:
|
||||
- cmd: packages-archive-wanted-download-{{ package }}
|
||||
- require_in:
|
||||
- archive: packages-archive-wanted-install-{{ package }}
|
||||
cmd.run:
|
||||
- name: rm {{ packages.tmpdir }}/{{ package }}
|
||||
- onfail:
|
||||
- module: packages-archive-wanted-{{ package }}-check-hashsum
|
||||
{%- endif %}
|
||||
|
||||
packages-archive-wanted-install-{{ package }}:
|
||||
{% if archive.dl.format|trim|lower in ('tar','zip', 'rar',) %}
|
||||
|
||||
archive.extracted:
|
||||
- source: file://{{ packages.tmpdir }}/{{ package }}
|
||||
- name: {{ archive.dest }}
|
||||
- archive_format: {{ archive.dl.format }}
|
||||
{%- if 'hashurl' in archive.dl and archive.dl.hashurl %}
|
||||
- source_hash: {{ archive.dl.hashurl }}
|
||||
{%- endif %}
|
||||
{%- if 'options' in archive and archive.options %}
|
||||
- options: {{ archive.options }}
|
||||
- enforce_toplevel: {{ 'False' if "strip-components" in archive.options else 'True' }}
|
||||
{%- endif %}
|
||||
- unless: test -d {{ archive.dest }}
|
||||
cmd.run:
|
||||
- name: rm {{ packages.tmpdir }}/{{ package }}
|
||||
- onfail:
|
||||
- archive: packages-archive-wanted-install-{{ package }}
|
||||
|
||||
{% else %}
|
||||
|
||||
test.show_notification:
|
||||
- text: |
|
||||
The value of "packages.archives.wanted.{{ package }}.dl.format' is unsupported (skipping {{ package }}).
|
||||
|
||||
{% endif %}
|
||||
- onchanges:
|
||||
- packages-archive-wanted-download-{{ package }}
|
||||
- require_in:
|
||||
- packages-archive-wanted-cleanup-{{ package }}
|
||||
|
||||
packages-archive-wanted-cleanup-{{ package }}:
|
||||
file.absent:
|
||||
- name: {{ packages.tmpdir }}/{{ package }}
|
||||
- onchanges:
|
||||
- packages-archive-wanted-install-{{ package }}
|
||||
|
||||
{%- endfor %}
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=yaml
|
||||
packages:
|
||||
tmpdir: /tmp/saltstack-packages-formula-archives
|
||||
remote_pkgs: {}
|
||||
pkgs:
|
||||
held: {}
|
||||
|
@ -32,3 +33,8 @@ packages:
|
|||
required:
|
||||
states: []
|
||||
pkgs: []
|
||||
archives:
|
||||
wanted: {} #note: dict
|
||||
unwanted: []
|
||||
required:
|
||||
archives: {} #note: dict
|
||||
|
|
|
@ -6,4 +6,5 @@ include:
|
|||
- packages.remote_pkgs
|
||||
- packages.pips
|
||||
- packages.gems
|
||||
- packages.archives
|
||||
- packages.snaps
|
||||
|
|
|
@ -21,6 +21,7 @@ packages:
|
|||
- avahi-daemon
|
||||
required:
|
||||
pkgs:
|
||||
- wget
|
||||
- git
|
||||
pips:
|
||||
wanted:
|
||||
|
@ -45,6 +46,26 @@ packages:
|
|||
- test-snapd-hello-classic
|
||||
unwanted:
|
||||
- goodbye-world
|
||||
archives:
|
||||
wanted:
|
||||
terminator:
|
||||
dest: /usr/local/terminator
|
||||
options: '--strip-components=1' #recommended option, but beware tarbombs
|
||||
dl:
|
||||
format: tar
|
||||
source: https://launchpad.net/terminator/gtk3/1.91/+download/terminator-1.91.tar.gz
|
||||
#hashurl: https://launchpad.net/terminator/gtk3/1.91/+download/terminator-1.91.tar.gz/+md5
|
||||
hashsum: md5=2eed999d7a41f2e18eaa511bbbf80f58
|
||||
phantomjs:
|
||||
dest: /usr/local/src #beware tarbombs
|
||||
user: root
|
||||
mode: '0700'
|
||||
dl:
|
||||
format: tar
|
||||
source: https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
|
||||
hashsum: md5=1c947d57fce2f21ce0b43fe2ed7cd361
|
||||
unwanted:
|
||||
- /usr/local/boring_archive_software
|
||||
|
||||
remote_pkgs:
|
||||
zoom: 'https://zoom.us/client/latest/zoom_amd64.deb'
|
||||
|
|
Loading…
Add table
Reference in a new issue