├── test ├── yaml │ ├── 1 │ │ ├── output_X4.yaml │ │ ├── output_X2.yaml │ │ ├── output_X3.yaml │ │ ├── output_X1.yaml │ │ └── input.yaml │ ├── 2 │ │ ├── output_X1.yaml │ │ ├── output_X2.yaml │ │ ├── output_X3.yaml │ │ ├── input.yaml │ │ └── output_X4.yaml │ ├── 3 │ │ ├── output_X4.yaml │ │ ├── sub │ │ │ └── b.yaml │ │ ├── a.yaml │ │ ├── output_X2.yaml │ │ ├── output_X1.yaml │ │ ├── output_X3.yaml │ │ └── input.yaml │ ├── 4 │ │ ├── output_X4.yaml │ │ ├── output_X2.yaml │ │ ├── output_X3.yaml │ │ ├── output_X1.yaml │ │ └── input.yaml │ ├── 5 │ │ ├── output_X4.yaml │ │ ├── output_X3.yaml │ │ ├── output_X2.yaml │ │ ├── output_X1.yaml │ │ └── input.yaml │ ├── 6 │ │ ├── output_X4.yaml │ │ ├── output_X2.yaml │ │ ├── input.yaml │ │ ├── output_X3.yaml │ │ └── output_X1.yaml │ ├── 99 │ │ ├── output_X4.yaml │ │ ├── output_X2.yaml │ │ ├── output_X1.yaml │ │ ├── output_X3.yaml │ │ ├── a.yaml │ │ └── input.yaml │ ├── 100 │ │ ├── output_X4.yaml │ │ ├── output_X3.yaml │ │ ├── output_X1.yaml │ │ ├── output_X2.yaml │ │ └── input.yaml │ ├── README │ ├── test.yaml │ └── test.sh ├── exit_status_cases │ ├── shebang_linux.sh │ ├── shebang_bsd.sh │ ├── prompt.yaml │ ├── fail_pp_assert.yaml │ ├── fail_pp_clone_malformed.yaml │ ├── fail_pp_include_file.yaml │ ├── fail_pp_include_module.yaml │ ├── fail_pp_clone.yaml │ ├── fail_pp_include_file_on_included.yaml │ └── test.yaml ├── function │ ├── README │ ├── FILTER │ │ └── test_filter.yaml │ ├── copy │ │ ├── test_copy.yaml │ │ └── test_copy.bash │ ├── helpusage │ │ ├── test_helpusage.yaml │ │ └── test_helpusage.bash │ ├── quicksort │ │ ├── test_quicksort.yaml │ │ └── test_quicksort.bash │ ├── helpversion │ │ ├── test_helpversion.yaml │ │ └── test_helpversion.bash │ ├── helpnode │ │ ├── test_helpnode.yaml │ │ └── test_helpnode.bash │ ├── pp_yaml │ │ ├── bad_clone.yml │ │ ├── bad_assert.yml │ │ ├── bad_include.yml │ │ ├── good_config.yml │ │ └── test_pp_yaml.yaml │ ├── parse_yaml │ │ ├── test_parse_yaml.yaml │ │ └── test_parse_yaml.bash │ ├── yaml_get_row │ │ ├── test_yaml_get_row.yaml │ │ └── test_yaml_get_row.bash │ ├── PRINT │ │ ├── test_PRINT.yaml │ │ └── test_PRINT.bash │ ├── sort_pad │ │ ├── test_sort_pad.yaml │ │ └── test_sort_pad.bash │ ├── source │ │ ├── test_source.yaml │ │ └── test_source.bash │ ├── source_added │ │ └── test_source_added.yaml │ ├── source_file │ │ └── test_source_file.yaml │ └── test_spacefile.yml ├── core │ ├── README │ ├── validate_basedir │ │ ├── test_validate_basedir.yaml │ │ └── test_validate_basedir.bash │ ├── validate_version │ │ ├── test_validate_version.yaml │ │ └── test_validate_version.bash │ └── read_program_name │ │ ├── test_read_program_name.yaml │ │ ├── test_read_program_name.bash │ │ └── test_read_program_name_source.bash ├── test_core.sh ├── test_yaml.sh ├── test_function.sh ├── README.md ├── Spacefile.yaml ├── build │ ├── check_base_libraries.sh │ └── check_base_binaries.sh ├── test_build.sh ├── test_shebang_bsd.sh ├── test_shebang_linux.sh └── Spacefile.bash ├── .gitignore ├── manuals ├── README └── versions.md ├── completion └── README ├── gui └── README ├── tools ├── README ├── bsdvm │ ├── README │ ├── 01_bsdvm_create.sh │ ├── 02_bsdvm_run.sh │ └── 00_bsdvm_fetch.sh ├── packer │ ├── README.md │ └── Spacefile.yaml ├── installer │ ├── README.md │ └── install.sh ├── manpage_exporter │ ├── README.md │ ├── Spacefile.yaml │ └── Spacefile.sh ├── static_analysis │ ├── README.md │ └── Spacefile.yaml └── spacedoc │ ├── README.md │ └── Spacefile.yaml ├── doc ├── index.md ├── space-modules │ ├── index.md │ ├── modules-advanced-topics.md │ ├── modules-versioning.md │ ├── what-are-space-modules.md │ ├── modules-best-practices.md │ ├── why-space-modules.md │ └── running-a-space-module.md ├── contributing │ └── index.md ├── getting-help │ └── index.md ├── installing-and-running-your-first-space-command │ ├── verifying-installation.md │ ├── running-your-first-space-command.md │ ├── installing-current-version-from-source-control-repository.md │ ├── customizing-installation-parameters.md │ ├── installing-latest-stable-version-from-spacesh-site.md │ ├── index.md │ └── installing-from-latest-tarball.md ├── references │ └── index.md ├── why-space │ ├── index.md │ └── benefits-and-advantages-of-using-space.md ├── advanced-space-sh-configuration │ └── index.md ├── troubleshooting │ └── index.md ├── glossary │ └── index.md ├── how-space-works │ └── index.md └── introduction-to-space │ └── index.md ├── .gitlab └── issue_templates │ ├── Feature-proposal.md │ └── Bug.md ├── CONTRIBUTING.md ├── Spacefile.yaml ├── bump_version.sh └── README.md /test/yaml/1/output_X4.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/yaml/100/output_X4.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/yaml/3/output_X4.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/yaml/4/output_X4.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/yaml/5/output_X4.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/yaml/6/output_X4.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/yaml/99/output_X4.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **.*.cache 2 | test-*-*.txt 3 | release/* 4 | space.1 5 | hugo 6 | -------------------------------------------------------------------------------- /test/exit_status_cases/shebang_linux.sh: -------------------------------------------------------------------------------- 1 | #!space -m utils /waitforfile/ -- 1 2 | -------------------------------------------------------------------------------- /test/exit_status_cases/shebang_bsd.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env space ! -m utils /waitforfile/ -- 1 ! 2 | -------------------------------------------------------------------------------- /manuals/README: -------------------------------------------------------------------------------- 1 | This directory contains Markdown documentation files covering various aspects of Space.sh. 2 | 3 | -------------------------------------------------------------------------------- /completion/README: -------------------------------------------------------------------------------- 1 | This directory contains files needed to set up integration of Space with shell auto completion. 2 | 3 | -------------------------------------------------------------------------------- /gui/README: -------------------------------------------------------------------------------- 1 | This directory contains Space GUI specific programs. 2 | Note: this directory will be deprecated soon. 3 | 4 | -------------------------------------------------------------------------------- /tools/README: -------------------------------------------------------------------------------- 1 | This directory contains all individual tools that help ease and enhance the Space development process. 2 | 3 | -------------------------------------------------------------------------------- /tools/bsdvm/README: -------------------------------------------------------------------------------- 1 | This directory contains a set of scripts to help setting up a disposable ssh-enabled BSD Virtual Machine for testing purposes. 2 | 3 | -------------------------------------------------------------------------------- /test/function/README: -------------------------------------------------------------------------------- 1 | This directory contains unit tests for space functions. 2 | 3 | A single test can be run with the following command: 4 | space -f /test_name.yaml /tests/0/ -a 5 | 6 | -------------------------------------------------------------------------------- /test/yaml/README: -------------------------------------------------------------------------------- 1 | This directory contains integration tests for space YAML loading, parsing and processing. 2 | 3 | A single test can be run with the following command: 4 | space -f /test_name.yaml /tests/0/ -a 5 | -------------------------------------------------------------------------------- /test/yaml/5/output_X3.yaml: -------------------------------------------------------------------------------- 1 | test_gt: | 2 | Now these lines will be joinedbut with no spaces inbetween!But line will end with \n 3 | test_gt_dash: And these lineswill be joinedalso with no spaces inbetween!But line will not end with \n thanks to the '-'. 4 | -------------------------------------------------------------------------------- /test/core/README: -------------------------------------------------------------------------------- 1 | This directory contains unit tests for core program functionalities such as variable testing, OS-specific and shell related behaviours. 2 | 3 | A single test can be run with the following command: 4 | space -f /test_name.yaml /tests/0/ -a 5 | -------------------------------------------------------------------------------- /test/yaml/5/output_X2.yaml: -------------------------------------------------------------------------------- 1 | _sg1_test0x5fgt=Now these lines will be joinedbut with no spaces inbetween!But line will end with \n 2 | 3 | _sg1_test0x5fgt0x5fdash=And these lineswill be joinedalso with no spaces inbetween!But line will not end with \n thanks to the '-'. 4 | -------------------------------------------------------------------------------- /test/exit_status_cases/prompt.yaml: -------------------------------------------------------------------------------- 1 | @prompt: userinput "Enter some input" 2 | @prompt:- userinput "Never called" 3 | 4 | env: 5 | 6 | print_input: 7 | @userinput: "[prompt.yaml] overwriting prompt answer... " 8 | _env: 9 | - RUN: printf @{userinput} 10 | 11 | -------------------------------------------------------------------------------- /test/yaml/99/output_X2.yaml: -------------------------------------------------------------------------------- 1 | _sg1_list_0_A_info=A 2 | _sg1_list_1_B_info=B 3 | _sg1_SUM_0_A_info=A 4 | _sg1_SUM_1_B_info=B 5 | _sg1_nodes_A_info=This is A 6 | _sg1_nodes_B_info=This is B 7 | _sg1_nodes2_A_info=This is A 8 | _sg1_nodes2_B_info=This is B 9 | _sg1_nodes3= 10 | -------------------------------------------------------------------------------- /test/yaml/4/output_X2.yaml: -------------------------------------------------------------------------------- 1 | _sg1_test0x5fdash0=Multi line 2 | string, 3 | with new lines kept. 4 | Thanks to '-' this line does not end with \n 5 | _sg1_test0x5fdash1=These lines will be one one long line, where each line will be space separated. But the single line will not have \n thanks to '-' 6 | -------------------------------------------------------------------------------- /test/yaml/4/output_X3.yaml: -------------------------------------------------------------------------------- 1 | test_dash0: |- 2 | Multi line 3 | string, 4 | with new lines kept. 5 | Thanks to '-' this line does not end with \n 6 | test_dash1: These lines will be one one long line, where each line will be space separated. But the single line will not have \n thanks to '-' 7 | -------------------------------------------------------------------------------- /doc/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: The Space Tool 3 | next: /introduction-to-space/ 4 | next_title: "An introduction to Space" 5 | giturl: github.com/space-sh/space 6 | editurl: /edit/master/doc/index.md 7 | weight: 1 8 | --- 9 | # The Space Tool 10 | 11 | Here you will find the documentation for the Space.sh. 12 | -------------------------------------------------------------------------------- /test/yaml/100/output_X3.yaml: -------------------------------------------------------------------------------- 1 | test_node_name: 2 | 2node_name: 0987654321 3 | NoDE_1NAME: TeSt 4 | _env: 5 | title: Test node names 6 | node3_N4M3: 7 | _s_b_u_: "123456789042!" 8 | _sub_: "TeSt" 9 | s_b_u: 10 | 1234: | 11 | Multiline just for kicks 12 | -------------------------------------------------------------------------------- /.gitlab/issue_templates/Feature-proposal.md: -------------------------------------------------------------------------------- 1 | # Feature proposal 2 | 3 | (What is the problem that you would like to be addressed?) 4 | (What would be the main use case?) 5 | (If inclined, describe what would be the expected inputs and outputs.) 6 | 7 | ## Additional information 8 | (Any extra files? Consider adding attachments.) 9 | 10 | -------------------------------------------------------------------------------- /test/yaml/1/output_X2.yaml: -------------------------------------------------------------------------------- 1 | _sg1_First_sub1=Hello 2 | _sg1_First_sub2=World 3 | _sg1_First_SUB3_sub31="HELLO" 4 | _sg1_First_SUB3_sub32="WORLD!" 5 | _sg1_First_SUB3_sub4_sub341=This is a 6 | 7 | multiline! 8 | 9 | _sg1_First_SUB3_sub4_sub342=This is a collapsed multiline without newlines. 10 | 11 | _sg1_First_0x5fenv_title=First test 12 | -------------------------------------------------------------------------------- /test/yaml/100/output_X1.yaml: -------------------------------------------------------------------------------- 1 | test_node_name: 2 | NoDE_1NAME: TeSt 3 | 2node_name: 0987654321 4 | node3_N4M3: 5 | _sub_: "TeSt" 6 | _s_b_u_: "123456789042!" 7 | s_b_u: 8 | 1234: > 9 | Multiline just 10 | for kicks 11 | _env: 12 | title: Test node names 13 | -------------------------------------------------------------------------------- /test/yaml/5/output_X1.yaml: -------------------------------------------------------------------------------- 1 | test_gt: !nospace > 2 | Now these lines 3 | will be joined 4 | but with no spaces inbetween! 5 | But line will end with \n 6 | test_gt_dash: !nospace >- 7 | And these lines 8 | will be joined 9 | also with no spaces inbetween! 10 | But line will not end with \n thanks to the '-'. 11 | -------------------------------------------------------------------------------- /test/yaml/4/output_X1.yaml: -------------------------------------------------------------------------------- 1 | test_dash0: |- 2 | Multi line 3 | string, 4 | with new lines kept. 5 | Thanks to '-' this line does not end with \n 6 | test_dash1: >- 7 | These lines 8 | will be one 9 | one long line, 10 | where each line will be 11 | space separated. But the single line will not have \n thanks to '-' 12 | -------------------------------------------------------------------------------- /tools/packer/README.md: -------------------------------------------------------------------------------- 1 | Space Packer module 2 | ------------------- 3 | 4 | ## Configuration 5 | Files can be specified by editing the `RELEASE_FILES` variable defined in the module _YAML_ file. 6 | 7 | ## Running 8 | Expected to be run from the project root directory. 9 | 10 | ``` 11 | $ ./space -f ./tools/packer/Spacefile.yaml /make/ 12 | ``` 13 | 14 | -------------------------------------------------------------------------------- /test/yaml/99/output_X1.yaml: -------------------------------------------------------------------------------- 1 | list: 2 | - A: 3 | info: A 4 | - B: 5 | info: B 6 | SUM: 7 | - A: 8 | info: A 9 | - B: 10 | info: B 11 | nodes: 12 | A: 13 | info: This is A 14 | B: 15 | info: This is B 16 | nodes2: 17 | A: 18 | info: This is A 19 | B: 20 | info: This is B 21 | nodes3: 22 | -------------------------------------------------------------------------------- /test/yaml/1/output_X3.yaml: -------------------------------------------------------------------------------- 1 | First: 2 | SUB3: 3 | sub4: 4 | sub341: | 5 | This is a 6 | 7 | multiline! 8 | sub342: | 9 | This is a collapsed multiline without newlines. 10 | sub31: "HELLO" 11 | sub32: "WORLD!" 12 | _env: 13 | title: First test 14 | sub1: Hello 15 | sub2: World 16 | -------------------------------------------------------------------------------- /test/yaml/100/output_X2.yaml: -------------------------------------------------------------------------------- 1 | _sg1_test0x5fnode0x5fname_NoDE0x5f1NAME=TeSt 2 | _sg1_test0x5fnode0x5fname_2node0x5fname=0987654321 3 | _sg1_test0x5fnode0x5fname_node30x5fN4M3_0x5fsub0x5f="TeSt" 4 | _sg1_test0x5fnode0x5fname_node30x5fN4M3_0x5fs0x5fb0x5fu0x5f="123456789042!" 5 | _sg1_test0x5fnode0x5fname_node30x5fN4M3_s0x5fb0x5fu_1234=Multiline just for kicks 6 | 7 | _sg1_test0x5fnode0x5fname_0x5fenv_title=Test node names 8 | -------------------------------------------------------------------------------- /doc/space-modules/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: /installing-and-running-your-first-space-command/ 3 | prev_title: "Installing and running your first Space command" 4 | next: ./why-space-modules/ 5 | next_title: "Why Space Modules" 6 | title: Space Modules 7 | weight: 500 8 | giturl: github.com/space-sh/space 9 | editurl: /edit/master/doc/space-modules/index.md 10 | icon: "5. " 11 | --- 12 | 13 | # Space Modules 14 | -------------------------------------------------------------------------------- /test/yaml/1/output_X1.yaml: -------------------------------------------------------------------------------- 1 | First: 2 | sub1: Hello 3 | sub2: World 4 | SUB3: 5 | sub31: "HELLO" 6 | sub32: "WORLD!" 7 | sub4: 8 | sub341: | 9 | This is a 10 | 11 | multiline! 12 | sub342: > 13 | This is a collapsed multiline without 14 | newlines. 15 | _env: 16 | title: First test 17 | -------------------------------------------------------------------------------- /doc/contributing/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: /getting-help/ 3 | prev_title: "Getting help" 4 | next: /troubleshooting/ 5 | next_title: "Troubleshooting" 6 | title: Contributing 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/contributing/index.md 9 | weight: 1200 10 | icon: "11. " 11 | --- 12 | 13 | # Contributing 14 | 15 | Contributions are welcome via [GiHub pull requests](https://github.com/space-sh/space/pulls). 16 | -------------------------------------------------------------------------------- /test/yaml/99/output_X3.yaml: -------------------------------------------------------------------------------- 1 | SUM: 2 | 0: 3 | A: 4 | info: A 5 | 1: 6 | B: 7 | info: B 8 | list: 9 | 0: 10 | A: 11 | info: A 12 | 1: 13 | B: 14 | info: B 15 | nodes: 16 | A: 17 | info: This is A 18 | B: 19 | info: This is B 20 | nodes2: 21 | A: 22 | info: This is A 23 | B: 24 | info: This is B 25 | nodes3: 26 | -------------------------------------------------------------------------------- /doc/getting-help/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: /references/ 3 | prev_title: "References" 4 | next: /contributing/ 5 | next_title: "Contributing" 6 | title: Getting help 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/getting-help/index.md 9 | weight: 1100 10 | icon: "10. " 11 | --- 12 | 13 | # Getting help 14 | 15 | For issues and feature requests, please refer to the project page [GitHub Issues](https://github.com/space-sh/space/issues). 16 | Visit https://space.sh for up to date news, information and tutorials. 17 | -------------------------------------------------------------------------------- /.gitlab/issue_templates/Bug.md: -------------------------------------------------------------------------------- 1 | # Bug report 2 | (What is the issue?) 3 | (What should have happened instead?) 4 | (What was the expected output?) 5 | 6 | ## Steps to reproduce 7 | (Add detailed steps on how to reproduce the problem) 8 | (Paste here the command line call and output, if possible. Add it between \`\`\` to format the output and make it easier to read) 9 | 10 | ## Additional information 11 | (Paste here the contents of `space -V`. Please use \`\`\` to format the output) 12 | (Paste here the contents of `space -m os /info`. Please use \`\`\` to format the output) 13 | (Any extra files? Consider adding attachments.) 14 | 15 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Code contributions are welcome via [GitHub pull requests](https://github.com/space-sh/space/pulls). 4 | 5 | In order to submit patches, create a fork of Space and apply your changes to a new branch. After the new bug fix or feature is ready, go to the _Pull Request_ tab in your GitHub fork and create a new pull request. In the _Pull Request_ page, choose your forked project's branch as the source and the _space-sh/space_ project as the destination and then submit the pull request. 6 | 7 | For issues and feature requests, please refer to the project [GitHub Issues](https://github.com/space-sh/space/issues) page. 8 | -------------------------------------------------------------------------------- /doc/installing-and-running-your-first-space-command/verifying-installation.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: ../customizing-installation-parameters/ 3 | prev_title: "Customizing installation parameters" 4 | next: ../running-your-first-space-command/ 5 | next_title: "Running your first Space command" 6 | title: Verifying installation 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/installing-and-running-your-first-space-command/verifying-installation.md 9 | weight: 405 10 | --- 11 | 12 | # Verifying installation 13 | 14 | In order to double check the installation has succeeded, do: 15 | 16 | ```sh 17 | which space 18 | space -V 19 | ``` 20 | 21 | Help can be requested with the `-H` command at the end of any command. 22 | -------------------------------------------------------------------------------- /manuals/versions.md: -------------------------------------------------------------------------------- 1 | # Versions 2 | 3 | New versions are set with the `bump_version.sh` script. 4 | 5 | ## Stable 6 | All released versions are marked as _Git tags_ on the [source repository](https://github.com/space-sh/space/tags). Those are referred to as _stable_ versions, which are the ones packaged and distributed on [space.sh](https://space.sh) website. For instructions, check the _Installing latest stable version from Space.sh site_ section in the [official documentation](https://space.sh). 7 | 8 | ## Current 9 | The _master_ branch on the repository is expected to regularly change. For this reason, _master_ branch is referred to as the _current_ version. Relevant changes can be followed by reading the [CHANGELOG](CHANGELOG.md). 10 | 11 | -------------------------------------------------------------------------------- /test/yaml/3/sub/b.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | third: 20 | c: 21 | -------------------------------------------------------------------------------- /test/yaml/99/a.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | A: 21 | info: This is A 22 | B: 23 | info: This is B 24 | ... 25 | -------------------------------------------------------------------------------- /tools/installer/README.md: -------------------------------------------------------------------------------- 1 | Space Installer 2 | --------------- 3 | 4 | Please note that this tool is intended to be used as base template installer for a given version release. All the steps required to build an installer script based on this template can be found on the _Configuration_ section below. 5 | 6 | ## Configuration 7 | 8 | 1. Package version must be configured according to release version; 9 | 2. Package hashes must be correctly specified according to _Space Packer_ generated _.sha_ and _.sha256_ information; 10 | 3. Download base URL must be correctly defined for curl download to work. 11 | 12 | ## Running 13 | 14 | It is possible to run the _install.sh_ script from the _./release/_ folder, after running the _Space Packer_ tool and having generated all the necessary release files. 15 | 16 | -------------------------------------------------------------------------------- /test/yaml/test.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _PARSE_YAML 27 | 28 | -------------------------------------------------------------------------------- /test/function/FILTER/test_filter.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _TEST_FILTER 27 | -------------------------------------------------------------------------------- /test/function/copy/test_copy.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _TEST_COPY 27 | 28 | -------------------------------------------------------------------------------- /test/function/helpusage/test_helpusage.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _TEST_HELPUSAGE 27 | 28 | -------------------------------------------------------------------------------- /test/function/quicksort/test_quicksort.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _TEST_QUICKSORT 27 | 28 | -------------------------------------------------------------------------------- /test/function/helpversion/test_helpversion.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _TEST_HELPVERSION 27 | 28 | -------------------------------------------------------------------------------- /test/core/validate_basedir/test_validate_basedir.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _VALIDATE_BASEDIR 27 | 28 | -------------------------------------------------------------------------------- /test/core/validate_version/test_validate_version.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _VALIDATE_VERSION 27 | 28 | -------------------------------------------------------------------------------- /test/yaml/3/a.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | first: 20 | a: 21 | second: 22 | aa: 23 | all: 24 | @include: |/second/ 25 | @include: |/first/ 26 | @include: sub/b.yaml|/third/ 27 | -------------------------------------------------------------------------------- /test/exit_status_cases/fail_pp_assert.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | @assert: nonempty @{non_existent_value} 20 | 21 | env: 22 | 23 | source_failure: 24 | - RUN: _SOME_NON_EXISTENT_FUNCTION 25 | 26 | -------------------------------------------------------------------------------- /doc/references/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: /glossary/ 3 | prev_title: "Glossary" 4 | next: /getting-help/ 5 | next_title: "Getting help" 6 | title: References 7 | weight: 1000 8 | giturl: github.com/space-sh/space 9 | editurl: /edit/master/doc/references/index.md 10 | icon: "9. " 11 | --- 12 | 13 | # References 14 | 15 | 1. Raymond, Eric Steven. 2003. The Art of Unix Programming. http://www.catb.org/esr/writings/taoup/html/ 16 | 17 | 2. POSIX. 2016. IEEE Std 1003.1-2008: Shell command language. http://pubs.opengroup.org/onlinepubs/9699919799/idx/shell.html 18 | 19 | 3. Free Software Foundation. 2016. Bash Reference Manual. http://www.gnu.org/software/bash/manual/bash.html 20 | 21 | 4. Greg's Wiki. 2015. BashGuide. http://mywiki.wooledge.org/FullBashGuide 22 | 23 | 5. Cooper, Mendel. 2014. Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting. http://www.tldp.org/LDP/abs/html/abs-guide.html 24 | -------------------------------------------------------------------------------- /doc/why-space/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Why Space 3 | prev: /introduction-to-space/ 4 | prev_title: "An introduction to Space" 5 | next: ./benefits-and-advantages-of-using-space/ 6 | next_title: "Benefits and advantages of using Space" 7 | weight: 200 8 | giturl: github.com/space-sh/space 9 | editurl: /edit/master/doc/why-space/index.md 10 | icon: "2. " 11 | --- 12 | 13 | # Why Space 14 | 15 | _Space_ has been created for solving automation, reproducibility and large scale orchestration problems in a non-intrusive way by leveraging core utilities present in _UNIX-like_ operating systems. _Space_ provides a single-file program with minimal size footprint which only depends on _Bash_ for running. 16 | 17 | The idea behind _Space_ is to offer a base set of operations and structures for organizing and describing command line operations and rules that can be easily reused and shared. Those are referred to as _Space_ modules. 18 | -------------------------------------------------------------------------------- /test/core/read_program_name/test_read_program_name.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | @source: "@{DIR}/test_read_program_name_source.bash" 20 | 21 | _env: 22 | 23 | tests: 24 | - 25 | - 26 | _env: 27 | - RUN: _READ_PROGRAM_NAME 28 | 29 | -------------------------------------------------------------------------------- /test/core/read_program_name/test_read_program_name.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _READ_PROGRAM_NAME() 20 | { 21 | SPACE_DEP="PRINT _READ_PROGRAM_NAME_SOURCE" 22 | SPACE_ENV="_SPACEBIN" 23 | 24 | _READ_PROGRAM_NAME_SOURCE "${_SPACEBIN}" 25 | } 26 | 27 | -------------------------------------------------------------------------------- /test/test_core.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2016-2017 Blockie AB 4 | # 5 | # This file is part of Space. 6 | # 7 | # Space is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation version 3 of the License. 10 | # 11 | # Space is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Space. If not, see . 18 | # 19 | 20 | #====================== 21 | # Test Space core functionality 22 | # 23 | # 24 | #====================== 25 | set -o nounset 26 | 27 | ./space -f ./test/Spacefile.yaml /run/ -- "core" 28 | 29 | -------------------------------------------------------------------------------- /test/test_yaml.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2016-2017 Blockie AB 4 | # 5 | # This file is part of Space. 6 | # 7 | # Space is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation version 3 of the License. 10 | # 11 | # Space is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Space. If not, see . 18 | # 19 | 20 | #====================== 21 | # Test Space core functionality 22 | # 23 | # 24 | #====================== 25 | set -o nounset 26 | 27 | ./space -f ./test/Spacefile.yaml /run/ -- "yaml" 28 | 29 | -------------------------------------------------------------------------------- /tools/manpage_exporter/README.md: -------------------------------------------------------------------------------- 1 | # Man page exporter 2 | 3 | This Space.sh module exports Markdown documentation to roff man pages and HTML. 4 | 5 | ## Dependencies 6 | Depends on `ronn` which can be downloaded from: [https://github.com/rtomayko/ronn/blob/master/INSTALLING](https://github.com/rtomayko/ronn/blob/master/INSTALLING). 7 | 8 | ## Usage 9 | 10 | Export man page for some `input_file`: 11 | ``` 12 | space -f ./tools/manpage_exporter/Spacefile.yaml /man/ -- 13 | ``` 14 | 15 | Export HTML documentation page for some `input_file`: 16 | ``` 17 | space -f ./tools/manpage_exporter/Spacefile.yaml /html/ -- 18 | ``` 19 | 20 | ## Known issues 21 | 22 | ### "`split': invalid byte sequence in US-ASCII (ArgumentError)" 23 | 24 | `ronn` might throw an error due to missing locale settings. Make sure UTF-8 encoding is set: 25 | ``` 26 | $ export LC_ALL=en_US.UTF-8 27 | $ export LANG=en_US.UTF-8 28 | ``` 29 | 30 | -------------------------------------------------------------------------------- /test/exit_status_cases/fail_pp_clone_malformed.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | @assert: nonempty $HOME 20 | @debug: HOME is ${HOME} 21 | @cache: 1 22 | @clone: Spacefile.yaml 23 | 24 | env: 25 | 26 | source_failure: 27 | - RUN: _SOME_NON_EXISTENT_FUNCTION 28 | 29 | -------------------------------------------------------------------------------- /test/exit_status_cases/fail_pp_include_file.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | @assert: nonempty $HOME 20 | @debug: HOME is ${HOME} 21 | @cache: 1 22 | @include: NonExistentFile.yaml 23 | 24 | env: 25 | 26 | source_failure: 27 | - RUN: _SOME_NON_EXISTENT_FUNCTION 28 | 29 | -------------------------------------------------------------------------------- /test/exit_status_cases/fail_pp_include_module.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | @assert: nonempty $HOME 20 | @debug: HOME is ${HOME} 21 | @cache: 1 22 | @include: username/module 23 | 24 | env: 25 | 26 | source_failure: 27 | - RUN: _SOME_NON_EXISTENT_FUNCTION 28 | 29 | -------------------------------------------------------------------------------- /test/test_function.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2016-2017 Blockie AB 4 | # 5 | # This file is part of Space. 6 | # 7 | # Space is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation version 3 of the License. 10 | # 11 | # Space is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Space. If not, see . 18 | # 19 | 20 | #====================== 21 | # Test Space functions (unit tests) 22 | # 23 | # 24 | #====================== 25 | set -o nounset 26 | 27 | ./space -f ./test/Spacefile.yaml /run/ -- "function" 28 | 29 | -------------------------------------------------------------------------------- /test/exit_status_cases/fail_pp_clone.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | @assert: nonempty $HOME 20 | @debug: HOME is ${HOME} 21 | @cache: 1 22 | @clone: test/cases/wrongrepo/Spacefile.yaml 23 | 24 | env: 25 | 26 | source_failure: 27 | - RUN: _SOME_NON_EXISTENT_FUNCTION 28 | 29 | -------------------------------------------------------------------------------- /test/function/helpnode/test_helpnode.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _TEST_HELPNODE_EMPTY_STRING_PARAMETER 27 | - 28 | _env: 29 | - RUN: _TEST_HELPNODE_WITH_PARAMETER 30 | 31 | -------------------------------------------------------------------------------- /test/exit_status_cases/fail_pp_include_file_on_included.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | @assert: nonempty $HOME 20 | @debug: HOME is ${HOME} 21 | @cache: 1 22 | @include: fail_pp_file_include.yaml 23 | 24 | env: 25 | 26 | source_failure: 27 | - RUN: _SOME_NON_EXISTENT_FUNCTION 28 | 29 | -------------------------------------------------------------------------------- /doc/installing-and-running-your-first-space-command/running-your-first-space-command.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: ../verifying-installation/ 3 | prev_title: "Verifying installation" 4 | next: /space-modules/ 5 | next_title: "Space Modules" 6 | title: Running your first Space command 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/installing-and-running-your-first-space-command/running-your-first-space-command.md 9 | weight: 406 10 | --- 11 | 12 | # Running your first Space command 13 | 14 | With the _Space_ program available on the system, it is now possible to run the most basic command. 15 | Create a new file named `Spacefile.yaml` and add the following contents to it: 16 | 17 | ```yaml 18 | _env: 19 | - RUN: printf "Hello World\n" 20 | ``` 21 | 22 | Now run `space` and it should output `Hello World` to the console `stdout`. 23 | 24 | Next section describes what _Space_ modules are. For jumping right into more code, see _Running a Space module_ section. 25 | -------------------------------------------------------------------------------- /test/exit_status_cases/test.yaml: -------------------------------------------------------------------------------- 1 | # Preprocessing variable assignment, set, unset and reset 2 | @ppvar1: "ppvar one" 3 | @ppvar1:- "ppvar one" 4 | @ppvar1:+ "ppvar one" 5 | @ppvar1:+ 6 | @ppvar1:+ "ppvar one" 7 | @ppvar1:- 8 | @ppvar1:+ 9 | @ppvar1: 10 | @ppvar1:- 11 | @ppvar1: "ppvar one reset" 12 | @ppvar1:- 13 | @somenotset:- 14 | 15 | # Preprocessing assert 16 | @assert: nonempty $HOME 17 | @assert: nonempty @ppvar1 18 | 19 | # Preprocessing debug print 20 | @debug: HOME is ${HOME} 21 | 22 | # Cache settings via preprocessor 23 | @cache: 1 24 | 25 | # Include good and bad files, filtered files, modules 26 | @include: Spacefile.yaml|/uninstall/ 27 | @include: Spacefile.yaml|/install/ 28 | @include:- non_existent_is_fine_with_dash.yaml 29 | 30 | # Clone good repo 31 | @clone: file 32 | 33 | 34 | _env: 35 | 36 | print_test: 37 | _env: 38 | - RUN: printf "[test.yaml] testing RUN node execution... " 39 | 40 | source_failure: 41 | - RUN: _SOME_NON_EXISTENT_FUNCTION 42 | 43 | -------------------------------------------------------------------------------- /test/function/pp_yaml/bad_clone.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | @clone: error_here123 21 | 22 | _env: 23 | - SOME_VAR: "false" 24 | 25 | install: 26 | _info: 27 | title: TEST TITLE 28 | desc:| 29 | t1 30 | t2 t7 31 | t3 t4 t5 32 | _env: 33 | - RUN: 34 | 35 | -------------------------------------------------------------------------------- /test/function/pp_yaml/bad_assert.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | @assert: nonempty @{tTt2} 21 | 22 | _env: 23 | - SOME_VAR: "false" 24 | 25 | install: 26 | _info: 27 | title: TEST TITLE 28 | desc:| 29 | t1 30 | t2 t7 31 | t3 t4 t5 32 | _env: 33 | - RUN: 34 | 35 | -------------------------------------------------------------------------------- /test/function/pp_yaml/bad_include.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | @include: "does_not_exist.yaml" 21 | 22 | _env: 23 | - SOME_VAR: "false" 24 | 25 | install: 26 | _info: 27 | title: TEST TITLE 28 | desc:| 29 | t1 30 | t2 t7 31 | t3 t4 t5 32 | _env: 33 | - RUN: 34 | 35 | -------------------------------------------------------------------------------- /doc/advanced-space-sh-configuration/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: /space-modules/ 3 | prev_title: "Space Modules" 4 | next: /shell-coding-and-style-guidelines/ 5 | next_title: "Shell coding and style guidelines" 6 | title: Advanced Space.sh configuration 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/advanced-space-sh-configuration/index.md 9 | weight: 600 10 | icon: "6. " 11 | --- 12 | 13 | # Advanced Space.sh configuration 14 | 15 | ### Environment variables and possible settings 16 | 17 | #### SPACE_LOG_ENABLE_COLORS 18 | Enables colored message output. 19 | Default: 1 20 | Set this from cmdline, using the `-e` flag or from the _YAML_. 21 | 22 | #### SPACE_LOG_LEVEL 23 | Set level of logging in interval [0,5] for the final script. 24 | Default: 4 25 | Set this from cmdline, using the `-e` flag or from the _YAML_. 26 | 27 | #### SPACE_MODULES_SHARED 28 | The directory for shared resources i.e. modules. 29 | Default: `~/.space/space_modules` 30 | Can only be set from the cmd line when invoking _Space_. 31 | -------------------------------------------------------------------------------- /test/function/parse_yaml/test_parse_yaml.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _TEST_PARSE_YAML_CHECK_STATUS_OK 27 | - 28 | _env: 29 | - RUN: _TEST_PARSE_YAML_CHECK_PARSED_YAML_OK 30 | - 31 | _env: 32 | - RUN: _TEST_PARSE_YAML_CHECK_PARSED_YAML_FAIL 33 | 34 | -------------------------------------------------------------------------------- /test/function/pp_yaml/good_config.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | @include: ./test/function/test_spacefile.yml 21 | @assert: nonempty $HOME 22 | 23 | _env: 24 | - SOME_VAR: "false" 25 | 26 | install: 27 | _info: 28 | title: TEST TITLE 29 | desc:| 30 | t1 31 | t2 t7 32 | t3 t4 t5 33 | _env: 34 | - RUN: "" 35 | -------------------------------------------------------------------------------- /test/yaml/5/input.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | # Test !nospace keyword 21 | test_gt: !nospace > 22 | Now these lines 23 | will be joined 24 | but with no spaces inbetween! 25 | But line will end with \n 26 | 27 | test_gt_dash: !nospace >- 28 | And these lines 29 | will be joined 30 | also with no spaces inbetween! 31 | But line will not end with \n thanks to the '-'. 32 | 33 | -------------------------------------------------------------------------------- /test/yaml/4/input.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | # Test |- and >- dash cases 21 | 22 | test_dash0: |- 23 | Multi line 24 | string, 25 | with new lines kept. 26 | Thanks to '-' this line does not end with \n 27 | 28 | test_dash1: >- 29 | These lines 30 | will be one 31 | one long line, 32 | where each line will be 33 | space separated. But the single line will not have \n thanks to '-' 34 | 35 | -------------------------------------------------------------------------------- /test/yaml/100/input.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | # Test node names 21 | # Underscores, letters and numbers 22 | test_node_name: 23 | NoDE_1NAME: TeSt 24 | 2node_name: 0987654321 25 | node3_N4M3: 26 | _sub_: "TeSt" 27 | _s_b_u_: "123456789042!" 28 | s_b_u: 29 | 1234: > 30 | Multiline just 31 | for kicks 32 | _env: 33 | title: Test node names 34 | -------------------------------------------------------------------------------- /doc/troubleshooting/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Troubleshooting 3 | prev: /contributing/ 4 | prev_title: "Contributing" 5 | weight: 1300 6 | giturl: github.com/space-sh/space 7 | editurl: /edit/master/doc/troubleshooting/index.md 8 | icon: "12. " 9 | --- 10 | 11 | # Troubleshooting 12 | 13 | ### Error #1 14 | ```sh 15 | bash: line 51: cannot create temp file for here-document: No space left on device 16 | ``` 17 | 18 | #### Reason 19 | Disk is likely to be full on remote machine. 20 | 21 | #### Explanation 22 | SSH connects to the SSH daemon on the remote machine which invokes the users login shell (in this case Bash) and then SSH streams the script to be run on the remote machine by the login shell. The login shell might need to create temporary files to interpret and handle the script. 23 | If the disk is full the shell cannot create temporary files at all. 24 | 25 | #### Solution 26 | SSH into the machine using the `ssh` module and delete old log files, etc 27 | to free up some space. 28 | For example: 29 | ```sh 30 | space -m ssh /ssh/ -- 1.2.3.4,1.2.3.5 user1,user2 id_rsa.machine1,id_rsa.machine2 31 | ``` 32 | 33 | -------------------------------------------------------------------------------- /test/function/yaml_get_row/test_yaml_get_row.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | tests: 21 | - 22 | - 23 | _env: 24 | - RUN: _TEST_YAML_GET_ROW_CHECK_STATUS_OK 25 | - 26 | _env: 27 | - RUN: _TEST_YAML_GET_ROW_CHECK_PREPROCESS_STATUS_OK 28 | - 29 | _env: 30 | - RUN: _TEST_YAML_GET_ROW_CHECK_RETURNED_ROW_OK 31 | - 32 | _env: 33 | - RUN: _TEST_YAML_GET_ROW_CHECK_RETURNED_PREPROCESS_ROW_OK 34 | 35 | -------------------------------------------------------------------------------- /doc/installing-and-running-your-first-space-command/installing-current-version-from-source-control-repository.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: ../installing-from-latest-tarball/ 3 | prev_title: "Installing from latest tarball" 4 | next: ../installing-latest-stable-version-from-spacesh-site/ 5 | next_title: "Installing latest stable version from space.sh" 6 | title: Installing current version from source control repository 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/installing-and-running-your-first-space-command/installing-current-version-from-source-control-repository.md 9 | weight: 402 10 | --- 11 | 12 | # Installing current version from source control repository 13 | 14 | Simply clone the repository: 15 | 16 | ```sh 17 | git clone https://github.com/space-sh/space 18 | ``` 19 | 20 | The _master_ branch is referred as the _current_ version of _Space_. For _stable_ releases, please checkout a specific _Git_ tag (see also: `git tag`). 21 | 22 | #### Installing from source control 23 | After cloning the repository, from the root directory call _Space_ for installing itself on the system: 24 | 25 | ```sh 26 | ./space /install/ 27 | ``` 28 | -------------------------------------------------------------------------------- /test/core/validate_basedir/test_validate_basedir.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _VALIDATE_BASEDIR() 20 | { 21 | SPACE_DEP="PRINT" 22 | SPACE_ENV="_BASEDIR" 23 | 24 | # Check if BASEDIR path is valid 25 | if [[ "${_BASEDIR}" =~ ^\/.*$ ]]; then 26 | PRINT "_BASEDIR test OK!" "ok" 27 | return 0 28 | else 29 | PRINT "_BASEDIR value=[${_BASEDIR}] doesn't match expected format" "error" 30 | return 1 31 | fi 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /test/core/validate_version/test_validate_version.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _VALIDATE_VERSION() 20 | { 21 | SPACE_DEP="PRINT" 22 | SPACE_ENV="_VERSION" 23 | 24 | # Check if version string is valid 25 | if [[ "${_VERSION}" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then 26 | PRINT "_VERSION test OK!" "ok" 27 | return 0 28 | else 29 | PRINT "_VERSION value=[${_VERSION}] doesn't match expected format" "error" 30 | return 1 31 | fi 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /test/yaml/1/input.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | # A simple object structure 21 | First: 22 | sub1: Hello 23 | sub2: World 24 | SUB3: 25 | sub31: "HELLO" 26 | sub32: "WORLD!" 27 | sub4: 28 | sub341: | 29 | This is a 30 | 31 | multiline! 32 | sub342: > 33 | This is a collapsed multiline without 34 | newlines. 35 | _env: 36 | title: First test 37 | -------------------------------------------------------------------------------- /doc/space-modules/modules-advanced-topics.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: ../modules-best-practices/ 3 | prev_title: "Modules best practices" 4 | next: /advanced-space-sh-configuration/ 5 | next_title: "Advanced Space.sh configuration" 6 | title: Modules advanced topics 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/space-modules/modules-advanced-topics.md 9 | weight: 510 10 | --- 11 | 12 | # Modules advanced topics 13 | 14 | #### Wrappers and outer functions 15 | Outer functions is a mechanism of using existing module functions in a given iteration. 16 | 17 | In the event where a module or function is to be run in a remote target, it is possible to leverage the _wrapping_ mechanism provided by _Space_. This _wrapping_ mechanism will wrap any command and run it inside some other context, for instance, a remote shell over _SSH_, a _container_ or a combination of the two. 18 | 19 | ##### Writing your own Space Module wrappers 20 | 1. Make your own wrapper. 21 | 2. Wrapping to be run inside a docker container. 22 | 3. Wrapping to be run over SSH. 23 | 4. Wrapping to be run inside a docker container over SSH. 24 | 5. Run outer functions locally 25 | 26 | [[ to be written ]] 27 | 28 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | # Tests 2 | This directory contains all tests needed in order to check Space.sh. Each directory marks a subsystem or category in which the tests are performed. 3 | 4 | ## List of available tests 5 | 6 | ### test_all_exit_status 7 | Tests all front-facing commands and options that can be issued by a regular user. Each test expects either an OK or FAILURE, checked via exit status code returned from each _Space_ program call. Tests also look for the existence of a particular text output caught from stdout/err, trying to match with an expected string to check for correct program behavior. 8 | 9 | ### test_build 10 | Tests the build process generated all the files as expected. 11 | 12 | ### test_core 13 | Tests all core program functionalities which relate to global state and OS-specific and shell-specific behaviours. 14 | 15 | ### test_function 16 | Tests different code paths, parameters and return values for Space functions. Unit tests. 17 | 18 | ### test_install 19 | Verifies all the steps taken during Space installation process. Asserts that both system-wide and custom installs are working correctly. 20 | 21 | ### test_yaml 22 | Tests all YAML related operations. 23 | 24 | -------------------------------------------------------------------------------- /doc/glossary/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: /shell-coding-and-style-guidelines/ 3 | prev_title: "Shell coding and style guidelines" 4 | next: /references/ 5 | next_title: "References" 6 | title: Glossary 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/glossary/index.md 9 | weight: 900 10 | icon: "8. " 11 | --- 12 | 13 | # Glossary 14 | 15 | - API: Application program interface 16 | - Bash: Bourne again shell, an sh-compatible shell 17 | - Blockie: Blockie.org is the company developing Space.sh 18 | - IoT: Internet of things 19 | - man: manual page documenting a computer program 20 | - Module: a Space Module 21 | - POSIX: standard set of guidelines and descriptions for operating systems 22 | - script: a computer program written in a scripting language 23 | - sh: shell script file extension and shorthand for shell. 24 | - shell: a program that serves as interface between a computer user and the operating system 25 | - Space: Space.sh 26 | - Space.sh: set of tools and services delivered by Blockie.org 27 | - stderr: standard error stream 28 | - stdout: standard output stream 29 | - terminal: a computer terminal 30 | - UNIX: a family of operating systems derived from AT&T Unix 31 | -------------------------------------------------------------------------------- /tools/static_analysis/README.md: -------------------------------------------------------------------------------- 1 | # static_analysis 2 | 3 | Helper module for running static analysis on a given file or directory structure recursively. 4 | 5 | 6 | ## Dependencies 7 | 8 | Depends on `command` and `grep`. 9 | Optionally requires `shellcheck` or `checkbashisms` for running the analysis. 10 | 11 | 12 | ## Usage 13 | 14 | For running Shellcheck: 15 | ``` 16 | ./space -f ./tools/static_analysis/Spacefile.yaml /shellcheck/ -- "space" "shellchecks.txt" 17 | ``` 18 | 19 | 20 | Checkbashisms: 21 | ``` 22 | ./space -f ./tools/static_analysis/Spacefile.yaml /checkbashisms/ -- "space" "bashisms.txt" 23 | ``` 24 | 25 | 26 | Running all tests: 27 | ``` 28 | ./space -f ./tools/static_analysis/Spacefile.yaml /all/ -- "space" "analysis_" 29 | ``` 30 | Note that on the ALL test, the output parameter is just a suffix. The final file name will be suffix+program_name.txt. 31 | 32 | 33 | Running all tests recursively: 34 | ``` 35 | ./space -f ./tools/static_analysis/Spacefile.yaml /all_recursively/ -- "results" 36 | ``` 37 | Instead of /all/, there is also all_recursively, which scans all the shell script files, starting from the current directory and outputs all results to a separate directory. 38 | 39 | -------------------------------------------------------------------------------- /test/function/PRINT/test_PRINT.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _TEST_PRINT_LEVEL_ERROR 27 | - 28 | _env: 29 | - RUN: _TEST_PRINT_LEVEL_SECURITY 30 | - 31 | _env: 32 | - RUN: _TEST_PRINT_LEVEL_WARNING 33 | - 34 | _env: 35 | - RUN: _TEST_PRINT_LEVEL_OK 36 | - 37 | _env: 38 | - RUN: _TEST_PRINT_LEVEL_INFO 39 | - 40 | _env: 41 | - RUN: _TEST_PRINT_LEVEL_DEBUG 42 | 43 | -------------------------------------------------------------------------------- /test/function/copy/test_copy.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _TEST_COPY() 20 | { 21 | SPACE_DEP="PRINT _copy" 22 | SPACE_ENV="_YAML_PREFIX _YAML_NAMESPACE" 23 | 24 | local _sg1_0x5fsomespace_node1_node3_Test0x5fnO0x5fd3="Passed" 25 | local _test_storage= 26 | _copy "_test_storage" "/_somespace/node1/node3/Test_nO_d3" 27 | 28 | if [ ${_test_storage} = "Passed" ]; then 29 | PRINT "_copy OK!" "ok" 30 | return 0 31 | else 32 | PRINT "_copy failed!" "error" 33 | return 1 34 | fi 35 | } 36 | 37 | -------------------------------------------------------------------------------- /test/function/sort_pad/test_sort_pad.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _TEST_SORT_PAD_SINGLE_DIGIT 27 | - 28 | _env: 29 | - RUN: _TEST_SORT_PAD_10_DIGITS 30 | - 31 | _env: 32 | - RUN: _TEST_SORT_PAD_20_DIGITS 33 | - 34 | _env: 35 | - RUN: _TEST_SORT_PAD_SINGLE_CHARACTER 36 | - 37 | _env: 38 | - RUN: _TEST_SORT_PAD_10_CHARACTERS 39 | - 40 | _env: 41 | - RUN: _TEST_SORT_PAD_20_CHARACTERS 42 | -------------------------------------------------------------------------------- /test/Spacefile.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _info: 21 | title: Space test helper module 22 | desc:| 23 | Provides functions to run one or more modules recursively as an expected test. 24 | 25 | _env: 26 | 27 | run: 28 | _info: 29 | title: Recursively test a given directory 30 | desc:| 31 | Iterate over a directory and run all test modules. 32 | If no directory is specified, traverse current directory instead. 33 | Parameters (optional): 34 | 1: directory path 35 | _env: 36 | - RUN: _TEST_ALL_RECURSIVELY 37 | 38 | -------------------------------------------------------------------------------- /test/core/read_program_name/test_read_program_name_source.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _READ_PROGRAM_NAME_SOURCE() 20 | { 21 | _BIN_NAME=$(basename "$1") 22 | shift || : 23 | 24 | # Check if bin name matches expected value 25 | if [ "${_BIN_NAME}" = "space" ]; then 26 | _BASE_PATH="$( cd "${_SPACEBIN%/*}" 2>/dev/null ; pwd )" 27 | PRINT "Base path = ${_BASE_PATH}" 28 | PRINT "_SPACEBIN test OK!" "ok" 29 | return 0 30 | else 31 | PRINT "_SPACEBIN value=[${_BIN_NAME}] doesn't match expected value [space]" "error" 32 | return 1 33 | fi 34 | } 35 | 36 | -------------------------------------------------------------------------------- /test/function/source/test_source.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _TEST_SOURCE_ONE_CHECK_STATUS 27 | - 28 | _env: 29 | - RUN: _TEST_SOURCE_ONE_CHECK_STATE_CHANGED 30 | - 31 | _env: 32 | - RUN: _TEST_SOURCE_ONE_CHECK_EXPECTED_OUTPUT 33 | - 34 | _env: 35 | - RUN: _TEST_SOURCE_MULTIPLE_CHECK_STATUS 36 | - 37 | _env: 38 | - RUN: _TEST_SOURCE_MULTIPLE_CHECK_STATE_CHANGED 39 | - 40 | _env: 41 | - RUN: _TEST_SOURCE_MULTIPLE_CHECK_EXPECTED_OUTPUT 42 | 43 | -------------------------------------------------------------------------------- /test/yaml/3/output_X2.yaml: -------------------------------------------------------------------------------- 1 | _sg1_subdoc_hello_title=Default value 2 | _sg1_subdoc_world_title= 3 | _sg1_test_info=here comes a.yaml 4 | _sg1_test_first_a= 5 | _sg1_test_second_aa= 6 | _sg1_test_all_aa= 7 | _sg1_test_all_a= 8 | _sg1_test_all_c= 9 | _sg1_test0_info=here comes a.yaml|first 10 | _sg1_test0_a= 11 | _sg1_test1_info=here comes a.yaml|second 12 | _sg1_test1_aa= 13 | _sg1_test2_info=here comes a.yaml|all 14 | _sg1_test2_aa= 15 | _sg1_test2_a= 16 | _sg1_test2_c= 17 | _sg1_test3_info=here comes an iteration of a.yaml|all with added sub document. 18 | _sg1_test3_aa_hello=world 19 | _sg1_test3_aa_good=stuff 20 | _sg1_test3_aa_oodier_0_aa=11 21 | _sg1_test3_aa_oodier_1_bb=22 22 | _sg1_test3_a_hello=world 23 | _sg1_test3_a_good=stuff 24 | _sg1_test3_a_oodier_0_aa=11 25 | _sg1_test3_a_oodier_1_bb=22 26 | _sg1_test3_c_hello=world 27 | _sg1_test3_c_good=stuff 28 | _sg1_test3_c_oodier_0_aa=11 29 | _sg1_test3_c_oodier_1_bb=22 30 | _sg1_test4_info=here comes an iteration of a.yaml|all with added sub include. 31 | Notice the args passed with the @include. o/ 32 | 33 | _sg1_test4_aa_hello_title=firstarg2/test4/aa/hello/ 34 | _sg1_test4_aa_world_title=secarg2world 35 | _sg1_test4_a_hello_title=firstarg2/test4/a/hello/ 36 | _sg1_test4_a_world_title=secarg2world 37 | _sg1_test4_c_hello_title=firstarg2/test4/c/hello/ 38 | _sg1_test4_c_world_title=secarg2world 39 | -------------------------------------------------------------------------------- /test/function/source_added/test_source_added.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _TEST_SOURCE_ADDED_SINGLE_CHECK_STATUS 27 | - 28 | _env: 29 | - RUN: _TEST_SOURCE_ADDED_SINGLE_CHECK_STATE_CHANGED_0 30 | - 31 | _env: 32 | - RUN: _TEST_SOURCE_ADDED_SINGLE_CHECK_STATE_CHANGED_1 33 | - 34 | _env: 35 | - RUN: _TEST_SOURCE_ADDED_MULTIPLE_CHECK_STATUS 36 | - 37 | _env: 38 | - RUN: _TEST_SOURCE_ADDED_MULTIPLE_CHECK_STATE_CHANGED_0 39 | - 40 | _env: 41 | - RUN: _TEST_SOURCE_ADDED_MULTIPLE_CHECK_STATE_CHANGED_1 42 | 43 | -------------------------------------------------------------------------------- /doc/space-modules/modules-versioning.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: ../spacefile-yaml-reference/ 3 | prev_title: "Spacefile YAML reference" 4 | next: ../modules-best-practices/ 5 | next_title: "Modules best practices" 6 | title: Modules versioning 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/space-modules/modules-versioning.md 9 | weight: 508 10 | --- 11 | 12 | # Modules versioning 13 | 14 | #### Stable version 15 | All released versions are expected to be marked as _Git tags_ in the repository. Those are referred to as _stable_ versions. 16 | 17 | The last known stable version name is marked in the `space-module.txt` file, expected to be in the module root directory. 18 | Stable version modules can be fetched either implicitly with `space -m ` or, preferably, by including the tag version name with `space -m :`. 19 | 20 | It is strongly advised to explicitly state the module version, in particular when using it as a dependency of some other module or program. 21 | 22 | #### Current version 23 | The _master_ branch on the repository is expected to regularly change. For this reason, the _master_ branch is referred to as the _current_ version. 24 | 25 | Relevant changes can be followed by reading the changelog file. 26 | 27 | The current version module can be fetched with `space -m :master`. 28 | -------------------------------------------------------------------------------- /doc/how-space-works/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: How Space works 3 | prev: /why-space/ 4 | prev_title: "Why Space" 5 | next: /installing-and-running-your-first-space-command/ 6 | next_title: "Installing and running your first Space command" 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/how-space-works/index.md 9 | weight: 300 10 | icon: "3. " 11 | --- 12 | 13 | # How Space works 14 | 15 | _Space_ is a single file program that runs in _Bash_ command line shell version 3.2 or later. General output results can be expected to be sent over to `stdout`, while user diagnostics can be caught on `stderr`. 16 | 17 | _Space_ uses some external programs for certain tasks, mostly coupled to tasks that involve disk and/or network access. These external programs are not all _POSIX 1003.1_ compliant but have been tested to work on a variety of platforms. For more information, search for the word EXTERNAL in the _Space_ source code and see how they are applied and used. 18 | Optional programs that are used when available for improving user experience include: _curl_, _git_, _shasum_, _sha1sum_, _sha256sum_ and _wget_. 19 | 20 | When performing installation, if `man` program is available, _Space_ installs the manual page file. _Bash_ tab completion is also installed if the current _Bash_ install supports such feature. 21 | _Space_ revolves around modules, covered in its own section - [Space modules](../space-modules). 22 | -------------------------------------------------------------------------------- /doc/space-modules/what-are-space-modules.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: ../why-space-modules/ 3 | prev_title: "Why Space Modules" 4 | next: ../running-a-space-module/ 5 | next_title: "Running a Space Module" 6 | title: What are Space modules 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/space-modules/what-are-space-modules.md 9 | weight: 502 10 | --- 11 | 12 | # What are Space modules 13 | 14 | Modules are exportable user extensions that can include each other to be loaded and run by _Space_ in a composable way. The execution can then be exported as a shell script, to be run directly or shared, all in a decentralized manner. 15 | 16 | Behind the scenes, _Space_ module is a directory on disk (often a _Git_ repository) which contains at least a _YAML_ description file (commonly named `Spacefile.yaml`) and most often also `Spacefile.sh/.bash` shell scripts. Modules are often located under `~/.space/space_modules/[reponame]`. 17 | 18 | A user creating a _YAML_ structure can clone and include modules into the _YAML_ file, reusing them. 19 | _Space_ modules exported scripts only depend on a POSIX-compliant shell, so they run with _Ash_, _Dash_ and _Bash_. 20 | 21 | However _Space_ modules which explicitly defines a __Bash__ file as `Spacefile.bash` will export _Bash_ compliant scripts. 22 | _Space.sh_ provides by default a module ban list server for checking modules that might be broken or flagged as inappropriate. 23 | -------------------------------------------------------------------------------- /doc/installing-and-running-your-first-space-command/customizing-installation-parameters.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: ../installing-latest-stable-version-from-spacesh-site/ 3 | prev_title: "Installing latest stable version from space.sh" 4 | next: ../verifying-installation/ 5 | next_title: "Verifying installation" 6 | title: Customizing installation parameters 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/installing-and-running-your-first-space-command/customizing-installation-parameters.md 9 | weight: 404 10 | --- 11 | 12 | # Customizing installation parameters 13 | 14 | While it is true that both the default install parameters and automatic OS platform detection will handle the majority of use cases, there might be special cases. 15 | It is possible to change the default installation directories for the _Space_ program and shell auto completion support. 16 | 17 | #### Customizing install.sh 18 | This script takes two optional parameters. The first one is the _Space_ program path and the second one is the auto completion path, where the customized _Space_ shell completion will be installed to. Paths can be either absolute or relative. 19 | 20 | #### Customizing Space base module 21 | The `/install/` node is defined inside the base Module that comes with _Space_ (Spacefile.yaml,bash). This Module is the actual installer and can read the same optional arguments as `install.sh`, which are the program path and the auto completion path for installing files, respectively. 22 | -------------------------------------------------------------------------------- /test/yaml/99/input.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | # A collection of bugs and abnormalities found in the yaml parsing. 21 | # These tests are made to pass, they serve as a showcase of the issues. 22 | 23 | ## Abnormality 1 24 | # Something with @including lists.. 25 | # Could also check the caveat about not indenting 26 | # list - under it's parent. 27 | list: 28 | - A: 29 | info: A 30 | 31 | - B: 32 | info: B 33 | SUM: 34 | @include: |/list/ 35 | # Uncomment this line and it crasches! 36 | #Add: yes 37 | 38 | ### Abnormanility 2 39 | nodes: 40 | @include: a.yaml 41 | 42 | nodes2: 43 | # This works. 44 | @include: |/nodes/ 45 | 46 | nodes3: 47 | # But this does not include anything... Which is not good. 48 | @include: |/nodes/A/ 49 | ... 50 | -------------------------------------------------------------------------------- /test/yaml/6/output_X2.yaml: -------------------------------------------------------------------------------- 1 | _sg1_str1=A string value 2 | _sg1_str2=A multiline value here A string value 3 | 4 | _sg1_A_0_final=A string value 5 | A multiline 6 | value here 7 | A string value 8 | _sg1_A_1_o=1 9 | _sg1_A_1_final=A string value A multiline value here A string value 10 | _sg1_A_2=A string value A multiline value here A string value 11 | _sg1_A_3=A string value 12 | A multiline 13 | value here 14 | A string value 15 | _sg1_A_4=A string valueA multilinevalue hereA string value 16 | 17 | _sg1_B_b1=Another string 18 | _sg1_B_b2=More multiline strings 19 | 20 | _sg1_B_b2=Even More multiline strings 21 | _sg1_B_b3=Further More 22 | multiline 23 | strings 24 | A multiline 25 | value here 26 | A string value 27 | 28 | _sg1_B_b4=Much of More 29 | multiline 30 | strings 31 | A string value 32 | _sg1_C_c1=-- Here comes /A/.* 33 | A string value 34 | A multiline 35 | value here 36 | A string value 37 | 1 38 | A string value 39 | A multiline 40 | value here 41 | A string value 42 | A string value 43 | A multiline 44 | value here 45 | A string value 46 | A string value 47 | A multiline 48 | value here 49 | A string value 50 | A string value 51 | A multiline 52 | value here 53 | A string value 54 | -- Here comes /B/.* 55 | Another string 56 | More 57 | multiline 58 | strings 59 | Even More 60 | multiline 61 | strings 62 | Further More 63 | multiline 64 | strings 65 | A multiline 66 | value here 67 | A string value 68 | Much of More 69 | multiline 70 | strings 71 | A string value 72 | -- end 73 | 74 | -------------------------------------------------------------------------------- /doc/installing-and-running-your-first-space-command/installing-latest-stable-version-from-spacesh-site.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: ../installing-current-version-from-source-control-repository/ 3 | prev_title: "Installing current version from source control repository" 4 | next: ../customizing-installation-parameters/ 5 | next_title: "Customizing installation parameters" 6 | title: Installing latest stable version from Space.sh site 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/installing-and-running-your-first-space-command/installing-latest-stable-version-from-spacesh-site.md 9 | weight: 403 10 | --- 11 | 12 | # Installing latest stable version from Space.sh site 13 | 14 | It is possible to download the installer from _space.sh_ site: 15 | 16 | ```sh 17 | curl https://get.space.sh > install-space-latest.sh 18 | ``` 19 | 20 | For older versions, `install.sh` is available under: 21 | 22 | ```sh 23 | curl -O https://space.sh/static/download/space-/install-.sh 24 | ``` 25 | 26 | #### Installing from Space.sh 27 | 28 | Download `install.sh` and pipe into shell: 29 | 30 | ```sh 31 | curl https://get.space.sh | sh 32 | ``` 33 | 34 | or use the `install-space-latest.sh` downloaded in the _Downloading_ section and execute it: 35 | 36 | ```sh 37 | sh install-space-latest.sh 38 | ``` 39 | 40 | Non-root users might need `sudo` for default installation. In that case, use the following command: 41 | 42 | ```sh 43 | sudo sh -c "curl https://get.space.sh | sh" 44 | ``` 45 | -------------------------------------------------------------------------------- /test/build/check_base_libraries.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # 3 | # Copyright 2016-2017 Blockie AB 4 | # 5 | # This file is part of Space. 6 | # 7 | # Space is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation version 3 of the License. 10 | # 11 | # Space is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Space. If not, see . 18 | # 19 | 20 | # 21 | # Check for base system libraries 22 | # 23 | set -o nounset 24 | 25 | _check_library() 26 | { 27 | local _lib_name=$1 28 | local _output= 29 | 30 | for _ext in ".a" ".so" ".so.*"; do 31 | _output=$(find /usr/lib -name "${_lib_name}${_ext}" -print) 32 | if [ -n "$_output" ]; then 33 | return 0 34 | fi 35 | 36 | _output=$(find /usr/local/lib -name "${_lib_name}${_ext}" -print) 37 | if [ -n "$_output" ]; then 38 | return 0 39 | fi 40 | done 41 | 42 | printf "FAIL: could not find library %s\n" "$_lib_name" 1>&2 43 | exit 1 44 | } 45 | 46 | _YAML_LIB_NAME="libyaml" 47 | _check_library "$_YAML_LIB_NAME" 48 | printf "OK: %s\n" "$_YAML_LIB_NAME" 49 | 50 | -------------------------------------------------------------------------------- /test/yaml/3/output_X1.yaml: -------------------------------------------------------------------------------- 1 | subdoc: 2 | hello: 3 | title: Default value 4 | world: 5 | title: 6 | test: 7 | info: here comes a.yaml 8 | first: 9 | a: 10 | second: 11 | aa: 12 | all: 13 | aa: 14 | a: 15 | c: 16 | test0: 17 | info: here comes a.yaml|first 18 | a: 19 | test1: 20 | info: here comes a.yaml|second 21 | aa: 22 | test2: 23 | info: here comes a.yaml|all 24 | aa: 25 | a: 26 | c: 27 | test3: 28 | info: here comes an iteration of a.yaml|all with added sub document. 29 | aa: 30 | hello: world 31 | good: stuff 32 | oodier: 33 | - aa: 11 34 | - bb: 22 35 | a: 36 | hello: world 37 | good: stuff 38 | oodier: 39 | - aa: 11 40 | - bb: 22 41 | c: 42 | hello: world 43 | good: stuff 44 | oodier: 45 | - aa: 11 46 | - bb: 22 47 | test4: 48 | info: | 49 | here comes an iteration of a.yaml|all with added sub include. 50 | Notice the args passed with the @include. o/ 51 | aa: 52 | hello: 53 | title: firstarg2/test4/aa/hello/ 54 | world: 55 | title: secarg2world 56 | a: 57 | hello: 58 | title: firstarg2/test4/a/hello/ 59 | world: 60 | title: secarg2world 61 | c: 62 | hello: 63 | title: firstarg2/test4/c/hello/ 64 | world: 65 | title: secarg2world 66 | -------------------------------------------------------------------------------- /tools/bsdvm/01_bsdvm_create.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # 3 | # Copyright 2016-2017 Blockie AB 4 | # 5 | # This file is part of Space. 6 | # 7 | # Space is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation version 3 of the License. 10 | # 11 | # Space is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Space. If not, see . 18 | # 19 | 20 | # 21 | # Create new VM 22 | # 23 | 24 | if ! command -v VBoxManage >/dev/null; then 25 | printf "FAIL: VBoxManage program is required\n" 1>&2 26 | exit 1 27 | fi 28 | 29 | _bsd_image_name="FreeBSD-11.2-RELEASE-amd64.vhd" 30 | 31 | if [ ! -f "${_bsd_image_name}" ]; then 32 | printf "Missing %s. Please run \"sh 00_bsdvm_fetch.sh\" first.\n" "${_bsd_image_name}" 1>&2 33 | exit 1 34 | fi 35 | 36 | VBoxManage createvm --name SpaceBSD --ostype FreeBSD_64 --register 37 | VBoxManage modifyvm SpaceBSD --memory 1024 38 | VBoxManage modifyvm SpaceBSD --natpf1 rule1,tcp,,2222,,22 39 | VBoxManage storagectl SpaceBSD --name "SATA Controller" --add sata --controller IntelAhci 40 | VBoxManage storageattach SpaceBSD --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium ${_bsd_image_name} 41 | 42 | -------------------------------------------------------------------------------- /test/function/pp_yaml/test_pp_yaml.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | - DEFINITION_ONE: "defined" 22 | 23 | tests: 24 | - 25 | - 26 | _env: 27 | - RUN: _TEST_PP_YAML_CHECK_STATUS_OK 28 | - 29 | _env: 30 | - RUN: _TEST_PP_YAML_CHECK_PREPROCESSED_OK 31 | - 32 | _env: 33 | - RUN: _TEST_PP_YAML_CHECK_STATUS_FAIL_1 34 | - 35 | _env: 36 | - RUN: _TEST_PP_YAML_CHECK_STATUS_FAIL_2 37 | - 38 | _env: 39 | - RUN: _TEST_PP_YAML_CHECK_STATUS_FAIL_3 40 | - 41 | _env: 42 | - RUN: _TEST_PP_YAML_CHECK_STATUS_FAIL_4 43 | - 44 | _env: 45 | - RUN: _TEST_PP_YAML_CHECK_FILTER_STATUS_OK 46 | - 47 | _env: 48 | - RUN: _TEST_PP_YAML_CHECK_FILTER_PREPROCESSED_OK 49 | - 50 | _env: 51 | - RUN: _TEST_PP_YAML_CHECK_INHERITED_INDENT_PREPROCESSED_OK 52 | 53 | -------------------------------------------------------------------------------- /doc/space-modules/modules-best-practices.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: ../modules-versioning/ 3 | prev_title: "Modules versioning" 4 | next: ../modules-advanced-topics/ 5 | next_title: "Modules advanced topics" 6 | title: Modules best practices 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/space-modules/modules-best-practices.md 9 | weight: 509 10 | --- 11 | 12 | # Modules best practices 13 | 14 | 15 | Checklist: 16 | 17 | 1. Perform module static analysis 18 | ```sh 19 | space -m spacechecker /run/ -- . 20 | ``` 21 | 22 | 2. Spell checking 23 | ```sh 24 | :set spell 25 | ``` 26 | 27 | 3. Document all shell script functions for `spacedoc` export 28 | 29 | 4. Document all nodes in the configuration file with proper Title and Description i.e. `_info/title` and `_info/desc` 30 | 31 | 5. Run shell script static code analysis tools: `checkbashisms` and `shellcheck` 32 | 33 | 6. Generate README file 34 | ```sh 35 | GENERATE_VARIABLES=0 GENERATE_TOC=0 space -f ../space/tools/spacedoc/Spacefile.yaml /module/ -- Spacefile.sh 36 | ``` 37 | 38 | 7. Create test directory with testrunner-compatible tests 39 | 40 | 8. Add continuous integration targets for running tests on external test and build servers 41 | 42 | 9. Always take careful action when making decisions based on data gathered, be it locally or remotely, because data could be tampered, misdirected or turned malicious by a compromised remote server. 43 | 44 | 10. Make sure build time module functions specify `SPACE_FN` header variable at the beginning of the function scope for clarity. Preferably in the very first line or the second line if first line is `SPACE_SIGNATURE=""`. 45 | -------------------------------------------------------------------------------- /tools/packer/Spacefile.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | @include: @{DIR}/../spacedoc/Spacefile.yaml 21 | @include: @{DIR}/../manpage_exporter/Spacefile.yaml 22 | @source: @{DIR}/../spacedoc/Spacefile.bash 23 | @source: @{DIR}/../manpage_exporter/Spacefile.sh 24 | 25 | _env: 26 | - RELEASE_FILES: "space Spacefile.sh Spacefile.yaml completion/init_autocompletion.sh space.1" 27 | 28 | _info: 29 | title: Space.sh packer 30 | desc: | 31 | Builds new packages for Space releases. 32 | 33 | make: 34 | _info: 35 | title: Make new release package 36 | desc: | 37 | Performs Space.sh packaging process. 38 | Generates a new package file containing the release file set for current Space version, 39 | along with exporting code documentation and user man page. 40 | Also creates hashes and GPG signature for verifying file integrity and authorship. 41 | _env: 42 | - RUN: SPACE_PACKER_MAKE 43 | ... 44 | -------------------------------------------------------------------------------- /test/yaml/3/output_X3.yaml: -------------------------------------------------------------------------------- 1 | subdoc: 2 | hello: 3 | title: Default value 4 | world: 5 | title: 6 | test: 7 | all: 8 | a: 9 | aa: 10 | c: 11 | first: 12 | a: 13 | info: here comes a.yaml 14 | second: 15 | aa: 16 | test0: 17 | a: 18 | info: here comes a.yaml|first 19 | test1: 20 | aa: 21 | info: here comes a.yaml|second 22 | test2: 23 | a: 24 | aa: 25 | c: 26 | info: here comes a.yaml|all 27 | test3: 28 | a: 29 | good: stuff 30 | hello: world 31 | oodier: 32 | 0: 33 | aa: 11 34 | 1: 35 | bb: 22 36 | aa: 37 | good: stuff 38 | hello: world 39 | oodier: 40 | 0: 41 | aa: 11 42 | 1: 43 | bb: 22 44 | c: 45 | good: stuff 46 | hello: world 47 | oodier: 48 | 0: 49 | aa: 11 50 | 1: 51 | bb: 22 52 | info: here comes an iteration of a.yaml|all with added sub document. 53 | test4: 54 | a: 55 | hello: 56 | title: firstarg2/test4/a/hello/ 57 | world: 58 | title: secarg2world 59 | aa: 60 | hello: 61 | title: firstarg2/test4/aa/hello/ 62 | world: 63 | title: secarg2world 64 | c: 65 | hello: 66 | title: firstarg2/test4/c/hello/ 67 | world: 68 | title: secarg2world 69 | info: | 70 | here comes an iteration of a.yaml|all with added sub include. 71 | Notice the args passed with the @include. o/ 72 | -------------------------------------------------------------------------------- /test/function/source_file/test_source_file.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | tests: 23 | - 24 | - 25 | _env: 26 | - RUN: _TEST_SOURCE_FILE_NON_EXISTANT_CHECK_FAILURE 27 | - 28 | _env: 29 | - RUN: _TEST_SOURCE_FILE_NON_EXISTANT_CHECK_NO_TOUCH 30 | - 31 | _env: 32 | - RUN: _TEST_SOURCE_FILE_ONE_CHECK_RETURN 33 | - 34 | _env: 35 | - RUN: _TEST_SOURCE_FILE_ONE_CHECK_TOUCH 36 | #- 37 | # _env: 38 | # - RUN: _TEST_SOURCE_FILE_ONE_CHECK_SYNTAX_RETURN 39 | #- 40 | # _env: 41 | # - RUN: _TEST_SOURCE_FILE_ONE_CHECK_SYNTAX_TOUCH 42 | - 43 | _env: 44 | - RUN: _TEST_SOURCE_FILE_MULTIPLE_CHECK_RETURN 45 | - 46 | _env: 47 | - RUN: _TEST_SOURCE_FILE_MULTIPLE_CHECK_TOUCH 48 | #- 49 | # _env: 50 | # - RUN: _TEST_SOURCE_FILE_MULTIPLE_CHECK_SYNTAX_RETURN 51 | #- 52 | # _env: 53 | # - RUN: _TEST_SOURCE_FILE_MULTIPLE_CHECK_SYNTAX_TOUCH 54 | 55 | -------------------------------------------------------------------------------- /doc/why-space/benefits-and-advantages-of-using-space.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: ../ 3 | prev_title: "Why Space" 4 | next: /how-space-works/ 5 | next_title: "How Space works" 6 | title: Benefits and advantages of using Space 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/why-space/benefits-and-advantages-of-using-space.md 9 | weight: 201 10 | --- 11 | 12 | # Benefits and advantages of using Space 13 | 14 | - **Solid foundation**: based on tried-and-true _POSIX-compatible_ environment 15 | - **Embedded and IoT friendly**: compact codebase and single file distribution 16 | - **Simple**: single-file makes it easier for running and setting up local or system-wide installs 17 | - **Efficient**: no code bloat policy leads to a small executable with around 5K lines of code 18 | - **Small**: less than 200K bytes in size 19 | - **Fast**: leverages existing core system command line utilities 20 | - **Intuitive**: shell integration and smart tab completions 21 | - **No dependencies**: _Bash_ is available everywhere 22 | - **Compatible**: follows _POSIX-like_ philosophy and standards 23 | - **Configurable**: ability to use the preprocessor for tweakable settings 24 | - **Extensible**: ability to expand the core concepts and creating derivative programs with _Space_ modules 25 | - **Composable**: modules can be combined to quickly create new programs, giving great flexibility 26 | - **Decentralized content**: distributed user-content by design 27 | - **Exportable**: possibility to build standalone programs for more secure deployments by exporting _Space_ modules where any redundant code has been removed by tree-shaking, for easy inspection 28 | - **Agentless**: no agents required for running commands on remote targets 29 | 30 | -------------------------------------------------------------------------------- /test/yaml/2/output_X1.yaml: -------------------------------------------------------------------------------- 1 | _env: 2 | - RUN: here it is 3 | CMD2: something more 4 | CMD3: "" 5 | - PIPE: input comes from here 6 | - elm1: 7 | elm2: data here 2 8 | elm3: "data here 3" 9 | - 10 | obj1: 11 | - Elm1: 12 | - Elm2: Data2 13 | obj2: 14 | - Elm3: Data3 15 | - Elm4: Data4 16 | _env: 17 | - A: 18 | B: my data is visible 19 | - A: my data is visible 20 | B: my data is visible 21 | - A: hej 22 | B: hej 23 | - A: san 24 | B: san 25 | - WRAPCMD: "" 26 | - STDIN: /dev/stdin 27 | - abcdef: 28 | - name: spaces stripped 29 | - ignored:no it becomes an indexed array value. 30 | - OK: some text 31 | OK2: | 32 | One row, 33 | two rows. 34 | OK3: > 35 | One row, 36 | still one row. 37 | strange_place: indeed 38 | hej: 39 | - a: Testing syntax 40 | - b: Works 41 | - c: great. 42 | hej2: 43 | - A: More syntax. 44 | - B: B 45 | - C: | 46 | One row, 47 | two rows. 48 | - OK4: Yes! 49 | OK4a: 50 | - 51 | - 52 | - Spaces removed. index 2. 53 | - "Astro Physics" 54 | - | 55 | Multiline 56 | right here, 57 | thanks. 58 | - Old school. 59 | - Great school. 60 | - Astro School. 61 | - > 62 | Gotta love these 63 | collapsed lines. 64 | - 65 | - A: Aaa 66 | A2: A2aa 67 | - B: Bbb 68 | - 69 | - 70 | - 71 | - Come on 72 | - Let's go 73 | - Where too? 74 | names: 75 | - Mary Smith 76 | - "Ester J:son" 77 | names: 78 | - John Smith 79 | - Susan Williams 80 | - Bill Jones 81 | _env: 82 | 9999: 83 | RUN: OK prio 84 | -------------------------------------------------------------------------------- /doc/space-modules/why-space-modules.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: ../ 3 | prev_title: "Space Modules" 4 | next: ../what-are-space-modules/ 5 | next_title: "What are Space Modules" 6 | title: Why Space modules 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/space-modules/why-space-modules.md 9 | weight: 501 10 | --- 11 | 12 | # Why Space modules 13 | 14 | One of the first important requirements around the design of _Space_ is to empower programmers to describe complex behaviors using straightforward rules and script code, taking advantage of decades old base technology provided by _UNIX-like_ tools. The idea of creating more power without adding platform constraints or compromises has always been the primary aim when developing _Space_. Also, in the event of external dependencies, _Space_ should always aid the user to install all the requirements without extra work. 15 | 16 | _Space_ is designed to be lean - small in disk size, with few lines of code and most importantly a public _API_ which is as simple as possible without compromising on function. In order to expand core functionality, users describe an extension, called Module, and define its functions via shell code. Modules can contain their own functions and also refer to functions from other modules which they are dependent on. The resulting composition will become exported as a single script file.This strategy makes it possible to create new modules from existing modules, by mixing, matching and composing them. The exported script enables offline usage and code audition, by delivering _POSIX-friendly_ program output. 17 | 18 | Decentralization is one of the core principles of _Space_. For this reason, user created content can exist in any _Git_ repository. 19 | -------------------------------------------------------------------------------- /test/yaml/2/output_X2.yaml: -------------------------------------------------------------------------------- 1 | _sg1_0x5fenv_0_RUN=here it is 2 | _sg1_0x5fenv_0_CMD2=something more 3 | _sg1_0x5fenv_0_CMD3="" 4 | _sg1_0x5fenv_1_PIPE=input comes from here 5 | _sg1_0_elm1= 6 | _sg1_0_elm2=data here 2 7 | _sg1_0_elm3="data here 3" 8 | _sg1_1_obj1_0_Elm1= 9 | _sg1_1_obj1_1_Elm2=Data2 10 | _sg1_1_obj2_0_Elm3=Data3 11 | _sg1_1_obj2_1_Elm4=Data4 12 | _sg1_0x5fenv_2_A= 13 | _sg1_0x5fenv_2_B=my data is visible 14 | _sg1_0x5fenv_3_A=my data is visible 15 | _sg1_0x5fenv_3_B=my data is visible 16 | _sg1_0x5fenv_4_A=hej 17 | _sg1_0x5fenv_4_B=hej 18 | _sg1_0x5fenv_5_A=san 19 | _sg1_0x5fenv_5_B=san 20 | _sg1_0x5fenv_6_WRAPCMD="" 21 | _sg1_0x5fenv_7_STDIN=/dev/stdin 22 | _sg1_2_abcdef_0_name=spaces stripped 23 | _sg1_2_abcdef_1=ignored:no it becomes an indexed array value. 24 | _sg1_3_OK=some text 25 | _sg1_3_OK2=One row, 26 | two rows. 27 | 28 | _sg1_3_OK3=One row, still one row. 29 | 30 | _sg1_strange0x5fplace=indeed 31 | _sg1_hej_0_a=Testing syntax 32 | _sg1_hej_1_b=Works 33 | _sg1_hej_2_c=great. 34 | _sg1_hej2_0_A=More syntax. 35 | _sg1_hej2_1_B=B 36 | _sg1_hej2_2_C=One row, 37 | two rows. 38 | 39 | _sg1_4_OK4=Yes! 40 | _sg1_4_OK4a_0= 41 | _sg1_4_OK4a_1= 42 | _sg1_4_OK4a_2=Spaces removed. index 2. 43 | _sg1_4_OK4a_3="Astro Physics" 44 | _sg1_4_OK4a_4=Multiline 45 | right here, 46 | thanks. 47 | 48 | _sg1_5=Old school. 49 | _sg1_6=Great school. 50 | _sg1_7=Astro School. 51 | _sg1_8=Gotta love these collapsed lines. 52 | 53 | _sg1_9_0_A=Aaa 54 | _sg1_9_0_A2=A2aa 55 | _sg1_9_1_B=Bbb 56 | _sg1_10_0_0_0=Come on 57 | _sg1_10_0_0_1=Let's go 58 | _sg1_10_0_1=Where too? 59 | _sg1_names_0=Mary Smith 60 | _sg1_names_1="Ester J:son" 61 | _sg1_names_2=John Smith 62 | _sg1_names_3=Susan Williams 63 | _sg1_names_4=Bill Jones 64 | _sg1_0x5fenv_9999_RUN=OK prio 65 | -------------------------------------------------------------------------------- /doc/installing-and-running-your-first-space-command/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: /how-space-works/ 3 | prev_title: "How Space works" 4 | next: ./installing-from-latest-tarball/ 5 | next_title: "Installing from latest tarball" 6 | title: Installing and running your first Space command 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/installing-and-running-your-first-space-command/index.md 9 | weight: 400 10 | icon: "4. " 11 | --- 12 | 13 | # Installing and running your first Space command 14 | 15 | Manual install can be performed by downloading the _release tarball_ and using _Space_ itself to install the release files on the system. This process does not perform any file integrity checks, neither does it verify _GPG_ signatures. 16 | 17 | The other method is performing the automatic install process by using the _Space_ installer script, which is automatically generated on every new _Space_ release to match the new version and new file hashes. This method automatically performs file integrity checks (shasum) on the downloaded files to ensure the files were not corrupted or modified before installing. 18 | 19 | Release files are expected to contain at least the following set of items: 20 | - `space-.tar.gz`: the release tarball 21 | - `space-.tar.gz.asc`: _GPG_ signature for the release tarball 22 | - `space-.sha`: _shasum_ hash for the release tarball 23 | - `space-.sha256`: _shasum_ hash for the release tarball 24 | - `space-.md5`: _MD5_ hash for the release tarball 25 | - `install-.sh`: installer script which installs the tarball automatically 26 | - `space-.md`: auto-generated code documentation 27 | 28 | Default _Space_ installs to `/usr/local/bin` that requires administrator rights in order to succeed. 29 | -------------------------------------------------------------------------------- /test/yaml/3/input.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | # Do some pre processing includes 21 | @a: Default value 22 | subdoc: 23 | hello: 24 | @a: @{1-@a} 25 | title: @{a} 26 | world: 27 | title: @{2} 28 | 29 | test: 30 | info: here comes a.yaml 31 | @include: a.yaml 32 | 33 | test0: 34 | info: here comes a.yaml|first 35 | @include: a.yaml|/first/ 36 | 37 | test1: 38 | info: here comes a.yaml|second 39 | @include: a.yaml|/second/ 40 | 41 | test2: 42 | info: here comes a.yaml|all 43 | @include: a.yaml|/all/ 44 | 45 | test3: 46 | info: here comes an iteration of a.yaml|all with added sub document. 47 | @include: a.yaml|/all/ 48 | hello: world 49 | good: stuff 50 | oodier: 51 | - aa: 11 52 | - bb: 22 53 | 54 | test4: 55 | info: | 56 | here comes an iteration of a.yaml|all with added sub include. 57 | Notice the args passed with the @include. o/ 58 | @DIRs: @{DIR} 59 | @include: a.yaml|/all/(firstarg secondarg) 60 | @include: @{DIRs}/input.yaml|/subdoc/(firstarg2@{PARENTPATH} secarg2@{PARENT}) 61 | -------------------------------------------------------------------------------- /test/test_build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # 3 | # Copyright 2016-2017 Blockie AB 4 | # 5 | # This file is part of Space. 6 | # 7 | # Space is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation version 3 of the License. 10 | # 11 | # Space is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Space. If not, see . 18 | # 19 | 20 | #====================== 21 | # Test Space build node 22 | # 23 | # Test Space base module 24 | # and make sure build process works 25 | # 26 | #====================== 27 | 28 | set -o nounset 29 | set -o pipefail 30 | 31 | if ! command -v docker >/dev/null; then 32 | printf "\033[35mDocker command is not available.\033[0m\n" 33 | exit 1 34 | else 35 | printf "\033[35mDocker command is available.\033[0m\n" 36 | fi 37 | 38 | CI_REGISTRY_IMAGE="docker.pkg.github.com/space-sh/space" 39 | IMAGE_VERSION="latest" 40 | 41 | cat ./test/build/check_base_binaries.sh | docker run --rm -i $CI_REGISTRY_IMAGE:$IMAGE_VERSION /bin/bash 42 | if [ "$?" -eq 0 ]; then 43 | printf "\033[32m[OK] Base binaries\033[0m\n" 44 | else 45 | printf "\033[31m[OK] Base binaries\033[0m\n" 46 | exit 1 47 | fi 48 | 49 | cat ./test/build/check_base_libraries.sh | docker run --rm -i $CI_REGISTRY_IMAGE:$IMAGE_VERSION /bin/bash 50 | if [ "$?" -eq 0 ]; then 51 | printf "\033[32m[OK] Base libraries\033[0m\n" 52 | else 53 | printf "\033[31m[ERROR] Base libraries\033[0m\n" 54 | exit 1 55 | fi 56 | -------------------------------------------------------------------------------- /doc/introduction-to-space/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Introduction to Space 3 | next: /why-space/ 4 | next_title: "Why Space" 5 | weight: 100 6 | giturl: github.com/space-sh/space 7 | editurl: /edit/master/doc/introduction-to-space/index.md 8 | icon: "1. " 9 | --- 10 | 11 | # Introduction to Space 12 | 13 | _Space.sh_, or simply _Space_, is an open source automation software for the _Internet of Things_ and digital life. 14 | 15 | _Space_ is a single-file, dependency-free, command-line program written in _Bash_ programming language. It offers a parser and preprocessor for creating and executing user-authored content described in a _YAML-like_ declarative language and shell scripts. 16 | 17 | _Space_ relies on base _UNIX-like_ command line utilities and offers users the ability to describe more complex behaviors and create reusable content called modules. _Space_ modules can be mixed and matched with each other and then exported as a _POSIX-compliant_ standalone application for sharing. 18 | One of _Space's_ most basic use-case is enabling infrastructure communication and automation. 19 | 20 | Other typical actions of _Space_: 21 | 1. Create a _Space_ module, or download an existing one, then run operations with a single command 22 | 2. Export an entire module or part of it as standalone program for sharing or replicating somewhere else 23 | 3. Create a new _Space_ module derived from an existing one 24 | 4. Run a _Space_ module operation wrapped around another Module's function, like a command line hook 25 | 26 | _Space_ was first publicly available on November 30th, 2016, and it is part of _Space.sh_. 27 | 28 | The next section talks about ["why"](../why-space/#content) _Space_ has been created, the reason behind it and project goals. 29 | For code examples, refer to [Installing and running your first Space command](../installing-and-running-your-first-space-command/#content) section. 30 | 31 | 32 | -------------------------------------------------------------------------------- /tools/bsdvm/02_bsdvm_run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # 3 | # Copyright 2016-2017 Blockie AB 4 | # 5 | # This file is part of Space. 6 | # 7 | # Space is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation version 3 of the License. 10 | # 11 | # Space is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Space. If not, see . 18 | # 19 | 20 | # 21 | # Run VM 22 | # 23 | 24 | if ! command -v VBoxManage >/dev/null; then 25 | printf "FAIL: VBoxManage program is required\n" 1>&2 26 | exit 1 27 | fi 28 | 29 | VBoxManage startvm SpaceBSD 30 | # shellcheck disable=2181 31 | if [ "$?" -ne 0 ]; then 32 | exit 1 33 | fi 34 | 35 | printf "\n===== INSTRUCTIONS =====\n\n Inside SpaceBSD (Guest): 36 | > login: root 37 | > 38 | # passwd 39 | # dhclient em0 40 | # pkg update 41 | # pkg install bash curl git 42 | # printf \"fdesc\\\t/dev/fd\\\\tfdescfs\\\trw\\\t0\\\t0\\\n\" >> /etc/fstab 43 | # echo sshd_enable=\\\"YES\\\" > /etc/rc.conf 44 | # echo ifconfig_em0=\\\"DHCP\\\" >> /etc/rc.conf 45 | # echo \"PasswordAuthentication yes\" >> /etc/ssh/sshd_config 46 | # echo \"PermitRootLogin yes\" >> /etc/ssh/sshd_config 47 | # service sshd start 48 | # shutdown -p now 49 | 50 | On host: 51 | $ VBoxManage startvm SpaceBSD --type headless 52 | $ ssh -p 2222 -o PubkeyAuthentication=no root@127.0.0.1 53 | 54 | Running Space tests inside the Guest OS: 55 | # ./test/test_all_exit_status.sh 56 | # ./test/test_install.sh 57 | # ./test/test_core.sh 58 | # ./test/test_function.sh 59 | # ./test/test_yaml.sh 60 | \n" 61 | 62 | -------------------------------------------------------------------------------- /tools/manpage_exporter/Spacefile.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _env: 20 | - MAN_NAME: "Space.sh Manual" 21 | - ORGANIZATION_NAME: ${ORGANIZATION_NAME-} 22 | - DATE_NOW: ${DATE_NOW-} 23 | 24 | _info: 25 | title: Man page exporter 26 | desc:| 27 | Exports Markdown documentation to roff man pages and HTML. 28 | man: 29 | _info: 30 | title: Export man page to roff format 31 | desc:| 32 | Takes a Markdown documentation as input, transforms it into a valid man page and exports as roff file. 33 | Parameters: 34 | 1: input Markdown documentation 35 | Example: 36 | ./space -f ./tools/manpage_exporter/Spacefile.yaml /man/ -- ./manuals/space.md 37 | _env: 38 | - RUN: _EXPORT_MAN 39 | 40 | html: 41 | _info: 42 | title: Export man page to HTML format 43 | desc:| 44 | Takes a Markdown documentation as input, transforms it into a valid man page and exports as HTML. 45 | Parameters: 46 | 1: input Markdown documentation 47 | Example: 48 | ./space -f ./tools/manpage_exporter/Spacefile.yaml /html/ -- ./manuals/space.md 49 | _env: 50 | - RUN: _EXPORT_HTML 51 | 52 | -------------------------------------------------------------------------------- /test/yaml/6/input.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | # Test @include from within multilines. 21 | str1: A string value 22 | str2: > 23 | A multiline 24 | value here 25 | @include: |/str1 26 | 27 | A: 28 | # Using regex is ok 29 | # ending with $ is recommended for "open" node paths. 30 | - final: |- 31 | @include: |/str.$ 32 | - o: 1 33 | final: >- 34 | @include: |/str1$ 35 | @include: |/str2$ 36 | - >- 37 | @include: |/str1$ 38 | @include: |/str2$ 39 | - |- 40 | @include: |/str1$ 41 | @include: |/str2$ 42 | - !nospace > 43 | @include: |/str1$ 44 | @include: |/str2$ 45 | B: 46 | b1: Another string 47 | b2: > 48 | More 49 | multiline 50 | strings 51 | b2: >- 52 | Even More 53 | multiline 54 | strings 55 | b3: | 56 | Further More 57 | multiline 58 | strings 59 | @include: |/str2$ 60 | b4: |- 61 | Much of More 62 | multiline 63 | strings 64 | @include: |/str1$ 65 | C: 66 | c1: | 67 | -- Here comes /A/.* 68 | @include: |/A/.* 69 | -- Here comes /B/.* 70 | @include: |/B/.* 71 | -- end 72 | -------------------------------------------------------------------------------- /test/function/test_spacefile.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | - BIN_PREFIX: "/usr/local" 22 | - AC_PREFIX: "/usr/share/bash-completion/completions" 23 | 24 | _info: 25 | title: Space.sh installer 26 | desc:| 27 | Provides system wide installation and Bash auto-completion setup. 28 | Provides an uninstall utility for listing files originally installed by Space. 29 | 30 | _dep_install: 31 | _info: 32 | title: Verify Space dependencies 33 | _env: 34 | - RUN: SPACE_DEP_INSTALL 35 | install: 36 | _info: 37 | title: Install Space.sh 38 | desc:| 39 | Perform Space.sh install. 40 | Parameters (both optional): 41 | 1: BIN_PREFIX which is where the program and man page will be installed. 42 | 2: AC_PREFIX where the auto completion will be installed. 43 | Example (using default values): 44 | ./space /install/ -- "/usr/local" "/usr/share/bash-completion/completions" 45 | _env: 46 | - RUN: SPACE_INSTALL 47 | 48 | uninstall: 49 | _info: 50 | title: Uninstall Space.sh 51 | desc:| 52 | Auto detects and lists all the files originally installed by Space.sh. 53 | _env: 54 | - RUN: SPACE_UNINSTALL 55 | 56 | -------------------------------------------------------------------------------- /test/yaml/6/output_X3.yaml: -------------------------------------------------------------------------------- 1 | A: 2 | 0: 3 | final: |- 4 | A string value 5 | A multiline 6 | value here 7 | A string value 8 | 1: 9 | final: A string value A multiline value here A string value 10 | o: 1 11 | 2: A string value A multiline value here A string value 12 | 3: |- 13 | A string value 14 | A multiline 15 | value here 16 | A string value 17 | 4: | 18 | A string valueA multilinevalue hereA string value 19 | B: 20 | b1: Another string 21 | b2: Even More multiline strings 22 | b3: | 23 | Further More 24 | multiline 25 | strings 26 | A multiline 27 | value here 28 | A string value 29 | b4: |- 30 | Much of More 31 | multiline 32 | strings 33 | A string value 34 | C: 35 | c1: | 36 | -- Here comes /A/.* 37 | A string value 38 | A multiline 39 | value here 40 | A string value 41 | 1 42 | A string value 43 | A multiline 44 | value here 45 | A string value 46 | A string value 47 | A multiline 48 | value here 49 | A string value 50 | A string value 51 | A multiline 52 | value here 53 | A string value 54 | A string value 55 | A multiline 56 | value here 57 | A string value 58 | -- Here comes /B/.* 59 | Another string 60 | More 61 | multiline 62 | strings 63 | Even More 64 | multiline 65 | strings 66 | Further More 67 | multiline 68 | strings 69 | A multiline 70 | value here 71 | A string value 72 | Much of More 73 | multiline 74 | strings 75 | A string value 76 | -- end 77 | str1: A string value 78 | str2: | 79 | A multiline value here A string value 80 | -------------------------------------------------------------------------------- /test/function/quicksort/test_quicksort.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _TEST_QUICKSORT() 20 | { 21 | SPACE_DEP="PRINT _quicksort _sort_pad" 22 | SPACE_ENV="_ALLOW_EXTERNAL" 23 | 24 | _ALLOW_EXTERNAL=0 25 | 26 | local _unsorted_array=("654" "2" "200000" "z" "c" "d" "y" "e" "zxczxcwqewqee" "dsijewr" "_ae" "_yo_namespace" "no_marrianne" "sq3" "paleo_chicken" "mc_R4men") 27 | local _sorted_array=("2" "654" "200000" "_ae" "_yo_namespace" "c" "d" "dsijewr" "e" "mc_R4men" "no_marrianne" "paleo_chicken" "sq3" "y" "z" "zxczxcwqewqee") 28 | local _quicksort_output=() 29 | 30 | # Store current locale settings 31 | local _unset_locale_flag=0 32 | local _stored_locale= 33 | if [ -z "${LC_ALL+unset}" ]; then 34 | _unset_locale_flag=1 35 | else 36 | _stored_locale="${LC_ALL}" 37 | fi 38 | # Set locale to get traditional sort order (bytes comparison) 39 | LC_ALL="C" 40 | 41 | _quicksort "${_unsorted_array[@]}" 42 | 43 | # Restore locale settings to their original state 44 | if [ "${_unset_locale_flag}" -eq "1" ]; then 45 | unset LC_ALL 46 | else 47 | LC_ALL="${_stored_locale}" 48 | fi 49 | 50 | if [[ "${_quicksort_output[*]}" == "${_sorted_array[*]}" ]]; then 51 | PRINT "_quicksort OK!" "ok" 52 | return 0 53 | else 54 | PRINT "_quicksort failed!" "error" 55 | return 1 56 | fi 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Spacefile.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | - BIN_PREFIX: "/usr/local" 22 | - AC_PREFIX: "/usr/share/bash-completion/completions" 23 | 24 | _info: 25 | title: Space.sh installer 26 | desc: | 27 | Provides system wide installation and Bash auto-completion setup. 28 | Provides an uninstall utility for listing files originally installed by Space. 29 | 30 | _dep_install: 31 | _info: 32 | title: Verify Space dependencies 33 | _env: 34 | - RUN: SPACE_DEP_INSTALL 35 | 36 | _build: 37 | _info: 38 | title: Build Space Docker image 39 | _env: 40 | - RUN: SPACE_BUILD 41 | 42 | install: 43 | _info: 44 | title: Install Space.sh 45 | desc: | 46 | Perform Space.sh install. 47 | Parameters (both optional): 48 | 1: BIN_PREFIX which is where the program and man page will be installed. 49 | 2: AC_PREFIX where the auto completion will be installed. 50 | Example (using default values): 51 | ./space /install/ -- "/usr/local" "/usr/share/bash-completion/completions" 52 | _env: 53 | - RUN: SPACE_INSTALL 54 | 55 | uninstall: 56 | _info: 57 | title: Uninstall Space.sh 58 | desc: | 59 | Auto detects and lists all the files originally installed by Space.sh. 60 | _env: 61 | - RUN: SPACE_UNINSTALL 62 | 63 | -------------------------------------------------------------------------------- /test/yaml/2/output_X3.yaml: -------------------------------------------------------------------------------- 1 | 0: 2 | elm1: 3 | elm2: data here 2 4 | elm3: "data here 3" 5 | 1: 6 | obj1: 7 | 0: 8 | Elm1: 9 | 1: 10 | Elm2: Data2 11 | obj2: 12 | 0: 13 | Elm3: Data3 14 | 1: 15 | Elm4: Data4 16 | 2: 17 | abcdef: 18 | 0: 19 | name: spaces stripped 20 | 1: ignored:no it becomes an indexed array value. 21 | 3: 22 | OK: some text 23 | OK2: | 24 | One row, 25 | two rows. 26 | OK3: | 27 | One row, still one row. 28 | 4: 29 | OK4: Yes! 30 | OK4a: 31 | 0: 32 | 1: 33 | 2: Spaces removed. index 2. 34 | 3: "Astro Physics" 35 | 4: | 36 | Multiline 37 | right here, 38 | thanks. 39 | 5: Old school. 40 | 6: Great school. 41 | 7: Astro School. 42 | 8: | 43 | Gotta love these collapsed lines. 44 | 9: 45 | 0: 46 | A: Aaa 47 | A2: A2aa 48 | 1: 49 | B: Bbb 50 | 10: 51 | 0: 52 | 0: 53 | 0: Come on 54 | 1: Let's go 55 | 1: Where too? 56 | _env: 57 | 0: 58 | CMD2: something more 59 | CMD3: "" 60 | RUN: here it is 61 | 1: 62 | PIPE: input comes from here 63 | 2: 64 | A: 65 | B: my data is visible 66 | 3: 67 | A: my data is visible 68 | B: my data is visible 69 | 4: 70 | A: hej 71 | B: hej 72 | 5: 73 | A: san 74 | B: san 75 | 6: 76 | WRAPCMD: "" 77 | 7: 78 | STDIN: /dev/stdin 79 | 9999: 80 | RUN: OK prio 81 | hej: 82 | 0: 83 | a: Testing syntax 84 | 1: 85 | b: Works 86 | 2: 87 | c: great. 88 | hej2: 89 | 0: 90 | A: More syntax. 91 | 1: 92 | B: B 93 | 2: 94 | C: | 95 | One row, 96 | two rows. 97 | names: 98 | 0: Mary Smith 99 | 1: "Ester J:son" 100 | 2: John Smith 101 | 3: Susan Williams 102 | 4: Bill Jones 103 | strange_place: indeed 104 | -------------------------------------------------------------------------------- /doc/space-modules/running-a-space-module.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: ../what-are-space-modules/ 3 | prev_title: "What are Space Modules" 4 | next: ../how-space-modules-work/ 5 | next_title: "How Space Modules work" 6 | title: Running a Space module 7 | giturl: github.com/space-sh/space 8 | editurl: /edit/master/doc/space-modules/running-a-space-module.md 9 | weight: 503 10 | --- 11 | 12 | # Running a Space module 13 | 14 | _Space_ modules are run following the command format: 15 | 16 | ```sh 17 | space -m [reponame] /[nodename]/ -- [arguments] 18 | ``` 19 | 20 | The following example describes a new module that runs a shell script function when called. 21 | Before running the module, create the following files: `Spacefile.yaml` and `Spacefile.sh`. 22 | 23 | Spacefile.yaml: 24 | 25 | ```yaml 26 | _env: 27 | - RUN: MY_FUNCTION 28 | ``` 29 | 30 | Spacefile.sh: 31 | 32 | ```yaml 33 | MY_FUNCTION() 34 | { 35 | printf "Hello from MY_FUNCTION\n" 36 | } 37 | ``` 38 | 39 | Now run `space -f Spacefile.yaml`. This is the same as running `space` without specifying a YAML file because `Spacefile.yaml` is the default file name (implicit module loading). _Space_ will then look for the accompanied `.sh` or `.bash` file, in this case `Spacefile.sh`, for loading the code 40 | 41 | 42 | #### Where to look for existing Space Modules? 43 | Official core Modules are located at [https://github.com/space-sh](https://github.com/space-sh). 44 | 45 | 46 | #### Downloading and running a Space Module 47 | Let's run the core Module named `os`, located at [https://github.com/space-sh/os](https://github.com/space-sh/os). Its description says: 48 | 49 | >Space.sh module to handle operating system tasks such as user processes, packages and services management 50 | 51 | Now run: 52 | 53 | ```sh 54 | space -m os /info/ 55 | ``` 56 | 57 | The previous command reads as follows: 58 | 59 | >Tell Space program to run module named `os` and run node named `info` 60 | 61 | Nodes are the units in which the Module hierarchy are laid out. Whenever creating a new Module function, a YAML node will be required for exposing public functionality. 62 | 63 | Module hierarchy, nodes and more are explained in depth in section _How Space Modules work_ 64 | -------------------------------------------------------------------------------- /test/yaml/6/output_X1.yaml: -------------------------------------------------------------------------------- 1 | str1: A string value 2 | str2: > 3 | A multiline 4 | value here 5 | A string value 6 | A: 7 | - final: |- 8 | A string value 9 | A multiline 10 | value here 11 | A string value 12 | - o: 1 13 | final: >- 14 | A string value 15 | A multiline 16 | value here 17 | A string value 18 | - >- 19 | A string value 20 | A multiline 21 | value here 22 | A string value 23 | - |- 24 | A string value 25 | A multiline 26 | value here 27 | A string value 28 | - !nospace > 29 | A string value 30 | A multiline 31 | value here 32 | A string value 33 | B: 34 | b1: Another string 35 | b2: > 36 | More 37 | multiline 38 | strings 39 | b2: >- 40 | Even More 41 | multiline 42 | strings 43 | b3: | 44 | Further More 45 | multiline 46 | strings 47 | A multiline 48 | value here 49 | A string value 50 | b4: |- 51 | Much of More 52 | multiline 53 | strings 54 | A string value 55 | C: 56 | c1: | 57 | -- Here comes /A/.* 58 | A string value 59 | A multiline 60 | value here 61 | A string value 62 | 1 63 | A string value 64 | A multiline 65 | value here 66 | A string value 67 | A string value 68 | A multiline 69 | value here 70 | A string value 71 | A string value 72 | A multiline 73 | value here 74 | A string value 75 | A string value 76 | A multiline 77 | value here 78 | A string value 79 | -- Here comes /B/.* 80 | Another string 81 | More 82 | multiline 83 | strings 84 | Even More 85 | multiline 86 | strings 87 | Further More 88 | multiline 89 | strings 90 | A multiline 91 | value here 92 | A string value 93 | Much of More 94 | multiline 95 | strings 96 | A string value 97 | -- end 98 | -------------------------------------------------------------------------------- /bump_version.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # 3 | # Copyright 2016-2017 Blockie AB 4 | # 5 | # This file is part of Space. 6 | # 7 | # Space is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation version 3 of the License. 10 | # 11 | # Space is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Space. If not, see . 18 | # 19 | 20 | # 21 | # Bump Space version 22 | # 23 | 24 | set -o errexit 25 | set -o nounset 26 | 27 | 28 | # 29 | # Check arguments 30 | if [ "$#" -lt 1 ]; then 31 | printf "Missing version name. Example: $0 1.0.0\n" >&2 32 | fi 33 | 34 | # 35 | # Check requirements 36 | if ! command -v sed >/dev/null; then 37 | printf "Missing sed program. Exiting...\n" >&2 38 | exit 1 39 | fi 40 | 41 | # 42 | # Data 43 | _current_version_name=$(./space -V 2>&1) 44 | for token in $_current_version_name; do # Get only version numbert 45 | _current_version_name=$token 46 | done 47 | _version_name="$1" 48 | _version_date=$(date "+%Y-%m-%d") 49 | 50 | # 51 | # Files to change 52 | _changelog_file="./CHANGELOG.md" 53 | _readme_file="./README.md" 54 | _space_file="./space" 55 | _installsh_file="./tools/installer/install.sh" 56 | 57 | # Update files 58 | sed -i.bak "s/\[current\]/\[${_version_name} - ${_version_date}\]/" "$_changelog_file" 59 | sed -i.bak "s/${_current_version_name}/${_version_name}/g" "$_readme_file" 60 | sed -i.bak "s/readonly \_VERSION\=\"${_current_version_name}\"/readonly \_VERSION\=\"${_version_name}\"/g" "$_space_file" 61 | sed -i.bak "s/\_version\=\"${_current_version_name}\"/\_version\=\"${_version_name}\"/g" "$_installsh_file" 62 | 63 | # 64 | # Cleanup temporary files 65 | if [ -f "$_changelog_file" ]; then 66 | rm "${_changelog_file}.bak" 67 | fi 68 | 69 | if [ -f "$_readme_file" ]; then 70 | rm "${_readme_file}.bak" 71 | fi 72 | 73 | if [ -f "$_space_file" ]; then 74 | rm "${_space_file}.bak" 75 | fi 76 | 77 | if [ -f "$_installsh_file" ]; then 78 | rm "${_installsh_file}.bak" 79 | fi 80 | 81 | 82 | -------------------------------------------------------------------------------- /tools/bsdvm/00_bsdvm_fetch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # 3 | # Copyright 2016-2017 Blockie AB 4 | # 5 | # This file is part of Space. 6 | # 7 | # Space is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation version 3 of the License. 10 | # 11 | # Space is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Space. If not, see . 18 | # 19 | 20 | # 21 | # Download and extract BSD VM image 22 | # 23 | 24 | # 25 | # Check required programs 26 | if ! command -v curl >/dev/null; then 27 | printf "FAIL: curl program is required\n" 1>&2 28 | exit 1 29 | fi 30 | 31 | if ! command -v xz >/dev/null; then 32 | printf "FAIL: xz program is required\n" 1>&2 33 | exit 1 34 | fi 35 | 36 | # 37 | # Setup URL and file name 38 | _bsd_image_base_url="ftp://ftp.freebsd.org/pub/FreeBSD/releases/VM-IMAGES/11.2-RELEASE/amd64/Latest/" 39 | _bsd_image_name="FreeBSD-11.2-RELEASE-amd64.vhd" 40 | _bsd_image_name_compressed="${_bsd_image_name}.xz" 41 | 42 | # 43 | # Check file is available and download it if needed 44 | if [ ! -f "./${_bsd_image_name_compressed}" ]; then 45 | printf "Image file %s was not found. Downloading from %s...\n" "${_bsd_image_name_compressed}" "${_bsd_image_base_url}" 1>&2 46 | curl -O "${_bsd_image_base_url}${_bsd_image_name_compressed}" 47 | _exit_code="$?" 48 | if [ "$_exit_code" -ne 0 ]; then 49 | printf "Failed to curl %s from %s. Returned %s\n" "${_bsd_image_name_compressed}" "${_bsd_image_base_url}" "$_exit_code" 1>&2 50 | exit "$_exit_code" 51 | fi 52 | fi 53 | 54 | 55 | # 56 | # FIXME: missing file integrity check around here 57 | 58 | # 59 | # Extract file image 60 | xz --verbose --decompress "${_bsd_image_name_compressed}" 61 | _exit_code="$?" 62 | if [ "$_exit_code" -ne 0 ]; then 63 | printf "Failed to extract %s. Returned %s\n" "${_bsd_image_name_compressed}" "$_exit_code" 1>&2 64 | exit "$_exit_code" 65 | else 66 | if [ -f "${_bsd_image_name}" ]; then 67 | printf "%s\n" "${_bsd_image_name}" 68 | exit 0 69 | fi 70 | fi 71 | 72 | -------------------------------------------------------------------------------- /test/function/helpusage/test_helpusage.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _TEST_HELPUSAGE() 20 | { 21 | SPACE_DEP="PRINT _helpusage" 22 | SPACE_ENV="_USAGE" 23 | 24 | local _tmp_file_name="./tmp_test_helpusage" 25 | 26 | # 27 | # Create temporary file 28 | 29 | # Make sure it doesn't already exist 30 | if [ -f "$_tmp_file_name" ]; then 31 | PRINT "File $_tmp_file_name already exists. That was unexpected!" "error" 32 | return 1 33 | fi 34 | 35 | # Create 36 | touch "$_tmp_file_name" 37 | 38 | # Make sure it was indeed created 39 | if [ ! -f "$_tmp_file_name" ]; then 40 | PRINT "Failed to create temporary file needed for testing" "error" 41 | return 1 42 | fi 43 | 44 | PRINT "Calling _helpusage..." 45 | # Redirect stderr to file 46 | _helpusage 2> "$_tmp_file_name" 47 | PRINT "Checking if it generated any output..." 48 | 49 | # Check if file size is >0 50 | if [ ! -s "$_tmp_file_name" ]; then 51 | PRINT "_helpusage FAILED!" "error" 52 | 53 | # Remove tmp file 54 | rm "$_tmp_file_name" 55 | return 1 56 | else 57 | # Check if file contains some manually picked strings 58 | local _count1=$(grep -c "Blockie AB" "${_tmp_file_name}") 59 | local _count2=$(grep -c "Usage:" "${_tmp_file_name}") 60 | PRINT "Trying to look for predefined strings..." 61 | if [ "$_count1" -gt 0 ] && [ "$_count2" -gt 0 ]; then 62 | PRINT "_helpusage OK!" "ok" 63 | # remove tmp file 64 | rm "$_tmp_file_name" 65 | return 0 66 | else 67 | PRINT "_helpusage failed!" "error" 68 | # remove tmp file 69 | rm "$_tmp_file_name" 70 | return 2 71 | fi 72 | fi 73 | } 74 | 75 | -------------------------------------------------------------------------------- /test/function/helpversion/test_helpversion.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _TEST_HELPVERSION() 20 | { 21 | SPACE_DEP="PRINT _helpversion" 22 | SPACE_ENV="_VERSION" 23 | 24 | local _tmp_file_name="./tmp_test_helpversion" 25 | 26 | # 27 | # Create temporary file 28 | 29 | # Make sure it doesn't already exist 30 | if [ -f "$_tmp_file_name" ]; then 31 | PRINT "File $_tmp_file_name already exists. That was unexpected!" "error" 32 | return 1 33 | fi 34 | 35 | # Create 36 | touch "$_tmp_file_name" 37 | 38 | # Make sure it was indeed created 39 | if [ ! -f "$_tmp_file_name" ]; then 40 | PRINT "Failed to create temporary file needed for testing" "error" 41 | return 1 42 | fi 43 | 44 | PRINT "Calling _helpversion..." 45 | # Redirect expected stderr to file 46 | _helpversion 2> "$_tmp_file_name" 47 | PRINT "Checking if it generated any output..." 48 | 49 | # Check if file size is > 0 50 | if [ ! -s "$_tmp_file_name" ]; then 51 | PRINT "_helpversion FAILED!" "error" 52 | 53 | # Remove tmp file 54 | rm "$_tmp_file_name" 55 | return 1 56 | else 57 | # Read first line of file 58 | local _version="0" 59 | read -r _version<"$_tmp_file_name" 60 | PRINT "version=[$_version]" 61 | 62 | # Check version indeed matches a version pattern 63 | PRINT "Trying to match results with expected version format..." 64 | if [[ "$_version" =~ ^(Space )+[0-9]+\.[0-9]+\.[0-9] ]]; then 65 | PRINT "_helpversion OK!" "ok" 66 | # remove tmp file 67 | rm "$_tmp_file_name" 68 | return 0 69 | else 70 | PRINT "_helpversion failed!" "error" 71 | # remove tmp file 72 | rm "$_tmp_file_name" 73 | return 2 74 | fi 75 | fi 76 | } 77 | 78 | -------------------------------------------------------------------------------- /tools/spacedoc/README.md: -------------------------------------------------------------------------------- 1 | # Spacedoc 2 | 3 | Spacedoc is a module for Space.sh that generates Markdown and HTML documentation based on code comments surrounding global variables and procedures in shell scripts. 4 | 5 | 6 | ## Dependencies 7 | Bash, cat, date, echo and rm. 8 | 9 | Optionally requires `Markdown.pl` for exporting the HTML documentation, which can be downloaded from: [http://daringfireball.net/projects/downloads/Markdown_1.0.1.zip](http://daringfireball.net/projects/downloads/Markdown_1.0.1.zip) 10 | 11 | 12 | ## Usage 13 | 14 | ### Comments: Marking code 15 | 16 | Code documentation is based on global variables, constants and functions. 17 | Comments on top of globals are exported as formatted code documentation. Example: 18 | ```sh 19 | # Check the Git url to clone or update against the banlist. 20 | # 0=do not check at all 21 | # 1=check and accept "unknown" and "non banned" modules. 22 | # 2=check and require "trusted" status for module. 23 | _SECURITY_CHECK_BANNED=1 24 | ``` 25 | 26 | Function comments support more complex descriptions. Format is the function name in the first line, followed by a full description and specific sections: Example, Parameters, Expects and Returns. 27 | Example: 28 | ```sh 29 | #========== 30 | # _pp_yaml 31 | # 32 | # Preprocess YAML 33 | # 34 | # Parameters: 35 | # $1: name of variable to store result in. 36 | # $2: filepath to read YAML from. 37 | # $3: filter 38 | # $4: subdoc 39 | # $5-x: preprocess variable value assigned to @1, etc. 40 | # 41 | # Expects: 42 | # _yamlfilelist 43 | # _SPACEGAL_EOF_TAG 44 | # _CACHE_LEVEL 45 | # 46 | # Returns: 47 | # 1 if YAML file not found. 48 | # 2 if recursion error occurred. 49 | # 3 if failed to clone modules 50 | # 4 if assertion failure was triggered. 51 | # 52 | #========== 53 | _pp_yaml() 54 | { 55 | local _varname=$1 56 | shift 57 | #.. 58 | } 59 | ``` 60 | 61 | ### Generating documentation 62 | It is possible to generate a complete Table of Contents (TOC) automatically by setting the environment variable GENERATE_TOC=1 when running the command. 63 | ``` 64 | GENERATE_TOC=1 space /markdown/ -- 65 | ``` 66 | 67 | Generate Markdown documentation for some `input_file`: 68 | ``` 69 | space -f ./tools/spacedoc/Spacefile.yaml /markdown/ -- 70 | ``` 71 | 72 | Generate Markdown and HTML documentation for some `input_file`: 73 | ``` 74 | space -f ./tools/spacedoc/Spacefile.yaml /html/ -- 75 | ``` 76 | 77 | It is also possible to use the short implicit form when calling from the spacedoc directory: 78 | ``` 79 | space /markdown/ -- 80 | ``` 81 | 82 | 83 | -------------------------------------------------------------------------------- /doc/installing-and-running-your-first-space-command/installing-from-latest-tarball.md: -------------------------------------------------------------------------------- 1 | --- 2 | prev: ../ 3 | prev_title: "Installing and running your first Space command" 4 | next: ../installing-current-version-from-source-control-repository/ 5 | next_title: "Installing current version from source control repository" 6 | title: Installing from latest tarball 7 | toc: true 8 | giturl: github.com/space-sh/space 9 | editurl: /edit/master/doc/installing-and-running-your-first-space-command/installing-from-latest-tarball.md 10 | weight: 401 11 | --- 12 | 13 | # Installing from latest tarball 14 | 15 | Follow the example code below for downloading, extracting, verifying _GPG_ signature and performing file integrity checks. 16 | 17 | ```sh 18 | curl -O https://space.sh/static/download/space-0.12.0/space-0.12.0.tar.gz 19 | curl -O https://space.sh/static/download/space-0.12.0/space-0.12.0.tar.gz.asc 20 | curl -O https://space.sh/static/download/space-0.12.0/space-0.12.0.sha 21 | curl -O https://space.sh/static/download/space-0.12.0/space-0.12.0.sha256 22 | curl -O https://space.sh/static/download/space-0.12.0/space-0.12.0.md5 23 | curl -O https://space.sh/static/download/space-0.12.0/install-0.12.0.sh 24 | ``` 25 | 26 | #### Verifying package _GPG_ signature 27 | This step is not required for installing _Space_, hence it is optional. 28 | Releases are signed either by one of the following keys: 29 | 30 | - Thomas Backlund 31 | - **Fingerprint**: `CEE9 3024 3EBA C1B1 D08A B73D 3611 E9C2 4F6C 6E63` 32 | - **Key**: [blund-3611E9C24F6C6E63.asc](https://gitlab.com/space-sh/space/snippets/32500/raw) 33 | - Maicon Diniz Filippsen 34 | - **Fingerprint**: `295E 7B7B 14D8 8EEC 62E7 FBB1 DC8D 6348 0F72 A139` 35 | - **Key**: [filippsen-DC8D63480F72A139.asc](https://gitlab.com/space-sh/space/snippets/32501/raw) 36 | 37 | 38 | It is then possible to verify the release signatures using the following command: 39 | 40 | ```sh 41 | gpg --verify space-0.12.0.tar.gz.asc space-0.12.0.tar.gz 42 | ``` 43 | 44 | #### Performing package integrity check. 45 | This step is not required for installing _Space_, hence it is optional. 46 | Each release provides more than one way to verify file integrity, along with _GPG_ verification. 47 | Current generated hashes are: _SHA1_, _SHA256_ and _MD5_. 48 | 49 | Example checking _SHA256_: 50 | 51 | ```sh 52 | sha256sum -c space-0.12.0.sha256 53 | space-0.12.0.tar.gz: OK 54 | ``` 55 | 56 | #### Installing from tarball 57 | After extracting the files use _Space_ for installing itself on the system: 58 | 59 | ```sh 60 | ./space /install/ 61 | ``` 62 | 63 | or use the `install-.sh` file and manually call it: 64 | 65 | ```sh 66 | sh install-.sh 67 | ``` 68 | -------------------------------------------------------------------------------- /tools/spacedoc/Spacefile.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | - GENERATE_TOC: ${GENERATE_TOC-0} 22 | - GENERATE_VARIABLES: ${GENERATE_VARIABLES-1} 23 | 24 | _info: 25 | title: Spacedoc: code documentation exporter 26 | desc:| 27 | Exports code documentation from shell script source files. 28 | 29 | markdown: 30 | _info: 31 | title: Generate code documentation and export as a Markdown file 32 | desc:| 33 | Takes a shell script code as input, parse all its comments and generate a 34 | Markdown formatted documentation file in the current directory as result. 35 | If GENERATE_TOC environment variable is set to 1, documentation will 36 | automatically generate and include table of contents section. 37 | If GENERATE_VARIABLES environment variable is set to 0, documentation will 38 | not export the Variables section. 39 | Parameters: 40 | 1: input shell script 41 | Example: 42 | ./space -f ./tools/spacedoc/Spacefile.yaml /markdown/ -- ./space 43 | _env: 44 | - RUN: _EXPORT_MARKDOWN 45 | 46 | html: 47 | _info: 48 | title: Generate code documentation and export as a Markdown and HTML files 49 | desc:| 50 | Takes a shell script code as input, parse all its comments and generate a 51 | Markdown formatted documentation file, including a copy as HTML, in the 52 | current directory as result. 53 | If GENERATE_TOC environment variable is set to 1, documentation will 54 | automatically generate and include table of contents section. 55 | If GENERATE_VARIABLES environment variable is set to 0, documentation will 56 | not export the Variables section. 57 | Parameters: 58 | 1: input shell script 59 | Example: 60 | ./space -f ./tools/spacedoc/Spacefile.yaml /html/ -- ./space 61 | 62 | _env: 63 | - RUN: _EXPORT_HTML 64 | -------------------------------------------------------------------------------- /test/yaml/test.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | #======================= 20 | # _CHECK_EXIT_STATUS 21 | # 22 | # Check for status code and increment a counter on error 23 | # 24 | # Parameters: 25 | # $1: the status code to check 26 | # 27 | # Expects: 28 | # _exit_status 29 | # 30 | #======================= 31 | _CHECK_EXIT_STATUS() 32 | { 33 | local _status_code="$1" 34 | 35 | if [ "$_status_code" -gt 0 ]; then 36 | PRINT " Failed!" "error" 37 | 38 | # Update exit counter. Cap to 255 to prevent the value wrapping back 39 | if [ "$_exit_status" -lt 255 ]; then 40 | _exit_status=$((_exit_status + 1 )) 41 | fi 42 | else 43 | PRINT " [OK!]" "ok" 44 | fi 45 | 46 | } 47 | 48 | _PARSE_YAML() 49 | { 50 | # External 51 | SPACE_DEP="PRINT _CHECK_EXIT_STATUS" 52 | 53 | DIFF_BIN=diff 54 | 55 | if [ ! -d "./test" ] && [ ! -f "./space" ]; then 56 | PRINT "Tests must be performed from space root development directory" "error" 57 | return 58 | fi 59 | 60 | # Loop through all subdirs for testing 61 | local _exit_status=0 62 | for _dir_name in ./test/yaml/* ; do 63 | if [ -d "$_dir_name" ]; then 64 | PRINT "Performing test: \"$_dir_name\" *" 65 | 66 | PRINT " X1: preprocess step" 67 | ./space -C0 -f ./"$_dir_name"/input.yaml -X1 | \ 68 | $DIFF_BIN - ./"$_dir_name"/output_X1.yaml 69 | _CHECK_EXIT_STATUS "$?" 70 | 71 | PRINT " X2: parse step" 72 | ./space -C0 -f ./"$_dir_name"/input.yaml -X2 | \ 73 | $DIFF_BIN - ./"$_dir_name"/output_X2.yaml 74 | _CHECK_EXIT_STATUS "$?" 75 | 76 | PRINT " X3: transform step" 77 | ./space -C0 -f ./"$_dir_name"/input.yaml -X3 | \ 78 | $DIFF_BIN - ./"$_dir_name"/output_X3.yaml 79 | _CHECK_EXIT_STATUS "$?" 80 | 81 | PRINT " X4: env eval step" 82 | ./space -C0 -f ./"$_dir_name"/input.yaml -X4 | \ 83 | $DIFF_BIN - ./"$_dir_name"/output_X4.yaml 84 | _CHECK_EXIT_STATUS "$?" 85 | 86 | PRINT "" 87 | fi 88 | done 89 | 90 | return "$_exit_status" 91 | } 92 | 93 | -------------------------------------------------------------------------------- /test/test_shebang_bsd.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2016-2017 Blockie AB 4 | # 5 | # This file is part of Space. 6 | # 7 | # Space is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation version 3 of the License. 10 | # 11 | # Space is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Space. If not, see . 18 | # 19 | 20 | #====================== 21 | # Test Space shebang line 22 | # OSX/BSD style. 23 | # 24 | #====================== 25 | set -o nounset 26 | 27 | #====================== 28 | # _CHECK_CONTAINS 29 | # 30 | # Checks if a piece of data is part of a bigger string 31 | # 32 | # Parameters: 33 | # 1: the string to find 34 | # 2: the data to check against 35 | # 36 | # Returns: 37 | # 1 if it finds a match 38 | # 39 | #====================== 40 | _CHECK_CONTAINS() 41 | { 42 | local _contains="$1" 43 | local _string="$2" 44 | if [ -z "${_string##*$_contains*}" ]; then 45 | return 1 46 | else 47 | return 0 48 | fi 49 | } 50 | 51 | #====================== 52 | # _RUN_CHECK_FAIL 53 | # 54 | # Wraps a Space command line call for testing 55 | # 56 | # Note: 57 | # Avoiding command substitution and subshelling while still 58 | # providing full command call via parameters. 59 | # Makes it so that the test toolset can keep track of function calls. 60 | # 61 | # Parameters: 62 | # 1: message describing what the check is about 63 | # 2: expected message on stdout/err 64 | # 3: command line to test 65 | #====================== 66 | _RUN_CHECK_FAIL() 67 | { 68 | local _message_description=$1 69 | shift 70 | local _expected_message=$1 71 | shift 72 | local _command_line=$@ 73 | local _status= 74 | local _output= 75 | 76 | _output=$($_command_line 2>&1) 77 | _status="$?" 78 | if [ "$_status" -ne 0 ]; then 79 | _CHECK_CONTAINS "$_expected_message" "$_output" 80 | if [ "$?" -eq 1 ]; then 81 | printf "\033[32m[OK] %s\033[0m\n" "$_message_description" 82 | else 83 | printf "\033[31m[ERROR] %s\n\tCommand: \"%s\"\n\tExpected output to contain: \"%s\"\n\tOutput: \"%s\"\033[0m\n" "$_message_description" "$_command_line" "$_expected_message" "$_output" 84 | exit 1 85 | fi 86 | else 87 | printf "\033[31m[ERROR] %s\n\tCommand: \"%s\"\n\tFailed with exit status (%s)\n\tOutput: \"%s\"\033[0m\n" "$_message_description" "$_command_line" "$_status" "$_output" 88 | exit 1 89 | fi 90 | } 91 | 92 | _RUN_CHECK_FAIL "Test shebang line" "Wait for files timeouted after 2 seconds" ./test/exit_status_cases/shebang_bsd.sh -m docker /run_wrap/ -- 2 93 | -------------------------------------------------------------------------------- /test/test_shebang_linux.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2016-2017 Blockie AB 4 | # 5 | # This file is part of Space. 6 | # 7 | # Space is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation version 3 of the License. 10 | # 11 | # Space is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Space. If not, see . 18 | # 19 | 20 | #====================== 21 | # Test Space shebang line 22 | # Linux style 23 | # 24 | #====================== 25 | set -o nounset 26 | 27 | #====================== 28 | # _CHECK_CONTAINS 29 | # 30 | # Checks if a piece of data is part of a bigger string 31 | # 32 | # Parameters: 33 | # 1: the string to find 34 | # 2: the data to check against 35 | # 36 | # Returns: 37 | # 1 if it finds a match 38 | # 39 | #====================== 40 | _CHECK_CONTAINS() 41 | { 42 | local _contains="$1" 43 | local _string="$2" 44 | if [ -z "${_string##*$_contains*}" ]; then 45 | return 1 46 | else 47 | return 0 48 | fi 49 | } 50 | 51 | #====================== 52 | # _RUN_CHECK_FAIL 53 | # 54 | # Wraps a Space command line call for testing 55 | # 56 | # Note: 57 | # Avoiding command substitution and subshelling while still 58 | # providing full command call via parameters. 59 | # Makes it so that the test toolset can keep track of function calls. 60 | # 61 | # Parameters: 62 | # 1: message describing what the check is about 63 | # 2: expected message on stdout/err 64 | # 3: command line to test 65 | #====================== 66 | _RUN_CHECK_FAIL() 67 | { 68 | local _message_description=$1 69 | shift 70 | local _expected_message=$1 71 | shift 72 | local _command_line=$@ 73 | local _status= 74 | local _output= 75 | 76 | _output=$($_command_line 2>&1) 77 | _status="$?" 78 | if [ "$_status" -ne 0 ]; then 79 | _CHECK_CONTAINS "$_expected_message" "$_output" 80 | if [ "$?" -eq 1 ]; then 81 | printf "\033[32m[OK] %s\033[0m\n" "$_message_description" 82 | else 83 | printf "\033[31m[ERROR] %s\n\tCommand: \"%s\"\n\tExpected output to contain: \"%s\"\n\tOutput: \"%s\"\033[0m\n" "$_message_description" "$_command_line" "$_expected_message" "$_output" 84 | exit 1 85 | fi 86 | else 87 | printf "\033[31m[ERROR] %s\n\tCommand: \"%s\"\n\tFailed with exit status (%s)\n\tOutput: \"%s\"\033[0m\n" "$_message_description" "$_command_line" "$_status" "$_output" 88 | exit 1 89 | fi 90 | } 91 | 92 | _RUN_CHECK_FAIL "Test shebang line" "Wait for files timeouted after 2 seconds" ./test/exit_status_cases/shebang_linux.sh -m docker /run_wrap/ -- 2 93 | -------------------------------------------------------------------------------- /test/yaml/2/input.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | # A very advanced yaml structure. 21 | _env: 22 | - RUN: here it is 23 | CMD2: something more 24 | CMD3: "" 25 | - PIPE: input comes from here 26 | 27 | - elm1: 28 | elm2: data here 2 29 | elm3: "data here 3" 30 | - 31 | obj1: 32 | - Elm1: 33 | - Elm2: Data2 34 | obj2: 35 | - Elm3: Data3 36 | - Elm4: Data4 37 | _env: 38 | # var set but empty 39 | @var: 40 | @a: my data 41 | - A: @{var-@{a} not visible} 42 | B: @{var:-@{a} is visible} 43 | # unset var, due to no trailing space(s) (cowboy space(s)). 44 | @var: 45 | - A: @{var-@{a} is visible} 46 | B: @{var:-@{a} is visible} 47 | @var:- hej 48 | - A: @{var-@{a} is visible} 49 | B: @{var:-@{a} is visible} 50 | @var:+ san 51 | - A: @{var-@{a} is visible} 52 | B: @{var:-@{a} is visible} 53 | - WRAPCMD: "" 54 | - STDIN: /dev/stdin 55 | 56 | - abcdef: 57 | - name: spaces stripped 58 | - ignored:no it becomes an indexed array value. 59 | -ignored:indeed, simply malformed. 60 | 61 | - OK: some text 62 | OK2: | 63 | One row, 64 | two rows. 65 | OK3: > 66 | One row, 67 | still one row. 68 | 69 | strange_place: indeed 70 | 71 | hej: 72 | - a: Testing syntax 73 | - b: Works 74 | - c: great. 75 | 76 | hej2: 77 | - A: More syntax. 78 | - B: B 79 | - C: | 80 | One row, 81 | two rows. 82 | 83 | - OK4: Yes! 84 | OK4a: 85 | # not ignored, even though no trailing space 86 | - 87 | # Not ignored, trailing space. 88 | - 89 | - Spaces removed. index 2. 90 | - "Astro Physics" 91 | - | 92 | Multiline 93 | right here, 94 | thanks. 95 | 96 | # Numeric index 97 | - Old school. 98 | - Great school. 99 | - Astro School. 100 | - > 101 | Gotta love these 102 | collapsed lines. 103 | 104 | - 105 | - A: Aaa 106 | A2: A2aa 107 | - B: Bbb 108 | - 109 | - 110 | - 111 | - Come on 112 | - Let's go 113 | - Where too? 114 | 115 | names: 116 | - Mary Smith 117 | - "Ester J:son" 118 | names: 119 | - John Smith 120 | - Susan Williams 121 | - Bill Jones 122 | _env: 123 | 9999: 124 | RUN: OK prio 125 | -------------------------------------------------------------------------------- /tools/static_analysis/Spacefile.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | --- 20 | _env: 21 | 22 | _info: 23 | title: Static analysis 24 | desc:| 25 | Performs static analysis on shell scripts using external tools. 26 | 27 | shellcheck: 28 | _info: 29 | title: Run shellcheck against a shell script 30 | desc:| 31 | Takes a shell script code as input, run shellcheck analysis and output results to a file. 32 | Parameters: 33 | 1: input shell script to analyze 34 | 2: output file 35 | Example: 36 | ./space -f ./tools/static_analysis/Spacefile.yaml /shellcheck/ -- "space" "checks.txt" 37 | _env: 38 | - RUN: _RUN_SHELLCHECK 39 | 40 | checkbashisms: 41 | _info: 42 | title: Run checkbashisms against a shell script 43 | desc:| 44 | Takes a shell script code as input, run checkbashisms analysis and output results to a file. 45 | Parameters: 46 | 1: input shell script to analyze 47 | 2: output file 48 | Example: 49 | ./space -f ./tools/static_analysis/Spacefile.yaml /checkbashisms/ -- "space" "bashisms.txt" 50 | _env: 51 | - RUN: _RUN_CHECKBASHISMS 52 | 53 | all: 54 | _info: 55 | title: Run all static analysis tools against a shell script 56 | desc:| 57 | Takes a shell script code as input, run all static analysis tools available and output results to one separate file for each analysis. 58 | Parameters: 59 | 1: input shell script to analyze 60 | 2: output file suffix where results will be saved to. 61 | Example: 62 | ./space -f ./tools/static_analysis/Spacefile.yaml /all/ -- "space" "results" 63 | _env: 64 | - RUN: _RUN_ALL 65 | 66 | all_recursively: 67 | _info: 68 | title: Run all static analysis tools recursively 69 | desc:| 70 | Runs all static analysis tools available recursively, starting in the current directory. 71 | Outputs one file per analysis check to the output directory given as parameter and a summary at the end. 72 | Parameters: 73 | 1: output directory to store analysis files. If the directory doesn't exit, it will be created. 74 | Example: 75 | ./space -f ./tools/static_analysis/Spacefile.yaml /all_recursively/ -- "results" 76 | _env: 77 | - RUN: _RUN_ALL_RECURSIVELY 78 | 79 | -------------------------------------------------------------------------------- /test/function/yaml_get_row/test_yaml_get_row.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _TEST_YAML_GET_ROW_CHECK_STATUS_OK() 20 | { 21 | SPACE_DEP="PRINT _yaml_get_row" 22 | SPACE_ENV="" 23 | 24 | local _row_index=0 25 | local _preprocess=0 26 | local _allrows=("row1" "row two three four" "another one" "testing anOther_row:") 27 | 28 | _yaml_get_row "$_row_index" "$_preprocess" 29 | 30 | # Check return status is good 31 | if [ "$?" -eq 0 ]; then 32 | PRINT "_yaml_get_row OK!" "ok" 33 | return 0 34 | else 35 | PRINT "_yaml_get_row failed!" "error" 36 | return "$?" 37 | fi 38 | } 39 | 40 | _TEST_YAML_GET_ROW_CHECK_PREPROCESS_STATUS_OK() 41 | { 42 | SPACE_DEP="PRINT _yaml_get_row" 43 | SPACE_ENV="" 44 | 45 | local _row_index=0 46 | local _preprocess=1 47 | local _allrows=("row1" "row two three four" "another one" "testing anOther_row:") 48 | 49 | _yaml_get_row "$_row_index" "$_preprocess" 50 | 51 | # Expect failure here 52 | if [ "$?" -eq 0 ]; then 53 | PRINT "_yaml_get_row OK!" "ok" 54 | return 0 55 | else 56 | PRINT "_yaml_get_row failed!" "error" 57 | return "$?" 58 | fi 59 | } 60 | 61 | _TEST_YAML_GET_ROW_CHECK_RETURNED_ROW_OK() 62 | { 63 | SPACE_DEP="PRINT _yaml_get_row" 64 | SPACE_ENV="" 65 | 66 | local _row_index=3 67 | local _preprocess=0 68 | local _allrows=("row1" "row two three four" "another one" "testing anOther_row:") 69 | local _row='' 70 | 71 | _yaml_get_row "$_row_index" "$_preprocess" 72 | 73 | # Check returned row matches expected output 74 | if [ "$_row" = "testing anOther_row:" ]; then 75 | PRINT "_yaml_get_row OK!" "ok" 76 | return 0 77 | else 78 | PRINT "_yaml_get_row failed!" "error" 79 | return "$?" 80 | fi 81 | } 82 | 83 | _TEST_YAML_GET_ROW_CHECK_RETURNED_PREPROCESS_ROW_OK() 84 | { 85 | SPACE_DEP="PRINT _yaml_get_row" 86 | SPACE_ENV="" 87 | 88 | local _row_index=1 89 | local _preprocess=1 90 | local _allrows=("row1" "A: @{_PP_somevar:-test data is good}" "another one" "testing anOther_row:") 91 | local _row='' 92 | 93 | _yaml_get_row "$_row_index" "$_preprocess" 94 | 95 | # Check returned row matches expected output 96 | if [ "$_row" = "A: test data is good" ]; then 97 | PRINT "_yaml_get_row OK!" "ok" 98 | return 0 99 | else 100 | PRINT "_yaml_get_row failed!" "error" 101 | return "$?" 102 | fi 103 | } 104 | 105 | -------------------------------------------------------------------------------- /test/function/sort_pad/test_sort_pad.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _TEST_SORT_PAD_SINGLE_DIGIT() 20 | { 21 | SPACE_DEP="PRINT _sort_pad" 22 | 23 | local _value="2" 24 | local _padded_value= 25 | 26 | _sort_pad "_padded_value" "$_value" 27 | if [ "$_padded_value" = "0000000002" ]; then 28 | PRINT "_sort_pad OK!" "ok" 29 | return 0 30 | else 31 | PRINT "_sort_pad failed!" "error" 32 | return 1 33 | fi 34 | } 35 | 36 | _TEST_SORT_PAD_SINGLE_CHARACTER() 37 | { 38 | SPACE_DEP="PRINT _sort_pad" 39 | 40 | local _value="k" 41 | local _padded_value= 42 | 43 | _sort_pad "_padded_value" "$_value" 44 | if [ "$_padded_value" = "k" ]; then 45 | PRINT "_sort_pad OK!" "ok" 46 | return 0 47 | else 48 | PRINT "_sort_pad failed!" "error" 49 | return 1 50 | fi 51 | } 52 | 53 | _TEST_SORT_PAD_10_DIGITS() 54 | { 55 | SPACE_DEP="PRINT _sort_pad" 56 | 57 | local _value="0000000002" 58 | local _padded_value= 59 | 60 | _sort_pad "_padded_value" "$_value" 61 | if [ "$_padded_value" = "0000000002" ]; then 62 | PRINT "_sort_pad OK!" "ok" 63 | return 0 64 | else 65 | PRINT "_sort_pad failed!" "error" 66 | return 1 67 | fi 68 | } 69 | 70 | _TEST_SORT_PAD_10_CHARACTERS() 71 | { 72 | SPACE_DEP="PRINT _sort_pad" 73 | 74 | local _value="abeOPuzMvk" 75 | local _padded_value= 76 | 77 | _sort_pad "_padded_value" "$_value" 78 | if [ "$_padded_value" = "abeOPuzMvk" ]; then 79 | PRINT "_sort_pad OK!" "ok" 80 | return 0 81 | else 82 | PRINT "_sort_pad failed!" "error" 83 | return 1 84 | fi 85 | } 86 | 87 | _TEST_SORT_PAD_20_DIGITS() 88 | { 89 | SPACE_DEP="PRINT _sort_pad" 90 | 91 | local _value="00000000000000000002" 92 | local _padded_value= 93 | 94 | _sort_pad "_padded_value" "$_value" 95 | if [ "$_padded_value" = "0000000002" ]; then 96 | PRINT "_sort_pad OK!" "ok" 97 | return 0 98 | else 99 | PRINT "_sort_pad failed!" "error" 100 | return 1 101 | fi 102 | } 103 | 104 | _TEST_SORT_PAD_20_CHARACTERS() 105 | { 106 | SPACE_DEP="PRINT _sort_pad" 107 | 108 | local _value="abeOPuzMvkUOPQWEZADs" 109 | local _padded_value= 110 | 111 | _sort_pad "_padded_value" "$_value" 112 | if [ "$_padded_value" = "abeOPuzMvkUOPQWEZADs" ]; then 113 | PRINT "_sort_pad OK!" "ok" 114 | return 0 115 | else 116 | PRINT "_sort_pad failed!" "error" 117 | return 1 118 | fi 119 | } 120 | -------------------------------------------------------------------------------- /tools/manpage_exporter/Spacefile.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | # 20 | # manpage_exporter - Exports Markdown files to roff and HTML 21 | # 22 | 23 | _EXPORT_MAN() 24 | { 25 | SPACE_DEP="PRINT" 26 | SPACE_ENV="DATE_NOW MAN_NAME ORGANIZATION_NAME" 27 | 28 | if [ "$#" -eq 0 ]; then 29 | PRINT "missing input file to generate man page from" "error" 30 | return 1 31 | fi 32 | 33 | local _doc_file_path="$1" 34 | local _doc_file_name= 35 | _doc_file_name=$(basename "$_doc_file_path") 36 | local _doc_export_path= 37 | _doc_export_path="$(pwd)/${_doc_file_name%.*}.1" 38 | 39 | # Check if file exists 40 | if [ ! -f "$_doc_file_path" ]; then 41 | PRINT "Failed to load $_doc_file_path" "error" 42 | return 1 43 | fi 44 | 45 | # Check if ronn is available 46 | if ! command -v ronn >/dev/null; then 47 | PRINT "ronn program not found. Please check the README file for instructions on how to install it" "error" 48 | exit 1 49 | fi 50 | 51 | ronn --roff --date="$DATE_NOW" --manual="$MAN_NAME" --organization="$ORGANIZATION_NAME" --pipe "$_doc_file_path" > "$_doc_export_path" 52 | 53 | # shellcheck disable=2181 54 | if [ $? -ne 0 ]; then 55 | PRINT "Failed to generate man page for $_doc_file_name" "error" 56 | return 1 57 | else 58 | PRINT "Man page exported to $_doc_export_path" 59 | fi 60 | } 61 | 62 | _EXPORT_HTML() 63 | { 64 | # shellcheck disable=2034 65 | SPACE_DEP="PRINT" 66 | # shellcheck disable=2034 67 | SPACE_ENV="DATE_NOW MAN_NAME ORGANIZATION_NAME" 68 | 69 | if [ "$#" -eq 0 ]; then 70 | PRINT "missing input file to generate man page from" "error" 71 | return 1 72 | fi 73 | 74 | local _doc_file_path="$1" 75 | local _doc_file_name= 76 | _doc_file_name=$(basename "$_doc_file_path") 77 | local _doc_export_path= 78 | _doc_export_path="$(pwd)/${_doc_file_name%.*}.html" 79 | 80 | # Check if file exists 81 | if [ ! -f "$_doc_file_path" ]; then 82 | PRINT "Failed to load $_doc_file_path" "error" 83 | return 1 84 | fi 85 | 86 | # Check if ronn is available 87 | if ! command -v ronn >/dev/null; then 88 | PRINT "ronn program not found. Please check the README file for instructions on how to install it" "error" 89 | exit 1 90 | fi 91 | 92 | ronn --html --date="$DATE_NOW" --manual="$MAN_NAME" --organization="$ORGANIZATION_NAME" --pipe "$_doc_file_path" > "$_doc_export_path" 93 | 94 | # shellcheck disable=2181 95 | if [ $? -ne 0 ]; then 96 | PRINT "Failed to generate HTML page for $_doc_file_name" "error" 97 | return 1 98 | else 99 | PRINT "HTML page exported to $_doc_export_path" 100 | fi 101 | } 102 | 103 | -------------------------------------------------------------------------------- /test/yaml/2/output_X4.yaml: -------------------------------------------------------------------------------- 1 | local __spacegaltmp_= 2 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 3 | something more 4 | _SPACEGAL_SAYS_END_OF_FINITY_ 5 | local CMD2=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 6 | unset __spacegaltmp_ 7 | local __spacegaltmp_= 8 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 9 | 10 | _SPACEGAL_SAYS_END_OF_FINITY_ 11 | local CMD3=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 12 | unset __spacegaltmp_ 13 | local __spacegaltmp_= 14 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 15 | here it is 16 | _SPACEGAL_SAYS_END_OF_FINITY_ 17 | local RUN=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 18 | unset __spacegaltmp_ 19 | local __spacegaltmp_= 20 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 21 | input comes from here 22 | _SPACEGAL_SAYS_END_OF_FINITY_ 23 | local PIPE=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 24 | unset __spacegaltmp_ 25 | local __spacegaltmp_= 26 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 27 | ${A-} 28 | _SPACEGAL_SAYS_END_OF_FINITY_ 29 | local A=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 30 | unset __spacegaltmp_ 31 | local __spacegaltmp_= 32 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 33 | my data is visible 34 | _SPACEGAL_SAYS_END_OF_FINITY_ 35 | local B=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 36 | unset __spacegaltmp_ 37 | local __spacegaltmp_= 38 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 39 | my data is visible 40 | _SPACEGAL_SAYS_END_OF_FINITY_ 41 | local A=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 42 | unset __spacegaltmp_ 43 | local __spacegaltmp_= 44 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 45 | my data is visible 46 | _SPACEGAL_SAYS_END_OF_FINITY_ 47 | local B=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 48 | unset __spacegaltmp_ 49 | local __spacegaltmp_= 50 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 51 | hej 52 | _SPACEGAL_SAYS_END_OF_FINITY_ 53 | local A=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 54 | unset __spacegaltmp_ 55 | local __spacegaltmp_= 56 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 57 | hej 58 | _SPACEGAL_SAYS_END_OF_FINITY_ 59 | local B=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 60 | unset __spacegaltmp_ 61 | local __spacegaltmp_= 62 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 63 | san 64 | _SPACEGAL_SAYS_END_OF_FINITY_ 65 | local A=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 66 | unset __spacegaltmp_ 67 | local __spacegaltmp_= 68 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 69 | san 70 | _SPACEGAL_SAYS_END_OF_FINITY_ 71 | local B=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 72 | unset __spacegaltmp_ 73 | local __spacegaltmp_= 74 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 75 | 76 | _SPACEGAL_SAYS_END_OF_FINITY_ 77 | local WRAPCMD=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 78 | unset __spacegaltmp_ 79 | local __spacegaltmp_= 80 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 81 | /dev/stdin 82 | _SPACEGAL_SAYS_END_OF_FINITY_ 83 | local STDIN=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 84 | unset __spacegaltmp_ 85 | local __spacegaltmp_= 86 | IFS= read -d '' -r __spacegaltmp_ << _SPACEGAL_SAYS_END_OF_FINITY_ 87 | OK prio 88 | _SPACEGAL_SAYS_END_OF_FINITY_ 89 | local RUN=${__spacegaltmp_: 0:$(( ${#__spacegaltmp_} > 0 ? ${#__spacegaltmp_}-1 : 0 ))} 90 | unset __spacegaltmp_ 91 | -------------------------------------------------------------------------------- /tools/installer/install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # 3 | # Copyright 2016-2017 Blockie AB 4 | # 5 | # This file is part of Space. 6 | # 7 | # Space is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation version 3 of the License. 10 | # 11 | # Space is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Space. If not, see . 18 | # 19 | 20 | # 21 | # Space install script 22 | # 23 | 24 | # Definitions 25 | _current_directory="$PWD" 26 | _program_name="space" 27 | _version="1.5.0" 28 | _package_base="${_program_name}-${_version}" 29 | _package_name="${_package_base}.tar.gz" 30 | _package_sha1='6ba96d4e10696e89ba2da41e522636fb089ed26a' 31 | _package_sha256='9dd79869a35edd7230b4a555e4a550cc2667621326d9fc91eb9397bee5dd3423' 32 | _package_hash='' 33 | _download_base_url="https://space.sh/static/download" 34 | _download_url="${_download_base_url}/${_package_base}/${_package_name}" 35 | 36 | # shasum binary 37 | if command -v sha256sum >/dev/null; then 38 | _SHASUMBIN=sha256sum 39 | _package_hash="$_package_sha256" 40 | elif command -v shasum >/dev/null; then 41 | _SHASUMBIN="shasum -a 256" 42 | _package_hash="$_package_sha256" 43 | elif command -v sha1sum >/dev/null; then 44 | _SHASUMBIN=sha1sum 45 | _package_hash="$_package_sha1" 46 | else 47 | printf "Missing required sha256 or shasum binaries. Exiting...\n" 48 | exit 1 49 | fi 50 | 51 | # Check if package hasn't been downloaded yet 52 | if [ ! -f "$_package_name" ]; then 53 | printf "Package %s not found locally. Downloading...\n" "$_package_name" 54 | curl -L --remote-name "${_download_url}" 55 | else 56 | printf "Found local package %s.\n" "$_package_name" 57 | fi 58 | 59 | # Verify package integrity 60 | printf "Verifying package integrity...\t" 61 | printf "%s %s" $_package_hash $_package_name | $_SHASUMBIN -c 62 | # shellcheck disable=2181 63 | if [ "$?" -ne 0 ]; then 64 | printf "Package download is invalid or corrupted. Please remove it and re-run the installation process\n" 65 | exit 1 66 | fi 67 | 68 | # Create temporary directory 69 | _tmp_dir=$(mktemp -d 2>/dev/null || mktemp -d -t ${_package_name}) 70 | # shellcheck disable=2181 71 | if [ $? -ne 0 ]; then 72 | printf "Could not create temp directory. Exiting..." 73 | exit 1 74 | fi 75 | 76 | # Extract package 77 | printf "Extracting package %s to TMPDIR...\n" "$_package_name" 78 | tar xzf "$_package_name" -C "$_tmp_dir" 79 | rm ./"$_package_name" 80 | 81 | # 82 | # Enter directory 83 | printf "Starting install procedure...\n" 84 | cd "$_tmp_dir" 85 | 86 | # Change shebang line according to environment 87 | _bash_path=$(which bash) 88 | sed -i.bak "1 s@^#\!.*@#\!${_bash_path}@" ./space 89 | if [ "$?" -ne 0 ]; then 90 | printf "Failed to set shebang line according to bash path: %s. Exiting...\n" "${_bash_path}" 91 | exit 1 92 | fi 93 | 94 | # Install 95 | if [ -n "$1" ]; then 96 | _bin_path=$1 97 | # Append PWD from where it was called to relative path 98 | if [ "$_bin_path" = "${_bin_path#/}" ]; then 99 | _bin_path=${_current_directory}/${_bin_path} 100 | fi 101 | if [ -n "$2" ]; then 102 | _completion_path=$2 103 | if [ "$_completion_path" = "${_completion_path#/}" ]; then 104 | _completion_path=${_current_directory}/${_completion_path} 105 | fi 106 | ./space /install/ -- "$_bin_path" "$_completion_path" 107 | else 108 | ./space /install/ -- "$_bin_path" "" 109 | fi 110 | else 111 | ./space /install/ 112 | fi 113 | 114 | -------------------------------------------------------------------------------- /test/function/PRINT/test_PRINT.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _TEST_PRINT() 20 | { 21 | SPACE_DEP="PRINT" 22 | 23 | SPACE_LOG_LEVEL=5 24 | 25 | local _tmp_file_name="./tmp_test_PRINT" 26 | 27 | local _level=$1 28 | local _level_tag="" 29 | 30 | if [ "$_level" = "error" ]; then 31 | _level_tag="\[ERROR\]" 32 | elif [ "$_level" = "security" ]; then 33 | _level_tag="\[SEC\]" 34 | elif [ "$_level" = "warning" ]; then 35 | _level_tag="\[WARN\]" 36 | elif [ "$_level" = "ok" ]; then 37 | _level_tag="\[OK\]" 38 | elif [ "$_level" = "info" ]; then 39 | _level_tag="\[INFO\]" 40 | elif [ "$_level" = "debug" ]; then 41 | _level_tag="\[DEBUG\]" 42 | fi 43 | 44 | # 45 | # Create temporary file 46 | 47 | # Make sure it doesn't already exist 48 | if [ -f "$_tmp_file_name" ]; then 49 | PRINT "File $_tmp_file_name already exists. That was unexpected!" "error" 50 | return 1 51 | fi 52 | 53 | # Create 54 | touch "$_tmp_file_name" 55 | 56 | # Make sure it was indeed created 57 | if [ ! -f "$_tmp_file_name" ]; then 58 | PRINT "Failed to create temporary file needed for testing" "error" 59 | return 1 60 | fi 61 | 62 | # Redirect expected output to file 63 | PRINT "testing 1, 2, 3 . . ." "$_level" 2> "$_tmp_file_name" 64 | 65 | # Check if file size is > 0 66 | if [ ! -s "$_tmp_file_name" ]; then 67 | PRINT "PRINT FAILED!" "error" 68 | 69 | # Remove tmp file 70 | rm "$_tmp_file_name" 71 | return 1 72 | else 73 | # Read first line of file 74 | local _print_line="0" 75 | read -r _print_line<"$_tmp_file_name" 76 | #PRINT "read=[$_print_line]" 77 | 78 | # Check pattern matches expected results 79 | PRINT "Trying to match results with expected print format..." 80 | local _extracted_tag='' 81 | if [[ "$_print_line" =~ (${_level_tag})(.*) ]]; then 82 | _extracted_tag=${BASH_REMATCH[1]} 83 | fi 84 | 85 | if [ "$_extracted_tag" = "${_level_tag//\\}" ]; then 86 | PRINT "PRINT $_level OK!" "ok" 87 | # remove tmp file 88 | rm "$_tmp_file_name" 89 | return 0 90 | else 91 | PRINT "PRINT failed! Extracted tag: $_extracted_tag" "error" 92 | # remove tmp file 93 | rm "$_tmp_file_name" 94 | return 2 95 | fi 96 | fi 97 | } 98 | 99 | _TEST_PRINT_LEVEL_ERROR() 100 | { 101 | SPACE_DEP="_TEST_PRINT" 102 | 103 | _TEST_PRINT "error" 104 | } 105 | 106 | 107 | _TEST_PRINT_LEVEL_SECURITY() 108 | { 109 | SPACE_DEP="_TEST_PRINT" 110 | 111 | _TEST_PRINT "security" 112 | } 113 | 114 | _TEST_PRINT_LEVEL_WARNING() 115 | { 116 | SPACE_DEP="_TEST_PRINT" 117 | 118 | _TEST_PRINT "warning" 119 | } 120 | 121 | _TEST_PRINT_LEVEL_OK() 122 | { 123 | SPACE_DEP="_TEST_PRINT" 124 | 125 | _TEST_PRINT "ok" 126 | } 127 | 128 | _TEST_PRINT_LEVEL_INFO() 129 | { 130 | SPACE_DEP="_TEST_PRINT" 131 | 132 | _TEST_PRINT "info" 133 | } 134 | _TEST_PRINT_LEVEL_DEBUG() 135 | { 136 | SPACE_DEP="_TEST_PRINT" 137 | 138 | _TEST_PRINT "debug" 139 | } 140 | 141 | -------------------------------------------------------------------------------- /test/function/parse_yaml/test_parse_yaml.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _TEST_PARSE_YAML_CHECK_STATUS_OK() 20 | { 21 | SPACE_DEP="PRINT _yaml_get_multiline _yaml_get_next _yaml_get_row _yaml_find_nextindent _pp_yaml _parse_yaml" 22 | SPACE_ENV="_SPACEGAL_EOF_TAG" 23 | 24 | local _yamlrows=() _yamlfilelist="" 25 | local _yamlfile="./test/function/test_spacefile.yml" 26 | local _PP_DIR=${_yamlfile%/*} 27 | local _INCLUDEPATH=("") 28 | local _parsedyaml=() 29 | 30 | _pp_yaml "_yamlrows" $_yamlfile 31 | _parse_yaml "_yamlrows" "_parsedyaml" "_parsedyamlcompletion" 32 | 33 | # Check return status is good 34 | if [ "$?" -eq 0 ]; then 35 | PRINT "_parse_yaml OK!" "ok" 36 | return 0 37 | else 38 | PRINT "_parse_yaml failed!" "error" 39 | return "$?" 40 | fi 41 | } 42 | 43 | _TEST_PARSE_YAML_CHECK_PARSED_YAML_OK() 44 | { 45 | SPACE_DEP="PRINT _yaml_get_multiline _yaml_get_next _yaml_get_row _yaml_find_nextindent _pp_yaml _parse_yaml" 46 | SPACE_ENV="_SPACEGAL_EOF_TAG" 47 | 48 | local _yamlrows=() _yamlfilelist="" 49 | local _yamlfile="./test/function/test_spacefile.yml" 50 | local _PP_DIR=${_yamlfile%/*} 51 | local _INCLUDEPATH=("") 52 | local _parsedyaml=() 53 | 54 | local _expected_result='_0x5fenv_0_BIN0x5fPREFIX "/usr/local" _SPACEGAL_SAYS_END_OF_FINITY_ _0x5fenv_1_AC0x5fPREFIX "/usr/share/bash-completion/completions" _SPACEGAL_SAYS_END_OF_FINITY_ _0x5finfo_title Space.sh installer _SPACEGAL_SAYS_END_OF_FINITY_ _0x5finfo_desc Provides system wide installation and Bash auto-completion setup. Provides an uninstall utility for listing files originally installed by Space. _SPACEGAL_SAYS_END_OF_FINITY_ _0x5fdep0x5finstall_0x5finfo_title Verify Space dependencies _SPACEGAL_SAYS_END_OF_FINITY_ _0x5fdep0x5finstall_0x5fenv_0_RUN SPACE_DEP_INSTALL _SPACEGAL_SAYS_END_OF_FINITY_ _install_0x5finfo_title Install Space.sh _SPACEGAL_SAYS_END_OF_FINITY_ _install_0x5finfo_desc Perform Space.sh install. Parameters (both optional): 1: BIN_PREFIX which is where the program and man page will be installed. 2: AC_PREFIX where the auto completion will be installed. Example (using default values): ./space /install/ -- "/usr/local" "/usr/share/bash-completion/completions" _SPACEGAL_SAYS_END_OF_FINITY_ _install_0x5fenv_0_RUN SPACE_INSTALL _SPACEGAL_SAYS_END_OF_FINITY_ _uninstall_0x5finfo_title Uninstall Space.sh _SPACEGAL_SAYS_END_OF_FINITY_ _uninstall_0x5finfo_desc Auto detects and lists all the files originally installed by Space.sh. _SPACEGAL_SAYS_END_OF_FINITY_ _uninstall_0x5fenv_0_RUN SPACE_UNINSTALL _SPACEGAL_SAYS_END_OF_FINITY_' 55 | 56 | _pp_yaml "_yamlrows" $_yamlfile 57 | _parse_yaml "_yamlrows" "_parsedyaml" "_parsedyamlcompletion" 58 | 59 | # Check return status is good 60 | if [ "${_parsedyaml[*]}" = "${_expected_result}" ]; then 61 | PRINT "_parse_yaml OK!" "ok" 62 | return 0 63 | else 64 | PRINT "_parse_yaml failed!" "error" 65 | return "$?" 66 | fi 67 | } 68 | 69 | _TEST_PARSE_YAML_CHECK_PARSED_YAML_FAIL() 70 | { 71 | SPACE_DEP="PRINT _yaml_get_multiline _yaml_get_next _yaml_get_row _yaml_find_nextindent _pp_yaml _parse_yaml" 72 | SPACE_ENV="_SPACEGAL_EOF_TAG" 73 | 74 | local _yamlrows=("") _yamlfilelist="" 75 | local _yamlfile="./Spacefile.bash" 76 | local _PP_DIR=${_yamlfile%/*} 77 | local _INCLUDEPATH=("") 78 | local _parsedyaml=("") 79 | 80 | _pp_yaml "_yamlrows" $_yamlfile 81 | _parse_yaml "_yamlrows" "_parsedyaml" "_parsedyamlcompletion" 82 | 83 | # Expect empty parse 84 | if [ "${_parsedyaml[0]}" = "" ]; then 85 | PRINT "_parse_yaml OK!" "ok" 86 | return 0 87 | else 88 | PRINT "_parse_yaml failed!" "error" 89 | return "$?" 90 | fi 91 | } 92 | 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Space | [![build status](https://github.com/space-sh/space/actions/workflows/main.yml/badge.svg)](https://github.com/space-sh/space/commits/master) [![latest stable version](https://img.shields.io/badge/latest%20stable-1.5.0-blue.svg?style=flat)](https://github.com/space-sh/space/releases/tag/1.5.0) [![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/blockie-org/space.sh) 3 | 4 | ![Space.sh](https://space.sh/static/img/logo.png) 5 | 6 | Welcome to Space! 7 | 8 | This tool is not for the faint of heart, but here we go! 9 | 10 | The _Space.sh_ is a single file program, referred to as _Space_, that relies only on _Bash version 3.2 or later_ as dependency for loading and running configuration files and invoking programs in a structured manner. 11 | 12 | _Space_ assembles shell script applications built out of reusable modules and it also provides automation features. 13 | 14 | One could say "it's like Ansible but written in Bash". 15 | 16 | _Space_ provides the notion of _Modules_, which in essence are _Git_ repositories filled with user content defined as _Space_ descriptions and operations. _Modules_ can also point to other modules, so it is possible to create content on top of other users' work. 17 | 18 | _Space_ is part of _Space.sh_ and can be found at [https://space.sh](https://space.sh). 19 | 20 | 21 | ## Dependencies 22 | 23 | _Space_ requires _Bash_ version 3.2 or later. 24 | 25 | Some external programs related to I/O operations are not _POSIX 1003.1_ compliant. Non-standard programs have been tested to work with: 26 | - GNU/Linux 27 | - BusyBox/Linux (Android) 28 | - MacOS 10+ 29 | 30 | 31 | ## Quick start 32 | 33 | Please choose one of the methods below for installing _Space_ or read the [installation documents](manuals/install.md) in the /doc directory for the complete guide. 34 | 35 | 36 | ### Automated install 37 | 38 | Install the latest stable version of _Space_ from terminal: 39 | 40 | ``` 41 | curl https://get.space.sh/ | sh 42 | ``` 43 | 44 | ### Manual install via tarball 45 | Download, extract and install the latest stable version of _Space_: 46 | 47 | ``` 48 | mkdir space 49 | curl https://space.sh/static/download/space-1.5.0/space-1.5.0.tar.gz | tar xvfz - -C ./space && cd ./space && ./space /install/ 50 | ``` 51 | Note: this exact method does not check for the integrity of the downloaded .tar.gz file. It is possible to do so while still performing a manual install, please refer to the [install documentation](manuals/install.md). 52 | 53 | 54 | ### First steps 55 | _Space_ is now installed. Run `space -h` anywhere to read the help instructions. 56 | For a simple module example, please refer to EXAMPLE section in the [user manual page](manuals/space.md). For more advanced modules, check out the [Spacefile.yaml](Spacefile.yaml) and [Spacefile.sh](Spacefile.sh) files and the core modules located at [https://github.com/space-sh](https://github.com/space-sh). 57 | 58 | For more information, please refer to the documentation files located in the `doc` directory or the man pages. 59 | For the latest news and online reference, please visit [https://space.sh](https://space.sh). 60 | 61 | Further questions can be asked via the [GitHub Issues](https://github.com/space-sh/space/issues) page. 62 | 63 | 64 | ## Community 65 | 66 | * Chat on _Gitter_: https://gitter.im/blockie-org/space.sh 67 | 68 | 69 | ## Contributing 70 | 71 | Code contributions are welcome via [GitHub pull requests](https://github.com/space-sh/space/pulls). More information and details on how to do it can be found in the [CONTRIBUTING](CONTRIBUTING.md) document. 72 | 73 | 74 | ## Issues 75 | 76 | Bug reports and suggestions can be filed at the project [GitHub Issues](https://github.com/space-sh/space/issues) page. 77 | 78 | 79 | ## Authors 80 | 81 | Copyright 2016-2017 Blockie AB [Blockie.org](https://blockie.org) 82 | 83 | 84 | ## License 85 | 86 | >This program is free software: you can redistribute it and/or modify 87 | >it under the terms of the GNU General Public License as published by 88 | >the Free Software Foundation version 3 of the License. 89 | 90 | >This program is distributed in the hope that it will be useful, 91 | >but WITHOUT ANY WARRANTY; without even the implied warranty of 92 | >MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 93 | >GNU General Public License for more details. 94 | 95 | >You should have received a copy of the GNU General Public License 96 | >along with this program. If not, see . 97 | 98 | -------------------------------------------------------------------------------- /test/build/check_base_binaries.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # 3 | # Copyright 2016-2017 Blockie AB 4 | # 5 | # This file is part of Space. 6 | # 7 | # Space is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation version 3 of the License. 10 | # 11 | # Space is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Space. If not, see . 18 | # 19 | 20 | # 21 | # Check for base system binaries 22 | # 23 | set -o nounset 24 | 25 | 26 | #========================= 27 | # _check_version 28 | # 29 | # Checks current major.minor version is equal or bigger than 30 | # required major.minor 31 | # 32 | # Parameters: 33 | # 1: program name for message output 34 | # 2: required major version number 35 | # 3: required minor version number 36 | # 4: current major version number 37 | # 5: current minor version number 38 | # 39 | #========================= 40 | _check_version() 41 | { 42 | local _program_name=$1 43 | local _required_major=$2 44 | local _required_minor=$3 45 | local _current_major=$4 46 | local _current_minor=$5 47 | if [ "$_current_major" -lt "$_required_major" ] \ 48 | || ( [ "$_current_major" -le "$_required_major" ] && [ "$_current_minor" -lt "$_required_minor" ]); then 49 | printf "FAIL: %s version is too old. Version %s.%s or later is required. Current version: %s.%s\n" \ 50 | "$_program_name" "$_required_major" "$_required_minor" "$_current_major" "$_current_minor" 1>&2 51 | exit 1 52 | fi 53 | } 54 | 55 | # 56 | # bash 57 | if ! command -v bash >/dev/null; then 58 | printf "Missing bash program\n" 1>&2 59 | exit 1 60 | else 61 | _BASH_REQUIRED_MAJOR="3" 62 | _BASH_REQUIRED_MINOR="2" 63 | _BASH_CURRENT_MAJOR="${BASH_VERSINFO[0]}" 64 | _BASH_CURRENT_MINOR="${BASH_VERSINFO[1]}" 65 | _check_version "bash" "$_BASH_REQUIRED_MAJOR" "$_BASH_REQUIRED_MINOR" "$_BASH_CURRENT_MAJOR" "$_BASH_CURRENT_MINOR" 66 | printf "OK: bash %s.%s\n" "$_BASH_CURRENT_MAJOR" "$_BASH_CURRENT_MINOR" 67 | fi 68 | 69 | # 70 | # base64 71 | if ! command -v base64 >/dev/null; then 72 | printf "Missing base64 program\n" 1>&2 73 | exit 1 74 | else 75 | printf "OK: base64\n" 76 | fi 77 | 78 | # 79 | # curl 80 | if ! command -v curl >/dev/null; then 81 | printf "Missing curl program\n" 1>&2 82 | exit 1 83 | else 84 | _CURL_REQUIRED_MAJOR="7" 85 | _CURL_REQUIRED_MINOR="51" 86 | _CURL_VERSION=$(curl --version | grep curl | cut -d ' ' -f2) 87 | _CURL_CURRENT_MAJOR="$(printf $_CURL_VERSION | cut -d. -f1)" 88 | _CURL_CURRENT_MINOR="$(printf $_CURL_VERSION | cut -d. -f2)" 89 | _check_version "Curl" "$_CURL_REQUIRED_MAJOR" "$_CURL_REQUIRED_MINOR" "$_CURL_CURRENT_MAJOR" "$_CURL_CURRENT_MINOR" 90 | printf "OK: curl %s.%s\n" "$_CURL_CURRENT_MAJOR" "$_CURL_CURRENT_MINOR" 91 | fi 92 | 93 | # 94 | # git 95 | if ! command -v git >/dev/null; then 96 | printf "Missing git program\n" 1>&2 97 | exit 1 98 | else 99 | _GIT_REQUIRED_MAJOR="2" 100 | _GIT_REQUIRED_MINOR="8" 101 | _GIT_VERSION=$(git --version | cut -d ' ' -f3) 102 | _GIT_CURRENT_MAJOR="$(printf $_GIT_VERSION | cut -d. -f1)" 103 | _GIT_CURRENT_MINOR="$(printf $_GIT_VERSION | cut -d. -f2)" 104 | _check_version "Git" "$_GIT_REQUIRED_MAJOR" "$_GIT_REQUIRED_MINOR" "$_GIT_CURRENT_MAJOR" "$_GIT_CURRENT_MINOR" 105 | printf "OK: git %s.%s\n" "$_GIT_CURRENT_MAJOR" "$_GIT_CURRENT_MINOR" 106 | fi 107 | 108 | # 109 | # space 110 | if ! command -v space >/dev/null; then 111 | printf "Missing space program\n" 1>&2 112 | exit 1 113 | else 114 | _SPACE_REQUIRED_MAJOR="0" 115 | _SPACE_REQUIRED_MINOR="10" 116 | _SPACE_VERSION=$(space -V 2>&1 | cut -d ' ' -f2) 117 | _SPACE_CURRENT_MAJOR="$(printf $_SPACE_VERSION | cut -d. -f1)" 118 | _SPACE_CURRENT_MINOR="$(printf $_SPACE_VERSION | cut -d. -f2)" 119 | _check_version "Space" "$_SPACE_REQUIRED_MAJOR" "$_SPACE_REQUIRED_MINOR" "$_SPACE_CURRENT_MAJOR" "$_SPACE_CURRENT_MINOR" 120 | printf "OK: space %s.%s\n" "$_SPACE_CURRENT_MAJOR" "$_SPACE_CURRENT_MINOR" 121 | fi 122 | 123 | -------------------------------------------------------------------------------- /test/Spacefile.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _TEST_ALL_RECURSIVELY() 20 | { 21 | # shellcheck disable=2034 22 | SPACE_DEP="PRINT" 23 | 24 | # Use parameter as target, otherwise defaults to iterate over everything 25 | local _target_directory="${1-*}" 26 | local _output_file_name= 27 | if [ "$_target_directory" = "*" ]; then 28 | _output_file_name="./test-results.txt" 29 | else 30 | _output_file_name="./test-${_target_directory}-results.txt" 31 | fi 32 | 33 | # Overwrite output file 34 | PRINT "${_output_file_name}" > "$_output_file_name" 35 | 36 | # Check if this is being run from project root directory 37 | if [ -d "./test" ] && [ -f "./space" ]; then 38 | 39 | # Iterate all dirs 40 | for dir in ./test/$_target_directory; do 41 | if [ -d "$dir" ]; then 42 | # Check if any YAML to run 43 | for file in "$dir"/*.yaml; do 44 | if [ -f "$file" ]; then 45 | PRINT "Performing test: $file..." 46 | ./space -f "$file" /tests/0/ -a >> "$_output_file_name" 2>&1; 47 | 48 | # Check for failed execution 49 | if [ "$?" -ne 0 ]; then 50 | PRINT "Failed to execute test for $file" "error" >> "$_output_file_name" 2>&1 51 | fi 52 | break 53 | fi 54 | done 55 | 56 | # Jump to sub directories 57 | for subdir in ./"$dir"/*; do 58 | # Check if any YAML to run 59 | for file in "$subdir"/*.yaml; do 60 | # HACK: skip ./test/yaml subdirs 61 | if [[ "$subdir" == *"/test/yaml"* ]]; then 62 | break 63 | fi 64 | if [ -f "$file" ]; then 65 | PRINT "Performing test: $file..." 66 | ./space -f "$file" /tests/0/ -a >> "$_output_file_name" 2>&1; 67 | 68 | # Check for failed execution 69 | if [ "$?" -ne 0 ]; then 70 | PRINT "Failed to execute test for $file" "error" >> "$_output_file_name" 2>&1 71 | fi 72 | 73 | break 74 | fi 75 | done 76 | done 77 | fi 78 | done 79 | 80 | # Count occurrences 81 | # EXTERNAL: grep 82 | local _num_ok= 83 | local _num_warn= 84 | local _num_error= 85 | _num_ok=$(grep -c "OK" "$_output_file_name") 86 | _num_warn=$(grep -c "WARN" "$_output_file_name") 87 | _num_error=$(grep -c "ERROR" "$_output_file_name") 88 | 89 | PRINT "----------------" 90 | PRINT "Test summary:" 91 | PRINT "OK: $(echo "$_num_ok")" "ok" 92 | PRINT "WARNING: $(echo "$_num_warn")" "warning" 93 | PRINT "ERROR: $(echo "$_num_error")" "error" 94 | PRINT "----------------" 95 | 96 | # List all functions that failed 97 | if [ "$_num_error" -gt 0 ]; then 98 | PRINT "----------------" 99 | PRINT "More information:" 100 | while read -r line; do 101 | if [[ "$line" =~ (\[ERROR\][[:space:]])(.*)(\:)(.*) ]]; then 102 | PRINT "${BASH_REMATCH[4]}" "error" 103 | fi 104 | done < "$_output_file_name" 105 | PRINT "----------------" 106 | fi 107 | else 108 | PRINT "Tests must be called from space root development directory" 109 | fi 110 | 111 | # Cap max return value 112 | if [ "$_num_error" -gt 255 ]; then 113 | _num_error=255 114 | fi 115 | exit "$_num_error" 116 | } 117 | 118 | -------------------------------------------------------------------------------- /test/function/source/test_source.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _TEST_SOURCE_ONE_CHECK_STATUS() 20 | { 21 | SPACE_DEP="PRINT _source" 22 | 23 | _SOURCE_FILES=() 24 | local _expected_output=("./adding_file.extension") 25 | 26 | _source "./adding_file.extension" 27 | 28 | # Check return is OK 29 | if [ "$?" -eq 0 ]; then 30 | PRINT "_source OK!" "ok" 31 | return 0 32 | else 33 | PRINT "_source failed!" "error" 34 | return "$?" 35 | fi 36 | } 37 | 38 | _TEST_SOURCE_ONE_CHECK_STATE_CHANGED() 39 | { 40 | SPACE_DEP="PRINT _source" 41 | 42 | _SOURCE_FILES=() 43 | local _expected_output=("./adding_file.extension") 44 | 45 | _source "./adding_file.extension" 46 | 47 | # Check SOURCE_FILES has been filled 48 | if [ "${#_SOURCE_FILES[@]}" -eq 1 ]; then 49 | PRINT "_source OK!" "ok" 50 | return 0 51 | else 52 | PRINT "_source failed!" "error" 53 | return "$?" 54 | fi 55 | } 56 | 57 | _TEST_SOURCE_ONE_CHECK_EXPECTED_OUTPUT() 58 | { 59 | SPACE_DEP="PRINT _source" 60 | 61 | _SOURCE_FILES=() 62 | local _expected_output=("./adding_file.extension") 63 | 64 | _source "./adding_file.extension" 65 | 66 | # Check expected output matches current SOURCE_FILES 67 | if [ "${_SOURCE_FILES[*]}" = "${_expected_output[*]}" ]; then 68 | PRINT "_source OK!" "ok" 69 | return 0 70 | else 71 | PRINT "_source failed!" "error" 72 | return "$?" 73 | fi 74 | } 75 | 76 | _TEST_SOURCE_MULTIPLE_CHECK_STATUS() 77 | { 78 | SPACE_DEP="PRINT _source" 79 | 80 | _SOURCE_FILES=() 81 | local _expected_output=("./adding_file.extension" "adding_various_files" "/more/source/testing_123/" "path_shouldnt_matter_at_this_stage!!11" "/more/source/testing_123/") 82 | 83 | _source "./adding_file.extension" 84 | _source "adding_various_files" 85 | _source "/more/source/testing_123/" 86 | _source "path_shouldnt_matter_at_this_stage!!11" 87 | _source "/more/source/testing_123/" "multiple params also shouldn't matter" 88 | 89 | # Check return is OK 90 | if [ "$?" -eq 0 ]; then 91 | PRINT "_source OK!" "ok" 92 | return 0 93 | else 94 | PRINT "_source failed!" "error" 95 | return "$?" 96 | fi 97 | } 98 | 99 | _TEST_SOURCE_MULTIPLE_CHECK_STATE_CHANGED() 100 | { 101 | SPACE_DEP="PRINT _source" 102 | 103 | _SOURCE_FILES=() 104 | local _expected_output=("./adding_file.extension" "adding_various_files" "/more/source/testing_123/" "path_shouldnt_matter_at_this_stage!!11" "/more/source/testing_123/") 105 | 106 | _source "./adding_file.extension" 107 | _source "adding_various_files" 108 | _source "/more/source/testing_123/" 109 | _source "path_shouldnt_matter_at_this_stage!!11" 110 | _source "/more/source/testing_123/" "multiple params also shouldn't matter" 111 | 112 | # Check SOURCE_FILES has been filled 113 | if [ "${#_SOURCE_FILES[@]}" -eq 5 ]; then 114 | PRINT "_source OK!" "ok" 115 | return 0 116 | else 117 | PRINT "_source failed!" "error" 118 | return "$?" 119 | fi 120 | } 121 | 122 | _TEST_SOURCE_MULTIPLE_CHECK_EXPECTED_OUTPUT() 123 | { 124 | SPACE_DEP="PRINT _source" 125 | 126 | _SOURCE_FILES=() 127 | local _expected_output=("./adding_file.extension" "adding_various_files" "/more/source/testing_123/" "path_shouldnt_matter_at_this_stage!!11" "/more/source/testing_123/") 128 | 129 | _source "./adding_file.extension" 130 | _source "adding_various_files" 131 | _source "/more/source/testing_123/" 132 | _source "path_shouldnt_matter_at_this_stage!!11" 133 | _source "/more/source/testing_123/" "multiple params also shouldn't matter" 134 | 135 | # Check expected output matches current SOURCE_FILES 136 | if [ "${_SOURCE_FILES[*]}" = "${_expected_output[*]}" ]; then 137 | PRINT "_source OK!" "ok" 138 | return 0 139 | else 140 | PRINT "_source failed!" "error" 141 | return "$?" 142 | fi 143 | } 144 | 145 | -------------------------------------------------------------------------------- /test/function/helpnode/test_helpnode.bash: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2017 Blockie AB 3 | # 4 | # This file is part of Space. 5 | # 6 | # Space is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation version 3 of the License. 9 | # 10 | # Space is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Space. If not, see . 17 | # 18 | 19 | _TEST_HELPNODE_EMPTY_STRING_PARAMETER() 20 | { 21 | SPACE_DEP="PRINT _helpnode _print _copy _list" 22 | SPACE_ENV="_YAML_PREFIX _YAML_NAMESPACE" 23 | 24 | local _tmp_file_name="./tmp_test_helpnode" 25 | 26 | # 27 | # Create temporary file 28 | 29 | # Make sure it doesn't already exist 30 | if [ -f "$_tmp_file_name" ]; then 31 | PRINT "File $_tmp_file_name already exists. That was unexpected!" "error" 32 | return 1 33 | fi 34 | 35 | # Create 36 | touch "$_tmp_file_name" 37 | 38 | # Make sure it was indeed created 39 | if [ ! -f "$_tmp_file_name" ]; then 40 | PRINT "Failed to create temporary file needed for testing" "error" 41 | return 1 42 | fi 43 | 44 | # 45 | # Mock intricate dependency 46 | _list() 47 | { 48 | local _output=$1 49 | local _nodes=() 50 | _nodes+=("Predefined_node1") 51 | _nodes+=("preDefined_NODE2") 52 | eval "${_output}=(\"\${_nodes[@]}\")" 53 | } 54 | 55 | _helpnode "" >> "$_tmp_file_name" 2>&1 56 | 57 | # Check if file size is >0 58 | if [ ! -s "$_tmp_file_name" ]; then 59 | PRINT "_helpnode FAILED!" "error" 60 | 61 | # Remove tmp file 62 | rm "$_tmp_file_name" 63 | return 1 64 | else 65 | # Check if file contents match the expected string 66 | local _expected_string= 67 | _expected_string=$(printf "\n\t\n\n+ Predefined_node1\n+ preDefined_NODE2") 68 | 69 | PRINT "Looking for expected results..." 70 | PRINT "Testing: $(cat ${_tmp_file_name})" 71 | PRINT "Expected: $_expected_string" 72 | if [ "$(cat ${_tmp_file_name})" = "$_expected_string" ]; then 73 | PRINT "_helpnode OK!" "ok" 74 | # remove tmp file 75 | rm "$_tmp_file_name" 76 | return 0 77 | else 78 | PRINT "_helpnode failed!" "error" 79 | # remove tmp file 80 | rm "$_tmp_file_name" 81 | return 2 82 | fi 83 | fi 84 | 85 | PRINT "_helpnode OK!" "ok" 86 | } 87 | 88 | _TEST_HELPNODE_WITH_PARAMETER() 89 | { 90 | SPACE_DEP="PRINT _helpnode _print _copy _list" 91 | SPACE_ENV="_YAML_PREFIX _YAML_NAMESPACE" 92 | 93 | local _tmp_file_name="./tmp_test_helpnode" 94 | 95 | # 96 | # Create temporary file 97 | 98 | # Make sure it doesn't already exist 99 | if [ -f "$_tmp_file_name" ]; then 100 | PRINT "File $_tmp_file_name already exists. That was unexpected!" "error" 101 | return 1 102 | fi 103 | 104 | # Create 105 | touch "$_tmp_file_name" 106 | 107 | # Make sure it was indeed created 108 | if [ ! -f "$_tmp_file_name" ]; then 109 | PRINT "Failed to create temporary file needed for testing" "error" 110 | return 1 111 | fi 112 | 113 | # 114 | # Mock intricate dependency 115 | _list() 116 | { 117 | local _output=$1 118 | local _nodes=() 119 | _nodes+=("Predefined_node1") 120 | _nodes+=("preDefined_NODE2") 121 | eval "${_output}=(\"\${_nodes[@]}\")" 122 | } 123 | 124 | _helpnode "/test123/" >> "$_tmp_file_name" 2>&1 125 | 126 | # Check if file size is >0 127 | if [ ! -s "$_tmp_file_name" ]; then 128 | PRINT "_helpnode FAILED!" "error" 129 | 130 | # Remove tmp file 131 | rm "$_tmp_file_name" 132 | return 1 133 | else 134 | # Check if file contents match the expected string 135 | local _expected_string= 136 | _expected_string=$(printf "/test123/\n\t\n\n+ Predefined_node1\n+ preDefined_NODE2") 137 | 138 | PRINT "Looking for expected results..." 139 | PRINT "Testing: $(cat ${_tmp_file_name})" 140 | PRINT "Expected: $_expected_string" 141 | if [ "$(cat ${_tmp_file_name})" = "$_expected_string" ]; then 142 | PRINT "_helpnode OK!" "ok" 143 | # remove tmp file 144 | rm "$_tmp_file_name" 145 | return 0 146 | else 147 | PRINT "_helpnode failed!" "error" 148 | # remove tmp file 149 | rm "$_tmp_file_name" 150 | return 2 151 | fi 152 | fi 153 | 154 | PRINT "_helpnode OK!" "ok" 155 | } 156 | 157 | --------------------------------------------------------------------------------