diff --git a/.gitignore b/.gitignore index 1552802..7d7c3c2 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ _scraps build dist docs/build +help/site htmlcov tmp.* tmp diff --git a/help/docs/commands/django.md b/help/docs/commands/django.md new file mode 100644 index 0000000..1c0a72a --- /dev/null +++ b/help/docs/commands/django.md @@ -0,0 +1,118 @@ +# Django + +Summary: Work with Django management commands. + +## Common Options for Django Commands + +You will generally want to include `cd` to change to the project directory and `prefix` to load the virtual environment. + +```yaml +- collect static files: + django: static + cd: /path/to/project/source + prefix: source ../python/bin/activate +``` + +## Automatic Conversion of Django Command Switches + +Options provided in the command configuration file are automatically converted to command line switches. + +```yaml +- run database migrations: + django: migrate + settings: tenants.example_com.settings + +- dump some data: + django: dumpdata + indent: 4 + natural_foreign: yes + natural_primary: yes +``` + +## Available Commands + +### check + +```ini +[run django checks] +django: check +``` + +```yaml +- run django checks: + django: check +``` + +### dumpdata + +Dump fixture data. + +- app: Required. The name of the app. +- model: Optional. A model name within the app. +- path: The path to the JSON file. When a model is provided, this defaults to `fixtures/app/model.json`. Otherwise, it is `fixtures/app/initial.json`. + +```ini +[dump project data] +django: dumpdata +app: projects + +[dump project categories] +django: dumpdata +app: projects +model: Category +path: local/projects/fixtures/default-categories.json +``` + +### loaddata + +Load fixture data. + +- path: The path to the JSON file. When a model is provided, this defaults to `fixtures/app/model.json`. Otherwise, it is `fixtures/app/initial.json`. + +### migrate + +Run database migrations. + +```ini +[run database migrations] +django: migrate +``` + +```yaml +- run database migrations: + django: migrate +``` + +### static + +Collect static files. + +```ini +[collect static files] +django: static +``` + +```yaml +- collect static files: + django: static +``` + +## Custom or Ad Hoc Commands + +It is possible to work with any Django management command provided the parameters may be specified as a switch. + +```ini +[run any django command] +django: command_name +first_option_name: asdf +second_option_name: 1234 +third_option_name: yes +``` + +```yaml +- run any django command: + django: command_name + first_option_name: asdf + second_option_name: 1234 + third_option_name: yes +``` diff --git a/help/docs/commands/messages.md b/help/docs/commands/messages.md new file mode 100644 index 0000000..3fff90f --- /dev/null +++ b/help/docs/commands/messages.md @@ -0,0 +1,111 @@ +# Messages + +Summary: Send feedback to users. + +## Available Commands + +### dialog + +Use the dialog CLI to display a message. + +- `height`: The height of the dialog box. Default: `15` +- `title`: An optional title to display as part of the dialog box. Default: `Message`. +- `width`: The width of the dialog box. Default: `100` + +```ini +[send some feedback] +dialog: "This is a message." +``` + +```yaml +- send some feedback: + dialog: "This is a message." +``` + +!!! warning + + The dialog command line utility must be installed. + +### explain + +Provide an explanation. When generating code this is added as a comment. When documentation is generated, it is output as text. + +```ini +[introduction] +explain: "These steps will set up a Radicale CalDav/CardDav server." +header: Introduction +``` + +The `header` option is not used in comments, but makes documentation more readable and facilitates the creation of tutorials or install guides that re-use the defined steps. + +### echo + +Display a simple message. + +```ini +[send some feedback] +echo: "This is a message." +``` + +```yaml +- send some feedback: + echo: "This is a message." +``` + +### slack + +Send a message via Slack. + +- `url`: Required. The URL to which the message should be sent. + +```ini +[send some feedback] +slack: "This is a message." +url: https://subdomain.slack.com/path/to/your/integration +``` + +```yaml +- send some feedback: + slack: "This is a message." + url: https://subdomain.slack.com/path/to/your/integration +``` + +!!! note + You could easily define a variable for the Slack URL and set ``url: {{ slack_url }}`` to save some typing. See [variables](../config/variables.md). + +### screenshot + +Like `explain` above, a screenshot adds detail to comments or documentation, but does not produce a command statement. + +```ini +[login screenshot after successful install] +screenshot: images/login.png +caption: Login Page +height: 50% +width: 50% +``` + +The value of `screenshot` may be relative to the command file or a full URL to the image. If `caption` is omitted the section (comment) is used. + +### twist + +Send a message via [Twist](https://twist.com). + +- `title`: The title of the message. Default: `Notice` +- `url`: Required. The URL to which the message should be sent. + +```ini +[send some feedback] +twist: "This is a message." +url: https://subdomain.twist.com/path/to/your/integration +``` + +```yaml +- send some feedback: + twist: "This is a message." + url: https://subdomain.twist.com/path/to/your/integration +``` + +!!! note + + As with Slack, you could easily define a variable for the Twist URL and set ``url: {{ twist_url }}``. See [variables](../config/variables.md). diff --git a/help/docs/commands/mysql.md b/help/docs/commands/mysql.md new file mode 100644 index 0000000..bd539d7 --- /dev/null +++ b/help/docs/commands/mysql.md @@ -0,0 +1,64 @@ +# MySQL + +Summary: Work with MySQL (and Maria) databases. + +## Common Options + +- `admin_pass`: The password off the admin-authorized user. +- `admin_user`: The user name of the admin-authorized user. Default: `root` +- `host`: The host name. Default: `localhost` +- `port`: The TCP port. Default: `3306` + +## Available Commands + +### mysql.create + +Create a database. Argument is the database name. + +- `owner`: The user name that owns the database. + +```ini +[create the database] +mysql.create: database_name +``` + +### mysql.drop + +Drop a database. Argument is the database name. + +### mysql.dump + +Dump the database schema. Argument is the database name. + +- `path`: The path to the dump file. Default: `dump.sql` + +### mysql.exec + +Execute an SQL statement. Argument is the SQL statement. + +- `database`: The name of the database where the statement will be executed. Default: `default` + +### mysql.exists + +Determine if a database exists. Argument is the database name. + +### mysql.grant + +Grant privileges to a user. Argument is the privileges to be granted. + +- `database`: The database name where privileges are granted. +- `user`: The user name for which the privileges are provided. + +### mysql.user.create + +Create a user. Argument is the user name. + +- `password`: The user's password. + +### mysql.user.drop + +Remove a user. Argument is the user name. + +### mysql.user.exists + +Determine if a user exists. Argument is the user name. diff --git a/help/docs/commands/pgsql.md b/help/docs/commands/pgsql.md new file mode 100644 index 0000000..4f9e423 --- /dev/null +++ b/help/docs/commands/pgsql.md @@ -0,0 +1,57 @@ +# PostgreSQL + +Summary: Work with Postgres databases. + +## Common Options + +- `admin_pass`: The password off the admin-authorized user. +- `admin_user`: The user name of the admin-authorized user. Default: `postgres` +- `host`: The host name. Default: `localhost` +- `port`: The TCP port. Default: `5432` + +## Available Commands + +### pgsql.create + +Create a database. Argument is the database name. + +- `owner`: The user name that owns the database. + +```ini +[create the database] +pgsql.create: database_name +``` + +### pgsql.drop + +Drop a database. Argument is the database name. + +### pgsql.dump + +Dump the database schema. Argument is the database name. + +- `path`: The path to the dump file. Default: `dump.sql` + +### pgsql.exec + +Execute an SQL statement. Argument is the SQL statement. + +- `database`: The name of the database where the statement will be executed. Default: `default` + +### pgsql.exists + +Determine if a database exists. Argument is the database name. + +### pgsql.user.create + +Create a user. Argument is the user name. + +- `password`: The user's password. + +### pgsql.user.drop + +Remove a user. Argument is the user name. + +### pgsql.user.exists + +Determine if a user exists. Argument is the user name. diff --git a/help/docs/commands/php.md b/help/docs/commands/php.md new file mode 100644 index 0000000..12c5a6b --- /dev/null +++ b/help/docs/commands/php.md @@ -0,0 +1,9 @@ +# PHP + +Summary: Work with PHP. + +## Available Commands + +### module + +Enable a PHP module. Argument is the module name. diff --git a/help/docs/commands/posix.md b/help/docs/commands/posix.md new file mode 100644 index 0000000..b08419d --- /dev/null +++ b/help/docs/commands/posix.md @@ -0,0 +1,148 @@ +# POSIX + +Summary: Work with common POSIX-compliant commands.. + +## Available Commands + +### append + +Append content to a file. Argument is the file name. + +- `content`: The content to be appended. + +### archive + +Create an archive (tarball). Argument is the target file or directory. + +- `absolute`: Don't strip leading slashes from file names. +- `view`: View the progress. +- `exclude`: Exclude file name patterns. +- `strip`: Strip component paths to the given depth (integer). +- `to`: The path to where the archive will be created. + +### copy + +Copy a file or directory. First argument is the target file/directory. Second argument is the destination. + +- `overwrite`: Overwrite an existing target. +- `recursive`: Copy directories recursively. + +### dir + +Create a directory. Argument is the path. + +- `group`: Set the group to the given group name. +- `mode`: Set the mode on the path. +- `owner`: Set the owner to the given owner name. +- `recursive`: Create the full path even if intermediate directories do not exist. + +### extract + +Extract an archive (tarball). Argument is the path to the archive file. + +- `absolute`: Strip leading slashes from file names. +- `view`: View the progress. +- `exclude`: Exclude file name patterns. +- `strip`: Strip component paths to the given depth (integer). +- `to`: The path to where the archive will be extracted. Defaults to the current working directory. + +### file + +Create a file. Argument is the path. + +- `content`: The content of the file. Otherwise, an empty file is created. +- `group`: Set the group to the given group name. +- `mode`: Set the mode on the path. +- `owner`: Set the owner to the given owner name. + +### link + +Create a symlink. First argument is the target. Second argument is the destination. + +- `force`: Force creation of the link. + +### move + +Move a file or directory. First argument is the target. Second argument is the desitnation. + +### perms + +Set permissions on a file or directory. Argument is the path. + +- `group`: Set the group to the given group name. +- `mode`: Set the mode on the path. +- `owner`: Set the owner to the given owner name. +- `recursive`: Apply permission recursively (directories only). + +### push + +Push (rsync) a path to a remote server. First argument is the local path. Second argument is the remote path. + +- `delete`: Delete existing files/directories. +- `host`: The host name. Required. +- `key_file`: Use the given SSL (private) key. Required. +- `links`: Copy symlinks. +- `exclude`: Exclude patterns from the given (local) file. +- `port`: The TCP port on the host. Default: `22` +- `recursive`: Operate recursively on directories. +- `user`: The user name. Required. + +### remove + +Remove a file or directory. Argument is the path. + +- `force`: Force the removal. +- `recursive`: Remove (directories) rescurisvely. + +### rename + +Rename a file or directory. First argument is the target. Second argument is the destination. + +### replace + +Replace something in a file. First argument is the path. + +- `backup`: Create a backup. +- `delimiiter`: The sed delimiter. Default: `/` +- `find`: The text to be found. Required. +- `sub`: The text to be replaced. Required. + +### scopy + +Copy a file to a remote server. First argument is the local file name. Second argument is the remote destination. + +- `key_file`: The private key file to use for the connection. +- `host`: The host name. Required. +- `port`: The TCP port. Default: `22` +- `user`: The user name. Required. + +### ssl + +Use Let's Encrypt (certbot) to acquire an SSL certificate. Argument is the domain name. + +- `email`: The email address for "agree tos". Default: `webmaster@domain_name` +- `webroot`: The webroot to use. Default: `/var/www/maint/www` + +### sync + +Sync (rsync) local files and directories. First argument is the target. Second argument is the destination. + +- `delete`: Delete existing files/directories. +- `links`: Copy symlinks. +- `exclude`: Exclude patterns from the given (local) file. +- `recursive`: Operate recursively on directories. + +### touch + +Touch a file, whether it exists or not. Argument is the path. + +### wait + +Wait for n number of seconds before continuing. Argument is the number of seconds. + +### write + +Write to a file. Argument is the path. + +- `content`: The content to write to the file. Replaces existing content. + diff --git a/help/docs/commands/python.md b/help/docs/commands/python.md new file mode 100644 index 0000000..2f94e5f --- /dev/null +++ b/help/docs/commands/python.md @@ -0,0 +1,20 @@ +# Python + +Summary: Work with Python. + +## Available Commands + +### pip + +Use the pip command. Argument is the package name. + +- `op`: The operation; `install` (the default), `remove`, or `updgrade`. +- `venv`: The name of the virtual environment to use. + +### pip3 + +Use Python3 pip. See pip above. + +### virtualenv + +Create a python virtual environment. Argument is the environment name. diff --git a/help/docs/config/command-file.md b/help/docs/config/command-file.md new file mode 100644 index 0000000..299ddc0 --- /dev/null +++ b/help/docs/config/command-file.md @@ -0,0 +1,208 @@ +# Command File + +A command file contains the metadata about the commands to be generated. INI and YAML formats are supported. + +In an INI file, each section is a command. With YAML, each top-level list item is a command. + +## The Comment/Description + +With INI files, the section name is the command comment. + +```ini +[this becomes the command comment] +; ... +``` + +With YAML, each command is a list item and the item name becomes the command comment: + +```yaml +- this becomes the command comment: + # ... +``` + +## First Option and Arguments + +The first variable in the section is the command name. It's value contains the required arguments. + +```ini +[restart the postfix service] +restart: postfix +``` + +```yaml +- restart the postfix service: + restart: postfix +``` + +## Formatting Notes + +With both INI and YAML files, the formatting rules are: + +- The first part of each command is the INI section or YAML item and is used as the comment. +- The command name *must* be the *first* option in the section. +- The arguments for the command appear as the value of the first option in the section. Arguments are separated by a + space. +- Arguments that should be treated as a single value should be enclosed in double quotes. +- `yes` and `no` are interpreted as boolean values. `maybe` is interpreted as `None`. +- List values, where required, are separated by commas when appearing in INI files, but are a `[standard, list, of, values]` in a YAML file. + +## Additional Attributes + +Additional variables in the section are generally optional parameters that inform or control how the command should be executed and are sometimes used to add switches to the statement. + +!!! warning + + This is not always the case, so consult the documentation for the command in question, because some parameters that appear after the first line are actually required. + +## Common Attributes + +A number of common options are recognized. Some of these have no bearing on statement generation but may be used for filtering. Others may be optionally included, and a few may only be used programmatically. + +### cd + +The `cd` option sets the directory (path) from which the statement should be executed. It is included by default when the statement is generated, but may be suppressed using `cd=False`. + +```ini +[create a python virtual environment] +virtualenv: python +cd: /path/to/project +``` + +### comment + +The comment comes from the section name (INI) or list name (YAML). It is included by default when the statement is generated, by may be suppressed using `include_comment=False`. + +```ini +[this becomes the comment] +; ... +``` + +```yaml +- this becomes the comment: + # ... +``` + +### env + +The `env` option indicates the target environment (or environments) in which the statement should run. This is not used in command generation, but may be used for filtering. + +```yaml +- set up the database: + pgsql.create: example_com + env: [staging, live] +``` + +This option may be given as `environments`, `environs`, `envs`, or simply `env`. It may be a list or CSV string. + +### prefix + +The `prefix` option is used to define a statement to be executed before the main statement is executed. + +```ini +[migrate the database] +django: migrate +cd: /path/to/project/source +prefix: source ../python/bin/activate +``` + +### register + +`register` defines the name of a variable to which the result of the statement should be saved. It is included by default when the statement is generated, but may be suppressed using `include_register=False`. + +```yaml +- check apache configuration: + apache: test + register: apache_ok +``` + +### shell + +The `shell` defines the shell to be used for command execution. It is not used for statement generation, but may be used programmatically -- for example, with Python's subprocess module. Some commands (such as Django management commands) need a shell to be explicitly defined. + +```ini +[run django checks] +django: check +cd: /path/to/project/source +prefix: source ../python/bin/activate +shell: /bin/bash +``` + +!!! note + + As this option is intended for programmatic use, it would be better to define a default shell for all command execution and use this option only when the default should be overridden. + +### stop + +A `yes` indicates processing should stop if the statement fails to execute with success. It is included by default when the statement is generated, but may be suppressed. Additionally, when [register](#register) is defined, this option will use the result of the command to determine success. This option is also useful for programmatic execution. + +```yaml +- check apache configuration: + apache: test + register: apache_ok + stop: yes +``` + +!!! warning + + Some commands do not provide an zero or non-zero exit code on success or failure. You should verify that the `stop` will actually be used. + +### sudo + +The `sudo` option may be defined as `yes` or a username. This will cause the statement to be generated with sudo. + +```ini +[install apache] +install: apache2 +sudo: yes +``` + +!!! note + + When present, sudo is always generated as part of the statement. For programmatic use, it may be better to control how and when sudo is applied using some other mechanism. If sudo should be used for all statements, it can be passed as a global option. + +### tags + +`tags` is a comma separated list (INI) or list (YAML) of tag names. These may be used for filtering. + +```yaml +- install apache: + install: apache2 + tags: [apache, web] + +- enable wsgi: + apache.enable: mod_wsgi + tags: [apache, web] + +- restart apache: + apache.restart: + tags: [apache, web] + +- run django checks: + django: check + tags: [django, python] + +- apply database migrations: + django: migrate + tags: [django, python] +``` + +## Ad Hoc Options + +Options that are not recognized as common or as part of those specific to a command are still processed by the loader. This makes it possible to define your own options based on the needs of a given implementation. + +For example, suppose you are implementing a deployment system where some commands should run locally, but most should run on the remote server. + +```ini +[run tests to validate the system] +run: make tests +local: yes +stop: yes + +[install apache] +install: apache2 +remote: yes + +; and so on ... +``` + +This will be of no use as a generated script since the generator does not know about `local` and `remote`, but these could be used programmatically to control whether Python subprocess or an SSH client is invoked. diff --git a/help/docs/config/variables.md b/help/docs/config/variables.md new file mode 100644 index 0000000..03480b0 --- /dev/null +++ b/help/docs/config/variables.md @@ -0,0 +1,79 @@ +# Variables File + +A variables file contains variable definitions that may be used as the context for parsing a [command file](command-file.md) *before* the actual commands are generated. + +Unlike a command file, the INI format is the only supported format for a variables file. + +## The Variable Name + +The variable name is defined in the section: + +```ini +[domain_name] +value: example.com +``` + +## The Variable Value + +As seen in the example above, the value is defined by simply adding a variable parameter: + +```ini +[domain_name] +value: example.com + +[database_host] +value: db1.example.com +``` + +!!! note + + This is the minimum definition for all variables. + +## Defining An Environment + +You may define an environment for any given variable that may be used for filtering variables. This is done by adding the environment name to the variable name: + +```ini +[database_host:development] +comment: Local host used in development. +value: localhost + +[database_host:live] +value: db1.example.com +``` + +In this way, variables of the same name may be supported across different deployment environments. + +## Adding Comments + +As demonstrated in the example above, you may comment on a variable by adding a `comment:` attribute to the section. + +## Defining Tags + +Tags may be defined for any variable as a comma separated list. This is useful for filtering. + +```ini +[database_host:development] +value: localhost +tags: database + +[database_host:live] +value: db1.example.com +tags: database + +[domain_name] +value: example.app +tags: application +``` + +## Other Attributes + +Any other variable defined in the section is dynamically available. + +```ini +[domain_name] +value: example.app +other: test +``` + +The value of `other` is `test`. diff --git a/help/docs/index.md b/help/docs/index.md new file mode 100644 index 0000000..0e9f4ad --- /dev/null +++ b/help/docs/index.md @@ -0,0 +1,58 @@ +# Python Script Tease + +## Overview + +Script Tease is a library and command line tool for generating Bash commands programmatically and (especially) using configuration files. + +The primary focus (and limit) is to convert plain text instructions (in INI or YAML format) into valid command line statements for a given platform. It does *not* provide support for executing those statements. + +## Concepts + +### Command Generation + +Script Tease may be used in two (2) ways: + +1. Using the library to programmatically define commands and export them as command line statements. +2. Using the `tease` command to generate commands from a configuration file. See [command file configuration](config/command-file.md). + +This documentation focuses on the second method, but the developer docs may be used in your own implementation. + +### Self-Documenting + +The format of INI and YAML files is self-documenting. The command comment is this section (INI) or start of a list item (YAML). This ensures that all commands have a basic description of their purpose or intent. + +### Snippets + +An *snippet* is simply a tokenized command that may be customized based on the instructions found in a command file. Related snippets are collected into groups and then merged into a larger set that define the capabilities of a specific operating system. + +!!! note + At present, the only fully defined operating systems are for Cent OS and Ubuntu. + +Snippets are defined in Python dictionaries. These include a "canonical" command name as the key and either a string or list which define the command. In both cases, the contents are parsed as Jinja templates. There are various approaches to evaluating a snippet. + +First: The snippet is a simple mapping of command name and command snippet. This is easy. Find the command name in the dictionary, and we have the snippet to be used. For example the `append` command in the `posix` dictionary. + +Second: The snippet is a mapping of command name and a list of snippets to be combined. Find the command name in the dictionary, and iterate through the snippets. For example, many of the commands in the `posix` dictionary takes this form. Command identification is the same as the first condition. + +Third: The command is a mapping to informal sub-commands. Examples include `apache` and `system` in the `ubuntu` dictionary. There are a couple of ways to handle this in the config file: + +- Use the outer command as the command with the inner command as the first (and perhaps only) argument. For example `apache: reload` or `system: upgrade`. +- Use a "dotted path" to find the command. For example: `apache.reload: (implicity True)` or `system.upgrade: (implicitly True)`. Or `apache.enable_site: example.com`. + +The first approach complicates things when detecting actual sub-commands (below). Script Tease supports both of these approaches. + +Fourth: The command also expects a sub-command. In some cases, the sub-command may be implicit, like `pip install`. In other cases, a number of sub-commands may be pre-defined, but ad hoc sub-commands should also be supported as with Django commands. + +Fifth: Builds upon the third and fourth conditions where the commands have lots of options, some of which may be defined at runtime. Postgres and MySQL may use be presented as informal sub-commands, but there are lots of options and challenges in building the final command. Django management commands have a number of standard options, specific options, and must also support ad hoc commands. + +## Terms and Definitions + +command +: When used in Script Tease documentation, this is a command instance which contains the properties and parameters for a command line statement. + +statement +: A specific statement (string) to be executed. A *statement* is contained within a *command*. + +## License + +Python Script Tease is released under the BSD 3 clause license. diff --git a/help/docs/profiles/centos.md b/help/docs/profiles/centos.md new file mode 100644 index 0000000..639355a --- /dev/null +++ b/help/docs/profiles/centos.md @@ -0,0 +1,124 @@ +# CentOS + +## Available Commands + +The `centos` profile incorporates commands from [Django](../commands/django.md), [messages](../commands/messages.md), [MySQL](../commands/mysql.md), [PHP](../commands/php.md), [POSIX](../commands/posix.md), [Postgres](../commands/pgsql.md), and [Python](../commands/python.md). + +### apache + +Work with Apache. + +- `apache.disable_module: module_name` (not supported) +- `apache.disable_site: site_name` (not supported) +- `apache.enable_module: module_name` (not supported) +- `apache.enable_site: site_name` (not supported) +- `apache.reload` +- `apache.restart` +- `apache.start` +- `apache.stop` +- `apache.test` + +### install + +Install a system package. + +```ini +[install apache] +install: apache2 +``` + +### reload + +Reload a service. + +```ini +[reload postgres] +reload: postgresql +``` + +### restart + +Restart a service: + +```ini +[restart postgres] +restart: postgresql +``` + +### run + +Run any shell command. + +```ini +[run a useless listing command] +run: "ls -ls" +``` + +Note that commands with arguments will need to be in quotes. + +### start + +Start a service: + +```ini +[start postgres] +start: postgresql +``` + +### stop + +Stop a service: + +```ini +[stop postgres] +stop: postgresql +``` + +### system + +With with the system. + +- `system.reboot` +- `system.update` +- `system.upgrade` + +### uninstall + +Uninstall a package. + +```ini +[remove libxyz development package] +uninstall: libxyz-dev +``` + +### upgrade + +Upgrade a package. + +```ini +[upgrade libxyz development package] +upgrade: libxyz-dev +``` + +### user + +Create a user: + +- `groups`: A comma separated list of groups to which the user should be added. +- `home`: The user's home directory. +- `login`: The shell to use. +- `system`: Create as a system user. + +```ini +[create the deploy user] +user.add: deploy +groups: www-data +home: /var/www +``` + +Remove a user: + +```ini +[remove bob] +user.remove: bob +``` diff --git a/help/docs/profiles/ubuntu.md b/help/docs/profiles/ubuntu.md new file mode 100644 index 0000000..299313f --- /dev/null +++ b/help/docs/profiles/ubuntu.md @@ -0,0 +1,124 @@ +# Ubuntu + +## Available Commands + +The `ubuntu` profile incorporates commands from [Django](../commands/django.md), [messages](../commands/messages.md), [MySQL](../commands/mysql.md), [PHP](../commands/php.md), [POSIX](../commands/posix.md), [Postgres](../commands/pgsql.md), and [Python](../commands/python.md). + +### apache + +Work with Apache. + +- `apache.disable_module: module_name` +- `apache.disable_site: site_name` +- `apache.enable_module: module_name` +- `apache.enable_site: site_name` +- `apache.reload` +- `apache.restart` +- `apache.start` +- `apache.stop` +- `apache.test` + +### install + +Install a system package. + +```ini +[install apache] +install: apache2 +``` + +### reload + +Reload a service. + +```ini +[reload postgres] +reload: postgresql +``` + +### restart + +Restart a service: + +```ini +[restart postgres] +restart: postgresql +``` + +### run + +Run any shell command. + +```ini +[run a useless listing command] +run: "ls -ls" +``` + +Note that commands with arguments will need to be in quotes. + +### start + +Start a service: + +```ini +[start postgres] +start: postgresql +``` + +### stop + +Stop a service: + +```ini +[stop postgres] +stop: postgresql +``` + +### system + +With with the system. + +- `system.reboot` +- `system.update` +- `system.upgrade` + +### uninstall + +Uninstall a package. + +```ini +[remove libxyz development package] +uninstall: libxyz-dev +``` + +### upgrade + +Upgrade a package. + +```ini +[upgrade libxyz development package] +upgrade: libxyz-dev +``` + +### user + +Create a user: + +- `groups`: A comma separated list of groups to which the user should be added. +- `home`: The user's home directory. +- `login`: The shell to use. +- `system`: Create as a system user. + +```ini +[create the deploy user] +user.add: deploy +groups: www-data +home: /var/www +``` + +Remove a user: + +```ini +[remove bob] +user.remove: bob +``` diff --git a/help/mkdocs.yml b/help/mkdocs.yml new file mode 100644 index 0000000..3a906e2 --- /dev/null +++ b/help/mkdocs.yml @@ -0,0 +1,26 @@ +site_name: Script Tease +copyright: Copyright © Pleasant Tents, LLC. All rights reserved. +markdown_extensions: + - toc: + permalink: True + - admonition + - attr_list + - def_list +nav: + - Home: index.md + - Configuration: + - Command File: config/command-file.md + - Variables: config/variables.md + - Commands: + - Django: commands/django.md + - Messages: commands/messages.md + - MySQL: commands/mysql.md + - PHP: commands/php.md + - Postgres: commands/pgsql.md + - POSIX: commands/posix.md + - Python: commands/python.md + - Profiles: + - Ubuntu: profiles/ubuntu.md +# - Developer Reference: /developers/ +repo_name: GitLab +repo_url: https://git.sixgunsoftware.com/python-scripttease diff --git a/scripttease/lib/snippets/mysql.py b/scripttease/lib/snippets/mysql.py index c841dfe..eda4fd1 100644 --- a/scripttease/lib/snippets/mysql.py +++ b/scripttease/lib/snippets/mysql.py @@ -54,7 +54,7 @@ mysql = { '{% if admin_pass %}--password="{{ admin_pass }}"{% endif %}', '--host={{ host|default("localhost") }}', '--port={{ port|default("3306") }}', - '--execute="GRANT {{ args[0] }} ON {{ database }}.* TO \'{{ user }}\'@\'{{ host|default("localhost") }}\'"' + '--execute="GRANT {{ args[0] }} ON {{ database|default("default") }}.* TO \'{{ user }}\'@\'{{ host|default("localhost") }}\'"' ], 'user': { 'create': [ diff --git a/scripttease/lib/snippets/pgsql.py b/scripttease/lib/snippets/pgsql.py index d5ce2a7..7da25e2 100644 --- a/scripttease/lib/snippets/pgsql.py +++ b/scripttease/lib/snippets/pgsql.py @@ -57,7 +57,7 @@ pgsql = { '--host={{ host|default("localhost") }}', '--port={{ port|default("5432") }}', "--column-inserts", - '--file={{ file_name|default("dump.sql") }}', + '--file={{ path|default("dump.sql") }}', "{{ args[0] }}" ], 'exec': [ diff --git a/scripttease/lib/snippets/ubuntu.py b/scripttease/lib/snippets/ubuntu.py index e2a65cc..9679320 100644 --- a/scripttease/lib/snippets/ubuntu.py +++ b/scripttease/lib/snippets/ubuntu.py @@ -1,9 +1,9 @@ ubuntu = { 'apache': { - 'disable': '{% if args[0].startswith("mod_") %}a2dismod{% else %}a2dissite{% endif %} {{ args[0] }}', - 'disable_module': "a2dissite {{ args[0] }}", - 'disable_site': "a2dismod {{ args[0] }}", - 'enable': '{% if args[0].startswith("mod_") %}a2enmod{% else %}a2ensite{% endif %} {{ args[0] }}', + # 'disable': '{% if args[0].startswith("mod_") %}a2dismod{% else %}a2dissite{% endif %} {{ args[0] }}', + 'disable_module': "a2dismod {{ args[0] }}", + 'disable_site': "a2dissite {{ args[0] }}", + # 'enable': '{% if args[0].startswith("mod_") %}a2enmod{% else %}a2ensite{% endif %} {{ args[0] }}', 'enable_module': "a2enmod {{ args[0] }}", 'enable_site': "a2ensite {{ args[0] }}", 'reload': "service apache2 reload",