diff --git a/README.rst b/README.rst index 1d8e3df..6539ebd 100644 --- a/README.rst +++ b/README.rst @@ -176,6 +176,16 @@ You can specify: Centos has no native ``snapd`` package at this time. + +``packages.golang`` +------------------- + +You can specify: + +* ``clean`` golang packages, removed using ``go clean -i ...``. +* ``goget`` golang packages, installed using ``go get``. + + ``packages.remote_pkgs`` ------------------------ diff --git a/packages/archives.sls b/packages/archives.sls index e666db4..54babfd 100644 --- a/packages/archives.sls +++ b/packages/archives.sls @@ -33,7 +33,7 @@ packages-archive-wanted-target-{{ package }}-directory: {%- if packages.tmpdir != '/tmp' %} - {{ packages.tmpdir }} {%- endif %} - - user: {{ 'root' if 'user' not in archive else archive.user }} + - user: {{ packages.rootuser if 'user' not in archive else archive.user }} - mode: {{ '0755' if 'mode' not in archive else archive.mode }} - makedirs: True - require_in: @@ -85,7 +85,7 @@ packages-archive-wanted-download-{{ package }}: - name: {{ archive.dest }}/{{ archivename }} - source: {{ archive.dl.source }} - mode: {{ '0755' if archive.dl.format in ('bin',) else '0644' if 'mode' not in archive else archive.mode }} - - user: {{ 'root' if 'user' not in archive else archive.user }} + - user: {{ packages.rootuser if 'user' not in archive else archive.user }} - makedirs: True {%- if 'hashsum' in archive.dl and archive.dl.hashsum %} - source_hash: {{ archive.dl.hashsum }} diff --git a/packages/defaults.yaml b/packages/defaults.yaml index dc18809..a363cdd 100644 --- a/packages/defaults.yaml +++ b/packages/defaults.yaml @@ -2,6 +2,7 @@ # vim: ft=yaml packages: tmpdir: /tmp/saltstack-packages-formula-archives + rootuser: root remote_pkgs: {} pkgs: held: {} @@ -40,6 +41,9 @@ packages: required: states: [] pkgs: [] + golang: + goget: [] + clean: [] archives: pkgs: required: ['curl', 'bzip2', 'gzip'] diff --git a/packages/golang/clean.sls b/packages/golang/clean.sls new file mode 100644 index 0000000..61f4739 --- /dev/null +++ b/packages/golang/clean.sls @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import packages with context %} + + {%- for package in packages.golang.clean %} + +packages-golang-clean-cmd-run-go-clean-{{ package }}: + cmd.run: + - name: go clean -i {{ package }}... + - runas: {{ packages.rootuser }} + + {%- endfor %} diff --git a/packages/golang/goget.sls b/packages/golang/goget.sls new file mode 100644 index 0000000..f0338dd --- /dev/null +++ b/packages/golang/goget.sls @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import packages with context %} + + {%- for package in packages.golang.goget %} + +packages-golang-goget-cmd-run-go-get-{{ package }}: + cmd.run: + - name: go get {{ package }} + - runas: {{ packages.rootuser }} + + {%- endfor %} diff --git a/packages/golang/init.sls b/packages/golang/init.sls new file mode 100644 index 0000000..ba0a430 --- /dev/null +++ b/packages/golang/init.sls @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .clean + - .goget diff --git a/packages/map.jinja b/packages/map.jinja index 401c360..c2d1a65 100644 --- a/packages/map.jinja +++ b/packages/map.jinja @@ -18,3 +18,10 @@ ), base='packages') %} + +{#- Post-processing for specific non-YAML customisations #} +{%- do packages.update({'kernel': grains.kernel | lower}) %} +{%- if grains.os == 'MacOS' %} +{%- set macos_user = salt['cmd.run']("stat -f '%Su' /dev/console") %} +{%- do packages.update({'rootuser': macos_user}) %} +{%- endif %} diff --git a/packages/npms.sls b/packages/npms.sls index c04c795..57b550f 100644 --- a/packages/npms.sls +++ b/packages/npms.sls @@ -32,8 +32,8 @@ npm_req_pkgs: npms_dir: file.directory: - name: {{ packages.npms.dir }} - - user: {{ 'root' if 'user' not in packages.npms else packages.npms.user }} - - group: {{ 'root' if 'group' not in packages.npms else packages.npms.group }} + - user: {{ packages.rootuser if 'user' not in packages.npms else packages.npms.user }} + - group: {{ packages.rootuser if 'group' not in packages.npms else packages.npms.group }} - mode: {{ '0755' if 'mode' not in packages.npms else packages.npms.mode }} - makedirs: True {% endif %} diff --git a/pillar.example b/pillar.example index e324d45..9ef9c94 100644 --- a/pillar.example +++ b/pillar.example @@ -61,6 +61,14 @@ packages: unwanted: - goodbye-world + golang: + goget: + - github.com/golang/example/hello + - github.com/golang/example/outyet + clean: + - github.com/golang/example/hello + - github.com/golang/example/outyet + npms: dir: /home/kitchen/npms # The target directory in which to install the package, or None for global installation user: kitchen # The user to run NPM with (and to assign to `dir`)