Page MenuHomeDevCentral

No OneTemporary

diff --git a/.arclint b/.arclint
index a9ea22d..a734f04 100644
--- a/.arclint
+++ b/.arclint
@@ -1,30 +1,33 @@
{
"linters": {
"chmod": {
"type": "chmod"
},
"shell": {
"type": "shellcheck",
"include": [
"(\\.sh$)"
]
},
"filename": {
"type": "filename"
},
"json": {
"type": "json",
"include": [
"(^\\.arcconfig$)",
"(^\\.arclint$)",
"(\\.json$)"
]
},
"python": {
"type": "flake8",
+ "severity": {
+ "F821": "advice"
+ },
"include": [
"(\\.py$)"
]
}
}
}
diff --git a/_modules/nano.py b/_modules/nano.py
new file mode 100644
index 0000000..7d8d726
--- /dev/null
+++ b/_modules/nano.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+
+# -------------------------------------------------------------
+# Salt — Nano execution module
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Created: 2020-02-09
+# Description: Allow to generate nano configuration
+# License: BSD-2-Clause
+# -------------------------------------------------------------
+
+
+import subprocess
+
+
+def _get_rc_includes(nanorc_dir):
+ process = subprocess.run(["find", nanorc_dir, "-type", "f"], check=True,
+ stdout=subprocess.PIPE, universal_newlines=True)
+ return ["include " + file for file in process.stdout.split()]
+
+
+def _get_rc_content(nanorc_dir):
+ nano_rc_includes = _get_rc_includes(nanorc_dir)
+
+ return "\n".join(nano_rc_includes) + "\n"
+
+
+def check_rc_up_to_date(name="/etc/nanorc", nanorc_dir="/usr/share/nano"):
+ expected_content = _get_rc_content(nanorc_dir)
+
+ try:
+ fd = open(name)
+ except OSError:
+ return False
+
+ actual_content = "".join(fd.readlines())
+ fd.close()
+
+ return actual_content == expected_content
+
+
+def config_autogenerate(name="/etc/nanorc", nanorc_dir="/usr/share/nano"):
+ nano_rc_content = _get_rc_content(nanorc_dir)
+
+ fd = open(name, "w")
+ fd.write(nano_rc_content)
+ fd.close()
diff --git a/_states/nano.py b/_states/nano.py
new file mode 100644
index 0000000..0cee266
--- /dev/null
+++ b/_states/nano.py
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+
+# -------------------------------------------------------------
+# Salt — Nano state
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Created: 2020-02-09
+# Description: Allow to generate nano configuration
+# License: BSD-2-Clause
+# -------------------------------------------------------------
+
+
+def config_autogenerated(name="/etc/nanorc", nanorc_dir="/usr/share/nano"):
+ ret = {'name': name,
+ 'result': False,
+ 'changes': {},
+ 'comment': ''}
+
+ if __salt__['nano.check_rc_up_to_date'](name=name, nanorc_dir=nanorc_dir):
+ ret['result'] = True
+ ret['comment'] = '{0} is already up to date'.format(name)
+ return ret
+
+ if __opts__['test']:
+ ret['result'] = None
+ ret['comment'] = 'State nano will write config file {0}'.format(name)
+ return ret
+
+ try:
+ __salt__['nano.config_autogenerate'](name=name, nanorc_dir=nanorc_dir)
+ except Exception as e:
+ ret['comment'] = e
+ return ret
+
+ ret['comment'] = "Configuration written"
+ ret['result'] = True
+ return ret
diff --git a/_tests/data/nanorc_dir/bar.nanorc b/_tests/data/nanorc_dir/bar.nanorc
new file mode 100644
index 0000000..e69de29
diff --git a/_tests/data/nanorc_dir/foo.nanorc b/_tests/data/nanorc_dir/foo.nanorc
new file mode 100644
index 0000000..e69de29
diff --git a/_tests/data/nanorc_not_ok b/_tests/data/nanorc_not_ok
new file mode 100644
index 0000000..83e4f08
--- /dev/null
+++ b/_tests/data/nanorc_not_ok
@@ -0,0 +1 @@
+include data/nanorc_dir/bar.nanorc
diff --git a/_tests/data/nanorc_ok b/_tests/data/nanorc_ok
new file mode 100644
index 0000000..c0000b9
--- /dev/null
+++ b/_tests/data/nanorc_ok
@@ -0,0 +1,2 @@
+include data/nanorc_dir/bar.nanorc
+include data/nanorc_dir/foo.nanorc
diff --git a/_tests/modules/test_nano.py b/_tests/modules/test_nano.py
new file mode 100644
index 0000000..85bd384
--- /dev/null
+++ b/_tests/modules/test_nano.py
@@ -0,0 +1,42 @@
+from importlib.machinery import SourceFileLoader
+import unittest
+
+
+salt_test_case = SourceFileLoader(
+ 'salt_test_case', "salt_test_case.py").load_module()
+nano = SourceFileLoader('nano', "../_modules/nano.py").load_module()
+
+
+DATA_DIR = "data/nanorc_dir"
+EXPECTED_INCLUDES = [
+ 'include data/nanorc_dir/bar.nanorc',
+ 'include data/nanorc_dir/foo.nanorc',
+]
+
+
+class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
+
+ def test_get_rc_contents(self):
+ actual_includes = nano._get_rc_content(DATA_DIR)
+ self.assertEqual(EXPECTED_INCLUDES,
+ sorted(actual_includes.strip().split("\n")))
+
+ def test_get_rc_includes(self):
+ self.assertEqual(EXPECTED_INCLUDES,
+ sorted(nano._get_rc_includes(DATA_DIR)))
+
+ def check_rc_up_to_date_when_it_is(self):
+ self.assertTrue(nano.check_rc_up_to_date(name="data/nanorc_ok",
+ nanorc_dir=DATA_DIR))
+
+ def check_rc_up_to_date_when_it_is_not(self):
+ self.assertFalse(nano.check_rc_up_to_date(name="data/nanorc_not_ok",
+ nanorc_dir=DATA_DIR))
+
+ def check_rc_up_to_date_when_it_is_does_not_exist(self):
+ self.assertFalse(nano.check_rc_up_to_date(name="/not/existing",
+ nanorc_dir=DATA_DIR))
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/roles/shellserver/userland-software/base.sls b/roles/shellserver/userland-software/base.sls
index 8780e27..cafc15d 100644
--- a/roles/shellserver/userland-software/base.sls
+++ b/roles/shellserver/userland-software/base.sls
@@ -1,282 +1,292 @@
# -------------------------------------------------------------
# Salt — Provision base software
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Created: 2016-04-09
# License: Trivial work, not eligible to copyright
# -------------------------------------------------------------
{% from "map.jinja" import dirs, packages, packages_prefixes with context %}
/opt:
file.directory
# -------------------------------------------------------------
# Editors
#
# Disclaimer: We don't caution the views of Richard Stallman
# or the Church of Emacs positions.
# See http://geekfeminism.wikia.com/wiki/EMACS_virgins_joke
# -------------------------------------------------------------
editors:
pkg.installed:
- pkgs:
- joe
- nano
- vim
- emacs-nox
# -------------------------------------------------------------
# General UNIX utilities
# -------------------------------------------------------------
utilities:
pkg.installed:
- pkgs:
- cmatrix
- figlet
- {{ packages.gpg }}
- grc
- moreutils
- mosh
- nmap
- toilet
- unrar
- whois
- woof
- zip
{% if grains['os_family'] == 'Debian' %}
- bsdmainutils
- dnsutils
- sockstat
- sysvbanner
- toilet-fonts
{% endif %}
{% if grains['os'] == 'FreeBSD' %}
- bind-tools
- coreutils
- figlet-fonts
- gsed
- sudo
{% endif %}
utilities_www:
pkg.installed:
- pkgs:
- links
- lynx
- w3m
# -------------------------------------------------------------
# More exotic shells
# -------------------------------------------------------------
userland_software_shells:
pkg.installed:
- pkgs:
- fish
# -------------------------------------------------------------
# Development
# -------------------------------------------------------------
dev:
pkg.installed:
- pkgs:
- {{ packages.ag }}
- autoconf
- automake
- cmake
- colordiff
- {{ packages.cppunit }}
- git
- git-lfs
- jq
- ripgrep
- valgrind
{% if grains['os'] == 'FreeBSD' %}
- hub
{% else %}
- arcanist
- clang
- llvm
- strace
{% endif %}
{% if grains['os_family'] == 'Debian' %}
dev_popular_libs:
pkg.installed:
- pkgs:
- libssl-dev
{% endif %}
# -------------------------------------------------------------
# Languages
# -------------------------------------------------------------
languages_removed:
pkg.removed:
- pkgs:
{% if grains['os_family'] == 'Debian' %}
- php7.0
- php7.1
- php7.2
{% elif grains['os'] == 'FreeBSD' %}
- php70
- php71
- php72
- php73
{% endif %}
languages:
pkg.installed:
- pkgs:
- python3
- {{ packages.tcl }}
{% if grains['os_family'] == 'Debian' %}
- php7.3
{% elif grains['os'] == 'FreeBSD' %}
- php74
{% endif %}
# -------------------------------------------------------------
# De facto standard libraries for languages
# -------------------------------------------------------------
languages_libs:
pkg.installed:
- pkgs:
# PHP extensions
- {{ packages_prefixes.php }}bcmath
- {{ packages_prefixes.php }}ctype
- {{ packages_prefixes.php }}curl
- {{ packages_prefixes.php }}dom
- {{ packages_prefixes.php }}gd
- {{ packages_prefixes.php }}intl
- {{ packages_prefixes.php }}json
- {{ packages_prefixes.php }}mbstring
- {{ packages_prefixes.php }}mysqli
- {{ packages_prefixes.php }}pdo
- {{ packages_prefixes.php }}phar
- {{ packages_prefixes.php }}simplexml
- {{ packages_prefixes.php }}soap
- {{ packages_prefixes.php }}tokenizer
- {{ packages_prefixes.php }}xml
- {{ packages_prefixes.php }}xmlwriter
- {{ packages_prefixes.php }}xsl
{% if grains['os_family'] == 'Debian' %}
# On Debian, these PDO extensions doesn't follow regular names
# but are installed if you require the legacy extension name.
- {{ packages_prefixes.php }}mysql
- {{ packages_prefixes.php }}sqlite3
{% else %}
# On Debian, these extensions are now shipped by default:
- {{ packages_prefixes.php }}fileinfo
- {{ packages_prefixes.php }}filter
- {{ packages_prefixes.php }}iconv
- {{ packages_prefixes.php }}openssl
- {{ packages_prefixes.php }}pcntl
- {{ packages_prefixes.php }}session
- {{ packages_prefixes.php }}xmlreader
- {{ packages_prefixes.php }}zlib
# On Debian, these PDO extensions doesn't follow regular names:
- {{ packages_prefixes.php }}pdo_mysql
- {{ packages_prefixes.php }}pdo_sqlite
{% endif %}
# PECL extensions
- {{ packages_prefixes.pecl }}yaml
# PHP utilities
{% if grains['os'] != 'FreeBSD' %}
# On FreeBSD, PEAR is still a PHP 5.6 package (last tested 2018-02-17).
# Same for Composer (last tested 2018-02-28)
- {{ packages.composer }}
- {{ packages.pear }}
- {{ packages.phpcs }}
{% endif %}
# Standard Python modules
{% if grains['os'] == 'FreeBSD' %}
- {{ packages_prefixes.python3 }}gdbm
- {{ packages_prefixes.python3 }}sqlite3
{% endif %}
# TCL
- tcllib
- {{ packages.tcltls }}
# -------------------------------------------------------------
# Workaround : install composer and phpcs on FreeBSD
# -------------------------------------------------------------
{% if grains['os'] == 'FreeBSD' %}
/opt/composer:
file.directory
/opt/composer/composer.phar:
file.managed:
- source: https://github.com/composer/composer/releases/download/1.9.1/composer.phar
- source_hash: ffd3a22e43cafbeff4b3c66e334efa87a27f309da565259741f111830b6fe1217d7ab31aef47563f14e18ebeeeece46f
- mode: 755
{{ dirs.bin }}/composer:
file.symlink:
- target: /opt/composer/composer.phar
- require:
- file: /opt/composer/composer.phar
/opt/phpcs:
file.directory
{% for command in ['phpcs', 'phpcbf'] %}
/opt/phpcs/{{ command }}:
file.managed:
- source: https://squizlabs.github.io/PHP_CodeSniffer/{{ command }}.phar
- skip_verify: True
- mode: 755
{{ dirs.bin }}/{{ command }}:
file.symlink:
- target: /opt/phpcs/{{ command }}
- require:
- file: /opt/phpcs/{{ command }}
{% endfor %}
{% endif %}
# -------------------------------------------------------------
# Spelling and language utilities
# -------------------------------------------------------------
spelling:
pkg.installed:
- pkgs:
- {{ packages['aspell-en'] }}
- {{ packages['aspell-fr'] }}
- {{ packages.verbiste }}
# -------------------------------------------------------------
# Media utilities
# -------------------------------------------------------------
media:
pkg.installed:
- pkgs:
- {{ packages.exiftool }}
- id3v2
- {{ packages.imagemagick }}
- optipng
- sox
# -------------------------------------------------------------
# Office utilities (bureautique)
# -------------------------------------------------------------
office_software:
pkg.installed:
- pkgs:
- gcal
- pdftk
- qpdf
+
+# -------------------------------------------------------------
+# Nano configuration
+# -------------------------------------------------------------
+
+{% set nano_rc_files = salt['cmd.shell']('find ' + dirs['share'] + '/nano/ -type f') %}
+
+{{ dirs.etc }}/nanorc:
+ nano.config_autogenerated:
+ - nanorc_dir: {{ dirs.share }}/nano
diff --git a/roles/shellserver/userland-software/files/nanorc b/roles/shellserver/userland-software/files/nanorc
new file mode 100644
index 0000000..62fae22
--- /dev/null
+++ b/roles/shellserver/userland-software/files/nanorc
@@ -0,0 +1,3 @@
+{%- for include in includes %}
+include {{ include }}
+{% endfor -%}

File Metadata

Mime Type
text/x-diff
Expires
Sun, May 3, 06:13 (1 d, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3665478
Default Alt Text
(14 KB)

Event Timeline