nix-amer/README.md

157 lines
5.0 KiB
Markdown
Raw Normal View History

2018-11-06 13:01:05 +00:00
# | nix-amer |
2018-11-06 10:17:33 +00:00
2018-11-11 00:08:33 +00:00
[![Go version](https://img.shields.io/badge/go_version-1.11-blue.svg)](https://golang.org/doc/go1.11)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Go Report Card](https://goreportcard.com/badge/git.xdrm.io/go/nix-amer)](https://goreportcard.com/report/git.xdrm.io/go/nix-amer)
[![Go doc](https://godoc.org/git.xdrm.io/go/nix-amer?status.svg)](https://godoc.org/git.xdrm.io/go/nix-amer)
2018-11-06 13:01:05 +00:00
```yaml
name: nix-amer
version: 0.1.0
description: Configuration automation tool
author: xdrm-brackets
```
2018-11-06 10:19:09 +00:00
2018-11-06 13:01:05 +00:00
>Need to automate the setup of your linux server or desktop ? This tool is made for you.
[TOC]
----
2018-11-06 16:17:39 +00:00
2018-11-06 13:01:05 +00:00
### I. Build Format
2018-11-06 16:17:39 +00:00
2018-11-06 13:01:05 +00:00
Your whole setup remains in 1 only build file. Each line contains one instruction, the list of instructions is listed below.
#### 1) package management
These instructions allow you to interact with the package system available on your system.
```
ins <packages>
```
Install the listed packages. If more than one, use spaces to separate package names.
```
del <packages>
```
Remove the listed packages. If more than one, use spaces to separate package names.
#### 3) update configuration files
This instruction allow you to update configuration files without the need of an editor and in a developer-readable manner.
```
cnf <expr> <content>
```
2018-11-06 16:17:39 +00:00
Update a configuration file where \<expr\> is a dot-separated human-readable [path expression](#ii-path-expressions) and \<content\> is a string or a file. If a string is given, it will <u>override/add the field</u> ; if a file is given the configuration file will be <u>replaced</u> by it.
2018-11-06 13:01:05 +00:00
```
cnf <expr>
```
Remove a configuration field matching the \<expr\> path.
2018-11-06 16:17:39 +00:00
2018-11-06 13:01:05 +00:00
#### 4) service management
These instructions allow you to interact with the service system (_cf. systemd_).
```
ser [enable|start|stop|restart|reload] <services>
```
Perform the action on services. If more than one, use spaces to separate service names.
2018-11-06 16:17:39 +00:00
#### 5) custom scripts
These instructions allow you to use custom scripts for complex operations.
```
run <script>
```
Execute the \<script\> file.
2018-11-06 13:01:05 +00:00
----
2018-11-06 16:17:39 +00:00
2018-11-06 13:01:05 +00:00
### II. Path Expressions
2018-11-11 18:06:00 +00:00
The syntax is pretty fast-forward, it uses 2 levels (file, fields) to find your configuration line : `location/path@field.path`.
2018-11-06 13:01:05 +00:00
| Field | Description | Example |
2018-11-06 16:17:39 +00:00
| --------- | :----------------------------------- | -------------------------- |
2018-11-11 18:06:00 +00:00
| `location/path` | Path to the configuration file to edit. The file will be created if not found. | `/etc/ssh/sshd_config`, `/etc/nginx/nginx.conf`, `/etc/nginx/sites-available/default` |
| `field.path` | Dot-separated chain of strings that match a configuration field. If **omitted**, the \<value\> will just be added at the end of the configuration file. In the same way if the field does not point to a raw field but a parent or group containing fields, the \<value\> will be added to the group. | `/etc/ssh/sshd_config@AllowGroups`, `/etc/nginx/nginx.conf@http.gzip` |
> When a file is given as \<content\>, the `cnf` command acts as the shell command `mv` (copy).
2018-11-06 16:17:39 +00:00
2018-11-07 10:56:53 +00:00
#### File Formats
Configuration files can be written according to some standards or application-specific syntax. This tool uses standard and third-party to parse the following formats :
- [xml](https://fr.wikipedia.org/wiki/Extensible_Markup_Language) and [json](https://json.org/) are read/written using the go standard library (_cf. [json](https://golang.org/pkg/encoding/json/), [xml](https://golang.org/pkg/encoding/xml/)_).
- [yaml](https://en.wikipedia.org/wiki/YAML) with [go-yaml/yaml](https://github.com/go-yaml/yaml).
- [ini](https://en.wikipedia.org/wiki/INI_file) with [go-ini/ini](https://github.com/go-ini/ini).
- <strike>[toml](https://en.wikipedia.org/wiki/TOML)</strike> with [BurntSushi/toml](https://github.com/BurntSushi/toml).
> not consistent ; overriding a toml file with this can mess with comments and duplicate sections. Also there is type inference to do (strings are surrounded with `"`, there is `true`, `false`, etc)
2018-11-07 10:56:53 +00:00
- [nginx configurations](https://docs.nginx.com/nginx/admin-guide/basic-functionality/managing-configuration-files/) with [lytics/confl](https://github.com/lytics/confl).
- _and more to come..._
2018-11-06 16:17:39 +00:00
----
## Example
_myserver.build_
```
2018-11-06 17:03:31 +00:00
sys name ubuntu # required to choose which
sys version 18.4 # package-manager to use
2018-11-06 16:17:39 +00:00
[install]
2018-11-06 16:17:39 +00:00
upd
ins nginx ssh sslh
[nginx]
cnf /etc/nginx/nginx.conf@http.gzip on
cnf /etc/nginx/sites-available/new-site ./localConfFile
2018-11-06 16:17:39 +00:00
ser enable nginx
ser start nginx
[sshd]
cnf /etc/ssh/sshd_config@PermitRootLogin no
cnf /etc/ssh/sshd_config@PermitEmptyPasswords no
cnf /etc/ssh/sshd_config@StrictModes yes
cnf /etc/ssh/sshd_config@Port 22
2018-11-06 16:17:39 +00:00
ser enable sshd
ser enable ssh
[sslh]
cnf /etc/default/sslh@RUN yes
cnf /etc/default/sslh@DEAMON_OPTS "--user sslh --listen 0.0.0.0:443 --ssh 127.0.0.1:22 --ssl 127.0.0.1:44300 --pidfile /var/run/sslh/sslh.pid"
2018-11-06 16:17:39 +00:00
ser enable sslh
ser start sslh
```