├── .gitattributes ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── need-help.md ├── codecov.yml └── workflows │ ├── aur-release.yml │ ├── codeql-analysis.yml │ ├── homebrew-release.yml │ ├── pypi-release.yml │ ├── snapcraft-release.yml │ ├── test-doc.yml │ └── testing.yml ├── .gitignore ├── .readthedocs.yaml ├── CONTRIBUTING.md ├── LICENSE ├── MANIFEST.in ├── README.md ├── assets └── dotdrop.svg ├── bootstrap.sh ├── completion ├── README.md ├── _dotdrop-completion.zsh ├── _dotdrop.sh-completion.zsh ├── dotdrop-completion.bash ├── dotdrop.fish ├── dotdrop.sh-completion.bash └── generate.sh ├── config.toml ├── config.yaml ├── docs ├── README.md ├── config │ ├── config-actions.md │ ├── config-config.md │ ├── config-dotfiles.md │ ├── config-dynvars.md │ ├── config-file.md │ ├── config-profiles.md │ ├── config-transformations.md │ ├── config-uservars.md │ └── config-variables.md ├── css │ └── extra.css ├── getting-started.md ├── howto │ ├── append.md │ ├── create-special-files.md │ ├── group-hosts.md │ ├── howto.md │ ├── improve-git-integration.md │ ├── include-in-template.md │ ├── manage-dconf-settings.md │ ├── merge-files-when-installing.md │ ├── prompt-user-for-variables.md │ ├── sensitive-dotfiles.md │ ├── sharing-content.md │ ├── special-chars.md │ ├── store-compressed-directories.md │ ├── symlink-dotfiles.md │ ├── system-config-files.md │ └── test-latest-dotdrop.md ├── installation.md ├── misc │ ├── migrate-from-submodule.md │ └── people-using-dotdrop.md ├── template │ ├── template-debug.md │ ├── template-filters.md │ ├── template-methods.md │ ├── template-variables.md │ └── templating.md └── usage.md ├── dotdrop.sh ├── dotdrop ├── __init__.py ├── action.py ├── cfg_aggregator.py ├── cfg_yaml.py ├── comparator.py ├── config.py ├── dictparser.py ├── dotdrop.py ├── dotfile.py ├── exceptions.py ├── ftree.py ├── importer.py ├── installer.py ├── jhelpers.py ├── linktypes.py ├── logger.py ├── options.py ├── profile.py ├── settings.py ├── templategen.py ├── uninstaller.py ├── updater.py ├── utils.py └── version.py ├── highlighters ├── README.md └── kakoune │ └── dotdrop.kak ├── manpage ├── dotdrop.1 ├── dotdrop.txt2man └── generate.sh ├── mkdocs.yml ├── packages ├── arch-dotdrop-git │ └── PKGBUILD ├── arch-dotdrop │ └── PKGBUILD ├── genpkg.sh └── snap │ └── snapcraft.yaml ├── pyproject.toml ├── requirements.txt ├── scripts ├── change_link.py ├── check-doc.sh ├── check-syntax.sh ├── check-tests-ng.sh ├── check-unittests.sh ├── check_links.py ├── dotdrop-version-manager.sh └── yaml_to_toml.py ├── tests-ng ├── README.md ├── actions-args-template.sh ├── actions-args.sh ├── actions-default.sh ├── actions-empty-dir.sh ├── actions-pre.sh ├── actions-template.sh ├── actions.sh ├── backup.sh ├── bad-diff-cmd.sh ├── chmod-compare.sh ├── chmod-import.sh ├── chmod-install-dir.sh ├── chmod-install.sh ├── chmod-more.sh ├── chmod-preserve-install.sh ├── chmod-preserve-update.sh ├── chmod-update.sh ├── clear-workdir.sh ├── compare-diff-types.sh ├── compare-global-negative-ignore.sh ├── compare-ignore-in-dotpath.sh ├── compare-ignore-missing.sh ├── compare-ignore-relative.sh ├── compare-ignore.sh ├── compare-include.sh ├── compare-negative-ignore-all-but.sh ├── compare-negative-ignore-relative.sh ├── compare-negative-ignore.sh ├── compare-profile-check.sh ├── compare.sh ├── corner-case.sh ├── deprecated-link.sh ├── diff-cmd.sh ├── dir-import-update.sh ├── dotdrop-variables.sh ├── dotfile-no-src.sh ├── dotfile-sub-variables.sh ├── dotfile-variables.sh ├── dotfiles-all.sh ├── dotfiles-dyn-paths.sh ├── double-config-import.sh ├── dry.sh ├── duplicate-key.sh ├── dynactions.sh ├── dyndotfilepaths.sh ├── dynextvariables.sh ├── dyninclude.sh ├── dynvariables.sh ├── env.sh ├── ext-actions.sh ├── extvariables.sh ├── filter_file.sh ├── force-actions.sh ├── func_file.sh ├── global-compare-ignore.sh ├── global-update-ignore.sh ├── globs.sh ├── header.sh ├── helpers ├── ignore-dir-when-sub-ignored.sh ├── ignore-empty.sh ├── ignore-patterns-negative.sh ├── ignore-patterns-regexp.sh ├── ignore-patterns.sh ├── import-as.sh ├── import-configs.sh ├── import-configs2.sh ├── import-duplicate.sh ├── import-ignore-in-dotpath.sh ├── import-ignore.sh ├── import-include.sh ├── import-link-children.sh ├── import-negative-ignore-all-but.sh ├── import-negative-ignore.sh ├── import-non-existing.sh ├── import-profile-dotfiles.sh ├── import-subfile.sh ├── import-to-no-profile.sh ├── import-variables.sh ├── import-with-empty.sh ├── import-with-key.sh ├── import-with-trans.sh ├── import.sh ├── imported-configs-variables.sh ├── imported-variables-from-config.sh ├── include-actions.sh ├── include-order.sh ├── include-variables.sh ├── include.sh ├── inst-link-default.sh ├── install-and-remove.sh ├── install-empty.sh ├── install-ignore.sh ├── install-link-children.sh ├── install-negative-ignore-all-but.sh ├── install-negative-ignore-no-match.sh ├── install-negative-ignore.sh ├── install-to-temp.sh ├── install.sh ├── jhelpers.sh ├── key-prefix-sep.sh ├── link-import-default.sh ├── link-templates-dir-home.sh ├── link-templates-dir.sh ├── link-templates.sh ├── link-value-tests.sh ├── macro-with-globals.sh ├── minversion.sh ├── misc.sh ├── notemplate.sh ├── profile-actions.sh ├── profile-dyninclude.sh ├── profile-dynvariables.sh ├── profile-import-dotfiles.sh ├── profile-undefined-variables.sh ├── re-import.sh ├── recinclude.sh ├── recvariables.sh ├── remove.sh ├── symlink-relative.sh ├── symlink.sh ├── template-dotpath.sh ├── template-link-value.sh ├── template-link.sh ├── template-trailing-new-line.sh ├── template-vars-dict.sh ├── tests_launcher.py ├── toml.sh ├── transformations-template.sh ├── transformations-with-args.sh ├── transformations.sh ├── uninstall-by-key.sh ├── uninstall-corner-cases.sh ├── uninstall.sh ├── update-global-negative-ignore.sh ├── update-ignore-in-dotpath.sh ├── update-ignore-missing.sh ├── update-ignore-relative.sh ├── update-ignore.sh ├── update-negative-ignore-all-but.sh ├── update-negative-ignore-relative.sh ├── update-negative-ignore.sh ├── update-profile-check.sh ├── update-rights.sh ├── update-templates.sh ├── update-with-key.sh ├── update.sh ├── uservariables.sh ├── variables-enrich.sh ├── variables-include.sh ├── variables-nested.sh ├── variables.sh ├── workdir-compare.sh ├── workdir.sh └── workers.sh ├── tests-requirements.txt ├── tests.sh └── tests ├── __init__.py ├── dummy.py ├── helpers.py ├── test_compare.py ├── test_import.py ├── test_install.py ├── test_jhelpers.py ├── test_listings.py ├── test_misc.py ├── test_options.py ├── test_remove.py ├── test_update.py └── test_yamlcfg.py /.gitattributes: -------------------------------------------------------------------------------- 1 | * linguist-vendored 2 | *.py linguist-vendored=false 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | ko_fi: deadc0de6 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: report bug 4 | title: "[bug] " 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | Dotdrop version (and git commit if run from source): v0.xxx 11 | Using dotdrop: as a submodule, from pypi, '...' 12 | 13 | **Describe the bug** 14 | 15 | A clear and concise description of what the bug is. 16 | 17 | **Steps to Reproduce** 18 | 19 | Steps to reproduce the behavior: 20 | 1. Create a dotfile with content '...' 21 | 2. '...' 22 | 4. See error 23 | 24 | **Expected behavior** 25 | 26 | A clear and concise description of what you expected to happen. 27 | 28 | **Additional information** 29 | 30 | The relevant part of the config file 31 | ```yaml 32 | config file content 33 | ``` 34 | 35 | Dotdrop's execution with the debug logs (`--verbose`) 36 | ```bash 37 | $ dotdrop --verbose ... 38 | ... 39 | ``` 40 | 41 | Any additional information that would help reproduce the bug. 42 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[feature]" 5 | labels: feature 6 | assignees: '' 7 | 8 | --- 9 | 10 | A clear and concise description of what you want to happen. 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/need-help.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Need help 3 | about: Get help 4 | title: "[help]" 5 | labels: help 6 | assignees: '' 7 | 8 | --- 9 | 10 | **What I am trying to achieve** 11 | 12 | **What I have tried so far** 13 | -------------------------------------------------------------------------------- /.github/codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | status: 3 | project: 4 | default: 5 | target: 90% 6 | threshold: 1% 7 | patch: off 8 | ignore: 9 | - "dotdrop/__init__.py" -------------------------------------------------------------------------------- /.github/workflows/aur-release.yml: -------------------------------------------------------------------------------- 1 | name: Release to aur 2 | on: 3 | release: 4 | types: [created] 5 | workflow_dispatch: 6 | jobs: 7 | aur_publish: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4 11 | - name: Prepare AUR package 12 | run: | 13 | version="" 14 | if [ hash git &>/dev/null ]; then 15 | version=$(git describe --abbrev=0 --tags | sed 's/^v//g') 16 | fi 17 | if [ -z "${version}" ]; then 18 | version=$(cat dotdrop/version.py | grep version | sed 's/^.*= .\(.*\).$/\1/g') 19 | fi 20 | [ -z "${version}" ] && exit 1 21 | sed -i "s/^pkgver=.*$/pkgver=${version}/g" packages/arch-dotdrop/PKGBUILD 22 | cat packages/arch-dotdrop/PKGBUILD 23 | - name: Publish to aur 24 | uses: KSXGitHub/github-actions-deploy-aur@v3.0.0 25 | with: 26 | pkgname: dotdrop 27 | pkgbuild: ./packages/arch-dotdrop/PKGBUILD 28 | commit_username: ${{ secrets.AUR_USERNAME }} 29 | commit_email: ${{ secrets.AUR_EMAIL }} 30 | ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }} 31 | commit_message: "bump version" 32 | -------------------------------------------------------------------------------- /.github/workflows/homebrew-release.yml: -------------------------------------------------------------------------------- 1 | name: Release to Homebrew 2 | on: 3 | release: 4 | types: [created] 5 | workflow_dispatch: 6 | jobs: 7 | homebrew-core: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: dawidd6/action-homebrew-bump-formula@v3 11 | with: 12 | token: ${{secrets.HOMEBREW_FORMULA_GH_TOKEN}} 13 | formula: dotdrop 14 | -------------------------------------------------------------------------------- /.github/workflows/pypi-release.yml: -------------------------------------------------------------------------------- 1 | name: Release to PyPI 2 | on: 3 | release: 4 | types: [created] 5 | workflow_dispatch: 6 | jobs: 7 | pypi_publish: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4 11 | - name: Set up Python 3.10 12 | uses: actions/setup-python@v4 13 | with: 14 | python-version: '3.10' 15 | - name: Install Tools 16 | run: | 17 | python -m pip install --upgrade pip 18 | pip install build packaging setuptools wheel twine 19 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 20 | - name: Build and Publish 21 | env: 22 | TWINE_USERNAME: __token__ 23 | TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} 24 | run: | 25 | python3 -m build --wheel --no-isolation 26 | twine upload dist/* 27 | -------------------------------------------------------------------------------- /.github/workflows/snapcraft-release.yml: -------------------------------------------------------------------------------- 1 | name: Release to Snapcraft 2 | on: 3 | release: 4 | types: [created] 5 | workflow_dispatch: 6 | jobs: 7 | build: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4 11 | - name: snapcraft setup 12 | run: | 13 | cp -r "${GITHUB_WORKSPACE}/packages/snap" "${GITHUB_WORKSPACE}" 14 | sed -i 's#source: ../../#source: \.#g' "${GITHUB_WORKSPACE}/snap/snapcraft.yaml" 15 | - uses: snapcore/action-build@v1 16 | id: build 17 | - uses: snapcore/action-publish@v1 18 | env: 19 | SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_LOGIN }} 20 | with: 21 | snap: ${{ steps.build.outputs.snap }} 22 | release: stable 23 | -------------------------------------------------------------------------------- /.github/workflows/test-doc.yml: -------------------------------------------------------------------------------- 1 | name: test-doc 2 | on: [push, pull_request, workflow_dispatch] 3 | jobs: 4 | test-doc: 5 | runs-on: ubuntu-22.04 6 | continue-on-error: true 7 | steps: 8 | - uses: actions/checkout@v4 9 | - name: Set up Python 10 | uses: actions/setup-python@v5 11 | with: 12 | python-version: '3.x' 13 | - name: Setup Node 14 | uses: actions/setup-node@v4 15 | with: 16 | node-version: 20 17 | - name: Install dependencies 18 | run: | 19 | python -m pip install --upgrade pip 20 | pip install -r tests-requirements.txt 21 | npm install -g remark-cli remark-validate-links 22 | - name: Check the doc 23 | run: | 24 | ./scripts/check-doc.sh 25 | -------------------------------------------------------------------------------- /.github/workflows/testing.yml: -------------------------------------------------------------------------------- 1 | name: tests 2 | on: [push, pull_request, workflow_dispatch] 3 | jobs: 4 | test: 5 | runs-on: ubuntu-22.04 6 | strategy: 7 | matrix: 8 | python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] 9 | steps: 10 | - uses: actions/checkout@v4 11 | - name: Set up Python ${{ matrix.python-version }} 12 | uses: actions/setup-python@v5 13 | with: 14 | python-version: ${{ matrix.python-version }} 15 | - name: Setup Node 16 | uses: actions/setup-node@v4 17 | with: 18 | node-version: 20 19 | - name: Install dependencies 20 | run: | 21 | python -m pip install --upgrade pip 22 | pip install -r tests-requirements.txt 23 | pip install -r requirements.txt 24 | sudo apt-get install shellcheck 25 | - name: Run with 1 worker 26 | run: | 27 | ./tests.sh 28 | - name: Upload coverage reports to Codecov 29 | uses: codecov/codecov-action@v3 30 | with: 31 | files: coverage.xml 32 | env: 33 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # python stuff 2 | *.pyc 3 | __pycache__ 4 | dist/ 5 | build/ 6 | *.egg-info/ 7 | tags 8 | env 9 | venv 10 | .pytest_cache 11 | .mypy_cache 12 | 13 | # coverage stuff 14 | .coverage 15 | .coverage* 16 | htmlcov 17 | coverages/ 18 | coverage.xml 19 | 20 | # IDE 21 | .idea/ 22 | .vscode/ 23 | .atom/ 24 | 25 | # Snap packages 26 | parts/ 27 | prime/ 28 | stage/ 29 | *.snap 30 | /packages/snap/.snapcraft/ 31 | /packages/*_source.tar.bz2 32 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # Read the Docs configuration file for MkDocs projects 2 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 3 | 4 | # Required 5 | version: 2 6 | 7 | # Set the version of Python and other tools you might need 8 | build: 9 | os: ubuntu-22.04 10 | tools: 11 | python: "3.11" 12 | 13 | mkdocs: 14 | configuration: mkdocs.yml -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md LICENSE requirements.txt 2 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | 5 | conf="config.yaml" 6 | 7 | # copy dotdrop entry point 8 | cp dotdrop/dotdrop.sh dotdrop.sh 9 | chmod +x dotdrop.sh 10 | mkdir -p dotfiles 11 | 12 | if [ ! -e "${conf}" ]; then 13 | # init config file 14 | ./dotdrop.sh gencfg > "${conf}" 15 | fi 16 | -------------------------------------------------------------------------------- /completion/README.md: -------------------------------------------------------------------------------- 1 | Here are completion files for `bash`, `zsh` and `fish` 2 | for the use of dotdrop through the bash script `dotdrop.sh` 3 | or through the Python script `dotdrop` (PyPI, snap, etc.). 4 | 5 | `bash` and `zsh` scripts are generated using 6 | [infi.docopt_completion](https://github.com/Infinidat/infi.docopt_completion). 7 | 8 | # bash 9 | 10 | Source the file 11 | 12 | * if using `dotdrop.sh`: [dotdrop.sh-completion.bash](dotdrop.sh-completion.bash) 13 | * If using `dotdrop`: [dotdrop-completion.bash](dotdrop-completion.bash) 14 | 15 | # zsh 16 | 17 | Copy the file to a path within `${fpath}` 18 | 19 | * If using `dotdrop.sh`: [_dotdrop.sh-completion.zsh](_dotdrop.sh-completion.zsh) 20 | * If using `dotdrop`: [_dotdrop-completion.zsh](_dotdrop-completion.zsh) 21 | 22 | # fish 23 | 24 | Install for your user: 25 | ```bash 26 | mkdir -p ~/.config/fish/completions 27 | cp dotdrop.fish ~/.config/fish/completions/ 28 | ``` 29 | 30 | Install system-wide: 31 | ```bash 32 | cp dotdrop.fish /usr/share/fish/completions/ 33 | ``` 34 | -------------------------------------------------------------------------------- /completion/generate.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # pip3 install --user infi.docopt_completion 6 | # 7 | 8 | set -eu -o errtrace -o pipefail 9 | 10 | bin="docopt-completion" 11 | if ! hash ${bin}; then 12 | echo "\"${bin}\" not found!" 13 | exit 1 14 | fi 15 | 16 | cur=$(cd "$(dirname "${0}")" && pwd) 17 | opwd=$(pwd) 18 | 19 | # output files 20 | compl="${cur}" 21 | dtsh_zsh="${compl}/_dotdrop.sh-completion.zsh" 22 | dtsh_bash="${compl}/dotdrop.sh-completion.bash" 23 | dt_zsh="${compl}/_dotdrop-completion.zsh" 24 | dt_bash="${compl}/dotdrop-completion.bash" 25 | 26 | # generate for dotdrop.sh 27 | cd "${cur}"/.. 28 | docopt-completion ./dotdrop.sh --manual-zsh 29 | mv ./_dotdrop.sh "${dtsh_zsh}" 30 | docopt-completion ./dotdrop.sh --manual-bash 31 | mv ./dotdrop.sh.sh "${dtsh_bash}" 32 | 33 | # generate for dotdrop 34 | vbin="virtualenv" 35 | if ! hash ${vbin}; then 36 | echo "\"${vbin}\" not found!" 37 | exit 1 38 | fi 39 | cd "${cur}"/.. 40 | venv="/tmp/dotdrop-venv" 41 | ${vbin} -p python3 ${venv} 42 | # shellcheck source=/dev/null 43 | source ${venv}/bin/activate 44 | pip install . 45 | cd /tmp 46 | docopt-completion dotdrop --manual-zsh 47 | mv ./_dotdrop "${dt_zsh}" 48 | docopt-completion dotdrop --manual-bash 49 | mv ./dotdrop.sh "${dt_bash}" 50 | deactivate 51 | rm -rf ${venv} 52 | 53 | # pivot back 54 | cd "${opwd}" 55 | -------------------------------------------------------------------------------- /config.toml: -------------------------------------------------------------------------------- 1 | [config] 2 | backup = true 3 | banner = true 4 | create = true 5 | dotpath = "dotfiles" 6 | keepdot = false 7 | link_dotfile_default = "nolink" 8 | link_on_import = "nolink" 9 | longkey = false -------------------------------------------------------------------------------- /config.yaml: -------------------------------------------------------------------------------- 1 | config: 2 | backup: true 3 | banner: true 4 | create: true 5 | dotpath: dotfiles 6 | keepdot: false 7 | link_dotfile_default: nolink 8 | link_on_import: nolink 9 | longkey: false 10 | dotfiles: 11 | profiles: 12 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Dotdrop 2 | 3 | [Dotdrop](https://github.com/deadc0de6/dotdrop) is a dotfiles manager that provides efficient 4 | ways to manage your dotfiles. 5 | It is especially powerful when it comes to managing those across different hosts. 6 | 7 | The idea of dotdrop is to have the ability to store each dotfile only once and deploy 8 | them with different content on different hosts/setups. 9 | 10 | Most information on using dotdrop is described in this documentation 11 | and in the [readme](https://github.com/deadc0de6/dotdrop/blob/master/README.md). 12 | 13 | For more, check: 14 | 15 | * [The walkthrough example](https://github.com/deadc0de6/dotdrop#getting-started) 16 | * [How people are using dotdrop](misc/people-using-dotdrop.md) 17 | 18 | For more config files examples, [search GitHub](https://github.com/search?q=path%3Aconfig.yaml+dotdrop&type=Code). 19 | -------------------------------------------------------------------------------- /docs/config/config-dynvars.md: -------------------------------------------------------------------------------- 1 | # Dynvariables entry 2 | 3 | The **dynvariables** entry (optional) contains an interpreted variables mapping. 4 | 5 | ```yaml 6 | dynvariables: 7 | : 8 | ``` 9 | 10 | You can also use multi-line (see [yaml related doc](https://yaml-multiline.info/)). 11 | For example: 12 | ```yaml 13 | dynvariables: 14 | : >- 15 | 16 | 17 | 18 | ``` 19 | 20 | For example: 21 | ```yaml 22 | dynvariables: 23 | dvar1: head -1 /proc/meminfo 24 | dvar2: "echo 'this is some test' | rev | tr ' ' ','" 25 | dvar3: /tmp/my_shell_script.sh 26 | user: "echo $USER" 27 | config_file: >- 28 | test -f "{{@@ base_config @@}}" && 29 | echo "{{@@ base_config @@}}" || 30 | echo "{{@@ dfl_config @@}}" 31 | variables: 32 | base_config: "profile_base.yaml" 33 | dfl_config: "profile_default.yaml" 34 | ``` 35 | 36 | They have the same properties as [Variables](config-variables.md). -------------------------------------------------------------------------------- /docs/config/config-uservars.md: -------------------------------------------------------------------------------- 1 | # Uservariables entry 2 | 3 | The **uservariables** entry (optional) contains a collection of variables 4 | whose values are queried from the user 5 | (See [User variables](config-variables.md)). 6 | 7 | ```yaml 8 | uservariables: 9 | : 10 | ``` 11 | 12 | If you want to manually enter variables' values, you can use the 13 | `uservariables` entry. Each variable will be prompted to the user. 14 | 15 | For example: 16 | ```yaml 17 | uservariables: 18 | emailvar: "email" 19 | ``` 20 | 21 | will prompt the user to enter a value for the variable `emailvar`: 22 | ``` 23 | Please provide the value for "email": 24 | ``` 25 | 26 | And store the entered text as the value for the variable `email`. 27 | The variable can then be used as any other [variable](config-file.md#variables). 28 | 29 | `uservariables` are eventually saved to `uservariables.yaml` (relatively to the 30 | config file). 31 | This allows to use the following construct to prompt once for some specific variables and 32 | then store them in a file. You might also want to add `uservariables.yaml` to your `.gitignore`. 33 | ```yaml 34 | uservariables: 35 | emailvar: "email" 36 | config: 37 | import_variables: 38 | - uservariables.yaml:optional 39 | ``` 40 | 41 | For an example, see [prompt user for variables](../howto/prompt-user-for-variables.md). 42 | -------------------------------------------------------------------------------- /docs/config/config-variables.md: -------------------------------------------------------------------------------- 1 | # Variables entry 2 | 3 | The **variables** entry (optional) contains a variables mapping (See [variables](config-file.md#variables)). 4 | 5 | ```yaml 6 | variables: 7 | : 8 | ``` 9 | 10 | Variables defined in the `variables` entry are made available within the config file. 11 | 12 | For example 13 | ```yaml 14 | variables: 15 | myvar: "some value" 16 | home: "{{@@ env['HOME'] @@}}" 17 | email: "user@domain.com" 18 | ``` 19 | 20 | Config variables are recursively evaluated, which means that 21 | a config like the below: 22 | ```yaml 23 | variables: 24 | var1: "var1" 25 | var2: "{{@@ var1 @@}} var2" 26 | var3: "{{@@ var2 @@}} var3" 27 | var4: "{{@@ dvar4 @@}}" 28 | dynvariables: 29 | dvar1: "echo dvar1" 30 | dvar2: "{{@@ dvar1 @@}} dvar2" 31 | dvar3: "{{@@ dvar2 @@}} dvar3" 32 | dvar4: "echo {{@@ var3 @@}}" 33 | ``` 34 | 35 | will result in the following available variables: 36 | 37 | * var1: `var1` 38 | * var2: `var1 var2` 39 | * var3: `var1 var2 var3` 40 | * var4: `echo var1 var2 var3` 41 | * dvar1: `dvar1` 42 | * dvar2: `dvar1 dvar2` 43 | * dvar3: `dvar1 dvar2 dvar3` 44 | * dvar4: `var1 var2 var3` 45 | 46 | Config variables can be nested as shown below: 47 | ```yaml 48 | variables: 49 | rofi: 50 | background_color: "rgba ( 33, 33, 33, 100 % );" 51 | polybar: 52 | background_color: "#cc222222" 53 | ``` 54 | 55 | Where the above would be referenced using `{{@@ rofi.background_color @@}}` 56 | and `{{@@ polybar.background_color @@}}`. -------------------------------------------------------------------------------- /docs/css/extra.css: -------------------------------------------------------------------------------- 1 | /* 2 | * from https://github.com/AaltoSciComp/scicomp-docs/blob/master/_static/theme_overrides.css 3 | */ 4 | 5 | /* override table width restrictions: 6 | https://github.com/rtfd/sphinx_rtd_theme/issues/117 */ 7 | .wy-table-responsive table td, .wy-table-responsive table th { 8 | white-space: normal !important; 9 | } 10 | 11 | @media screen and (min-width: 767px) { 12 | .wy-table-responsive { 13 | max-width: 100% !important; 14 | overflow: visible !important; 15 | } 16 | } 17 | 18 | /* RST has an extra space after sub-lists in unordered lists. This */ 19 | /* fixes that annoying problem. */ 20 | .rst-content .section ul p { 21 | margin-bottom: 0px; 22 | } 23 | .rst-content .section li ol { 24 | margin-bottom: 0px; 25 | } 26 | 27 | /* Strikethrough */ 28 | /* https://stackoverflow.com/questions/6518788/rest-strikethrough */ 29 | .strike { 30 | text-decoration: line-through; 31 | } 32 | 33 | /* */ 34 | .wy-side-nav-search > a img.logo, .wy-side-nav-search .wy-dropdown > a img.logo { 35 | max-width: 70%; 36 | } 37 | 38 | details summary { 39 | font-size: large; 40 | font-weight: bold; 41 | margin-bottom:12px 42 | } 43 | 44 | details { 45 | margin-bottom:20px 46 | } 47 | -------------------------------------------------------------------------------- /docs/getting-started.md: -------------------------------------------------------------------------------- 1 | # Getting started 2 | 3 | ## Repository setup 4 | 5 | Either create a Git repository on your prefered platform and clone it or create one locally. 6 | This repository will contain two main elements, dotdrop's config file (`config.yaml`) 7 | and a directory containing all your dotfiles managed by dotdrop. 8 | ```bash 9 | ## clone your repository (my-dotfiles) 10 | $ git clone /my-dotfiles 11 | $ cd my-dotfiles 12 | 13 | ## within the repository create a directory to store your dotfiles 14 | ## (refered by "dotpath" in the config, which defaults to "dotfiles") 15 | $ mkdir dotfiles 16 | ``` 17 | 18 | Then generate a base config file: 19 | ```bash 20 | $ dotdrop gencfg > config.yaml 21 | ``` 22 | 23 | It is recommended to store your config file directly within your repository 24 | (*my-dotfiles* in the example above), but you could save it in different places if you wish; 25 | see [config location](config/config-file.md#location) for more. 26 | 27 | ```bash 28 | $ tree my-dotfiles 29 | my-dotfiles 30 | ├── config.yaml 31 | └── dotfiles 32 | ``` 33 | 34 | If your config file is in an exotic location, you can add an alias 35 | in your preferred shell to call dotdrop with the config file path argument. 36 | ``` 37 | alias dotdrop='dotdrop --cfg=' 38 | ``` 39 | 40 | For more info on the config file format, see [the config file doc](config/config-file.md). 41 | 42 | ## Basic usage 43 | 44 | The basic use of dotdrop is: 45 | 46 | * Import a file/directory to manage (this will copy the files from the filesystem to your `dotpath`): `dotdrop import ` 47 | * Install the dotfiles (this will *copy/link* them from your `dotpath` to the filesystem): `dotdrop install` 48 | 49 | Then if you happen to update the file/directory directly on the filesystem (add a new file/dir, edit content, etc.) you can use the `update` command to mirror back those changes in dotdrop. 50 | 51 | For more advanced uses: 52 | 53 | * `dotdrop --help` for the CLI usage. 54 | * [The usage doc](usage.md) 55 | * [The example](https://github.com/deadc0de6/dotdrop#getting-started) 56 | * [The howto](howto/howto.md) -------------------------------------------------------------------------------- /docs/howto/append.md: -------------------------------------------------------------------------------- 1 | # Append text on install 2 | 3 | Sometimes it might be useful to be able to append some text to a 4 | file. Dotdrop is able to do that with the help of 5 | [actions](../config/config-actions.md) and a temporary file. 6 | 7 | Below is a config example to append to a file: 8 | ```yaml 9 | dynvariables: 10 | tmpfile: mktemp 11 | variables: 12 | somefile_final: ~/.somefile 13 | dotfiles: 14 | f_somefile: 15 | dst: "{{@@ tmpfile @@}}" 16 | src: somefile 17 | actions: 18 | - strip "{{@@ somefile_final @@}}" 19 | - append "{{@@ tmpfile @@}}" "{{@@ somefile_final @@}}" 20 | actions: 21 | pre: 22 | strip: "sed -i '/^# my pattern$/,$d' {0}" 23 | post: 24 | append: "cat {0} >> {1}; rm -f {0}" 25 | ``` 26 | During installation, the `strip` action is executed before the installation, and it strips everything from the pattern `# my pattern` to the end of the file. Then the dotfile `somefile` is installed in a temporary location (here `tmpfile`) and finally the post action `append` will append the contents of the `tmpfile` to the final dotfile pointed to by `somefile_final`. 27 | 28 | Obviously, the dotfile in the dotpath should start with a unique pattern (here `# my pattern`): 29 | ``` 30 | # my pattern 31 | this is the end 32 | ``` 33 | -------------------------------------------------------------------------------- /docs/howto/create-special-files.md: -------------------------------------------------------------------------------- 1 | # Create files on install 2 | 3 | One way to create symlinks (or any other special file) is to use a combination of 4 | [actions](../config/config-actions.md) and a *fake* dotfile. 5 | 6 | Let's say, for example, you have a list of directories you want to link 7 | from under `~/.original` to `~/symlinks`. 8 | ```bash 9 | $ tree ~/.original 10 | /home/user/.original 11 | ├── dir1 12 | ├── dir2 13 | └── dir3 14 | ``` 15 | 16 | First you would store these directory names in a text file in your `/links.txt`: 17 | ``` 18 | dir1 19 | dir2 20 | dir3 21 | ``` 22 | 23 | The config file would contain different elements: 24 | 25 | * A `dynvariables` that will read the above text file 26 | * A few `variables` for the source and destination 27 | * An action that will create the destination directory and symlink those directories 28 | * A *fake* dotfile (with no `src` and no `dst` values) that will be always installed with the above action 29 | 30 | ```yaml 31 | dynvariables: 32 | links_list: "cat {{@@ _dotdrop_dotpath @@}}/links.txt | xargs" 33 | ... 34 | variables: 35 | links_dst: "{{@@ env['HOME'] @@}}/.symlinks" 36 | links_src: "{{@@ env['HOME'] @@}}/.original" 37 | ... 38 | actions: 39 | symlink_them: 'mkdir -p "{1}" && for lnk in {0}; do ln -s "{{@@ links_src @@}}/$lnk" "{1}/$lnk"; done' 40 | ... 41 | fake: 42 | src: 43 | dst: 44 | actions: 45 | - symlink_them '{{@@ links_list @@}}' '{{@@ links_dst @@}}' 46 | ``` 47 | 48 | The result would be: 49 | ```bash 50 | $ tree ~/.symlinks 51 | /home/user/.symlinks 52 | ├── dir1 -> /home/user/.original/dir1 53 | ├── dir2 -> /home/user/.original/dir2 54 | └── dir3 -> /home/user/.original/dir3 55 | ``` 56 | 57 | For reference, see [issue 243](https://github.com/deadc0de6/dotdrop/issues/243). 58 | -------------------------------------------------------------------------------- /docs/howto/group-hosts.md: -------------------------------------------------------------------------------- 1 | # Group hosts in config and meta profiles 2 | 3 | Let's consider the situation where you have multiple hosts from different distros and you 4 | want an easy way to structure your config file nicely but also simplify the use 5 | of templates (since multiple hosts in the same distro would share the same configs parts - 6 | or if branch in templates). 7 | 8 | You define two types of profiles: 9 | 10 | * **Meta profiles**: for example for distros it would be something like `os_arch`, `os_debian` and so on. 11 | These are never directly used for installing dotfiles but instead included by other profiles. 12 | * **Host profiles** (defaults to hostnames): the usual `home`, `office`, etc 13 | 14 | Each *Host profile* would include a *meta profile* and inherit all its dotfiles as well as 15 | it variables. For example in the *meta profile* you would define variables like `distro: debian` 16 | that you could use in your templates with `{%@@ if distro == "debian" @@%}` to target all 17 | profiles that inherit from the same *meta profile*. 18 | 19 | ```yaml 20 | profiles: 21 | meta_base: 22 | dotfiles: 23 | - f_zshrc 24 | - f_zshrc 25 | os_arch: 26 | variables: 27 | distro: arch 28 | include: 29 | - meta-base 30 | os_debian: 31 | variables: 32 | distro: debian 33 | include: 34 | - meta-base 35 | home: 36 | include: 37 | - os_arch 38 | dotfiles: 39 | - f_vimrc 40 | office: 41 | include: 42 | - os_debian 43 | dotfiles: 44 | - f_something 45 | ``` 46 | 47 | You then have the opportunity in your templates to do the following 48 | that would select the if branch for all profiles inheriting from 49 | a specific *meta profile*. 50 | ``` 51 | # zsh-syntax-highlighting 52 | # https://github.com/zsh-users/zsh-syntax-highlighting 53 | {%@@ if distro == "arch" @@%} 54 | source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 55 | {%@@ elif distro == "debian" @@%} 56 | source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 57 | {%@@ endif @@%} 58 | ``` -------------------------------------------------------------------------------- /docs/howto/howto.md: -------------------------------------------------------------------------------- 1 | # How To 2 | 3 | ## Append text to a dotfile on install 4 | 5 | [Append text to a dotfile on install](append.md) 6 | 7 | ## Create files on install 8 | 9 | [Create files on install](create-special-files.md) 10 | 11 | ## Handle compressed directories 12 | 13 | [Store compressed directories](store-compressed-directories.md) 14 | 15 | ## Handle secrets 16 | 17 | [Handle secrets](sensitive-dotfiles.md) 18 | 19 | ## Handle special chars 20 | 21 | [Handle special chars](special-chars.md) 22 | 23 | ## Improve Git integration 24 | 25 | [Improve Git integration](improve-git-integration.md) 26 | 27 | ## Include files or templates in templates 28 | 29 | [Include files or templates in templates](include-in-template.md) 30 | 31 | ## Manage system dotfiles 32 | 33 | [Manage system dotfiles](system-config-files.md) 34 | 35 | ## Merge files on install 36 | 37 | [Merge files on install](merge-files-when-installing.md) 38 | 39 | ## Prompt user for variables 40 | 41 | [Prompt user for variables](prompt-user-for-variables.md) 42 | 43 | ## Share content across dotfiles 44 | 45 | [Share content across dotfiles](sharing-content.md) 46 | 47 | ## Symlink dotfiles 48 | 49 | [Symlink dotfiles](symlink-dotfiles.md) 50 | -------------------------------------------------------------------------------- /docs/howto/improve-git-integration.md: -------------------------------------------------------------------------------- 1 | # Improve Git integration 2 | 3 | The below aliases can help with the process of updating your dotfiles between multiple hosts. Add them to your `~/.zshrc` or `~/.bashrc`. You can then simply run `dotsync` to push or pull from your dotfile repository. 4 | 5 | ``` 6 | # Your dotdrop git repository location 7 | export DOTREPO="/path/to/your/dotdrop/repo" 8 | 9 | alias dotdrop="$DOTREPO/dotdrop.sh" 10 | alias dotgit="git -C $DOTREPO" 11 | alias dotsync="dotgit pull && dotgit add -A && dotgit commit && dotgit push; dotdrop install" 12 | ``` 13 | 14 | Provided by ReekyMarko. 15 | -------------------------------------------------------------------------------- /docs/howto/include-in-template.md: -------------------------------------------------------------------------------- 1 | # Include files or templates in templates 2 | 3 | [Jinja2](https://jinja.palletsprojects.com/en/2.11.x/templates/) provides the ability to include an external file/template from within a template with the directive `include`. See the [related docs](https://jinja.palletsprojects.com/en/2.11.x/templates/#include) for more. The path must be relative to the `dotpath`. 4 | 5 | For example: 6 | ```yaml 7 | {%@@ include 'colors/black.colors' @@%} 8 | ``` 9 | 10 | Of course, paths could be also dynamically generated using variables. 11 | For example: 12 | ```yaml 13 | {%@@ include colors_path + '/black.colors' @@%} 14 | ``` 15 | -------------------------------------------------------------------------------- /docs/howto/manage-dconf-settings.md: -------------------------------------------------------------------------------- 1 | # Manage dconf settings 2 | 3 | Here is an example (thanks [@gmvelencoso](https://github.com/gmvelencoso)) 4 | using dotdrop to manage dconf settings: 5 | 6 | ```yaml 7 | actions: 8 | dconf_load: dconf load "{0}" < "{{@@ _dotfile_abs_src @@}}" 9 | trans_update: 10 | dconf_dump: dconf dump "{2}" > "{1}" 11 | dconf_tilix: 12 | src: config/tilix/tilix.dconf 13 | dst: /tmp/tilix.dconf 14 | actions: 15 | - dconf_load /com/gexperts/Tilix/ 16 | trans_update: dconf_dump /com/gexperts/Tilix/ 17 | link: nolink 18 | ``` 19 | 20 | On `install`/`compare`, the [action](../config/config-actions.md) `dconf_load` will call `dconf` to load 21 | the configuration from the file stored in the *dotpath* under `config/tilix/tilix.dconf`. 22 | 23 | On `update`, the [transformation](../config/config-transformations.md) `trans_update` will dump the configuration 24 | entry and use it to update the file in the *dotpath*. 25 | -------------------------------------------------------------------------------- /docs/howto/merge-files-when-installing.md: -------------------------------------------------------------------------------- 1 | # Merge files on install 2 | 3 | Dotdrop allows to merge multiple files into one using Jinja2's `include` directive. 4 | 5 | For example, let's assume you want to keep your `.vimrc` split into multiple parts in dotdrop: 6 | * `/vimrc.d/top`: top part of the file 7 | * `/vimrc.d/bottom`: bottom part of the file 8 | 9 | And you want dotdrop to merge all those files into `~/.vimrc` whenever you process your .vimrc with dotdrop. 10 | 11 | First make sure `~/.vimrc` is present in your config file: 12 | ```yaml 13 | ... 14 | dotfiles: 15 | f_vimrc: 16 | dst: ~/.vimrc 17 | src: vimrc 18 | profiles: 19 | hostname: 20 | dotfiles: 21 | - f_vimrc 22 | ... 23 | ``` 24 | 25 | Note that the subfiles (`vimrc.d/top` and `vimrc.d/bottom`) 26 | are not known to the config and do not need to be. 27 | 28 | Edit the stored vimrc file to include the other files, for example: 29 | ```bash 30 | $ cat /vimrc 31 | {%@@ include 'vimrc.d/top' @@%} 32 | filetype on 33 | set t_Co=256 34 | set tw=0 35 | set tabstop=2 36 | set shiftwidth=2 37 | set expandtab 38 | set nocompatible 39 | set nomodeline 40 | syntax on 41 | {%@@ include 'vimrc.d/bottom' @@%} 42 | ``` 43 | 44 | The `include` path parameter needs to be relative to your `dotpath`. 45 | 46 | Dotdrop will then automagically include the files into your vimrc when handling `f_vimrc`. 47 | 48 | ## Merge all files in a directory 49 | 50 | To include all files in a directory, a combination of 51 | [dynvariables](../config/config-dynvars.md) 52 | and [Jinja2 directives](https://jinja.palletsprojects.com/en/2.11.x/) have to be used. 53 | 54 | Let's say all files in `/toinclude` need to be included into a dotfile. 55 | 56 | First define a [dynvariables](../config/config-dynvars.md) 57 | in the config file which will look for files to include in the above directory: 58 | ```yaml 59 | dynvariables: 60 | allfiles: "cd {{@@ _dotdrop_dotpath @@}}; find toinclude/ -type f | xargs" 61 | ``` 62 | 63 | Note that `_dotdrop_dotpath` is part of the built-in variables 64 | (For more, see [template variables](../template/template-variables.md#template-variables)). 65 | 66 | Then use the generated list in the dotfile template: 67 | ``` 68 | {%@@ for f in allfiles.split() @@%} 69 | {%@@ include f @@%} 70 | {%@@ endfor @@%} 71 | ``` 72 | -------------------------------------------------------------------------------- /docs/howto/prompt-user-for-variables.md: -------------------------------------------------------------------------------- 1 | # Prompt user for variables 2 | 3 | With the use of [uservariables](../config/config-uservars.md), 4 | one can define specific variables that need to be initially filled in manually 5 | by the user on first run. 6 | 7 | The provided values are then automatically saved by dotdrop to `uservariables.yaml`, 8 | which can be included in the main config as a file from which variables are imported 9 | using [import_variables](../config/config-config.md). 10 | 11 | Let's say, for example, that you want to manually provide the email value 12 | on new hosts you deploy your dotfiles to. 13 | 14 | You'd add the following elements to your config: 15 | ```yaml 16 | uservariables: 17 | emailvar: "email" 18 | config: 19 | import_variables: 20 | - uservariables.yaml:optional 21 | ``` 22 | 23 | On first run, the `emailvar` is prompted to the user and then saved 24 | to `uservariables.yaml`. Since this file is imported, the value for 25 | `emailvar` will automatically be filled in without prompting the 26 | user on subsequent calls. 27 | -------------------------------------------------------------------------------- /docs/howto/special-chars.md: -------------------------------------------------------------------------------- 1 | # Handle special chars 2 | 3 | * [Detect encoding](#detect-encoding) 4 | * [Special chars](#special-chars) 5 | * [Re-encode](#re-encode) 6 | 7 | --- 8 | 9 | ## Detect encoding 10 | 11 | Text file encoding can be identified using, for example, `file -b ` or in vim 12 | with `:set fileencoding`. 13 | 14 | Here's an example of encoding that will fully work with dotdrop: 15 | ```bash 16 | $ file -b 17 | UTF-8 Unicode text, with escape sequences 18 | ``` 19 | 20 | and another that will mislead the `compare` command and return false/inaccurate results: 21 | ```bash 22 | $ file -b 23 | ISO-8859 text, with escape sequences 24 | ``` 25 | 26 | ## Special chars 27 | 28 | ### CRLF 29 | 30 | The use of dotfiles with DOS/Windows line endings (CRLF, `\r\n`) will result in 31 | the comparison (`compare`) returning a difference where there is none. 32 | This is due to Jinja2 stripping CRLF. 33 | 34 | One solution is to use `dos2unix` to re-format the dotfiles before adding them 35 | to dotdrop. 36 | 37 | See . 38 | 39 | ### Non-Unicode chars 40 | 41 | Jinja2 is not able to process non-Unicode chars (). This means that dotfiles using non-Unicode chars can still be fully managed by dotdrop; however, when comparing the local file with the one stored in dotdrop, `compare` will return a difference even if there is none. 42 | 43 | Either replace the non-Unicode chars (see below [Re-encode](#re-encode)) or accept the fact the comparison shows a difference while there's none. 44 | 45 | See . 46 | 47 | ## Re-encode 48 | 49 | To change an existing file's encoding, you can use `recode UTF-8 ` (see [recode](https://linux.die.net/man/1/recode)) or in vim `:set fileencoding=utf-8`. 50 | -------------------------------------------------------------------------------- /docs/howto/store-compressed-directories.md: -------------------------------------------------------------------------------- 1 | # Handle compressed directories 2 | 3 | This is an example of how to use transformations (`trans_install` and `trans_update`) to store 4 | compressed directories and deploy them with dotdrop. 5 | 6 | Start by defining the transformations: 7 | ```yaml 8 | trans_install: 9 | uncompress: "mkdir -p {1} && tar -xf {0} -C {1}" 10 | trans_update: 11 | compress: "tar -cf {1} -C {0} ." 12 | ``` 13 | 14 | Then import the directory by specifying which transformations to apply/associate: 15 | ```bash 16 | dotdrop import --transw=compress --transr=uncompress ~/.somedir 17 | ``` 18 | 19 | The *read* transformation `uncompress` is used to execute the below command before installing/comparing the dotfile (where `{0}` is the source and `{1}` the destination): 20 | ```bash 21 | mkdir -p {1} && tar -xf {0} -C {1} 22 | ``` 23 | 24 | And the *write* transformation `compress` is run when updating the dotfile directory by compressing it (where `{0}` is the source and `{1}` the destination): 25 | ```bash 26 | tar -cf {1} -C {0} . 27 | ``` 28 | 29 | See [transformations](../config/config-transformations.md). -------------------------------------------------------------------------------- /docs/howto/system-config-files.md: -------------------------------------------------------------------------------- 1 | # Manage system dotfiles 2 | 3 | Dotdrop doesn't allow to handle file owernership (at least not directly). Every file operation (create/copy file/directory, create symlinks, etc.) is executed with the rights of the user calling dotdrop. 4 | 5 | Using dotdrop with `sudo` to manage unprivileged and privileged files in the same *session* is a bad idea as the resulting files will all have messed-up owners. 6 | 7 | It is therefore recommended to have two different config files (and thus two different *dotpath*s) 8 | for handling these two uses cases: 9 | 10 | For example: 11 | 12 | * One `config-user.yaml` for the local/user dotfiles (with its dedicated *dotpath*, for example `dotfiles-user`) 13 | * One `config-root.yaml` for the system/root dotfiles (with its dedicated *dotpath*, for example `dotfiles-root`) 14 | 15 | `config-user.yaml` is used when managing the user's dotfiles: 16 | ```bash 17 | ## user config file is config-user.yaml 18 | $ dotdrop import --cfg config-user.yaml 19 | $ dotdrop install --cfg config-user.yaml 20 | ... 21 | ``` 22 | 23 | `config-root.yaml` is used when managing the system's dotfiles and is to be used with `sudo` or directly by the root user: 24 | ```bash 25 | ## root config file is config-root.yaml 26 | $ sudo dotdrop import --cfg=config-root.yaml 27 | $ sudo dotdrop install --cfg=config-root.yaml 28 | ... 29 | ``` 30 | 31 | When commiting the local and system wide changes git will complain about permission. To fix that run: 32 | ``` 33 | $ sudo chown -R : 34 | ``` 35 | -------------------------------------------------------------------------------- /docs/howto/test-latest-dotdrop.md: -------------------------------------------------------------------------------- 1 | # Test latest dotdrop 2 | 3 | If you installed dotdrop from a package but want to test 4 | you current setup with the latest version from git 5 | (or from a specific branch), you can do the following 6 | 7 | ```bash 8 | $ cd /tmp/ 9 | $ git clone https://github.com/deadc0de6/dotdrop.git 10 | $ cd dotdrop 11 | ## switch to a specific branch if needed 12 | $ git checkout 13 | $ ./dotdrop.sh --cfg 14 | ``` -------------------------------------------------------------------------------- /docs/misc/migrate-from-submodule.md: -------------------------------------------------------------------------------- 1 | **WARNING** 2 | 3 | Only do the following if you are using dotdrop version `< 0.7.1` or if you encounter an issue when running dotdrop that redirects you here. 4 | 5 | --- 6 | 7 | Initially dotdrop was only available as a submodule directly in the 8 | dotfiles git tree. When updated to work with PyPI, some code changed 9 | that brought some issues to older versions. 10 | 11 | If you want to keep it as a submodule (recommended), simply do the following: 12 | ```bash 13 | $ cd 14 | 15 | ## get latest version of the submodule 16 | $ git submodule foreach git pull origin master 17 | 18 | ## and stage the changes 19 | $ git add dotdrop 20 | $ git commit -m 'update dotdrop' 21 | 22 | ## update the bash script wrapper 23 | $ ./dotdrop/bootstrap.sh 24 | 25 | ## and stage the change to the dotdrop.sh script 26 | $ git add dotdrop.sh 27 | $ git commit -m 'update dotdrop.sh' 28 | 29 | ## and finally push the changes upstream 30 | $ git push 31 | ``` 32 | 33 | Otherwise, simply install it from PyPI as shown below: 34 | 35 | * Move to the dotfiles directory where dotdrop is used as a submodule 36 | ```bash 37 | $ cd 38 | ``` 39 | * Remove the entire `submodule "dotdrop"` section in `.gitmodules` 40 | * Stage the changes 41 | ```bash 42 | $ git add .gitmodules 43 | ``` 44 | * Remove the entire `submodule "dotdrop"` section in `.git/config` 45 | * Remove the submodule 46 | ```bash 47 | $ git rm --cached dotdrop 48 | ``` 49 | * Remove the submodule from .git 50 | ```bash 51 | $ rm -rf .git/modules/dotdrop 52 | ``` 53 | * Commit the changes 54 | ```bash 55 | $ git commit -m 'removing dotdrop submodule' 56 | ``` 57 | * Remove any remaining files from the dotdrop submodule 58 | ```bash 59 | $ rm -rf dotdrop 60 | ``` 61 | * Remove `dotdrop.sh` 62 | ```bash 63 | $ git rm dotdrop.sh 64 | $ git commit -m 'remove dotdrop.sh script' 65 | ``` 66 | * Push upstream 67 | ```bash 68 | $ git push 69 | ``` 70 | -------------------------------------------------------------------------------- /docs/misc/people-using-dotdrop.md: -------------------------------------------------------------------------------- 1 | For more examples, see how people are using dotdrop: 2 | 3 | * [https://github.com/open-dynaMIX/dotfiles](https://github.com/open-dynaMIX/dotfiles) 4 | * [https://github.com/japorized/dotfiles](https://github.com/japorized/dotfiles) 5 | * [https://github.com/whitelynx/dotfiles](https://github.com/whitelynx/dotfiles) 6 | * [https://github.com/Eluminae/dotfiles](https://github.com/Eluminae/dotfiles) 7 | * [https://github.com/davla/dotfiles](https://github.com/davla/dotfiles) 8 | 9 | Dotfiles repositories using dotdrop on [GitHub](https://github.com/topics/dotdrop?o=desc&s=updated). 10 | 11 | Or search directly on [GitHub](https://github.com/search?q=path%3Aconfig.yaml+dotdrop&type=Code) for config examples. 12 | -------------------------------------------------------------------------------- /docs/template/template-debug.md: -------------------------------------------------------------------------------- 1 | ## Debugging templates 2 | 3 | To debug the result of a template, one can install the dotfiles to a temporary 4 | directory with the `install` command and the `-t` switch: 5 | ```bash 6 | $ dotdrop install -t 7 | Installed to tmp /tmp/dotdrop-6ajz7565 8 | ``` -------------------------------------------------------------------------------- /docs/template/template-filters.md: -------------------------------------------------------------------------------- 1 | # Template filters 2 | 3 | Besides [Jinja2 builtin filters](https://jinja.palletsprojects.com/en/2.11.x/templates/#builtin-filters), 4 | custom user-defined filter functions can be loaded using the config entry `filter_file`: 5 | 6 | Example: 7 | 8 | The config file: 9 | ```yaml 10 | config: 11 | filter_file: 12 | - /tmp/myfilter_file.py 13 | ``` 14 | 15 | The python filter under `/tmp/myfilter_file.py`: 16 | ```python 17 | def myfilter(arg1): 18 | return str(int(arg1) - 10) 19 | ``` 20 | 21 | The dotfile content: 22 | ``` 23 | {{@@ "13" | myfilter() @@}} 24 | ``` 25 | 26 | For more information on how to create filters, 27 | see [the Jinja2 official docs](https://jinja.palletsprojects.com/en/2.11.x/api/#writing-filters). -------------------------------------------------------------------------------- /docs/template/template-methods.md: -------------------------------------------------------------------------------- 1 | # Template methods 2 | 3 | Besides [Jinja2 global functions](https://jinja.palletsprojects.com/en/2.11.x/templates/#list-of-global-functions), 4 | the following methods can be used within templates: 5 | 6 | * `exists(path)`: returns true when path exists 7 | ``` 8 | {%@@ if exists('/dev/null') @@%} 9 | it does exist 10 | {%@@ endif @@%} 11 | ``` 12 | 13 | * `exists_in_path(name, path=None)`: returns true when executable exists in `$PATH` 14 | ``` 15 | {%@@ if exists_in_path('exa') @@%} 16 | alias ls='exa --git --color=always' 17 | {%@@ endif @@%} 18 | ``` 19 | 20 | * `basename(path)`: returns the `basename` of the path argument 21 | ``` 22 | {%@@ set dotfile_filename = basename( _dotfile_abs_dst ) @@%} 23 | dotfile dst filename: {{@@ dotfile_filename @@}} 24 | ``` 25 | 26 | * `dirname(path)`: returns the `dirname` of the path argument 27 | ``` 28 | {%@@ set dotfile_dirname = dirname( _dotfile_abs_dst ) @@%} 29 | dotfile dst dirname: {{@@ dotfile_dirname @@}} 30 | ``` 31 | 32 | Custom user-defined functions can be loaded with the help of the 33 | config entry `func_file`. 34 | 35 | Example: 36 | 37 | The config file: 38 | ```yaml 39 | config: 40 | func_file: 41 | - /tmp/myfuncs_file.py 42 | ``` 43 | 44 | The python function under `/tmp/myfuncs_file.py`: 45 | ```python 46 | def myfunc(arg): 47 | return not arg 48 | ``` 49 | 50 | The dotfile content: 51 | ``` 52 | {%@@ if myfunc(False) @@%} 53 | this should exist 54 | {%@@ endif @@%} 55 | ``` -------------------------------------------------------------------------------- /docs/template/templating.md: -------------------------------------------------------------------------------- 1 | # Templating 2 | 3 | Dotdrop leverages the power of [Jinja2](https://palletsprojects.com/p/jinja/) to handle the 4 | templating of dotfiles. See [the Jinja2 templates docs](https://jinja.palletsprojects.com/en/2.11.x/templates/) 5 | or the below sections for more information on how to template your dotfiles. 6 | 7 | ## Templating or not templating 8 | 9 | The dotfile config entry [template](../config/config-dotfiles.md#dotfiles-block) 10 | and the global config entry [template_dotfile_default](../config/config-config.md) 11 | allow to control whether a dotfile is processed by the templating engine. 12 | 13 | Obviously, if the dotfile uses template directives, it needs to be templated. However, if it 14 | is not, disabling templating will speed up its installation (since it won't have to be 15 | processed by the engine). 16 | 17 | For dotfiles being symlinked (`absolute`, `relative` or `link_children`), see 18 | [the dedicated doc](../howto/symlink-dotfiles.md#templating-symlinked-dotfiles). 19 | 20 | ## Delimiters 21 | 22 | Dotdrop uses different delimiters than 23 | [Jinja2](https://palletsprojects.com/p/jinja/)'s defaults: 24 | 25 | * Block/statement start = `{%@@` 26 | * Block/statement end = `@@%}` 27 | * Variable/expression start = `{{@@` 28 | * Variable/expression end = `@@}}` 29 | * Comment start = `{#@@` 30 | * Comment end = `@@#}` 31 | 32 | More info in [Jinja2 templating docs](https://jinja.palletsprojects.com/en/2.11.x/templates/?highlight=delimiter) 33 | 34 | ## Importing macros 35 | 36 | Macros must be imported `with context` in order to have access to the variables: 37 | ``` 38 | {%@@ from 'macro_file' import macro with context @@%} 39 | ``` 40 | 41 | For more information, see the [dedicated Jinja2 docs](https://jinja.palletsprojects.com/en/2.11.x/templates/#macros). 42 | 43 | ## Dotdrop header 44 | 45 | Dotdrop is able to insert a header in the generated dotfiles. This allows 46 | to remind anyone opening the file for editing that this file is managed by dotdrop. 47 | 48 | Here's what it looks like: 49 | ```none 50 | This dotfile is managed using dotdrop 51 | ``` 52 | 53 | The header can be automatically added with: 54 | ```none 55 | {{@@ header() @@}} 56 | ``` 57 | 58 | Properly commenting the header in templates is the responsibility of the user, 59 | as [Jinja2](https://palletsprojects.com/p/jinja/) has no way of knowing what is the proper char(s) used for comments. 60 | Either prepend the directive with the commenting char(s) used in the dotfile 61 | (for example `# {{@@ header() @@}}`) or provide it as an argument `{{@@ header('# ') @@}}`. 62 | The results are equivalent. -------------------------------------------------------------------------------- /dotdrop.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | 5 | ENV_DIR=${DOTDROP_VIRTUALENV:-} 6 | 7 | # setup variables 8 | args=("$@") 9 | cur=$(cd "$(dirname "${0}")" && pwd) 10 | opwd=$(pwd) 11 | 12 | # pivot 13 | cd "${cur}" || { echo "Directory \"${cur}\" doesn't exist, aborting." && exit 1; } 14 | 15 | # init/update the submodule 16 | if [ "${DOTDROP_AUTOUPDATE-yes}" = yes ] ; then 17 | git submodule update --init --recursive 18 | git submodule update --remote dotdrop 19 | fi 20 | 21 | # check python executable 22 | pybin="python3" 23 | if [ -z "${ENV_DIR}" ]; then 24 | hash ${pybin} 2>/dev/null || pybin="python" 25 | [[ "$(${pybin} -V 2>&1)" =~ "Python 3" ]] || { echo "install Python 3" && exit 1; } 26 | else 27 | # virtualenv 28 | pybin="${ENV_DIR}/bin/python" 29 | fi 30 | hash "${pybin}" 2>/dev/null || { echo "python executable not found" && exit 1; } 31 | 32 | # launch dotdrop 33 | PYTHONPATH=dotdrop:${PYTHONPATH} ${pybin} -m dotdrop.dotdrop "${args[@]}" 34 | ret="$?" 35 | 36 | # pivot back 37 | cd "${opwd}" || { echo "Directory \"${opwd}\" doesn't exist, aborting." && exit 1; } 38 | 39 | # exit with dotdrop exit code 40 | exit ${ret} 41 | -------------------------------------------------------------------------------- /dotdrop/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | author: deadc0de6 (https://github.com/deadc0de6) 3 | Copyright (c) 2017, deadc0de6 4 | """ 5 | 6 | # pylint: disable=C0415 7 | import sys 8 | 9 | 10 | def main(): 11 | """entry point""" 12 | import dotdrop.dotdrop 13 | if dotdrop.dotdrop.main(): 14 | sys.exit(0) 15 | sys.exit(1) 16 | -------------------------------------------------------------------------------- /dotdrop/config.py: -------------------------------------------------------------------------------- 1 | """ 2 | author: deadc0de6 (https://github.com/deadc0de6) 3 | Copyright (c) 2024, deadc0de6 4 | 5 | default config 6 | """ 7 | 8 | DEFAULT_CONFIG = """config: 9 | backup: true 10 | banner: true 11 | create: true 12 | dotpath: dotfiles 13 | keepdot: false 14 | link_dotfile_default: nolink 15 | link_on_import: nolink 16 | longkey: false 17 | dotfiles: 18 | profiles:""" 19 | -------------------------------------------------------------------------------- /dotdrop/dictparser.py: -------------------------------------------------------------------------------- 1 | """ 2 | author: deadc0de6 (https://github.com/deadc0de6) 3 | Copyright (c) 2019, deadc0de6 4 | 5 | dictionary parser abstract class 6 | """ 7 | 8 | from dotdrop.logger import Logger 9 | 10 | 11 | class DictParser: 12 | """a dict parser""" 13 | 14 | log = Logger() 15 | 16 | @classmethod 17 | def _adjust_yaml_keys(cls, value): 18 | """adjust value for object 'cls'""" 19 | return value 20 | 21 | @classmethod 22 | def parse(cls, key, value): 23 | """parse (key,value) and construct object 'cls'""" 24 | tmp = value 25 | try: 26 | tmp = value.copy() 27 | except AttributeError: 28 | pass 29 | newv = cls._adjust_yaml_keys(tmp) 30 | if not key: 31 | return cls(**newv) 32 | return cls(key=key, **newv) 33 | 34 | @classmethod 35 | def parse_dict(cls, items): 36 | """parse a dictionary and construct object 'cls'""" 37 | if not items: 38 | return [] 39 | return [cls.parse(k, v) for k, v in items.items()] 40 | -------------------------------------------------------------------------------- /dotdrop/exceptions.py: -------------------------------------------------------------------------------- 1 | """ 2 | author: deadc0de6 (https://github.com/deadc0de6) 3 | Copyright (c) 2019, deadc0de6 4 | 5 | diverse exceptions 6 | """ 7 | 8 | 9 | class YamlException(Exception): 10 | """exception in CfgYaml""" 11 | 12 | 13 | class ConfigException(Exception): 14 | """exception in config parsing/aggregation""" 15 | 16 | 17 | class OptionsException(Exception): 18 | """dotdrop options exception""" 19 | 20 | 21 | class UndefinedException(Exception): 22 | """exception in templating""" 23 | 24 | 25 | class UnmetDependency(Exception): 26 | """unmet dependency""" 27 | -------------------------------------------------------------------------------- /dotdrop/jhelpers.py: -------------------------------------------------------------------------------- 1 | """ 2 | author: deadc0de6 (https://github.com/deadc0de6) 3 | Copyright (c) 2018, deadc0de6 4 | 5 | jinja2 helper methods 6 | """ 7 | 8 | import os 9 | import shutil 10 | 11 | 12 | def exists(path): 13 | """return true when path exists""" 14 | return os.path.exists(os.path.expandvars(path)) 15 | 16 | 17 | def exists_in_path(name, path=None): 18 | """return true when executable exists in os path""" 19 | return shutil.which(name, os.F_OK | os.X_OK, path) is not None 20 | 21 | 22 | def basename(path): 23 | """return basename""" 24 | return os.path.basename(path) 25 | 26 | 27 | def dirname(path): 28 | """return dirname""" 29 | return os.path.dirname(path) 30 | -------------------------------------------------------------------------------- /dotdrop/linktypes.py: -------------------------------------------------------------------------------- 1 | """ 2 | author: deadc0de6 (https://github.com/deadc0de6) 3 | Copyright (c) 2020, deadc0de6 4 | 5 | represents a type of link in dotdrop 6 | """ 7 | 8 | # https://github.com/PyCQA/pylint/issues/2062 9 | # pylint: disable=E1101 10 | 11 | from enum import IntEnum 12 | 13 | 14 | class LinkTypes(IntEnum): 15 | """a type of link""" 16 | NOLINK = 0 17 | LINK = 1 18 | LINK_CHILDREN = 2 19 | ABSOLUTE = 3 20 | RELATIVE = 4 21 | 22 | @classmethod 23 | def get(cls, key, default=None): 24 | """get the linktype""" 25 | try: 26 | return key if isinstance(key, cls) else cls[key.upper()] 27 | except KeyError as exc: 28 | if default and isinstance(default, cls): 29 | return default 30 | err = f'bad {cls.__name__} value: "{key}"' 31 | raise ValueError(err) from exc 32 | 33 | def __str__(self): 34 | """linktype to string""" 35 | return self.name.lower() 36 | -------------------------------------------------------------------------------- /dotdrop/profile.py: -------------------------------------------------------------------------------- 1 | """ 2 | author: deadc0de6 (https://github.com/deadc0de6) 3 | Copyright (c) 2019, deadc0de6 4 | 5 | represent a profile in dotdrop 6 | """ 7 | 8 | from dotdrop.dictparser import DictParser 9 | from dotdrop.action import Action 10 | 11 | 12 | class Profile(DictParser): 13 | """dotdrop profile""" 14 | 15 | # profile keys 16 | key_include = 'include' 17 | key_import = 'import' 18 | 19 | def __init__(self, key, actions=None, dotfiles=None, 20 | variables=None, dynvariables=None): 21 | """ 22 | constructor 23 | @key: profile key 24 | @actions: list of action keys 25 | @dotfiles: list of dotfile keys 26 | @variables: list of variable keys 27 | @dynvariables: list of interpreted variable keys 28 | """ 29 | self.key = key 30 | self.actions = actions or [] 31 | self.dotfiles = dotfiles or [] 32 | self.variables = variables or [] 33 | self.dynvariables = dynvariables or [] 34 | 35 | def get_pre_actions(self): 36 | """return all 'pre' actions""" 37 | return [a for a in self.actions if a.kind == Action.pre] 38 | 39 | def get_post_actions(self): 40 | """return all 'post' actions""" 41 | return [a for a in self.actions if a.kind == Action.post] 42 | 43 | @classmethod 44 | def _adjust_yaml_keys(cls, value): 45 | """patch dict""" 46 | value.pop(cls.key_import, None) 47 | value.pop(cls.key_include, None) 48 | return value 49 | 50 | def __eq__(self, other): 51 | return self.__dict__ == other.__dict__ 52 | 53 | def __hash__(self): 54 | return (hash(self.key) ^ 55 | hash(tuple(self.dotfiles))) 56 | 57 | def __str__(self): 58 | return f'key:"{self.key}"' 59 | 60 | def __repr__(self): 61 | return f'profile({self})' 62 | -------------------------------------------------------------------------------- /dotdrop/version.py: -------------------------------------------------------------------------------- 1 | """ 2 | author: deadc0de6 (https://github.com/deadc0de6) 3 | Copyright (c) 2018, deadc0de6 4 | """ 5 | 6 | __version__ = '1.15.0' 7 | -------------------------------------------------------------------------------- /highlighters/README.md: -------------------------------------------------------------------------------- 1 | Highlighters for dotdrop templates 2 | 3 | * [kakoune](https://kakoune.org/) -> [dotdrop.kak](/highlighters/kakoune/dotdrop.kak) (see #305) 4 | -------------------------------------------------------------------------------- /highlighters/kakoune/dotdrop.kak: -------------------------------------------------------------------------------- 1 | hook global WinCreate .* %{ 2 | require-module python 3 | add-highlighter window/dotdrop regions 4 | 5 | add-highlighter window/dotdrop/expression region '\{\{@[@]' '[@]@\}\}' group 6 | add-highlighter window/dotdrop/statement region '\{%@[@]' '[@]@%\}' group 7 | add-highlighter window/dotdrop/comment region '\{#@[@]' '[@]@#\}' fill comment 8 | 9 | add-highlighter window/dotdrop/expression/ fill variable 10 | add-highlighter window/dotdrop/statement/ fill variable 11 | 12 | add-highlighter window/dotdrop/expression/ ref python 13 | add-highlighter window/dotdrop/statement/ ref python 14 | 15 | add-highlighter window/dotdrop/expression/ regex '\{\{@[@]|[@]@\}\}' 0:block 16 | add-highlighter window/dotdrop/statement/ regex '\{%@[@]|[@]@%\}' 0:block 17 | add-highlighter window/dotdrop/statement/ regex 'endfor|endif' 0:keyword 18 | } 19 | -------------------------------------------------------------------------------- /manpage/generate.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2023, deadc0de6 4 | 5 | # get current working directory 6 | cur=$(cd "$(dirname "${0}")" && pwd) 7 | 8 | # extract version from git latest tag 9 | #version=$(git describe --tags --abbrev=0) 10 | # extract version from version.py 11 | version=$(grep version "${cur}"/../dotdrop/version.py | sed 's/^.*= .\(.*\).$/\1/g') 12 | 13 | if ! hash txt2man 2>/dev/null; then 14 | echo "install txt2man" 15 | exit 1 16 | fi 17 | 18 | txt2man \ 19 | -t "dotdrop" \ 20 | -P "dotdrop" \ 21 | -r "dotdrop-${version}" \ 22 | -s 1 \ 23 | -v "Save your dotfiles once, deploy them everywhere" \ 24 | "${cur}/dotdrop.txt2man" > "${cur}/dotdrop.1" 25 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: dotdrop 2 | site_url: https://github.com/deadc0de6/dotdrop 3 | repo_url: https://github.com/deadc0de6/dotdrop 4 | theme: 5 | name: readthedocs 6 | highlightjs: true 7 | hljs_languages: 8 | - yaml 9 | #collapse_navigation: false 10 | use_directory_urls: true 11 | nav: 12 | - 'Dotdrop': 'README.md' 13 | - 'Installation': 'installation.md' 14 | - 'Getting started': 'getting-started.md' 15 | - 'Usage': 'usage.md' 16 | - 'Config': 17 | - 'Config file': 'config/config-file.md' 18 | - 'Config block': 'config/config-config.md' 19 | - 'Dotfiles block': 'config/config-dotfiles.md' 20 | - 'Profiles block': 'config/config-profiles.md' 21 | - 'Actions block': 'config/config-actions.md' 22 | - 'Transformations block': 'config/config-transformations.md' 23 | - 'Variables block': 'config/config-variables.md' 24 | - 'Dynvariables block': 'config/config-dynvars.md' 25 | - 'Uservariables block': 'config/config-uservars.md' 26 | - 'Templating': 27 | - 'Templating': 'template/templating.md' 28 | - 'Template variables': 'template/template-variables.md' 29 | - 'Template methods': 'template/template-methods.md' 30 | - 'Template filters': 'template/template-filters.md' 31 | - 'Debugging templates': 'template/template-debug.md' 32 | - 'HowTo': 33 | - 'Append text to a dotfile on install': 'howto/append.md' 34 | - 'Create files on install': 'howto/create-special-files.md' 35 | - 'Group hosts and meta profiles': 'howto/group-hosts.md' 36 | - 'Handle compressed directories': 'howto/store-compressed-directories.md' 37 | - 'Handle secrets': 'howto/sensitive-dotfiles.md' 38 | - 'Handle special chars': 'howto/special-chars.md' 39 | - 'Improve Git integration': 'howto/improve-git-integration.md' 40 | - 'Include files or templates in templates': 'howto/include-in-template.md' 41 | - 'Manage dconf settings': 'howto/manage-dconf-settings.md' 42 | - 'Manage system dotfiles': 'howto/system-config-files.md' 43 | - 'Merge files on install': 'howto/merge-files-when-installing.md' 44 | - 'Prompt user for variables': 'howto/prompt-user-for-variables.md' 45 | - 'Share content across dotfiles': 'howto/sharing-content.md' 46 | - 'Symlink dotfiles': 'howto/symlink-dotfiles.md' 47 | - 'Test latest dotdrop': 'howto/test-latest-dotdrop.md' 48 | - '': '' 49 | - '': '' 50 | markdown_extensions: 51 | - meta 52 | - tables 53 | - fenced_code 54 | - toc: 55 | permalink: True 56 | extra_css: 57 | - css/extra.css 58 | 59 | -------------------------------------------------------------------------------- /packages/arch-dotdrop-git/PKGBUILD: -------------------------------------------------------------------------------- 1 | _pkgname=dotdrop 2 | pkgname="${_pkgname}-git" 3 | pkgver=1.3.7.r13.g18b156e 4 | pkgrel=9 5 | pkgdesc="Save your dotfiles once, deploy them everywhere " 6 | arch=('any') 7 | url="https://github.com/deadc0de6/dotdrop" 8 | license=('GPL') 9 | groups=() 10 | depends=('python' 'python-jinja' 'python-docopt-ng' 'python-ruamel-yaml' 'python-magic' 'python-requests' 'python-packaging' 'python-tomli-w' 'python-distro') 11 | makedepends=('git' 'python-build' 'python-installer' 'python-setuptools') 12 | provides=(dotdrop) 13 | conflicts=(dotdrop) 14 | source=("git+https://github.com/deadc0de6/dotdrop.git") 15 | md5sums=('SKIP') 16 | 17 | pkgver() { 18 | cd "${_pkgname}" 19 | git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^v//g' 20 | } 21 | 22 | build() { 23 | cd "${_pkgname}" 24 | python -m build --wheel --no-isolation 25 | } 26 | 27 | package() { 28 | cd "${_pkgname}" 29 | python -m installer --destdir="${pkgdir}" dist/*.whl 30 | 31 | install -Dm644 ${srcdir}/${_pkgname}/completion/dotdrop-completion.bash "${pkgdir}/usr/share/bash-completion/completions/${_pkgname}" 32 | install -Dm644 ${srcdir}/${_pkgname}/completion/_dotdrop-completion.zsh "${pkgdir}/usr/share/zsh/site-functions/_${_pkgname}" 33 | install -Dm644 ${srcdir}/${_pkgname}/completion/dotdrop.fish "${pkgdir}/usr/share/fish/completions/${_pkgname}.fish" 34 | install -Dm644 ${srcdir}/${_pkgname}/LICENSE "${pkgdir}/usr/share/licenses/${_pkgname}/LICENSE" 35 | install -Dm644 ${srcdir}/${_pkgname}/README.md "${pkgdir}/usr/share/doc/${_pkgname}/README.md" 36 | } 37 | 38 | -------------------------------------------------------------------------------- /packages/arch-dotdrop/PKGBUILD: -------------------------------------------------------------------------------- 1 | pkgname=dotdrop 2 | pkgver=1.5.4 3 | pkgrel=1 4 | pkgdesc="Save your dotfiles once, deploy them everywhere " 5 | arch=('any') 6 | url="https://github.com/deadc0de6/dotdrop" 7 | license=('GPL') 8 | groups=() 9 | depends=('python' 'python-jinja' 'python-docopt-ng' 'python-ruamel-yaml' 'python-magic' 'python-requests' 'python-packaging' 'python-tomli-w' 'python-distro') 10 | makedepends=('git' 'python-build' 'python-installer' 'python-setuptools') 11 | source=("git+https://github.com/deadc0de6/dotdrop.git#tag=v${pkgver}") 12 | md5sums=('SKIP') 13 | 14 | pkgver() { 15 | cd "${pkgname}" 16 | git describe --abbrev=0 --tags | sed 's/^v//g' 17 | } 18 | 19 | build() { 20 | cd "${pkgname}" 21 | python -m build --wheel --no-isolation 22 | } 23 | 24 | package() { 25 | cd "${pkgname}" 26 | python -m installer --destdir="${pkgdir}" dist/*.whl 27 | 28 | install -Dm644 ${srcdir}/${pkgname}/completion/dotdrop-completion.bash "${pkgdir}/usr/share/bash-completion/completions/${pkgname}" 29 | install -Dm644 ${srcdir}/${pkgname}/completion/_dotdrop-completion.zsh "${pkgdir}/usr/share/zsh/site-functions/_${pkgname}" 30 | install -Dm644 ${srcdir}/${pkgname}/completion/dotdrop.fish "${pkgdir}/usr/share/fish/completions/${pkgname}.fish" 31 | install -Dm644 ${srcdir}/${pkgname}/LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE" 32 | install -Dm644 ${srcdir}/${pkgname}/README.md "${pkgdir}/usr/share/doc/${pkgname}/README.md" 33 | } 34 | 35 | -------------------------------------------------------------------------------- /packages/genpkg.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 3 | # 4 | # update packages 5 | # 6 | 7 | # $1: version 8 | up() 9 | { 10 | # update pkgver 11 | [ "${1}" != "" ] && sed -i "s/^pkgver=.*$/pkgver=${1}/g" "${pkgfile}" 12 | # create srcinfo 13 | rm -f .SRCINFO 14 | makepkg --printsrcinfo > .SRCINFO 15 | } 16 | 17 | # pivot 18 | cur=$(cd "$(dirname "${0}")" && pwd) 19 | opwd=$(pwd) 20 | pkgfile="PKGBUILD" 21 | cd "${cur}" || exit 1 22 | 23 | ######################## 24 | # update arch package 25 | # tag release 26 | ######################## 27 | dir="arch-dotdrop" 28 | echo "doing ${dir} ..." 29 | cd ${dir} || exit 1 30 | version="$(git describe --abbrev=0 --tags | sed 's/^v//g')" 31 | up "${version}" 32 | cd "${OLDPWD}" || exit 1 33 | 34 | ######################### 35 | ## update arch package 36 | ## git release 37 | ######################### 38 | #dir="arch-dotdrop-git" 39 | #echo "doing ${dir} ..." 40 | #cd ${dir} 41 | ## replace pkgver 42 | ##version="`git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^v//g'`" 43 | #up 44 | #cd ${OLDPWD} 45 | 46 | # pivot back 47 | cd "${opwd}" || exit 48 | -------------------------------------------------------------------------------- /packages/snap/snapcraft.yaml: -------------------------------------------------------------------------------- 1 | name: dotdrop 2 | base: core20 3 | adopt-info: version 4 | summary: Save your dotfiles once, deploy them everywhere 5 | description: | 6 | Dotdrop makes the management of dotfiles between different hosts easy. 7 | It allows to store your dotfiles on git and automagically deploy different versions 8 | of the same file on different setups. 9 | 10 | It also allows to manage different sets of dotfiles. 11 | For example you can have a set of dotfiles for your home laptop and a different 12 | set for your office desktop. Those sets may overlap and different versions of 13 | the same dotfiles can be deployed on different predefined profiles. 14 | Or you may have a main set of dotfiles for your everyday's host and a sub-set you 15 | only need to deploy to temporary hosts (cloud VM, etc) that may be using a slightly 16 | different version of some of the dotfiles. 17 | It allows to store your dotfiles on git and automagically deploy 18 | different versions of the same file on different setups. 19 | 20 | Project page: https://github.com/deadc0de6/dotdrop 21 | 22 | confinement: strict 23 | grade: stable 24 | 25 | apps: 26 | dotdrop: 27 | command: bin/dotdrop 28 | plugs: 29 | - home 30 | 31 | parts: 32 | dotdrop: 33 | plugin: python 34 | source: ../../ 35 | stage-packages: 36 | - file 37 | version: 38 | source: . 39 | plugin: nil 40 | override-build: | 41 | VERSION="" 42 | if [ hash git &>/dev/null ]; then 43 | VERSION=$(git describe --abbrev=0 --tags | sed 's/^v//g') 44 | fi 45 | if [ -z ${VERSION} ]; then 46 | VERSION=$(cat dotdrop/version.py | grep version | sed 's/^.*= .\(.*\).$/\1/g') 47 | fi 48 | [ -z "${VERSION}" ] && exit 1 49 | snapcraftctl set-version "${VERSION}" 50 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ['setuptools'] 3 | build-backend = 'setuptools.build_meta' 4 | 5 | [project] 6 | name = 'dotdrop' 7 | description = 'Save your dotfiles once, deploy them everywhere' 8 | readme = 'README.md' 9 | authors = [ {name = 'deadc0de6', email = 'deadc0de6@foo.bar'}, ] 10 | license = 'GPL-3.0' 11 | requires-python = ">=3" 12 | classifiers = [ 13 | 'Development Status :: 5 - Production/Stable', 14 | 'Programming Language :: Python :: 3.7', 15 | 'Programming Language :: Python :: 3.8', 16 | 'Programming Language :: Python :: 3.9', 17 | 'Programming Language :: Python :: 3.10', 18 | 'Programming Language :: Python :: 3.11', 19 | ] 20 | keywords = ['dotfiles', 'jinja2'] 21 | dependencies = [ 22 | 'Jinja2', 23 | 'distro', 24 | 'docopt-ng', 25 | 'packaging', 26 | 'python-magic', 27 | 'requests', 28 | 'ruamel.yaml', 29 | 'tomli; python_version < "3.11"', 30 | 'tomli_w', 31 | ] 32 | dynamic = ['version'] 33 | 34 | [project.urls] 35 | Documentation = 'https://dotdrop.readthedocs.io' 36 | Repository = 'https://github.com/deadc0de6/dotdrop' 37 | 38 | [project.optional-dependencies] 39 | dev = ['check-manifest'] 40 | test = ['coverage', 'pytest', 'pytest-cov'] 41 | 42 | [project.scripts] 43 | dotdrop = 'dotdrop:main' 44 | 45 | [tool.setuptools.dynamic] 46 | version = {attr = 'dotdrop.version.__version__'} 47 | 48 | [tool.setuptools.packages.find] 49 | include = ['dotdrop'] 50 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Jinja2; python_version > '3.5' 2 | docopt-ng; python_version > '3.5' 3 | ruamel.yaml; python_version > '3.5' 4 | python-magic; python_version > '3.5' 5 | packaging; python_version > '3.5' 6 | requests; python_version > '3.5' 7 | tomli; python_version > '3.5' and python_version < '3.11' 8 | tomli_w; python_version > '3.5' 9 | distro; python_version > '3.5' 10 | python-magic-bin; python_version > '3.5' and platform_system == 'Windows' 11 | -------------------------------------------------------------------------------- /scripts/change_link.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | author: deadc0de6 (https://github.com/deadc0de6) 4 | Copyright (c) 2018, deadc0de6 5 | 6 | change the `link` key in all dotfiles 7 | to a specific value 8 | 9 | usage example: 10 | ./change-link.py --true ../config.yaml --ignore f_vimrc --ignore f_xinitrc 11 | """ 12 | 13 | import os 14 | import sys 15 | from docopt import docopt 16 | from ruamel.yaml import YAML as yaml 17 | 18 | USAGE = """ 19 | change-link.py 20 | 21 | Usage: 22 | change-link.py --value= [--ignore=...] 23 | change-link.py --help 24 | 25 | Options: 26 | -h --help Show this screen. 27 | 28 | """ 29 | 30 | KEY = 'dotfiles' 31 | ENTRY = 'link' 32 | 33 | 34 | def change_link(path, value, ignores): 35 | """change link value""" 36 | with open(path, 'r', encoding='utf-8') as file: 37 | content = yaml(typ='safe').load(file) 38 | for k, val in content[KEY].items(): 39 | if k in ignores: 40 | continue 41 | val[ENTRY] = value 42 | 43 | data = yaml() 44 | data.default_flow_style = False 45 | data.indent = 2 46 | data.typ = 'rt' 47 | data.dump(content, sys.stdout) 48 | 49 | 50 | def main(): 51 | """entry point""" 52 | args = docopt(USAGE) 53 | path = os.path.expanduser(args['']) 54 | value = args['--value'] 55 | ignores = args['--ignore'] 56 | change_link(path, value, ignores) 57 | 58 | 59 | if __name__ == '__main__': 60 | main() 61 | -------------------------------------------------------------------------------- /scripts/check-doc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2022, deadc0de6 4 | 5 | # stop on first error 6 | set -eu -o errtrace -o pipefail 7 | 8 | ## test doc external links 9 | echo "------------------------" 10 | echo "checking external links" 11 | find . -type f -iname '*.md' | while read -r line; do 12 | ./scripts/check_links.py "${line}" 13 | done 14 | 15 | in_cicd="${GITHUB_WORKFLOW:-}" 16 | if [ -n "${in_cicd}" ]; then 17 | ## test the doc internal links when in CI/CD 18 | ## https://github.com/remarkjs/remark-validate-links 19 | ## https://github.com/tcort/markdown-link-check 20 | ## npm install -g remark-cli remark-validate-links 21 | if ! which remark >/dev/null 2>&1; then 22 | echo "[WARNING] install \"remark\" to test the doc" 23 | exit 1 24 | fi 25 | 26 | echo "------------------------" 27 | echo "checking internal links" 28 | find . -type f -iname '*.md' | while read -r line; do 29 | remark -f -u validate-links "${line}" 30 | done 31 | else 32 | echo "not checking internal links..." 33 | fi 34 | 35 | echo "documentation OK" 36 | -------------------------------------------------------------------------------- /scripts/check-tests-ng.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2023, deadc0de6 4 | 5 | # stop on first error 6 | set -eu -o errtrace -o pipefail 7 | 8 | tmpworkdir="/tmp/dotdrop-tests-workdir" 9 | export DOTDROP_WORKDIR="${tmpworkdir}" 10 | 11 | # check if tmp dir is present 12 | workdir_tmp_exists="no" 13 | [ -d "${HOME}/.config/dotdrop/tmp" ] && workdir_tmp_exists="yes" 14 | 15 | # run bash tests 16 | in_cicd=${GITHUB_WORKFLOW:-} 17 | if [ -z "${in_cicd}" ]; then 18 | ## local 19 | tests-ng/tests_launcher.py -s 20 | else 21 | ## CI/CD 22 | # running multiple jobs in parallel sometimes 23 | # messes with the results on remote servers 24 | tests-ng/tests_launcher.py -p 1 -n -s 25 | fi 26 | 27 | # clear workdir 28 | [ "${workdir_tmp_exists}" = "no" ] && rm -rf ~/.config/dotdrop/tmp 29 | # clear temp workdir 30 | rm -rf "${tmpworkdir}" 31 | 32 | echo "tests-ng done" -------------------------------------------------------------------------------- /scripts/check-unittests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2023, deadc0de6 4 | 5 | # stop on first error 6 | set -eu -o errtrace -o pipefail 7 | 8 | WORKERS=${DOTDROP_WORKERS:-} 9 | if [ -n "${WORKERS}" ]; then 10 | unset DOTDROP_WORKERS 11 | echo "DISABLE workers for unittests" 12 | fi 13 | 14 | mkdir -p coverages/ 15 | coverage run -p --data-file coverages/coverage --source=dotdrop -m pytest tests -x -------------------------------------------------------------------------------- /scripts/yaml_to_toml.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | author: deadc0de6 (https://github.com/deadc0de6) 4 | Copyright (c) 2022, deadc0de6 5 | 6 | convert yaml config file to toml 7 | """ 8 | 9 | import sys 10 | # pip3 install ruamel.yaml 11 | from ruamel.yaml import YAML as yaml 12 | # pip3 install tomli_w 13 | import tomli_w 14 | 15 | 16 | def yaml_load(path): 17 | """load from yaml""" 18 | with open(path, 'r', encoding='utf8') as file: 19 | cont = yaml() 20 | cont.typ = 'rt' 21 | content = cont.load(file) 22 | return content 23 | 24 | 25 | def replace_none(content): 26 | """replace any occurence of None with empty string""" 27 | new = {} 28 | for k in content: 29 | if content[k] is None: 30 | if k == 'dotfiles': 31 | continue 32 | if k == 'profiles': 33 | continue 34 | new[k] = "" 35 | continue 36 | if isinstance(content[k], dict): 37 | new[k] = replace_none(content[k]) 38 | continue 39 | new[k] = content[k] 40 | return new 41 | 42 | 43 | def toml_dump(content): 44 | """dump toml to stdout""" 45 | return tomli_w.dumps(content) 46 | 47 | 48 | def main(): 49 | """entry point""" 50 | if len(sys.argv) < 2: 51 | print(f"usage: {sys.argv[0]} ") 52 | sys.exit(1) 53 | 54 | data = yaml_load(sys.argv[1]) 55 | data = replace_none(data) 56 | out = toml_dump(data) 57 | print(out) 58 | 59 | 60 | if __name__ == '__main__': 61 | main() 62 | -------------------------------------------------------------------------------- /tests-ng/README.md: -------------------------------------------------------------------------------- 1 | These are tests for testing entire behavior through shell scripts more easily than 2 | the overly complicated Python tests. 3 | 4 | For adding your own test, create a new script, copy the beginning of an 5 | existing test script (before the *this is the test*), and complete it 6 | with your test. 7 | 8 | Helper functions are available in `helpers`. 9 | -------------------------------------------------------------------------------- /tests-ng/bad-diff-cmd.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2022, deadc0de6 4 | # 5 | # test bad diff cmd 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 30 | echo "[+] dotdrop dir: ${basedir}" 31 | 32 | clear_on_exit "${basedir}" 33 | 34 | # create the config file 35 | cfg="${basedir}/config.yaml" 36 | cat > "${cfg}" << _EOF 37 | config: 38 | backup: true 39 | create: true 40 | dotpath: dotfiles 41 | diff_command: xxxxxxxxx {0} {1} 42 | dotfiles: 43 | profiles: 44 | _EOF 45 | 46 | # check diff command is reported as error 47 | set +e 48 | cd "${ddpath}" | ${bin} compare -c "${cfg}" 49 | [ "$?" = "0" ] && exit 1 50 | out=$(cd "${ddpath}" | ${bin} compare -c "${cfg}") 51 | echo "${out}" | grep -i 'traceback' && exit 1 52 | set -e 53 | 54 | cat > "${cfg}" << _EOF 55 | config: 56 | backup: true 57 | create: true 58 | dotpath: dotfiles 59 | diff_command: 60 | dotfiles: 61 | profiles: 62 | _EOF 63 | 64 | # should fail 65 | set +e 66 | cd "${ddpath}" | ${bin} compare -c "${cfg}" 67 | [ "$?" = "0" ] && exit 1 68 | out=$(cd "${ddpath}" | ${bin} compare -c "${cfg}") 69 | echo "${out}" | grep -i 'traceback' && exit 1 70 | set -e 71 | 72 | echo "OK" 73 | exit 0 74 | -------------------------------------------------------------------------------- /tests-ng/chmod-more.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2020, deadc0de6 4 | # 5 | # test chmod on import 6 | # with files and directories 7 | # with different link 8 | # 9 | 10 | ## start-cookie 11 | set -eu -o errtrace -o pipefail 12 | cur=$(cd "$(dirname "${0}")" && pwd) 13 | ddpath="${cur}/../" 14 | PPATH="{PYTHONPATH:-}" 15 | export PYTHONPATH="${ddpath}:${PPATH}" 16 | altbin="python3 -m dotdrop.dotdrop" 17 | if hash coverage 2>/dev/null; then 18 | mkdir -p coverages/ 19 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 20 | fi 21 | bin="${DT_BIN:-${altbin}}" 22 | # shellcheck source=tests-ng/helpers 23 | source "${cur}"/helpers 24 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 25 | ## end-cookie 26 | 27 | ################################################################ 28 | # this is the test 29 | ################################################################ 30 | 31 | # $1 path 32 | # $2 rights 33 | has_rights() 34 | { 35 | echo "testing ${1} is ${2}" 36 | [ ! -e "$1" ] && echo "$(basename "$1") does not exist" && exit 1 37 | local mode 38 | mode=$(stat -L -c '%a' "$1") 39 | [ "${mode}" != "$2" ] && echo "bad mode for $(basename "$1") (${mode} instead of ${2})" && exit 1 40 | true 41 | } 42 | 43 | # the dotfile source 44 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 45 | mkdir -p "${tmps}"/dotfiles 46 | # the dotfile destination 47 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 48 | #echo "dotfile destination: ${tmpd}" 49 | 50 | clear_on_exit "${tmps}" 51 | clear_on_exit "${tmpd}" 52 | 53 | # create the dotfiles 54 | f1="${tmpd}/f1" 55 | touch "${f1}" 56 | chmod 777 "${f1}" 57 | stat -c '%a' "${f1}" 58 | 59 | f2="${tmpd}/f2" 60 | touch "${f2}" 61 | chmod 644 "${f2}" 62 | stat -c '%a' "${f2}" 63 | 64 | toimport="${f1} ${f2}" 65 | 66 | # create the config file 67 | cfg="${tmps}/config.yaml" 68 | 69 | cat > "${cfg}" << _EOF 70 | config: 71 | backup: true 72 | create: true 73 | dotpath: dotfiles 74 | dotfiles: 75 | profiles: 76 | _EOF 77 | #cat ${cfg} 78 | 79 | # import without --preserve-mode 80 | for i in ${toimport}; do 81 | stat -c '%a' "${i}" 82 | cd "${ddpath}" | ${bin} import -c "${cfg}" -f -p p1 -V "${i}" 83 | done 84 | 85 | cat "${cfg}" 86 | 87 | has_rights "${tmpd}/f1" "777" 88 | has_rights "${tmps}/dotfiles/${tmpd}/f1" "777" 89 | has_rights "${tmpd}/f2" "644" 90 | has_rights "${tmps}/dotfiles/${tmpd}/f2" "644" 91 | 92 | # install 93 | cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 -V | grep '0 dotfile(s) installed' || (echo "should not install" && exit 1) 94 | 95 | echo "OK" 96 | exit 0 97 | -------------------------------------------------------------------------------- /tests-ng/compare-diff-types.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2023, deadc0de6 4 | # 5 | # test updates 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | echo "[+] dotdrop dir: ${basedir}" 33 | echo "[+] dotpath dir: ${basedir}/dotfiles" 34 | mkdir -p "${basedir}/dotfiles" 35 | 36 | # the dotfile to be imported 37 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 38 | 39 | clear_on_exit "${basedir}" 40 | clear_on_exit "${tmpd}" 41 | 42 | # create the config file 43 | cfg="${basedir}/config.yaml" 44 | cat > "${cfg}" << _EOF 45 | config: 46 | backup: true 47 | create: true 48 | dotpath: dotfiles 49 | dotfiles: 50 | f_file: 51 | src: file 52 | dst: ${tmpd}/file 53 | d_file: 54 | src: dir 55 | dst: ${tmpd}/dir 56 | profiles: 57 | p1: 58 | dotfiles: 59 | - f_file 60 | p2: 61 | dotfiles: 62 | - d_file 63 | _EOF 64 | 65 | # file and dir 66 | echo "test" > "${basedir}"/dotfiles/file 67 | mkdir "${tmpd}"/file 68 | 69 | # dir and file 70 | mkdir "${basedir}"/dotfiles/dir 71 | echo "test" > "${tmpd}"/dir 72 | 73 | # compare 74 | echo "[+] comparing p1" 75 | set +e 76 | cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 --verbose 77 | [ "$?" = "0" ] && exit 1 78 | set -e 79 | 80 | echo "[+] comparing p2" 81 | set +e 82 | cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p2 --verbose 83 | [ "$?" = "0" ] && exit 1 84 | set -e 85 | 86 | echo "OK" 87 | exit 0 88 | -------------------------------------------------------------------------------- /tests-ng/compare-global-negative-ignore.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: jtt9340 (https://github.com/jtt9340) 3 | # author: deadc0de6 4 | # 5 | # test install cmpignore with negative ignores globally 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) 32 | echo "[+] dotdrop dir: ${basedir}" 33 | echo "[+] dotpath dir: ${basedir}/dotfiles" 34 | 35 | # the dotfile to be imported 36 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) 37 | 38 | clear_on_exit "${basedir}" 39 | clear_on_exit "${tmpd}" 40 | 41 | # some files 42 | mkdir -p "${tmpd}"/{program,config} 43 | touch "${tmpd}"/program/a 44 | touch "${tmpd}"/config/a 45 | 46 | # create the config file 47 | cfg="${basedir}/config.yaml" 48 | create_conf "${cfg}" # sets token 49 | 50 | # import 51 | echo "[+] import" 52 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/program 53 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/config 54 | 55 | # add files 56 | echo "[+] add files" 57 | touch "${tmpd}"/program/b 58 | touch "${tmpd}"/config/b 59 | 60 | # adding ignore in dotfile 61 | cfg2="${basedir}/config2.yaml" 62 | sed '/dotpath: dotfiles/a\ 63 | \ \ cmpignore:\ 64 | \ \ \ \ - "*/config/*"\ 65 | \ \ \ \ - "!*/config/a"\ 66 | ' "${cfg}" > "${cfg2}" 67 | cat "${cfg2}" 68 | 69 | # expects one diff 70 | echo "[+] comparing with ignore in dotfile - 1 diff" 71 | set +e 72 | cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose 73 | [ "$?" = "0" ] && exit 1 74 | set -e 75 | 76 | echo "OK" 77 | exit 0 78 | -------------------------------------------------------------------------------- /tests-ng/compare-ignore-in-dotpath.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2023, deadc0de6 4 | # 5 | # test compare ignore (see #405) 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | echo "[+] dotdrop dir: ${basedir}" 33 | echo "[+] dotpath dir: ${basedir}/dotfiles" 34 | 35 | # the dotfile to be imported 36 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 37 | 38 | clear_on_exit "${basedir}" 39 | clear_on_exit "${tmpd}" 40 | 41 | # some files 42 | mkdir -p "${tmpd}"/test 43 | echo 'original' > "${tmpd}"/test/config1 44 | mkdir -p "${tmpd}"/test/ignoreme 45 | echo 'original' > "${tmpd}"/test/ignoreme/config2 46 | 47 | # create the config file 48 | cfg="${basedir}/config.yaml" 49 | create_conf "${cfg}" # sets token 50 | 51 | # import 52 | echo "[+] import" 53 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/test 54 | 55 | # remove ignoreme 56 | echo "[+] remove ignoreme in dotpath" 57 | rm -r "${basedir}"/dotfiles/"${tmpd}"/test/ignoreme 58 | 59 | # expects diff 60 | echo "[+] comparing normal - diff expected" 61 | set +e 62 | cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose 63 | [ "$?" = "0" ] && exit 1 64 | set -e 65 | 66 | # expects zero diff diff 67 | patt="ignoreme" 68 | echo "[+] comparing with ignore (pattern: ${patt}) - no diff expected" 69 | set +e 70 | cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose --ignore="${patt}" 71 | [ "$?" != "0" ] && exit 1 72 | set -e 73 | 74 | echo "OK" 75 | exit 0 76 | -------------------------------------------------------------------------------- /tests-ng/compare-negative-ignore-all-but.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 3 | # 4 | # test negative ignore on compare 5 | # returns 1 in case of error 6 | # 7 | 8 | ## start-cookie 9 | set -eu -o errtrace -o pipefail 10 | cur=$(cd "$(dirname "${0}")" && pwd) 11 | ddpath="${cur}/../" 12 | PPATH="{PYTHONPATH:-}" 13 | export PYTHONPATH="${ddpath}:${PPATH}" 14 | altbin="python3 -m dotdrop.dotdrop" 15 | if hash coverage 2>/dev/null; then 16 | mkdir -p coverages/ 17 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 18 | fi 19 | bin="${DT_BIN:-${altbin}}" 20 | # shellcheck source=tests-ng/helpers 21 | source "${cur}"/helpers 22 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 23 | ## end-cookie 24 | 25 | ################################################################ 26 | # this is the test 27 | ################################################################ 28 | 29 | # dotdrop directory 30 | basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) 31 | # the dotfile to be updated 32 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) 33 | 34 | echo "[+] dotdrop dir: ${basedir}" 35 | echo "[+] dotpath dir: ${basedir}/dotfiles" 36 | echo "[+] dst dir: ${tmpd}" 37 | 38 | # dotfiles in dotdrop 39 | mkdir -p "${basedir}"/dotfiles/a/{b,c,x} 40 | echo 'original' > "${basedir}"/dotfiles/a/b/abfile1 41 | echo 'original' > "${basedir}"/dotfiles/a/b/abfile2 42 | echo 'original' > "${basedir}"/dotfiles/a/b/abfile3 43 | echo 'original' > "${basedir}"/dotfiles/a/c/acfile 44 | echo 'original' > "${basedir}"/dotfiles/a/x/axfile 45 | 46 | # filesystem 47 | mkdir -p "${tmpd}"/a/{b,c,d,x} 48 | echo "updated" > "${tmpd}/a/b/abfile1" 49 | echo "updated" > "${tmpd}/a/b/abfile2" 50 | echo "updated" > "${tmpd}/a/b/abfile3" 51 | echo "updated" > "${tmpd}/a/c/acfile" 52 | echo "updated" > "${tmpd}/a/d/adfile" 53 | echo "updated" > "${tmpd}/a/x/axfile" 54 | 55 | clear_on_exit "${basedir}" 56 | clear_on_exit "${tmpd}" 57 | 58 | # create the config file 59 | cfg="${basedir}/config.yaml" 60 | cat > "${cfg}" << _EOF 61 | config: 62 | backup: false 63 | create: true 64 | dotpath: dotfiles 65 | dotfiles: 66 | d_abc: 67 | dst: ${tmpd}/a 68 | src: a 69 | cmpignore: 70 | - "*" 71 | - "!*/c/**" 72 | - "!*/d/**" 73 | - "!x/**" 74 | profiles: 75 | p1: 76 | dotfiles: 77 | - d_abc 78 | _EOF 79 | 80 | # compare 81 | echo "[+] compare" 82 | set +e 83 | cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose --profile=p1 84 | ret="$?" 85 | echo "return code: ${ret}" 86 | [ "${ret}" != "1" ] && exit 1 87 | set -e 88 | 89 | echo "OK" 90 | exit 0 91 | -------------------------------------------------------------------------------- /tests-ng/corner-case.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # the only purpose is to test corner-cases 6 | # not covered by other tests like 7 | # dry 8 | # diff before write 9 | # etc 10 | # 11 | # returns 1 in case of error 12 | # 13 | 14 | ## start-cookie 15 | set -eu -o errtrace -o pipefail 16 | cur=$(cd "$(dirname "${0}")" && pwd) 17 | ddpath="${cur}/../" 18 | PPATH="{PYTHONPATH:-}" 19 | export PYTHONPATH="${ddpath}:${PPATH}" 20 | altbin="python3 -m dotdrop.dotdrop" 21 | if hash coverage 2>/dev/null; then 22 | mkdir -p coverages/ 23 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 24 | fi 25 | bin="${DT_BIN:-${altbin}}" 26 | # shellcheck source=tests-ng/helpers 27 | source "${cur}"/helpers 28 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 29 | ## end-cookie 30 | 31 | ################################################################ 32 | # this is the test 33 | ################################################################ 34 | 35 | # dotdrop directory 36 | basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 37 | echo "[+] dotdrop dir: ${basedir}" 38 | echo "[+] dotpath dir: ${basedir}/dotfiles" 39 | 40 | clear_on_exit "${basedir}" 41 | 42 | export DOTDROP_WORKERS=1 43 | 44 | # create the config file 45 | cfg="${basedir}/config.yaml" 46 | cat > "${cfg}" << _EOF 47 | config: 48 | backup: true 49 | create: true 50 | dotpath: dotfiles 51 | dotfiles: 52 | f_x: 53 | src: /tmp/x 54 | dst: 55 | f_y: 56 | src: /tmp/.i-do-not-exist-dotdrop 57 | dst: /tmp/y 58 | profiles: 59 | p1: 60 | dotfiles: 61 | - f_x 62 | - f_y 63 | 64 | _EOF 65 | 66 | echo "[+] test install dry" 67 | cd "${ddpath}" | ${bin} install -c "${cfg}" --dry -p p1 --verbose f_x 68 | [ "$?" != "0" ] && exit 1 69 | 70 | echo "[+] test install show-diff" 71 | cd "${ddpath}" | ${bin} install -c "${cfg}" -p p1 --verbose f_x 72 | [ "$?" != "0" ] && exit 1 73 | cd "${ddpath}" | ${bin} install -D -c "${cfg}" -p p1 --verbose f_x 74 | [ "$?" != "0" ] && exit 1 75 | 76 | echo "[+] test install not existing src" 77 | cd "${ddpath}" | ${bin} install -c "${cfg}" -f --dry -p p1 --verbose f_y 78 | 79 | echo "[+] test install to temp" 80 | cd "${ddpath}" | ${bin} install -t -c "${cfg}" -p p1 --verbose f_x > "${basedir}"/log 2>&1 81 | [ "$?" != "0" ] && echo "install to tmp failed" && exit 1 82 | 83 | # cleaning 84 | tmpfile=$(cat "${basedir}"/log | grep 'installed to tmp ' | sed 's/^.*to tmp "\(.*\)"./\1/') 85 | echo "tmpfile: ${tmpfile}" 86 | rm -rf "${tmpfile}" 87 | 88 | echo "OK" 89 | exit 0 90 | -------------------------------------------------------------------------------- /tests-ng/dir-import-update.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test importing and updating entire directories 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | echo "dotdrop dir: ${basedir}" 33 | # the dotfile 34 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 35 | create_dir "${tmpd}" 36 | 37 | clear_on_exit "${basedir}" 38 | clear_on_exit "${tmpd}" 39 | 40 | # create the config file 41 | cfg="${basedir}/config.yaml" 42 | create_conf "${cfg}" # sets token 43 | 44 | # import the dir 45 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}" 46 | 47 | # change token 48 | echo "changed" > "${token}" 49 | 50 | # update 51 | cd "${ddpath}" | ${bin} update -f -c "${cfg}" "${tmpd}" --verbose 52 | 53 | grep 'changed' "${token}" >/dev/null 2>&1 54 | 55 | echo "OK" 56 | exit 0 57 | -------------------------------------------------------------------------------- /tests-ng/dotdrop-variables.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # test dotdrop auto-added variables 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | #echo "dotfile source: ${tmps}" 34 | # the dotfile destination 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | #echo "dotfile destination: ${tmpd}" 37 | 38 | clear_on_exit "${tmps}" 39 | clear_on_exit "${tmpd}" 40 | 41 | # create the config file 42 | cfg="${tmps}/config.yaml" 43 | 44 | cat > "${cfg}" << _EOF 45 | config: 46 | backup: true 47 | create: true 48 | dotpath: dotfiles 49 | workdir: /tmp/xxx 50 | dotfiles: 51 | f_abc: 52 | dst: ${tmpd}/abc 53 | src: abc 54 | profiles: 55 | p1: 56 | dotfiles: 57 | - f_abc 58 | _EOF 59 | #cat ${cfg} 60 | 61 | # create the dotfile 62 | echo "dotpath: {{@@ _dotdrop_dotpath @@}}" > "${tmps}"/dotfiles/abc 63 | echo "cfgpath: {{@@ _dotdrop_cfgpath @@}}" >> "${tmps}"/dotfiles/abc 64 | echo "workdir: {{@@ _dotdrop_workdir @@}}" >> "${tmps}"/dotfiles/abc 65 | 66 | # install 67 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V 68 | 69 | cat "${tmpd}"/abc 70 | 71 | grep "^dotpath: ${tmps}/dotfiles$" "${tmpd}"/abc >/dev/null 72 | grep "^cfgpath: ${tmps}/config.yaml$" "${tmpd}"/abc >/dev/null 73 | grep "^workdir: /tmp/xxx$" "${tmpd}"/abc >/dev/null 74 | 75 | echo "OK" 76 | exit 0 77 | -------------------------------------------------------------------------------- /tests-ng/dotfile-no-src.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # test dotfiles with no 'src' 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | echo "dotfiles source (dotpath): ${tmps}" 34 | # the dotfile destination 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | echo "dotfiles destination: ${tmpd}" 37 | 38 | clear_on_exit "${tmps}" 39 | clear_on_exit "${tmpd}" 40 | 41 | # create the config file 42 | cfg="${tmps}/config.yaml" 43 | 44 | cat > "${cfg}" << _EOF 45 | config: 46 | backup: true 47 | create: true 48 | dotpath: dotfiles 49 | dotfiles: 50 | abc: 51 | dst: ${tmpd}/abc 52 | profiles: 53 | p1: 54 | dotfiles: 55 | - ALL 56 | _EOF 57 | #cat ${cfg} 58 | 59 | # create the dotfiles 60 | echo "abc" > "${tmps}"/dotfiles/abc 61 | 62 | ########################### 63 | # test install and compare 64 | ########################### 65 | 66 | # install 67 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V 68 | [ "$?" != "0" ] && exit 1 69 | 70 | # checks 71 | [ ! -e "${tmpd}"/abc ] && exit 1 72 | grep 'abc' "${tmpd}"/abc 73 | 74 | echo "OK" 75 | exit 0 76 | -------------------------------------------------------------------------------- /tests-ng/dotfile-sub-variables.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test dotfile sub file specific variables 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | # the dotfile destination 34 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 35 | 36 | clear_on_exit "${tmps}" 37 | clear_on_exit "${tmpd}" 38 | 39 | # create the config file 40 | cfg="${tmps}/config.yaml" 41 | 42 | cat > "${cfg}" << _EOF 43 | config: 44 | backup: true 45 | create: true 46 | dotpath: dotfiles 47 | dotfiles: 48 | d_abc: 49 | dst: ${tmpd}/abc 50 | src: abc 51 | profiles: 52 | p1: 53 | dotfiles: 54 | - d_abc 55 | _EOF 56 | #cat ${cfg} 57 | 58 | # create the dotfile 59 | mkdir -p "${tmps}"/dotfiles/abc 60 | # file1 61 | echo 'src:{{@@ _dotfile_sub_abs_src @@}}' > "${tmps}"/dotfiles/abc/file1 62 | echo 'dst:{{@@ _dotfile_sub_abs_dst @@}}' >> "${tmps}"/dotfiles/abc/file1 63 | 64 | # file2 65 | mkdir -p "${tmps}"/dotfiles/abc/subdir 66 | echo 'src:{{@@ _dotfile_sub_abs_src @@}}' > "${tmps}"/dotfiles/abc/subdir/file2 67 | echo 'dst:{{@@ _dotfile_sub_abs_dst @@}}' >> "${tmps}"/dotfiles/abc/subdir/file2 68 | 69 | # install 70 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V 71 | 72 | # checks 73 | [ ! -d "${tmpd}"/abc ] && echo 'dotfile not installed' && exit 1 74 | [ ! -e "${tmpd}"/abc/file1 ] && echo 'dotfile sub src not installed' && exit 1 75 | [ ! -e "${tmpd}"/abc/subdir/file2 ] && echo 'dotfile sub dst not installed' && exit 1 76 | 77 | cat "${tmpd}"/abc/file1 78 | cat "${tmpd}"/abc/subdir/file2 79 | 80 | grep "src:${tmps}/dotfiles/abc/file1" "${tmpd}"/abc/file1 >/dev/null 81 | grep "dst:${tmpd}/abc/file1" "${tmpd}"/abc/file1>/dev/null 82 | 83 | grep "src:${tmps}/dotfiles/abc/subdir/file2" "${tmpd}"/abc/subdir/file2 >/dev/null 84 | grep "dst:${tmpd}/abc/subdir/file2" "${tmpd}"/abc/subdir/file2 >/dev/null 85 | 86 | echo "OK" 87 | exit 0 88 | -------------------------------------------------------------------------------- /tests-ng/dotfile-variables.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test dotfile specific variables 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | # the dotfile destination 34 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 35 | 36 | clear_on_exit "${tmps}" 37 | clear_on_exit "${tmpd}" 38 | 39 | # create the config file 40 | cfg="${tmps}/config.yaml" 41 | 42 | cat > "${cfg}" << _EOF 43 | config: 44 | backup: true 45 | create: true 46 | dotpath: dotfiles 47 | dotfiles: 48 | f_abc: 49 | dst: ${tmpd}/abc 50 | src: abc 51 | profiles: 52 | p1: 53 | dotfiles: 54 | - f_abc 55 | _EOF 56 | #cat ${cfg} 57 | 58 | # create the dotfile 59 | echo 'src:{{@@ _dotfile_abs_src @@}}' > "${tmps}"/dotfiles/abc 60 | echo 'dst:{{@@ _dotfile_abs_dst @@}}' >> "${tmps}"/dotfiles/abc 61 | echo 'key:{{@@ _dotfile_key @@}}' >> "${tmps}"/dotfiles/abc 62 | echo 'link:{{@@ _dotfile_link @@}}' >> "${tmps}"/dotfiles/abc 63 | 64 | # install 65 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V 66 | 67 | # checks 68 | [ ! -e "${tmpd}"/abc ] && echo 'dotfile not installed' && exit 1 69 | cat "${tmpd}"/abc 70 | grep "src:${tmps}/dotfiles/abc" "${tmpd}"/abc >/dev/null 71 | grep "dst:${tmpd}/abc" "${tmpd}"/abc >/dev/null 72 | grep "key:f_abc" "${tmpd}"/abc >/dev/null 73 | grep "link:nolink" "${tmpd}"/abc >/dev/null 74 | 75 | echo "OK" 76 | exit 0 77 | -------------------------------------------------------------------------------- /tests-ng/dotfiles-all.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test ALL dotfiles 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | echo "dotfiles source (dotpath): ${tmps}" 34 | # the dotfile destination 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | echo "dotfiles destination: ${tmpd}" 37 | 38 | clear_on_exit "${tmps}" 39 | clear_on_exit "${tmpd}" 40 | 41 | # create the config file 42 | cfg="${tmps}/config.yaml" 43 | 44 | cat > "${cfg}" << _EOF 45 | config: 46 | backup: true 47 | create: true 48 | dotpath: dotfiles 49 | dotfiles: 50 | f_abc: 51 | dst: ${tmpd}/abc 52 | src: abc 53 | f_def: 54 | dst: ${tmpd}/def 55 | src: def 56 | d_ghi: 57 | dst: ${tmpd}/ghi 58 | src: ghi 59 | profiles: 60 | p1: 61 | dotfiles: 62 | - ALL 63 | _EOF 64 | #cat ${cfg} 65 | 66 | # create the dotfiles 67 | echo "abc" > "${tmps}"/dotfiles/abc 68 | echo "def" > "${tmps}"/dotfiles/def 69 | echo "ghi" > "${tmps}"/dotfiles/ghi 70 | 71 | ########################### 72 | # test install and compare 73 | ########################### 74 | 75 | # install 76 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V 77 | [ "$?" != "0" ] && exit 1 78 | 79 | # checks 80 | [ ! -e "${tmpd}"/abc ] && exit 1 81 | [ ! -e "${tmpd}"/def ] && exit 1 82 | [ ! -e "${tmpd}"/ghi ] && exit 1 83 | 84 | # modify the dotfiles 85 | echo "abc-modified" > "${tmps}"/dotfiles/abc 86 | echo "def-modified" > "${tmps}"/dotfiles/def 87 | echo "ghi-modified" > "${tmps}"/dotfiles/ghi 88 | 89 | # compare 90 | set +e 91 | cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -b -V 92 | ret="$?" 93 | set -e 94 | [ "$ret" = "0" ] && exit 1 95 | 96 | echo "OK" 97 | exit 0 98 | -------------------------------------------------------------------------------- /tests-ng/dotfiles-dyn-paths.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # test dotfile dynamic paths 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | echo "dotfiles source (dotpath): ${tmps}" 34 | # the dotfile destination 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | echo "dotfiles destination: ${tmpd}" 37 | 38 | clear_on_exit "${tmps}" 39 | clear_on_exit "${tmpd}" 40 | 41 | # create the config file 42 | cfg="${tmps}/config.yaml" 43 | 44 | cat > "${cfg}" << _EOF 45 | config: 46 | backup: true 47 | create: true 48 | dotpath: dotfiles 49 | variables: 50 | dst: "${tmpd}/abc" 51 | dynvariables: 52 | src: "echo abc" 53 | dotfiles: 54 | f_abc: 55 | dst: "{{@@ dst @@}}" 56 | src: "{{@@ src @@}}" 57 | profiles: 58 | p1: 59 | dotfiles: 60 | - f_abc 61 | _EOF 62 | #cat ${cfg} 63 | 64 | # create the dotfiles 65 | echo "abc" > "${tmps}"/dotfiles/abc 66 | 67 | ########################### 68 | # test install and compare 69 | ########################### 70 | 71 | # install 72 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V 73 | [ "$?" != "0" ] && exit 1 74 | 75 | # checks 76 | [ ! -e "${tmpd}"/abc ] && exit 1 77 | 78 | echo "OK" 79 | exit 0 80 | -------------------------------------------------------------------------------- /tests-ng/double-config-import.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: davla (https://github.com/davla) 3 | # Copyright (c) 2022, deadc0de6 4 | # 5 | # test error report on importing the same sub-config file more than once 6 | # 7 | 8 | ## start-cookie 9 | set -eu -o errtrace -o pipefail 10 | cur=$(cd "$(dirname "${0}")" && pwd) 11 | ddpath="${cur}/../" 12 | PPATH="{PYTHONPATH:-}" 13 | export PYTHONPATH="${ddpath}:${PPATH}" 14 | altbin="python3 -m dotdrop.dotdrop" 15 | if hash coverage 2>/dev/null; then 16 | mkdir -p coverages/ 17 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 18 | fi 19 | bin="${DT_BIN:-${altbin}}" 20 | # shellcheck source=tests-ng/helpers 21 | source "${cur}"/helpers 22 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 23 | ## end-cookie 24 | 25 | ################################################################ 26 | # this is the test 27 | ################################################################ 28 | 29 | # dotfile source path 30 | src="$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)" 31 | mkdir -p "${src}/dotfiles" 32 | clear_on_exit "${src}" 33 | 34 | # dotfile destination 35 | dst="$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)" 36 | clear_on_exit "${dst}" 37 | error_log="${dst}/error.log" 38 | 39 | # bottom-level 40 | bottom_level_cfg="${src}/bottom-level.yaml" 41 | cat > "${bottom_level_cfg}" << _EOF 42 | config: 43 | backup: true 44 | create: true 45 | dotpath: ${src}/dotfiles 46 | 47 | dotfiles: [] 48 | profiles: [] 49 | _EOF 50 | touch "${src}/dotfiles/bottom" 51 | 52 | # mid-level 53 | mid_level_cfg="${src}/mid-level.yaml" 54 | cat > "${mid_level_cfg}" << _EOF 55 | config: 56 | backup: true 57 | create: true 58 | dotpath: ${src}/dotfiles 59 | import_configs: 60 | - ${bottom_level_cfg} 61 | 62 | dotfiles: [] 63 | 64 | profiles: [] 65 | _EOF 66 | 67 | # top-level 68 | top_level_cfg="${src}/top-level.yaml" 69 | cat > "${top_level_cfg}" << _EOF 70 | config: 71 | backup: true 72 | create: true 73 | dotpath: ${src}/dotfiles 74 | import_configs: 75 | - ${mid_level_cfg} 76 | - ${bottom_level_cfg} 77 | 78 | dotfiles: [] 79 | 80 | profiles: [] 81 | _EOF 82 | 83 | # install 84 | set +e 85 | cd "${ddpath}" | ${bin} install -f -c "${top_level_cfg}" -p top-level 2> "${error_log}" 86 | set -e 87 | 88 | # checks 89 | grep "${bottom_level_cfg} imported more than once in ${top_level_cfg}" "${error_log}" > /dev/null 2>&1 90 | 91 | echo "OK" 92 | exit 0 93 | -------------------------------------------------------------------------------- /tests-ng/duplicate-key.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test duplicate keys 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | # the dotfile destination 34 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 35 | 36 | clear_on_exit "${tmps}" 37 | clear_on_exit "${tmpd}" 38 | 39 | # create the config file 40 | cfg="${tmps}/config.yaml" 41 | 42 | cat > "${cfg}" << _EOF 43 | config: 44 | backup: true 45 | create: true 46 | dotpath: dotfiles 47 | dotfiles: 48 | f_abc: 49 | dst: ${tmpd}/abc 50 | src: abc 51 | profiles: 52 | p1: 53 | dotfiles: 54 | - f_abc 55 | _EOF 56 | #cat ${cfg} 57 | 58 | # create the imported one 59 | mkdir -p "${tmps}"/dotfiles/"${tmpd}" 60 | echo "test" > "${tmps}"/dotfiles/"${tmpd}"/abc 61 | echo "test" > "${tmpd}"/abc 62 | 63 | # create the to-be-imported 64 | mkdir -p "${tmpd}"/sub 65 | echo "test2" > "${tmpd}"/sub/abc 66 | 67 | mkdir -p "${tmpd}"/sub/sub2 68 | echo "test2" > "${tmpd}"/sub/sub2/abc 69 | 70 | mkdir -p "${tmpd}"/sub/sub 71 | echo "test2" > "${tmpd}"/sub/sub/abc 72 | 73 | # import 74 | cd "${ddpath}" | ${bin} import -f --verbose -c "${cfg}" -p p2 \ 75 | "${tmpd}"/abc \ 76 | "${tmpd}"/sub/abc \ 77 | "${tmpd}"/sub/abc \ 78 | "${tmpd}"/sub/sub/abc \ 79 | "${tmpd}"/sub/sub2/abc 80 | 81 | # count dotfiles for p2 82 | cnt=$(cd "${ddpath}" | ${bin} files --verbose -c "${cfg}" -p p2 -b | grep '^f_' | wc -l) 83 | [ "${cnt}" != "4" ] && echo "bad count for p2: ${cnt} != 4" && exit 1 84 | 85 | echo "OK" 86 | exit 0 87 | -------------------------------------------------------------------------------- /tests-ng/dyndotfilepaths.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test dynamic variables in dotfile src/dst 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | # the dotfile destination 34 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 35 | 36 | clear_on_exit "${tmps}" 37 | clear_on_exit "${tmpd}" 38 | 39 | # create the config file 40 | cfg="${tmps}/config.yaml" 41 | 42 | dst=$(echo "${tmpd}" | rev) 43 | 44 | cat > "${cfg}" << _EOF 45 | config: 46 | backup: true 47 | create: true 48 | dotpath: dotfiles 49 | dynvariables: 50 | dpath: echo ${dst} | rev 51 | dotfiles: 52 | f_abc: 53 | dst: "{{@@ dpath @@}}/abc" 54 | src: abc 55 | profiles: 56 | p1: 57 | dotfiles: 58 | - f_abc 59 | _EOF 60 | #cat ${cfg} 61 | 62 | # create the dotfile 63 | echo "{{@@ dpath @@}}" > "${tmps}"/dotfiles/abc 64 | 65 | # install 66 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V 67 | 68 | #cat ${tmpd}/abc 69 | 70 | [ ! -e "${tmpd}"/abc ] && echo "abc not installed dynamically" && exit 1 71 | grep "^${tmpd}" "${tmpd}"/abc >/dev/null 72 | 73 | #cat ${tmpd}/abc 74 | 75 | echo "OK" 76 | exit 0 77 | -------------------------------------------------------------------------------- /tests-ng/dyninclude.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test dynamic includes 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | # the dotfile destination 34 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 35 | 36 | clear_on_exit "${tmps}" 37 | clear_on_exit "${tmpd}" 38 | 39 | # create the config file 40 | cfg="${tmps}/config.yaml" 41 | 42 | cat > "${cfg}" << _EOF 43 | variables: 44 | var1: "_1" 45 | dynvariables: 46 | dvar1: "echo _2" 47 | config: 48 | backup: true 49 | create: true 50 | dotpath: dotfiles 51 | dotfiles: 52 | f_abc: 53 | dst: ${tmpd}/abc 54 | src: abc 55 | f_def: 56 | dst: ${tmpd}/def 57 | src: def 58 | profiles: 59 | profile_1: 60 | dotfiles: 61 | - f_abc 62 | profile_2: 63 | dotfiles: 64 | - f_def 65 | profile_3: 66 | include: 67 | - profile{{@@ var1 @@}} 68 | profile_4: 69 | include: 70 | - profile{{@@ dvar1 @@}} 71 | _EOF 72 | #cat ${cfg} 73 | 74 | # create the dotfile 75 | c1="content:abc" 76 | echo "${c1}" > "${tmps}"/dotfiles/abc 77 | c2="content:def" 78 | echo "${c2}" > "${tmps}"/dotfiles/def 79 | 80 | # install 81 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p profile_3 --verbose 82 | 83 | # check dotfile exists 84 | [ ! -e "${tmpd}"/abc ] && exit 1 85 | #cat ${tmpd}/abc 86 | grep ${c1} "${tmpd}"/abc >/dev/null || exit 1 87 | 88 | # install 89 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p profile_4 --verbose 90 | 91 | # check dotfile exists 92 | [ ! -e "${tmpd}"/def ] && exit 1 93 | #cat ${tmpd}/def 94 | grep ${c2} "${tmpd}"/def >/dev/null || exit 1 95 | 96 | echo "OK" 97 | exit 0 98 | -------------------------------------------------------------------------------- /tests-ng/ext-actions.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # test external actions 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the action temp 31 | tmpa=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | # the dotfile source 33 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 34 | mkdir -p "${tmps}"/dotfiles 35 | # the dotfile destination 36 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 37 | 38 | clear_on_exit "${tmps}" 39 | clear_on_exit "${tmpd}" 40 | clear_on_exit "${tmpa}" 41 | 42 | act="${tmps}/actions.yaml" 43 | cat > "${act}" << _EOF 44 | actions: 45 | pre: 46 | preaction: echo 'pre' > ${tmpa}/pre 47 | post: 48 | postaction: echo 'post' > ${tmpa}/post 49 | nakedaction: echo 'naked' > ${tmpa}/naked 50 | overwrite: echo 'over' > ${tmpa}/write 51 | _EOF 52 | 53 | # create the config file 54 | cfg="${tmps}/config.yaml" 55 | 56 | cat > "${cfg}" << _EOF 57 | config: 58 | backup: true 59 | create: true 60 | dotpath: dotfiles 61 | import_actions: 62 | - ${tmps}/actions.yaml 63 | actions: 64 | overwrite: echo 'write' > ${tmpa}/write 65 | dotfiles: 66 | f_abc: 67 | dst: ${tmpd}/abc 68 | src: abc 69 | actions: 70 | - preaction 71 | - postaction 72 | - nakedaction 73 | - overwrite 74 | profiles: 75 | p1: 76 | dotfiles: 77 | - f_abc 78 | _EOF 79 | #cat ${cfg} 80 | 81 | # create the dotfile 82 | echo "test" > "${tmps}"/dotfiles/abc 83 | 84 | # install 85 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V 86 | 87 | # checks 88 | [ ! -e "${tmpa}"/pre ] && exit 1 89 | grep pre "${tmpa}"/pre >/dev/null 90 | echo "pre is ok" 91 | 92 | [ ! -e "${tmpa}"/post ] && exit 1 93 | grep post "${tmpa}"/post >/dev/null 94 | echo "post is ok" 95 | 96 | [ ! -e "${tmpa}"/naked ] && exit 1 97 | grep naked "${tmpa}"/naked >/dev/null 98 | echo "naked is ok" 99 | 100 | [ ! -e "${tmpa}"/write ] && exit 1 101 | grep over "${tmpa}"/write >/dev/null 102 | echo "write is ok" 103 | 104 | echo "OK" 105 | exit 0 106 | -------------------------------------------------------------------------------- /tests-ng/global-compare-ignore.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test cmpignore 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | echo "[+] dotdrop dir: ${basedir}" 33 | echo "[+] dotpath dir: ${basedir}/dotfiles" 34 | 35 | # the dotfile to be imported 36 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 37 | 38 | clear_on_exit "${basedir}" 39 | clear_on_exit "${tmpd}" 40 | 41 | # some files 42 | mkdir -p "${tmpd}"/{program,config} 43 | touch "${tmpd}"/program/a 44 | touch "${tmpd}"/config/a 45 | 46 | # create the config file 47 | cfg="${basedir}/config.yaml" 48 | cat > "${cfg}" << _EOF 49 | config: 50 | backup: true 51 | create: true 52 | dotpath: dotfiles 53 | dotfiles: 54 | profiles: 55 | _EOF 56 | 57 | # import 58 | echo "[+] import" 59 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/program 60 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/config 61 | 62 | # add files 63 | echo "[+] add files" 64 | touch "${tmpd}"/program/b 65 | touch "${tmpd}"/config/b 66 | 67 | # adding ignore in dotfile 68 | cfg2="${basedir}/config2.yaml" 69 | sed '/dotpath: dotfiles/a \ \ cmpignore:\n\ \ \ \ - "*/config/b"' "${cfg}" > "${cfg2}" 70 | cat "${cfg2}" 71 | 72 | # expects one diff 73 | echo "[+] comparing with ignore in dotfile - 1 diff" 74 | set +e 75 | cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose 76 | [ "$?" = "0" ] && exit 1 77 | set -e 78 | 79 | # adding ignore in dotfile 80 | cfg2="${basedir}/config2.yaml" 81 | sed '/dotpath: dotfiles/a \ \ cmpignore:\n\ \ \ \ - "*b"' "${cfg}" > "${cfg2}" 82 | cat "${cfg2}" 83 | 84 | # expects no diff 85 | echo "[+] comparing with ignore in dotfile - 0 diff" 86 | set +e 87 | cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose 88 | [ "$?" != "0" ] && exit 1 89 | set -e 90 | 91 | echo "OK" 92 | exit 0 93 | -------------------------------------------------------------------------------- /tests-ng/global-update-ignore.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test global ignore update 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | dt="${tmps}/dotfiles" 33 | mkdir -p "${dt}" 34 | mkdir -p "${dt}"/a/{b,c} 35 | echo 'a' > "${dt}"/a/b/abfile 36 | echo 'a' > "${dt}"/a/c/acfile 37 | 38 | # fs dotfiles 39 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 40 | cp -r "${dt}"/a "${tmpd}"/ 41 | 42 | clear_on_exit "${tmps}" 43 | clear_on_exit "${tmpd}" 44 | 45 | # create the config file 46 | cfg="${tmps}/config.yaml" 47 | cat > "${cfg}" << _EOF 48 | config: 49 | backup: false 50 | create: true 51 | dotpath: dotfiles 52 | upignore: 53 | - "*/cfile" 54 | - "*/newfile" 55 | - "*/newdir" 56 | dotfiles: 57 | f_abc: 58 | dst: ${tmpd}/a 59 | src: a 60 | profiles: 61 | p1: 62 | dotfiles: 63 | - f_abc 64 | _EOF 65 | #cat ${cfg} 66 | 67 | #tree ${dt} 68 | 69 | # edit/add files 70 | echo "[+] edit/add files" 71 | touch "${tmpd}"/a/newfile 72 | echo 'b' > "${tmpd}"/a/c/acfile 73 | mkdir -p "${tmpd}"/a/newdir/b 74 | touch "${tmpd}"/a/newdir/b/c 75 | 76 | #tree ${tmpd}/a 77 | 78 | # update 79 | echo "[+] update" 80 | cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=p1 --key f_abc 81 | 82 | #tree ${dt} 83 | 84 | # check files haven't been updated 85 | [ ! -e "${dt}"/a/c/acfile ] && echo "acfile not found" && exit 1 86 | set +e 87 | grep 'b' "${dt}"/a/c/acfile || (echo "acfile not updated" && exit 1) 88 | set -e 89 | [ -e "${dt}"/a/newfile ] && echo "newfile found" && exit 1 90 | 91 | echo "OK" 92 | exit 0 93 | -------------------------------------------------------------------------------- /tests-ng/globs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # ensure imports allow globs 6 | # - import_actions 7 | # - import_configs 8 | # - import_variables 9 | # - profile import 10 | # 11 | 12 | ## start-cookie 13 | set -eu -o errtrace -o pipefail 14 | cur=$(cd "$(dirname "${0}")" && pwd) 15 | ddpath="${cur}/../" 16 | PPATH="{PYTHONPATH:-}" 17 | export PYTHONPATH="${ddpath}:${PPATH}" 18 | altbin="python3 -m dotdrop.dotdrop" 19 | if hash coverage 2>/dev/null; then 20 | mkdir -p coverages/ 21 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 22 | fi 23 | bin="${DT_BIN:-${altbin}}" 24 | # shellcheck source=tests-ng/helpers 25 | source "${cur}"/helpers 26 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 27 | ## end-cookie 28 | 29 | ################################################################ 30 | # this is the test 31 | ################################################################ 32 | 33 | # the dotfile source 34 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 35 | mkdir -p "${tmps}"/dotfiles 36 | # the dotfile destination 37 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 38 | # temporary 39 | tmpa=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 40 | 41 | clear_on_exit "${tmps}" 42 | clear_on_exit "${tmpd}" 43 | clear_on_exit "${tmpa}" 44 | 45 | ########### 46 | # test globs in import_actions 47 | ########### 48 | # create the action files 49 | actionsd="${tmps}/actions" 50 | mkdir -p "${actionsd}" 51 | cat > "${actionsd}"/action1.yaml << _EOF 52 | actions: 53 | fromaction1: echo "fromaction1" > ${tmpa}/fromaction1 54 | _EOF 55 | cat > "${actionsd}"/action2.yaml << _EOF 56 | actions: 57 | fromaction2: echo "fromaction2" > ${tmpa}/fromaction2 58 | _EOF 59 | 60 | cfg="${tmps}/config.yaml" 61 | cat > "${cfg}" << _EOF 62 | config: 63 | backup: true 64 | create: true 65 | dotpath: dotfiles 66 | import_actions: 67 | - ${actionsd}/* 68 | dotfiles: 69 | f_abc: 70 | dst: ${tmpd}/abc 71 | src: abc 72 | actions: 73 | - fromaction1 74 | - fromaction2 75 | profiles: 76 | p1: 77 | dotfiles: 78 | - f_abc 79 | _EOF 80 | 81 | # create the source 82 | mkdir -p "${tmps}"/dotfiles/ 83 | echo "abc" > "${tmps}"/dotfiles/abc 84 | 85 | # install 86 | cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 -V 87 | 88 | # checks 89 | [ ! -e "${tmpd}"/abc ] && echo "dotfile not installed" && exit 1 90 | [ ! -e "${tmpa}"/fromaction1 ] && echo "action1 not executed" && exit 1 91 | grep fromaction1 "${tmpa}"/fromaction1 92 | [ ! -e "${tmpa}"/fromaction2 ] && echo "action2 not executed" && exit 1 93 | grep fromaction2 "${tmpa}"/fromaction2 94 | 95 | echo "OK" 96 | exit 0 97 | -------------------------------------------------------------------------------- /tests-ng/header.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test header 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | #echo "dotfile source: ${tmps}" 34 | # the dotfile destination 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | #echo "dotfile destination: ${tmpd}" 37 | 38 | clear_on_exit "${tmps}" 39 | clear_on_exit "${tmpd}" 40 | 41 | # create the config file 42 | cfg="${tmps}/config.yaml" 43 | 44 | cat > "${cfg}" << _EOF 45 | config: 46 | backup: true 47 | create: true 48 | dotpath: dotfiles 49 | dotfiles: 50 | f_abc: 51 | dst: ${tmpd}/abc 52 | src: abc 53 | profiles: 54 | p1: 55 | dotfiles: 56 | - f_abc 57 | _EOF 58 | #cat ${cfg} 59 | 60 | # create the dotfile 61 | echo "{{@@ header() @@}}" > "${tmps}"/dotfiles/abc 62 | echo "{{@@ header('# ') @@}}" >> "${tmps}"/dotfiles/abc 63 | echo "{{@@ header('// ') @@}}" >> "${tmps}"/dotfiles/abc 64 | echo "test" >> "${tmps}"/dotfiles/abc 65 | 66 | # install 67 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 68 | 69 | grep '^This dotfile is managed using dotdrop' "${tmpd}"/abc >/dev/null 70 | grep '^# This dotfile is managed using dotdrop' "${tmpd}"/abc >/dev/null 71 | grep '^// This dotfile is managed using dotdrop' "${tmpd}"/abc >/dev/null 72 | 73 | #cat ${tmpd}/abc 74 | 75 | echo "OK" 76 | exit 0 77 | -------------------------------------------------------------------------------- /tests-ng/import-configs2.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2021, deadc0de6 4 | # 5 | # import config testing 6 | # 7 | 8 | ## start-cookie 9 | set -eu -o errtrace -o pipefail 10 | cur=$(cd "$(dirname "${0}")" && pwd) 11 | ddpath="${cur}/../" 12 | PPATH="{PYTHONPATH:-}" 13 | export PYTHONPATH="${ddpath}:${PPATH}" 14 | altbin="python3 -m dotdrop.dotdrop" 15 | if hash coverage 2>/dev/null; then 16 | mkdir -p coverages/ 17 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 18 | fi 19 | bin="${DT_BIN:-${altbin}}" 20 | # shellcheck source=tests-ng/helpers 21 | source "${cur}"/helpers 22 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 23 | ## end-cookie 24 | 25 | ################################################################ 26 | # this is the test 27 | ################################################################ 28 | 29 | # the dotfile sources 30 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 31 | # the dotfile destination 32 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 33 | 34 | clear_on_exit "${tmps}" 35 | clear_on_exit "${tmpd}" 36 | 37 | first="${tmps}/first" 38 | second="${tmps}/second" 39 | mkdir -p "${first}" "${second}" 40 | 41 | # create the config file 42 | cfg1="${first}/config.yaml" 43 | cfg2="${second}/config.yaml" 44 | 45 | cat > "${cfg1}" << _EOF 46 | config: 47 | backup: true 48 | create: true 49 | dotpath: . 50 | import_configs: 51 | - ../second/config.yaml 52 | dotfiles: 53 | f_abc: 54 | dst: ${tmpd}/abc 55 | src: abc 56 | profiles: 57 | p0: 58 | include: 59 | - p1 60 | dotfiles: 61 | - f_abc 62 | _EOF 63 | 64 | cat > "${cfg2}" << _EOF 65 | config: 66 | backup: true 67 | create: true 68 | dotpath: . 69 | dotfiles: 70 | f_def: 71 | dst: ${tmpd}/def 72 | src: def 73 | profiles: 74 | p1: 75 | dotfiles: 76 | - f_def 77 | _EOF 78 | 79 | # create the source 80 | echo "abc" > "${first}"/abc 81 | echo "{{@@ _dotfile_abs_dst @@}}" >> "${first}"/abc 82 | 83 | echo "def" > "${second}"/def 84 | echo "{{@@ _dotfile_abs_dst @@}}" >> "${second}"/def 85 | 86 | # files comparison 87 | cd "${ddpath}" | ${bin} files -c "${cfg1}" -G -p p0 | grep '^f_abc' 88 | cd "${ddpath}" | ${bin} files -c "${cfg1}" -G -p p0 | grep '^f_def' 89 | cd "${ddpath}" | ${bin} files -c "${cfg1}" -G -p p1 | grep '^f_def' 90 | cd "${ddpath}" | ${bin} files -c "${cfg2}" -G -p p1 | grep '^f_def' 91 | 92 | # test compare too 93 | cd "${ddpath}" | ${bin} install -c "${cfg1}" -p p0 -V -f 94 | cd "${ddpath}" | ${bin} compare -c "${cfg1}" -p p0 -V 95 | 96 | [ ! -s "${tmpd}"/abc ] && echo "abc not installed" && exit 1 97 | [ ! -s "${tmpd}"/def ] && echo "def not installed" && exit 1 98 | 99 | echo "OK" 100 | exit 0 101 | -------------------------------------------------------------------------------- /tests-ng/import-ignore-in-dotpath.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2023, deadc0de6 4 | # 5 | # test ignore import in dotpath 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | # the dotfile destination 34 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 35 | mkdir -p "${tmpd}" 36 | #echo "dotfile destination: ${tmpd}" 37 | 38 | clear_on_exit "${tmps}" 39 | clear_on_exit "${tmpd}" 40 | 41 | # create to-be-imported files 42 | mkdir -p "${tmpd}"/test 43 | echo 'original' > "${tmpd}"/test/config1 44 | mkdir -p "${tmpd}"/test/ignoreme 45 | echo 'original' > "${tmpd}"/test/ignoreme/config2 46 | 47 | # create the config file 48 | cfg="${tmps}/config.yaml" 49 | cat > "${cfg}" << _EOF 50 | config: 51 | backup: false 52 | create: true 53 | dotpath: dotfiles 54 | impignore: 55 | - "*/ignoreme/*" 56 | dotfiles: 57 | profiles: 58 | _EOF 59 | 60 | # import 61 | echo "[+] import" 62 | cd "${ddpath}" | ${bin} import -c "${cfg}" -f --verbose --profile=p1 "${tmpd}"/test 63 | 64 | [ -d "${tmps}"/dotfiles/"${tmpd}"/test/ignoreme ] && echo "ignoreme not ignored" && exit 1 65 | 66 | echo "OK" 67 | exit 0 68 | -------------------------------------------------------------------------------- /tests-ng/import-ignore.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2020, deadc0de6 4 | # 5 | # test ignore import 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | # the dotfile destination 34 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 35 | mkdir -p "${tmpd}" 36 | #echo "dotfile destination: ${tmpd}" 37 | 38 | clear_on_exit "${tmps}" 39 | clear_on_exit "${tmpd}" 40 | 41 | # dotdrop directory 42 | mkdir -p "${tmpd}"/a/{b,c} 43 | echo 'a' > "${tmpd}"/a/b/abfile 44 | echo 'a' > "${tmpd}"/a/c/acfile 45 | echo 'a' > "${tmpd}"/a/b/newfile 46 | mkdir -p "${tmpd}"/a/newdir 47 | echo 'a' > "${tmpd}"/a/newdir/newfile 48 | 49 | # create the config file 50 | cfg="${tmps}/config.yaml" 51 | cat > "${cfg}" << _EOF 52 | config: 53 | backup: false 54 | create: true 55 | dotpath: dotfiles 56 | impignore: 57 | - "*/cfile" 58 | - "*/newfile" 59 | - "newdir" 60 | dotfiles: 61 | profiles: 62 | _EOF 63 | #cat ${cfg} 64 | 65 | # import 66 | echo "[+] import" 67 | cd "${ddpath}" | ${bin} import -c "${cfg}" -f --verbose --profile=p1 "${tmpd}"/a 68 | 69 | [ -d "${tmps}"/dotfiles/newdir ] && echo "newdir not ignored" && exit 1 70 | [ -e "${tmps}"/dotfiles/newdir/newfile ] && echo "newfile not ignored" && exit 1 71 | [ -e "${tmps}"/dotfiles/a/b/newfile ] && echo "newfile not ignored" && exit 1 72 | 73 | echo "OK" 74 | exit 0 75 | -------------------------------------------------------------------------------- /tests-ng/import-include.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2023, deadc0de6 4 | # 5 | # test import in profile which includes another 6 | # 7 | 8 | ## start-cookie 9 | set -eu -o errtrace -o pipefail 10 | cur=$(cd "$(dirname "${0}")" && pwd) 11 | ddpath="${cur}/../" 12 | PPATH="{PYTHONPATH:-}" 13 | export PYTHONPATH="${ddpath}:${PPATH}" 14 | altbin="python3 -m dotdrop.dotdrop" 15 | if hash coverage 2>/dev/null; then 16 | mkdir -p coverages/ 17 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 18 | fi 19 | bin="${DT_BIN:-${altbin}}" 20 | # shellcheck source=tests-ng/helpers 21 | source "${cur}"/helpers 22 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 23 | ## end-cookie 24 | 25 | ################################################################ 26 | # this is the test 27 | ################################################################ 28 | 29 | # the dotfile source 30 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 31 | mkdir -p "${tmps}"/dotfiles 32 | # the dotfile destination 33 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 34 | 35 | clear_on_exit "${tmps}" 36 | clear_on_exit "${tmpd}" 37 | 38 | # create the dotfile to import 39 | echo "file" > "${tmpd}"/file 40 | 41 | # create the dotfiles already imported 42 | echo "already in" > "${tmps}"/dotfiles/abc 43 | 44 | # create the config file 45 | cfg="${tmps}/config.yaml" 46 | 47 | cat > "${cfg}" << _EOF 48 | config: 49 | backup: true 50 | create: true 51 | dotpath: dotfiles 52 | dotfiles: 53 | f_abc: 54 | dst: ${tmpd}/abc 55 | src: abc 56 | profiles: 57 | p0: 58 | include: 59 | - p1 60 | p1: 61 | dotfiles: 62 | - f_abc 63 | _EOF 64 | cat "${cfg}" 65 | 66 | cnt=$(cd "${ddpath}" | ${bin} files -c "${cfg}" -p p0 | grep '^f_' | wc -l) 67 | [ "${cnt}" != "1" ] && echo "this is bad" && exit 1 68 | 69 | # import 70 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p0 --verbose "${tmpd}"/file 71 | 72 | [ ! -e "${tmps}"/dotfiles/"${tmpd}"/file ] && echo "file not imported" && exit 1 73 | 74 | # make sure file is in 75 | cnt=$(cd "${ddpath}" | ${bin} files -c "${cfg}" -p p0 | grep '^f_file' | wc -l) 76 | [ "${cnt}" != "1" ] && echo "dotfiles not in config" && exit 1 77 | 78 | # count 79 | cnt=$(cd "${ddpath}" | ${bin} files -c "${cfg}" -p p0 -b | grep '^f_' | wc -l) 80 | [ "${cnt}" != "2" ] && echo "not enough dotfile" exit 1 81 | 82 | echo "OK" 83 | exit 0 84 | -------------------------------------------------------------------------------- /tests-ng/import-negative-ignore-all-but.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 3 | # 4 | # test negative ignore on import 5 | # returns 1 in case of error 6 | # 7 | 8 | ## start-cookie 9 | set -eu -o errtrace -o pipefail 10 | cur=$(cd "$(dirname "${0}")" && pwd) 11 | ddpath="${cur}/../" 12 | PPATH="{PYTHONPATH:-}" 13 | export PYTHONPATH="${ddpath}:${PPATH}" 14 | altbin="python3 -m dotdrop.dotdrop" 15 | if hash coverage 2>/dev/null; then 16 | mkdir -p coverages/ 17 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 18 | fi 19 | bin="${DT_BIN:-${altbin}}" 20 | # shellcheck source=tests-ng/helpers 21 | source "${cur}"/helpers 22 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 23 | ## end-cookie 24 | 25 | ################################################################ 26 | # this is the test 27 | ################################################################ 28 | 29 | # $1 pattern 30 | # $2 path 31 | grep_or_fail() 32 | { 33 | [ ! -e "${2}" ] && (echo "file ${2} does not exist" && exit 1) 34 | grep "${1}" "${2}" >/dev/null 2>&1 || (echo "pattern \"${1}\" not found in ${2}" && exit 1) 35 | } 36 | 37 | # dotdrop directory 38 | basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) 39 | # the dotfile to be updated 40 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) 41 | 42 | echo "[+] dotdrop dir: ${basedir}" 43 | echo "[+] dotpath dir: ${basedir}/dotfiles" 44 | echo "[+] dst dir: ${tmpd}" 45 | 46 | # filesystem 47 | mkdir -p "${tmpd}"/a/{b,c,d,x} 48 | echo "updated" > "${tmpd}/a/b/abfile1" 49 | echo "updated" > "${tmpd}/a/b/abfile2" 50 | echo "updated" > "${tmpd}/a/b/abfile3" 51 | echo "updated" > "${tmpd}/a/c/acfile" 52 | echo "updated" > "${tmpd}/a/d/adfile" 53 | echo "updated" > "${tmpd}/a/x/axfile" 54 | 55 | clear_on_exit "${basedir}" 56 | clear_on_exit "${tmpd}" 57 | 58 | # create the config file 59 | cfg="${basedir}/config.yaml" 60 | cat > "${cfg}" << _EOF 61 | config: 62 | backup: false 63 | create: true 64 | dotpath: dotfiles 65 | impignore: 66 | - "*" 67 | - "!*/c/**" 68 | - "!*/d/**" 69 | - "!*/x/**" 70 | dotfiles: 71 | profiles: 72 | p1: 73 | _EOF 74 | 75 | # import 76 | echo "[+] import" 77 | set +e 78 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" --verbose --profile=p1 "${tmpd}/a/b" 79 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" --verbose --profile=p1 "${tmpd}/a/c" 80 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" --verbose --profile=p1 "${tmpd}/a/d" 81 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" --verbose --profile=p1 "${tmpd}/a/x" 82 | set -e 83 | 84 | [ -d "${basedir}/dotfiles/${tmpd}/a/b" ] && (echo "/a/b created" && exit 1) 85 | grep_or_fail "updated" "${basedir}/dotfiles/${tmpd}/a/c/acfile" 86 | grep_or_fail "updated" "${basedir}/dotfiles/${tmpd}/a/d/adfile" 87 | grep_or_fail "updated" "${basedir}/dotfiles/${tmpd}/a/x/axfile" 88 | 89 | echo "OK" 90 | exit 0 91 | -------------------------------------------------------------------------------- /tests-ng/import-negative-ignore.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: jtt9340 (https://github.com/jtt9340) 3 | # 4 | # test negative ignore import 5 | # returns 1 in case of error 6 | # 7 | 8 | ## start-cookie 9 | set -eu -o errtrace -o pipefail 10 | cur=$(cd "$(dirname "${0}")" && pwd) 11 | ddpath="${cur}/../" 12 | PPATH="{PYTHONPATH:-}" 13 | export PYTHONPATH="${ddpath}:${PPATH}" 14 | altbin="python3 -m dotdrop.dotdrop" 15 | if hash coverage 2>/dev/null; then 16 | mkdir -p coverages/ 17 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 18 | fi 19 | bin="${DT_BIN:-${altbin}}" 20 | # shellcheck source=tests-ng/helpers 21 | source "${cur}"/helpers 22 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 23 | ## end-cookie 24 | 25 | ################################################################ 26 | # this is the test 27 | ################################################################ 28 | # the dotfile source 29 | basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) 30 | mkdir -p "${basedir}"/dotfiles 31 | 32 | # the dotfile destination 33 | tmpd=$(mkdir -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) 34 | 35 | clear_on_exit "${basedir}" 36 | clear_on_exit "${tmpd}" 37 | 38 | # dotdrop directory 39 | echo "[+] dotdrop dir: ${basedir}" 40 | echo "[+] dotpath dir: ${basedir}/dotfiles" 41 | mkdir -p "${tmpd}"/a/{b,c} 42 | echo 'a' > "${tmpd}"/a/b/abfile1 43 | echo 'a' > "${tmpd}"/a/b/abfile2 44 | echo 'a' > "${tmpd}"/a/b/abfile3 45 | echo 'a' > "${tmpd}"/a/c/acfile 46 | mkdir -p "${tmpd}"/a/newdir/b 47 | touch "${tmpd}"/a/newdir/b/{c,d} 48 | 49 | # create the config file 50 | cfg="${basedir}/config.yaml" 51 | cfg2="${basedir}/config2.yaml" 52 | create_conf "${cfg}" # sets token 53 | sed '/dotpath: dotfiles/a\ 54 | \ \ impignore:\ 55 | \ \ \ \ - "*/newdir/b/*"\ 56 | \ \ \ \ - "!*/newdir/b/d"\ 57 | \ \ \ \ - "*/abfile?"\ 58 | \ \ \ \ - "!*/abfile3" 59 | ' "${cfg}" > "${cfg2}" 60 | 61 | # import 62 | echo "[+] import" 63 | cd "${ddpath}" | ${bin} import -f -c "${cfg2}" --verbose --profile=p1 "${tmpd}"/a --as=~/a 64 | 65 | # check files haven't been imported 66 | [ -e "${basedir}"/dotfiles/a/newdir/b/c ] && echo "newdir/b/c should not have been imported" && exit 1 67 | [ ! -e "${basedir}"/dotfiles/a/newdir/b/d ] && echo "newdir/b/d should have been imported" && exit 1 68 | [ -e "${basedir}"/dotfiles/a/b/abfile1 ] && echo "abfile1 should not have been imported" && exit 1 69 | [ -e "${basedir}"/dotfiles/a/b/abfile2 ] && echo "abfile2 should not have been imported" && exit 1 70 | [ ! -e "${basedir}"/dotfiles/a/b/abfile3 ] && echo "abfile3 should have been imported" && exit 1 71 | 72 | echo "OK" 73 | exit 0 74 | -------------------------------------------------------------------------------- /tests-ng/import-subfile.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # test import file in directory 6 | # after having imported directory 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | # the dotfile destination 34 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 35 | #echo "dotfile destination: ${tmpd}" 36 | 37 | clear_on_exit "${tmps}" 38 | clear_on_exit "${tmpd}" 39 | 40 | # create the dotfile 41 | mkdir -p "${tmpd}"/adir 42 | echo "first" > "${tmpd}"/adir/file1 43 | 44 | # create the config file 45 | cfg="${tmps}/config.yaml" 46 | 47 | cat > "${cfg}" << _EOF 48 | config: 49 | backup: true 50 | create: true 51 | dotpath: dotfiles 52 | dotfiles: 53 | profiles: 54 | _EOF 55 | #cat ${cfg} 56 | 57 | # import dir 58 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/adir 59 | 60 | # change the file 61 | echo "second" >> "${tmpd}"/adir/file1 62 | 63 | # import file 64 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/adir/file1 65 | 66 | # test 67 | #cat ${tmps}/dotfiles/${tmpd}/adir/file1 68 | [ ! -e "${tmps}"/dotfiles/"${tmpd}"/adir/file1 ] && echo "not exist" && exit 1 69 | grep 'second' "${tmps}"/dotfiles/"${tmpd}"/adir/file1 >/dev/null 70 | 71 | echo "OK" 72 | exit 0 73 | -------------------------------------------------------------------------------- /tests-ng/import-with-empty.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # test import new dotfiles with empty dst/src on existing dotfiles 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | echo "[+] dotdrop dir: ${basedir}" 33 | echo "[+] dotpath dir: ${basedir}/dotfiles" 34 | # the temp directory 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | 37 | clear_on_exit "${basedir}" 38 | clear_on_exit "${tmpd}" 39 | 40 | # create a dotfile 41 | dftoimport="${tmpd}/a_dotfile" 42 | echo 'some content' > "${dftoimport}" 43 | 44 | # create the config file 45 | cfg="${basedir}/config.yaml" 46 | cat > "${cfg}" << _EOF 47 | config: 48 | backup: true 49 | create: true 50 | dotpath: dotfiles 51 | dotfiles: 52 | f_x: 53 | src: /tmp/x 54 | dst: 55 | f_y: 56 | src: 57 | dst: /tmp/y 58 | f_z: 59 | src: 60 | dst: 61 | f_l: 62 | src: 63 | dst: 64 | link: link 65 | f_lc: 66 | src: 67 | dst: 68 | link: link_children 69 | profiles: 70 | p1: 71 | dotfiles: 72 | - f_x 73 | - f_y 74 | - f_z 75 | - f_l 76 | - f_lc 77 | _EOF 78 | 79 | echo "[+] import" 80 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 --verbose "${dftoimport}" 81 | [ "$?" != "0" ] && exit 1 82 | 83 | echo "[+] install" 84 | cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose | grep '^5 dotfile(s) installed.$' 85 | rm -f "${dftoimport}" 86 | cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose | grep '^6 dotfile(s) installed.$' 87 | 88 | nb=$(cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 --verbose | grep '^[a-zA-Z]' | grep -v '^Dotfile(s)' | wc -l) 89 | [ "${nb}" != "6" ] && echo "error in dotfile list (${nb} VS 6)" && exit 1 90 | 91 | #cat ${cfg} 92 | 93 | echo "OK" 94 | exit 0 95 | -------------------------------------------------------------------------------- /tests-ng/imported-variables-from-config.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: davla (https://github.com/davls) 3 | # Copyright (c) 2020, davla 4 | # 5 | # test variables imported from config and used in the importing yaml config 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | # the dotfile destination 34 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 35 | 36 | clear_on_exit "${tmps}" 37 | clear_on_exit "${tmpd}" 38 | 39 | # create the config file 40 | cfg="${tmps}/config.yaml" 41 | subcfg="${tmps}/subconfig.yaml" 42 | 43 | cat > "${cfg}" << _EOF 44 | config: 45 | backup: true 46 | create: true 47 | dotpath: dotfiles 48 | import_configs: 49 | - ${subcfg} 50 | dotfiles: 51 | f_abc: 52 | dst: ${tmpd}/abc 53 | src: '{{@@ abc_dyn_src @@}}{{@@ abc_src @@}}' 54 | profiles: 55 | p1: 56 | dotfiles: 57 | - f_abc 58 | _EOF 59 | cat "${cfg}" 60 | 61 | # create the subconfig file 62 | cat > "${subcfg}" << _EOF 63 | config: 64 | backup: true 65 | create: true 66 | dotpath: dotfiles 67 | variables: 68 | abc_src: c 69 | dynvariables: 70 | abc_dyn_src: 'echo ab' 71 | dotfiles: [] 72 | profiles: [] 73 | _EOF 74 | 75 | # create the dotfile 76 | dirname "${tmps}"/dotfiles/abc | xargs mkdir -p 77 | cat > "${tmps}"/dotfiles/abc << _EOF 78 | Hell yeah 79 | _EOF 80 | 81 | # install 82 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V 83 | 84 | # test file existence and content 85 | [ -f "${tmpd}/abc" ] || { 86 | echo 'Dotfile not installed' 87 | exit 1 88 | } 89 | 90 | echo "OK" 91 | exit 0 92 | -------------------------------------------------------------------------------- /tests-ng/include-variables.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test the use of the keyword "include" 6 | # and (dyn)variables precedence 7 | # returns 1 in case of error 8 | # 9 | 10 | ## start-cookie 11 | set -eu -o errtrace -o pipefail 12 | cur=$(cd "$(dirname "${0}")" && pwd) 13 | ddpath="${cur}/../" 14 | PPATH="{PYTHONPATH:-}" 15 | export PYTHONPATH="${ddpath}:${PPATH}" 16 | altbin="python3 -m dotdrop.dotdrop" 17 | if hash coverage 2>/dev/null; then 18 | mkdir -p coverages/ 19 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 20 | fi 21 | bin="${DT_BIN:-${altbin}}" 22 | # shellcheck source=tests-ng/helpers 23 | source "${cur}"/helpers 24 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 25 | ## end-cookie 26 | 27 | ################################################################ 28 | # this is the test 29 | ################################################################ 30 | 31 | # the dotfile source 32 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 33 | mkdir -p "${tmps}"/dotfiles 34 | # the dotfile destination 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | 37 | clear_on_exit "${tmps}" 38 | clear_on_exit "${tmpd}" 39 | 40 | # create the config file 41 | cfg="${tmps}/config.yaml" 42 | 43 | cat > "${cfg}" << _EOF 44 | config: 45 | backup: true 46 | create: true 47 | dotpath: dotfiles 48 | variables: 49 | var: nopv 50 | dynvariables: 51 | dvar: "echo nopdv" 52 | dotfiles: 53 | f_abc: 54 | dst: ${tmpd}/abc 55 | src: abc 56 | profiles: 57 | p0: 58 | variables: 59 | var: p0v 60 | dynvariables: 61 | dvar: "echo p0dv" 62 | include: 63 | - p1 64 | p1: 65 | dotfiles: 66 | - f_abc 67 | variables: 68 | var: p1v 69 | dynvariables: 70 | dvar: "echo p1dv" 71 | _EOF 72 | #cat ${cfg} 73 | 74 | # create the source 75 | mkdir -p "${tmps}"/dotfiles/ 76 | echo "head" > "${tmps}"/dotfiles/abc 77 | echo "{{@@ var @@}}" >> "${tmps}"/dotfiles/abc 78 | echo "{{@@ dvar @@}}" >> "${tmps}"/dotfiles/abc 79 | echo "tail" >> "${tmps}"/dotfiles/abc 80 | 81 | # install 82 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p0 --verbose 83 | 84 | #cat ${tmpd}/abc 85 | grep 'p0v' "${tmpd}"/abc 86 | grep 'p0dv' "${tmpd}"/abc 87 | 88 | echo "OK" 89 | exit 0 90 | -------------------------------------------------------------------------------- /tests-ng/install-and-remove.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2023, deadc0de6 4 | # 5 | # test install and remove existing file in fs 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${basedir}"/dotfiles 33 | echo "[+] dotdrop dir: ${basedir}" 34 | echo "[+] dotpath dir: ${basedir}/dotfiles" 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | 37 | clear_on_exit "${basedir}" 38 | clear_on_exit "${tmpd}" 39 | 40 | # create the config file 41 | cfg="${basedir}/config.yaml" 42 | cat > "${cfg}" << _EOF 43 | config: 44 | backup: true 45 | create: true 46 | dotpath: dotfiles 47 | dotfiles: 48 | d_dir: 49 | src: dir 50 | dst: ${tmpd}/dir 51 | profiles: 52 | p1: 53 | dotfiles: 54 | - d_dir 55 | _EOF 56 | 57 | # create the file in dotpath 58 | mkdir -p "${basedir}"/dotfiles/dir 59 | echo "content" > "${basedir}"/dotfiles/dir/file 60 | 61 | # create the file in fs 62 | mkdir -p "${tmpd}"/dir 63 | echo "content" > "${tmpd}"/dir/existing 64 | 65 | echo "[+] install" 66 | cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose 67 | [ "$?" != "0" ] && exit 1 68 | 69 | [ ! -e "${tmpd}"/dir/file ] && echo "d_dir file not installed" && exit 1 70 | [ ! -e "${tmpd}"/dir/existing ] && echo "existing removed" && exit 1 71 | 72 | echo "[+] install with remove" 73 | cd "${ddpath}" | ${bin} install --remove-existing -c "${cfg}" -f -p p1 --verbose 74 | [ "$?" != "0" ] && exit 1 75 | 76 | [ ! -e "${tmpd}"/dir/file ] && echo "d_dir file not installed" && exit 1 77 | [ -e "${tmpd}"/dir/existing ] && echo "existing not removed" && exit 1 78 | 79 | echo "OK" 80 | exit 0 81 | -------------------------------------------------------------------------------- /tests-ng/install-empty.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # test install empty dst or empty src 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | echo "[+] dotdrop dir: ${basedir}" 33 | echo "[+] dotpath dir: ${basedir}/dotfiles" 34 | 35 | clear_on_exit "${basedir}" 36 | 37 | # create the config file 38 | cfg="${basedir}/config.yaml" 39 | cat > "${cfg}" << _EOF 40 | config: 41 | backup: true 42 | create: true 43 | dotpath: dotfiles 44 | dotfiles: 45 | f_x: 46 | src: /tmp/x 47 | dst: 48 | f_y: 49 | src: 50 | dst: /tmp/y 51 | f_z: 52 | src: 53 | dst: 54 | f_l: 55 | src: 56 | dst: 57 | link: link 58 | f_lc: 59 | src: 60 | dst: 61 | link: link_children 62 | profiles: 63 | p1: 64 | dotfiles: 65 | - f_x 66 | - f_y 67 | - f_z 68 | - f_l 69 | - f_lc 70 | _EOF 71 | 72 | echo "[+] install" 73 | cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose | grep '^5 dotfile(s) installed.$' 74 | [ "$?" != "0" ] && exit 1 75 | 76 | echo "OK" 77 | exit 0 78 | -------------------------------------------------------------------------------- /tests-ng/install-negative-ignore-all-but.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 3 | # 4 | # test negative ignore on install 5 | # returns 1 in case of error 6 | # 7 | 8 | ## start-cookie 9 | set -eu -o errtrace -o pipefail 10 | cur=$(cd "$(dirname "${0}")" && pwd) 11 | ddpath="${cur}/../" 12 | PPATH="{PYTHONPATH:-}" 13 | export PYTHONPATH="${ddpath}:${PPATH}" 14 | altbin="python3 -m dotdrop.dotdrop" 15 | if hash coverage 2>/dev/null; then 16 | mkdir -p coverages/ 17 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 18 | fi 19 | bin="${DT_BIN:-${altbin}}" 20 | # shellcheck source=tests-ng/helpers 21 | source "${cur}"/helpers 22 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 23 | ## end-cookie 24 | 25 | ################################################################ 26 | # this is the test 27 | ################################################################ 28 | 29 | # $1 pattern 30 | # $2 path 31 | grep_or_fail() 32 | { 33 | [ ! -e "${2}" ] && (echo "file ${2} does not exist" && exit 1) 34 | grep "${1}" "${2}" >/dev/null 2>&1 || (echo "pattern \"${1}\" not found in ${2}" && exit 1) 35 | } 36 | 37 | # dotdrop directory 38 | basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) 39 | # the dotfile to be updated 40 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) 41 | 42 | echo "[+] dotdrop dir: ${basedir}" 43 | echo "[+] dotpath dir: ${basedir}/dotfiles" 44 | echo "[+] dst dir: ${tmpd}" 45 | 46 | # dotfiles in dotdrop 47 | mkdir -p "${basedir}"/dotfiles/a/{b,c,x} 48 | echo 'original' > "${basedir}"/dotfiles/a/b/abfile1 49 | echo 'original' > "${basedir}"/dotfiles/a/b/abfile2 50 | echo 'original' > "${basedir}"/dotfiles/a/b/abfile3 51 | echo 'original' > "${basedir}"/dotfiles/a/c/acfile 52 | echo 'original' > "${basedir}"/dotfiles/a/x/axfile 53 | 54 | clear_on_exit "${basedir}" 55 | clear_on_exit "${tmpd}" 56 | 57 | # create the config file 58 | cfg="${basedir}/config.yaml" 59 | cat > "${cfg}" << _EOF 60 | config: 61 | backup: false 62 | create: true 63 | dotpath: dotfiles 64 | dotfiles: 65 | d_abc: 66 | dst: ${tmpd}/a 67 | src: a 68 | instignore: 69 | - "*" 70 | - "!*/c/**" 71 | - "!*/d/**" 72 | - "!x/**" 73 | profiles: 74 | p1: 75 | dotfiles: 76 | - d_abc 77 | _EOF 78 | 79 | # install 80 | echo "[+] install" 81 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" --verbose --profile=p1 82 | 83 | [ -d "${tmpd}/a/b" ] && (echo "/a/b created" && exit 1) 84 | grep_or_fail "original" "${tmpd}/a/c/acfile" 85 | #grep_or_fail "original" "${tmpd}/a/d/adfile" 86 | grep_or_fail "original" "${tmpd}/a/x/axfile" 87 | 88 | echo "OK" 89 | exit 0 90 | -------------------------------------------------------------------------------- /tests-ng/install-negative-ignore-no-match.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: jtt9340 (https://github.com/jtt9340) 3 | # author: deadc0de6 4 | # 5 | # test that dotdrop warns when a negative ignore pattern 6 | # does not match a file that would be ignored 7 | # returns 1 in case of error 8 | # 9 | 10 | ## start-cookie 11 | set -eu -o errtrace -o pipefail 12 | cur=$(cd "$(dirname "${0}")" && pwd) 13 | ddpath="${cur}/../" 14 | PPATH="{PYTHONPATH:-}" 15 | export PYTHONPATH="${ddpath}:${PPATH}" 16 | altbin="python3 -m dotdrop.dotdrop" 17 | if hash coverage 2>/dev/null; then 18 | mkdir -p coverages/ 19 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 20 | fi 21 | bin="${DT_BIN:-${altbin}}" 22 | # shellcheck source=tests-ng/helpers 23 | source "${cur}"/helpers 24 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 25 | ## end-cookie 26 | 27 | ################################################################ 28 | # this is the test 29 | ################################################################ 30 | 31 | # dotdrop directory 32 | basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) 33 | echo "[+] dotdrop dir: ${basedir}" 34 | echo "[+] dotpath dir: ${basedir}/dotfiles" 35 | 36 | # the dotfile to be imported 37 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) 38 | 39 | clear_on_exit "${basedir}" 40 | clear_on_exit "${tmpd}" 41 | 42 | # some files 43 | mkdir -p "${tmpd}"/program/ignore_me 44 | echo "some data" > "${tmpd}"/program/a 45 | echo "some data" > "${tmpd}"/program/ignore_me/b 46 | echo "some data" > "${tmpd}"/program/ignore_me/c 47 | 48 | # create the config file 49 | cfg="${basedir}/config.yaml" 50 | create_conf "${cfg}" # sets token 51 | 52 | # import 53 | echo "[+] import" 54 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/program 55 | 56 | # adding ignore in dotfile 57 | cfg2="${basedir}/config2.yaml" 58 | sed '/d_program:/a\ 59 | \ \ \ \ instignore:\ 60 | \ \ \ \ - "!*/ignore_me/c" 61 | ' "${cfg}" > "${cfg2}" 62 | 63 | # install 64 | rm -rf "${tmpd}" 65 | echo "[+] install with negative ignore in dotfile" 66 | echo '(1) expect dotdrop install to warn when negative ignore pattern does not match an already-ignored file' 67 | 68 | patt="[WARN] no files that are currently being ignored match \"*/ignore_me/c\". In order for a negative ignore 69 | pattern to work, it must match a file that is being ignored by a previous ignore pattern." 70 | cd "${ddpath}" | ${bin} install -c "${cfg2}" --verbose 2>&1 >/dev/null | grep -F "${patt}" || 71 | (echo "dotdrop did not warn when negative ignore pattern did not match an already-ignored file" && exit 1) 72 | 73 | echo "OK" 74 | exit 0 75 | -------------------------------------------------------------------------------- /tests-ng/install-negative-ignore.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: jtt9340 (https://github.com/jtt9340) 3 | # 4 | # test install negative ignore absolute/relative 5 | # returns 1 in case of error 6 | # 7 | 8 | ## start-cookie 9 | set -eu -o errtrace -o pipefail 10 | cur=$(cd "$(dirname "${0}")" && pwd) 11 | ddpath="${cur}/../" 12 | PPATH="{PYTHONPATH:-}" 13 | export PYTHONPATH="${ddpath}:${PPATH}" 14 | altbin="python3 -m dotdrop.dotdrop" 15 | if hash coverage 2>/dev/null; then 16 | mkdir -p coverages/ 17 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 18 | fi 19 | bin="${DT_BIN:-${altbin}}" 20 | # shellcheck source=tests-ng/helpers 21 | source "${cur}"/helpers 22 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 23 | ## end-cookie 24 | 25 | ################################################################ 26 | # this is the test 27 | ################################################################ 28 | 29 | # dotdrop directory 30 | basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) 31 | echo "[+] dotdrop dir: ${basedir}" 32 | echo "[+] dotpath dir: ${basedir}/dotfiles" 33 | 34 | # the dotfile to be imported 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) 36 | 37 | clear_on_exit "${basedir}" 38 | clear_on_exit "${tmpd}" 39 | 40 | # some files 41 | mkdir -p "${tmpd}"/program/ignore_me 42 | echo "some data" > "${tmpd}"/program/a 43 | echo "some data" > "${tmpd}"/program/ignore_me/b 44 | echo "some data" > "${tmpd}"/program/ignore_me/c 45 | 46 | # create the config file 47 | cfg="${basedir}/config.yaml" 48 | create_conf "${cfg}" # sets token 49 | 50 | # import 51 | echo "[+] import" 52 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/program 53 | 54 | # adding ignore in dotfile 55 | cfg2="${basedir}/config2.yaml" 56 | sed '/d_program:/a\ 57 | \ \ \ \ instignore:\ 58 | \ \ \ \ - "*/ignore_me/*"\ 59 | \ \ \ \ - "!*/ignore_me/c" 60 | ' "${cfg}" > "${cfg2}" 61 | 62 | # install 63 | rm -rf "${tmpd}" 64 | echo "[+] install with negative ignore in dotfile" 65 | cd "${ddpath}" | ${bin} install -c "${cfg2}" --verbose 66 | [ "$?" != "0" ] && exit 1 67 | echo '(1) expect structure to be 68 | . 69 | └── program 70 | ├── a 71 | └── ignore_me 72 | └── c' 73 | 74 | [[ -n "$(find "${tmpd}"/program -name a)" ]] || exit 1 75 | echo "(1) found program/a ... good" 76 | [[ -n "$(find "${tmpd}"/program/ignore_me -name b)" ]] && exit 1 77 | echo "(1) didn't find program/b ... good" 78 | [[ -n "$(find "${tmpd}"/program/ignore_me -name c)" ]] || exit 1 79 | echo "(1) found program/c ... good" 80 | 81 | echo "OK" 82 | exit 0 83 | 84 | -------------------------------------------------------------------------------- /tests-ng/install-to-temp.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # test install to temp 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${basedir}"/dotfiles 33 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 34 | echo "[+] dotdrop dir: ${basedir}" 35 | echo "[+] dotpath dir: ${basedir}/dotfiles" 36 | 37 | clear_on_exit "${basedir}" 38 | clear_on_exit "${tmpd}" 39 | 40 | # create the config file 41 | cfg="${basedir}/config.yaml" 42 | cat > "${cfg}" << _EOF 43 | config: 44 | backup: true 45 | create: true 46 | dotpath: dotfiles 47 | dotfiles: 48 | f_x: 49 | src: x 50 | dst: ${tmpd}/x 51 | f_y: 52 | src: y 53 | dst: ${tmpd}/y 54 | link: link 55 | f_z: 56 | src: z 57 | dst: ${tmpd}/z 58 | profiles: 59 | p1: 60 | dotfiles: 61 | - f_x 62 | - f_y 63 | - f_z 64 | _EOF 65 | 66 | echo 'test_x' > "${basedir}"/dotfiles/x 67 | echo 'test_y' > "${basedir}"/dotfiles/y 68 | echo "00000000 01 02 03 04 05" | xxd -r - "${basedir}"/dotfiles/z 69 | 70 | echo "[+] install" 71 | log="${basedir}/log" 72 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 --showdiff --verbose --temp > "${log}" 73 | 74 | tmpfile=$(cat "${basedir}"/log | grep 'installed to tmp ' | sed 's/^.*to tmp "\(.*\)"./\1/') 75 | echo "tmpfile: ${tmpfile}" 76 | clear_on_exit "${tmpfile}" 77 | 78 | cat "${log}" | grep '^3 dotfile(s) installed.$' 79 | [ "$?" != "0" ] && exit 1 80 | 81 | echo "OK" 82 | exit 0 83 | -------------------------------------------------------------------------------- /tests-ng/link-import-default.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # test the use of the keyword "link_on_import" 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | # the dotfile destination 34 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 35 | 36 | clear_on_exit "${tmps}" 37 | clear_on_exit "${tmpd}" 38 | 39 | # create the config file 40 | cfg="${tmps}/config.yaml" 41 | 42 | # create the source 43 | echo "abc" > "${tmpd}"/abc 44 | 45 | # import with nolink by default 46 | cat > "${cfg}" << _EOF 47 | config: 48 | backup: true 49 | create: true 50 | dotpath: dotfiles 51 | link_on_import: nolink 52 | dotfiles: 53 | profiles: 54 | _EOF 55 | 56 | # import 57 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/abc 58 | 59 | # checks 60 | inside="${tmps}/dotfiles/${tmpd}/abc" 61 | [ ! -e "${inside}" ] && exit 1 62 | 63 | set +e 64 | cat "${cfg}" | grep 'link:' && exit 1 65 | set -e 66 | 67 | # import with parent by default 68 | cat > "${cfg}" << _EOF 69 | config: 70 | backup: true 71 | create: true 72 | dotpath: dotfiles 73 | link_on_import: link 74 | dotfiles: 75 | profiles: 76 | _EOF 77 | 78 | # import 79 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/abc 80 | 81 | # checks 82 | inside="${tmps}/dotfiles/${tmpd}/abc" 83 | [ ! -e "${inside}" ] && exit 1 84 | 85 | cat "${cfg}" 86 | cat "${cfg}" | grep 'link: absolute' >/dev/null 87 | 88 | echo "OK" 89 | exit 0 90 | -------------------------------------------------------------------------------- /tests-ng/link-templates-dir-home.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test link of directory containing templates on home 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | echo "dotfiles source (dotpath): ${tmps}" 34 | # the dotfile destination 35 | tmpd=$(mktemp -d -p "${HOME}" --suffix='-dotdrop-tests' || mktemp -d) 36 | echo "dotfiles destination: ${tmpd}" 37 | # the workdir 38 | tmpw=$(mktemp -d -p "${HOME}" --suffix='-dotdrop-tests' || mktemp -d) 39 | export DOTDROP_WORKDIR="${tmpw}" 40 | echo "workdir: ${tmpw}" 41 | 42 | clear_on_exit "${tmps}" 43 | clear_on_exit "${tmpd}" 44 | clear_on_exit "${tmpw}" 45 | 46 | # create the config file 47 | cfg="${tmps}/config.yaml" 48 | 49 | cat > "${cfg}" << _EOF 50 | config: 51 | backup: true 52 | create: true 53 | dotpath: dotfiles 54 | workdir: ${tmpw} 55 | dotfiles: 56 | f_abc: 57 | dst: ${tmpd}/abc 58 | src: abc 59 | link: true 60 | profiles: 61 | p1: 62 | dotfiles: 63 | - f_abc 64 | _EOF 65 | #cat ${cfg} 66 | 67 | # create the dotfile 68 | mkdir -p "${tmps}"/dotfiles/abc 69 | echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/abc/template 70 | echo "blabla" >> "${tmps}"/dotfiles/abc/template 71 | echo "blabla" > "${tmps}"/dotfiles/abc/nottemplate 72 | 73 | # install 74 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V 75 | 76 | # checks 77 | [ ! -d "${tmpd}"/abc ] && echo "[ERROR] dotfile not installed" && exit 1 78 | [ ! -h "${tmpd}"/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 79 | #cat ${tmpd}/abc/template 80 | #tree -a ${tmpd}/abc/ 81 | set +e 82 | grep '{{@@' "${tmpd}"/abc/template >/dev/null 2>&1 && echo "[ERROR] template in dir not replace" && exit 1 83 | set -e 84 | 85 | echo "OK" 86 | exit 0 87 | -------------------------------------------------------------------------------- /tests-ng/link-templates-dir.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test link of directory containing templates 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | echo "dotfiles source (dotpath): ${tmps}" 34 | # the dotfile destination 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | echo "dotfiles destination: ${tmpd}" 37 | # the workdir 38 | tmpw=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 39 | export DOTDROP_WORKDIR="${tmpw}" 40 | echo "workdir: ${tmpw}" 41 | 42 | clear_on_exit "${tmps}" 43 | clear_on_exit "${tmpd}" 44 | clear_on_exit "${tmpw}" 45 | 46 | # create the config file 47 | cfg="${tmps}/config.yaml" 48 | 49 | cat > "${cfg}" << _EOF 50 | config: 51 | backup: true 52 | create: true 53 | dotpath: dotfiles 54 | workdir: ${tmpw} 55 | dotfiles: 56 | f_abc: 57 | dst: ${tmpd}/abc 58 | src: abc 59 | link: true 60 | profiles: 61 | p1: 62 | dotfiles: 63 | - f_abc 64 | _EOF 65 | #cat ${cfg} 66 | 67 | # create the dotfile 68 | mkdir -p "${tmps}"/dotfiles/abc 69 | echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/abc/template 70 | echo "blabla" >> "${tmps}"/dotfiles/abc/template 71 | echo "blabla" > "${tmps}"/dotfiles/abc/nottemplate 72 | 73 | # install 74 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V 75 | 76 | # checks 77 | [ ! -d "${tmpd}"/abc ] && echo "[ERROR] dotfile not installed" && exit 1 78 | [ ! -h "${tmpd}"/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 79 | #cat ${tmpd}/abc/template 80 | #tree -a ${tmpd}/abc/ 81 | set +e 82 | grep '{{@@' "${tmpd}"/abc/template >/dev/null 2>&1 && echo "[ERROR] template in dir not replace" && exit 1 83 | set -e 84 | 85 | echo "OK" 86 | exit 0 87 | -------------------------------------------------------------------------------- /tests-ng/link-templates.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test link of templates 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | echo "dotfiles source (dotpath): ${tmps}" 34 | # the dotfile destination 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | echo "dotfiles destination: ${tmpd}" 37 | # the workdir 38 | tmpw=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 39 | export DOTDROP_WORKDIR="${tmpw}" 40 | echo "workdir: ${tmpw}" 41 | 42 | clear_on_exit "${tmps}" 43 | clear_on_exit "${tmpd}" 44 | clear_on_exit "${tmpw}" 45 | 46 | # create the config file 47 | cfg="${tmps}/config.yaml" 48 | 49 | cat > "${cfg}" << _EOF 50 | config: 51 | backup: true 52 | create: true 53 | dotpath: dotfiles 54 | workdir: ${tmpw} 55 | dotfiles: 56 | f_abc: 57 | dst: ${tmpd}/abc 58 | src: abc 59 | link: true 60 | profiles: 61 | p1: 62 | dotfiles: 63 | - f_abc 64 | _EOF 65 | #cat ${cfg} 66 | 67 | # create the dotfile 68 | echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/abc 69 | echo "blabla" >> "${tmps}"/dotfiles/abc 70 | 71 | # install 72 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V 73 | 74 | # checks 75 | [ ! -e "${tmpd}"/abc ] && echo "[ERROR] dotfile not installed" && exit 1 76 | [ ! -h "${tmpd}"/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 77 | 78 | echo "OK" 79 | exit 0 80 | -------------------------------------------------------------------------------- /tests-ng/macro-with-globals.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # import variables from file 6 | # 7 | 8 | ## start-cookie 9 | set -eu -o errtrace -o pipefail 10 | cur=$(cd "$(dirname "${0}")" && pwd) 11 | ddpath="${cur}/../" 12 | PPATH="{PYTHONPATH:-}" 13 | export PYTHONPATH="${ddpath}:${PPATH}" 14 | altbin="python3 -m dotdrop.dotdrop" 15 | if hash coverage 2>/dev/null; then 16 | mkdir -p coverages/ 17 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 18 | fi 19 | bin="${DT_BIN:-${altbin}}" 20 | # shellcheck source=tests-ng/helpers 21 | source "${cur}"/helpers 22 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 23 | ## end-cookie 24 | 25 | ################################################################ 26 | # this is the test 27 | ################################################################ 28 | 29 | # the dotfile source 30 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 31 | mkdir -p "${tmps}"/dotfiles 32 | # the dotfile destination 33 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 34 | 35 | clear_on_exit "${tmps}" 36 | clear_on_exit "${tmpd}" 37 | 38 | # create the config file 39 | cfg="${tmps}/config.yaml" 40 | 41 | cat > "${cfg}" << _EOF 42 | config: 43 | backup: true 44 | create: true 45 | dotpath: dotfiles 46 | dotfiles: 47 | f_abc: 48 | dst: ${tmpd}/abc 49 | src: abc 50 | profiles: 51 | p0: 52 | dotfiles: 53 | - f_abc 54 | variables: 55 | global: global_var 56 | local: local_var 57 | _EOF 58 | 59 | # create the source 60 | mkdir -p "${tmps}"/dotfiles/ 61 | 62 | cat > "${tmps}"/dotfiles/macro_file << _EOF 63 | {%@@ macro macro(var) @@%} 64 | {{@@ global @@}} 65 | {{@@ var @@}} 66 | {%@@ endmacro @@%} 67 | _EOF 68 | 69 | cat > "${tmps}"/dotfiles/abc << _EOF 70 | {%@@ from 'macro_file' import macro with context @@%} 71 | {{@@ macro(local) @@}} 72 | _EOF 73 | 74 | # install 75 | cd "${ddpath}" | ${bin} install -c "${cfg}" -p p0 -V -f 76 | 77 | # test file content 78 | cat "${tmpd}"/abc 79 | grep 'global_var' "${tmpd}"/abc >/dev/null 2>&1 80 | grep 'local_var' "${tmpd}"/abc >/dev/null 2>&1 81 | 82 | echo "OK" 83 | exit 0 84 | -------------------------------------------------------------------------------- /tests-ng/profile-import-dotfiles.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2022, deadc0de6 4 | # 5 | # test dotfiles imported in profile 6 | # and importing 7 | # returns 1 in case of error 8 | # 9 | 10 | ## start-cookie 11 | set -eu -o errtrace -o pipefail 12 | cur=$(cd "$(dirname "${0}")" && pwd) 13 | ddpath="${cur}/../" 14 | PPATH="{PYTHONPATH:-}" 15 | export PYTHONPATH="${ddpath}:${PPATH}" 16 | altbin="python3 -m dotdrop.dotdrop" 17 | if hash coverage 2>/dev/null; then 18 | mkdir -p coverages/ 19 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 20 | fi 21 | bin="${DT_BIN:-${altbin}}" 22 | # shellcheck source=tests-ng/helpers 23 | source "${cur}"/helpers 24 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 25 | ## end-cookie 26 | 27 | ################################################################ 28 | # this is the test 29 | ################################################################ 30 | 31 | # the dotfile source 32 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 33 | mkdir -p "${tmps}"/dotfiles 34 | # the dotfile destination 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | 37 | clear_on_exit "${tmps}" 38 | clear_on_exit "${tmpd}" 39 | 40 | # create the config file 41 | cfg="${tmps}/config.yaml" 42 | cfg2="${tmps}/dotfiles.yaml" 43 | 44 | src="dotdrop-test" 45 | dst=".dotdrop-test" 46 | clear_on_exit "${HOME}/${dst}" 47 | 48 | cat > "${cfg}" << _EOF 49 | config: 50 | dotpath: dotfiles 51 | dotfiles: 52 | f_abc: 53 | dst: ${tmpd}/abc 54 | src: abc 55 | f_def: 56 | dst: ~/${dst} 57 | src: ${src} 58 | profiles: 59 | p1: 60 | import: 61 | - dotfiles.yaml 62 | dotfiles: 63 | - f_abc 64 | _EOF 65 | cat "${cfg}" 66 | 67 | cat > "${cfg2}" << _EOF 68 | dotfiles: 69 | - f_def 70 | _EOF 71 | #cat ${cfg2} 72 | 73 | # create the dotfile 74 | echo "abc" > "${tmps}"/dotfiles/abc 75 | echo "abc" > "${tmpd}"/abc 76 | echo "def" > "${tmps}"/dotfiles/${src} 77 | echo "def" > "${HOME}"/${dst} 78 | 79 | # import 80 | ## this is a special case since the dotfile must 81 | ## be in home (because it is strip) 82 | echo "${ddpath}" 83 | echo "${bin}" 84 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 --verbose ~/${dst} 85 | 86 | cat "${cfg}" 87 | echo '----------' 88 | cat "${cfg2}" 89 | 90 | cnt=$(cd "${ddpath}" | ${bin} files -G -c "${cfg}" -p p1 | grep '^f_def' | wc -l) 91 | [ "${cnt}" != "1" ] && echo "imported twice! (${cnt})" && exit 1 92 | 93 | echo "OK" 94 | exit 0 95 | -------------------------------------------------------------------------------- /tests-ng/recvariables.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test recursive variables 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | # the dotfile destination 34 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 35 | #echo "dotfile destination: ${tmpd}" 36 | 37 | clear_on_exit "${tmps}" 38 | clear_on_exit "${tmpd}" 39 | 40 | # create the config file 41 | cfg="${tmps}/config.yaml" 42 | 43 | cat > "${cfg}" << _EOF 44 | config: 45 | backup: true 46 | create: true 47 | dotpath: dotfiles 48 | variables: 49 | var1: "var1" 50 | var2: "{{@@ var1 @@}} var2" 51 | var3: "{{@@ var2 @@}} var3" 52 | var4: "{{@@ dvar4 @@}}" 53 | dynvariables: 54 | dvar1: "echo dvar1" 55 | dvar2: "{{@@ dvar1 @@}} dvar2" 56 | dvar3: "{{@@ dvar2 @@}} dvar3" 57 | dvar4: "echo {{@@ var3 @@}}" 58 | dotfiles: 59 | f_abc: 60 | dst: ${tmpd}/abc 61 | src: abc 62 | profiles: 63 | p1: 64 | dotfiles: 65 | - f_abc 66 | _EOF 67 | #cat ${cfg} 68 | 69 | # create the dotfile 70 | echo "var3: {{@@ var3 @@}}" > "${tmps}"/dotfiles/abc 71 | echo "dvar3: {{@@ dvar3 @@}}" >> "${tmps}"/dotfiles/abc 72 | echo "var4: {{@@ var4 @@}}" >> "${tmps}"/dotfiles/abc 73 | echo "dvar4: {{@@ dvar4 @@}}" >> "${tmps}"/dotfiles/abc 74 | 75 | #cat ${tmps}/dotfiles/abc 76 | 77 | # install 78 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V 79 | 80 | #cat ${tmpd}/abc 81 | 82 | grep '^var3: var1 var2 var3' "${tmpd}"/abc >/dev/null 83 | grep '^dvar3: dvar1 dvar2 dvar3' "${tmpd}"/abc >/dev/null 84 | grep '^var4: echo var1 var2 var3' "${tmpd}"/abc >/dev/null 85 | grep '^dvar4: var1 var2 var3' "${tmpd}"/abc >/dev/null 86 | 87 | #cat ${tmpd}/abc 88 | 89 | echo "OK" 90 | exit 0 91 | -------------------------------------------------------------------------------- /tests-ng/template-dotpath.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2022, deadc0de6 4 | # 5 | # test dotpath templated 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | dotpath="xyz" 31 | 32 | # dotdrop directory 33 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 34 | mkdir -p "${tmps}"/${dotpath} 35 | echo "[+] dotdrop dir: ${tmps}" 36 | echo "[+] dotpath dir: ${tmps}/${dotpath}" 37 | 38 | # dotfile destination 39 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 40 | 41 | clear_on_exit "${tmps}" 42 | clear_on_exit "${tmpd}" 43 | 44 | echo "content" > "${tmps}"/${dotpath}/abc 45 | 46 | # create the config file 47 | cfg="${tmps}/config.yaml" 48 | cat > "${cfg}" << _EOF 49 | config: 50 | backup: true 51 | create: true 52 | dotpath: "{{@@ env['DOTDROP_DOTPATH'] @@}}" 53 | dotfiles: 54 | f_abc: 55 | src: abc 56 | dst: ${tmpd}/abc 57 | profiles: 58 | p1: 59 | dotfiles: 60 | - f_abc 61 | _EOF 62 | 63 | echo "[+] install" 64 | export DOTDROP_DOTPATH=${dotpath} 65 | cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose | grep '^1 dotfile(s) installed.$' 66 | [ "$?" != "0" ] && exit 1 67 | 68 | [ ! -e "${tmpd}"/abc ] && echo "f_abc not installed" && exit 1 69 | 70 | # clean 71 | rm "${tmpd}"/abc 72 | 73 | # create the config file 74 | cat > "${cfg}" << _EOF 75 | config: 76 | backup: true 77 | create: true 78 | dotpath: "{{@@ var1 @@}}" 79 | variables: 80 | var1: "${dotpath}" 81 | dotfiles: 82 | f_abc: 83 | src: abc 84 | dst: ${tmpd}/abc 85 | profiles: 86 | p1: 87 | dotfiles: 88 | - f_abc 89 | _EOF 90 | 91 | echo "[+] install" 92 | cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose | grep '^1 dotfile(s) installed.$' 93 | [ "$?" != "0" ] && exit 1 94 | 95 | [ ! -e "${tmpd}"/abc ] && echo "f_abc not installed" && exit 1 96 | 97 | echo "OK" 98 | exit 0 99 | -------------------------------------------------------------------------------- /tests-ng/template-vars-dict.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2023, deadc0de6 4 | # 5 | # use of template _vars 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | echo "[+] dotdrop dir: ${tmps}" 34 | echo "[+] dotpath dir: ${tmps}/dotfiles" 35 | 36 | # dotfile destination 37 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 38 | 39 | clear_on_exit "${tmps}" 40 | clear_on_exit "${tmpd}" 41 | 42 | cat << _EOF > "${tmps}"/dotfiles/abc 43 | BEGIN 44 | {%@@ for key in _vars @@%} 45 | key:{{@@ key @@}},value:{{@@ _vars[key] @@}} 46 | {%@@ endfor @@%} 47 | END 48 | _EOF 49 | 50 | # create the config file 51 | cfg="${tmps}/config.yaml" 52 | cat > "${cfg}" << _EOF 53 | config: 54 | backup: true 55 | create: true 56 | dotpath: dotfiles 57 | dotfiles: 58 | f_abc: 59 | src: abc 60 | dst: ${tmpd}/abc 61 | profiles: 62 | p1: 63 | dotfiles: 64 | - f_abc 65 | _EOF 66 | 67 | echo "[+] install" 68 | cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose 69 | [ "$?" != "0" ] && exit 1 70 | 71 | [ ! -f "${tmpd}/abc" ] && echo "abc not installed" && exit 1 72 | cat "${tmpd}/abc" 73 | cat "${tmpd}/abc" | grep 'key:profile,value:p1' 74 | cat "${tmpd}/abc" | grep "key:_dotdrop_cfgpath,value:${tmps}/config.yaml" 75 | cat "${tmpd}/abc" | grep "key:_dotdrop_workdir,value:${DOTDROP_WORKDIR}" 76 | cat "${tmpd}/abc" | grep "key:_dotdrop_dotpath,value:${tmps}/dotfiles" 77 | 78 | echo "OK" 79 | exit 0 80 | -------------------------------------------------------------------------------- /tests-ng/toml.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2022, deadc0de6 4 | # 5 | # test toml config 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmp=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | tmpf="${tmp}/dotfiles" 33 | mkdir -p "${tmpf}" 34 | echo "dotfiles source (dotpath): ${tmpf}" 35 | 36 | # create the config file 37 | cfg="${tmp}/config.toml" 38 | echo "config file: ${cfg}" 39 | 40 | # the dotfile destination 41 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 42 | echo "dotfiles destination: ${tmpd}" 43 | 44 | clear_on_exit "${tmp}" 45 | clear_on_exit "${tmpd}" 46 | 47 | ## RELATIVE 48 | cat > "${cfg}" << _EOF 49 | [config] 50 | backup = true 51 | create = true 52 | dotpath = "dotfiles" 53 | 54 | [dotfiles.f_abc] 55 | dst = "${tmpd}/abc" 56 | src = "abc" 57 | link = true 58 | 59 | [profiles.p1] 60 | dotfiles = [ "f_abc",] 61 | _EOF 62 | #cat ${cfg} 63 | 64 | # create the dotfile 65 | echo "{{@@ profile @@}}" > "${tmpf}"/abc 66 | echo "{{@@ profile @@}}" > "${tmpd}"/def 67 | 68 | # install 69 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V 70 | [ ! -e "${tmpd}"/abc ] && echo "[ERROR] dotfile not installed" && exit 1 71 | 72 | # import 73 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -b -V "${tmpd}"/def 74 | [ ! -e "${tmpf}""${tmpd}"/def ] && echo "[ERROR] dotfile not imported" && exit 1 75 | 76 | # checks 77 | cnt=$(cd "${ddpath}" | ${bin} files -G -c "${cfg}" -p p1 -V | grep '^f_' | wc -l) 78 | [ "${cnt}" != "2" ] && echo "[ERROR]" && exit 1 79 | 80 | ## CLEANING 81 | rm -rf "${tmp}" "${tmpd}" 82 | 83 | echo "OK" 84 | exit 0 85 | -------------------------------------------------------------------------------- /tests-ng/uninstall-by-key.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2024, deadc0de6 4 | # 5 | # test uninstall by key 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | # dotdrop directory 30 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 31 | echo "[+] dotdrop dir: ${tmps}" 32 | echo "[+] dotpath dir: ${tmps}/dotfiles" 33 | 34 | # the dotfile to be imported 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | 37 | clear_on_exit "${tmps}" 38 | clear_on_exit "${tmpd}" 39 | 40 | # create the config file 41 | cfg="${tmps}/config.yaml" 42 | create_conf "${cfg}" # sets token 43 | 44 | # single file 45 | echo 'file' > "${tmpd}"/file 46 | 47 | # import 48 | echo "import..." 49 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/file 50 | 51 | # install 52 | rm -f "${tmpd}"/file 53 | echo "install..." 54 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" 55 | 56 | # uninstall 57 | echo "uninstall..." 58 | cd "${ddpath}" | ${bin} uninstall -f -c "${cfg}" f_file 59 | 60 | # nothing to uninstall 61 | cat > "${cfg}" << _EOF 62 | config: 63 | backup: false 64 | create: true 65 | dotpath: dotfiles 66 | dotfiles: 67 | f_abc: 68 | dst: ${tmpd}/file 69 | src: file 70 | profiles: 71 | p1: 72 | dotfiles: 73 | _EOF 74 | 75 | echo "uninstall..." 76 | cd "${ddpath}" | ${bin} uninstall -f -c "${cfg}" --profile=p1 77 | 78 | echo "OK" 79 | exit 0 -------------------------------------------------------------------------------- /tests-ng/update-ignore-in-dotpath.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2023, deadc0de6 4 | # 5 | # test ignore update in dotpath 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | # fs dotfiles 33 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 34 | dt="${tmps}/dotfiles" 35 | mkdir -p "${dt}" 36 | 37 | clear_on_exit "${tmps}" 38 | clear_on_exit "${tmpd}" 39 | 40 | # create to-be-imported files 41 | mkdir -p "${tmpd}"/test 42 | echo 'original' > "${tmpd}"/test/config1 43 | mkdir -p "${tmpd}"/test/ignoreme 44 | echo 'original' > "${tmpd}"/test/ignoreme/config2 45 | 46 | # create the config file 47 | cfg="${tmps}/config.yaml" 48 | create_conf "${cfg}" # sets token 49 | 50 | # import 51 | echo "[+] import" 52 | cd "${ddpath}" | ${bin} import -c "${cfg}" -f --verbose --profile=p1 "${tmpd}"/test 53 | 54 | # remove ignoreme 55 | echo "[+] remove ignoreme" 56 | rm -r "${tmpd}"/test/ignoreme 57 | 58 | # update 59 | echo "[+] update" 60 | cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=p1 --key d_test 61 | 62 | # check files haven't been updated 63 | [ -d "${dt}"/"${tmpd}"/test/ignoreme ] && echo "ignoreme should have been removed" && exit 1 64 | 65 | echo "OK" 66 | exit 0 67 | -------------------------------------------------------------------------------- /tests-ng/update-ignore-relative.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # test ignore update relative pattern 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | dt="${tmps}/dotfiles" 33 | mkdir -p "${dt}" 34 | mkdir -p "${dt}"/a/{b,c} 35 | echo 'a' > "${dt}"/a/b/abfile 36 | echo 'a' > "${dt}"/a/c/acfile 37 | 38 | # fs dotfiles 39 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 40 | 41 | clear_on_exit "${tmps}" 42 | clear_on_exit "${tmpd}" 43 | 44 | cp -r "${dt}"/a "${tmpd}"/ 45 | 46 | # create the config file 47 | cfg="${tmps}/config.yaml" 48 | cat > "${cfg}" << _EOF 49 | config: 50 | backup: false 51 | create: true 52 | dotpath: dotfiles 53 | dotfiles: 54 | f_abc: 55 | dst: ${tmpd}/a 56 | src: a 57 | upignore: 58 | - "cfile" 59 | - "newfile" 60 | - "newdir" 61 | profiles: 62 | p1: 63 | dotfiles: 64 | - f_abc 65 | _EOF 66 | #cat ${cfg} 67 | 68 | #tree ${dt} 69 | 70 | # edit/add files 71 | echo "[+] edit/add files" 72 | touch "${tmpd}"/a/newfile 73 | echo 'b' > "${tmpd}"/a/c/acfile 74 | mkdir -p "${tmpd}"/a/newdir/b 75 | touch "${tmpd}"/a/newdir/b/c 76 | 77 | #tree ${tmpd}/a 78 | 79 | # update 80 | echo "[+] update" 81 | cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=p1 --key f_abc 82 | 83 | #tree ${dt} 84 | 85 | # check files haven't been updated 86 | grep 'b' "${dt}"/a/c/acfile >/dev/null || (echo "b not found" && exit 1) 87 | [ -e "${dt}"/a/newfile ] && echo "new file does not exist" && exit 1 88 | 89 | echo "OK" 90 | exit 0 91 | -------------------------------------------------------------------------------- /tests-ng/update-rights.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2019, deadc0de6 4 | # 5 | # test updates and rights 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | echo "[+] dotdrop dir: ${basedir}" 33 | echo "[+] dotpath dir: ${basedir}/dotfiles" 34 | 35 | # the dotfile directory to be imported 36 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 37 | # the dotfile file to be imported 38 | tmpf=$(mktemp) 39 | 40 | clear_on_exit "${basedir}" 41 | clear_on_exit "${tmpd}" 42 | 43 | # single file 44 | echo 'file' > "${tmpf}" 45 | 46 | mkdir "${tmpd}"/dir1 47 | echo 'dir1file1' > "${tmpd}"/dir1/file1 48 | echo 'dir1file2' > "${tmpd}"/dir1/file2 49 | 50 | # create the config file 51 | cfg="${basedir}/config.yaml" 52 | create_conf "${cfg}" # sets token 53 | 54 | # import dir1 55 | echo "[+] import" 56 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}" 57 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpf}" 58 | 59 | # change file 60 | chmod +x "${tmpf}" 61 | 62 | # update 63 | echo "[+] updating (1)" 64 | cd "${ddpath}" | ${bin} update -c "${cfg}" -f --verbose "${tmpf}" 65 | 66 | # test change applied 67 | [ "$(stat -c '%a' "${tmpf}")" != "$(stat -c '%a' "${basedir}"/dotfiles/"${tmpf}")" ] && exit 1 68 | 69 | # change file 70 | chmod +x "${tmpd}"/dir1/file2 71 | echo 'test' > "${tmpd}"/dir1/newfile 72 | chmod +x "${tmpd}"/dir1/newfile 73 | 74 | # update 75 | echo "[+] updating (2)" 76 | cd "${ddpath}" | ${bin} update -c "${cfg}" -f --verbose "${tmpd}" 77 | 78 | # test change applied 79 | stat1=$(stat -c '%a' "${tmpd}"/dir1/newfile) 80 | stat2=$(stat -c '%a' "${basedir}"/dotfiles/"${tmpd}"/dir1/newfile) 81 | [ "${stat1}" != "${stat2}" ] && echo "diff permissions for newfile: ${stat1} VS ${stat2}" && exit 1 82 | stat1=$(stat -c '%a' "${tmpd}"/dir1/file2) 83 | stat2=$(stat -c '%a' "${basedir}"/dotfiles/"${tmpd}"/dir1/file2) 84 | [ "${stat1}" != "${stat2}" ] && echo "diff permissions for file2: ${stat1} VS ${stat2}" && exit 1 85 | 86 | echo "OK" 87 | exit 0 88 | -------------------------------------------------------------------------------- /tests-ng/update-templates.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test update of templates 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | echo "dotfiles source (dotpath): ${tmps}" 34 | # the dotfile destination 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | echo "dotfiles destination: ${tmpd}" 37 | # the workdir 38 | tmpw=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 39 | export DOTDROP_WORKDIR="${tmpw}" 40 | echo "workdir: ${tmpw}" 41 | 42 | clear_on_exit "${tmps}" 43 | clear_on_exit "${tmpd}" 44 | clear_on_exit "${tmpw}" 45 | 46 | # create the config file 47 | cfg="${tmps}/config.yaml" 48 | 49 | cat > "${cfg}" << _EOF 50 | config: 51 | backup: true 52 | create: true 53 | dotpath: dotfiles 54 | workdir: ${tmpw} 55 | dotfiles: 56 | f_abc: 57 | dst: ${tmpd}/abc 58 | src: abc 59 | profiles: 60 | p1: 61 | dotfiles: 62 | - f_abc 63 | _EOF 64 | #cat ${cfg} 65 | 66 | # create the dotfile 67 | echo "head" > "${tmps}"/dotfiles/abc 68 | echo '{%@@ if profile == "p1" @@%}' >> "${tmps}"/dotfiles/abc 69 | echo "is p1" >> "${tmps}"/dotfiles/abc 70 | echo '{%@@ else @@%}' >> "${tmps}"/dotfiles/abc 71 | echo "is not p1" >> "${tmps}"/dotfiles/abc 72 | echo '{%@@ endif @@%}' >> "${tmps}"/dotfiles/abc 73 | echo "tail" >> "${tmps}"/dotfiles/abc 74 | 75 | # create the installed dotfile 76 | echo "head" > "${tmpd}"/abc 77 | echo "is p1" >> "${tmpd}"/abc 78 | echo "tail" >> "${tmpd}"/abc 79 | 80 | # update 81 | #cat ${tmps}/dotfiles/abc 82 | set +e 83 | patch=$(cd "${ddpath}" | ${bin} update -P -p p1 -k f_abc --cfg "${cfg}" 2>&1 | grep 'try patching with' | sed 's/"//g') 84 | set -e 85 | # shellcheck disable=SC2001 86 | patch=$(echo "${patch}" | sed 's/^.*: //g') 87 | echo "patching with: ${patch}" 88 | eval "${patch}" 89 | #cat ${tmps}/dotfiles/abc 90 | 91 | echo "OK" 92 | exit 0 93 | -------------------------------------------------------------------------------- /tests-ng/update-with-key.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test updates with key 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | echo "[+] dotdrop dir: ${basedir}" 33 | echo "[+] dotpath dir: ${basedir}/dotfiles" 34 | 35 | # the dotfile to be imported 36 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 37 | 38 | clear_on_exit "${basedir}" 39 | clear_on_exit "${tmpd}" 40 | 41 | # originally imported directory 42 | echo 'unique' > "${tmpd}"/uniquefile 43 | uniquefile_key="f_uniquefile" 44 | echo 'unique2' > "${tmpd}"/uniquefile2 45 | mkdir "${tmpd}"/dir1 46 | touch "${tmpd}"/dir1/dir1f1 47 | mkdir "${tmpd}"/dir1/dir1dir1 48 | 49 | # create the config file 50 | cfg="${basedir}/config.yaml" 51 | create_conf "${cfg}" # sets token 52 | 53 | # import dir1 54 | echo "[+] import" 55 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/dir1 56 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/uniquefile 57 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/uniquefile2 58 | 59 | # make some modification 60 | echo "[+] modify" 61 | echo 'changed' > "${tmpd}"/uniquefile 62 | echo 'changed' > "${tmpd}"/uniquefile2 63 | echo 'new' > "${tmpd}"/dir1/dir1dir1/new 64 | 65 | # update by key 66 | echo "[+] updating single key" 67 | cd "${ddpath}" | ${bin} update -c "${cfg}" -k -f --verbose ${uniquefile_key} 68 | 69 | # ensure changes applied correctly (only to uniquefile) 70 | diff "${tmpd}"/uniquefile "${basedir}"/dotfiles/"${tmpd}"/uniquefile # should be same 71 | set +e 72 | diff "${tmpd}"/uniquefile2 "${basedir}"/dotfiles/"${tmpd}"/uniquefile2 # should be different 73 | [ "${?}" != "1" ] && exit 1 74 | set -e 75 | 76 | # update all keys 77 | echo "[+] updating all keys" 78 | cd "${ddpath}" | ${bin} update -c "${cfg}" -k -f --verbose 79 | 80 | # ensure all changes applied 81 | diff "${tmpd}" "${basedir}"/dotfiles/"${tmpd}" 82 | 83 | echo "OK" 84 | exit 0 85 | -------------------------------------------------------------------------------- /tests-ng/variables-include.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test variables from yaml file 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | #echo "dotfile source: ${tmps}" 34 | # the dotfile destination 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | #echo "dotfile destination: ${tmpd}" 37 | 38 | clear_on_exit "${tmps}" 39 | clear_on_exit "${tmpd}" 40 | 41 | # create the config file 42 | cfg="${tmps}/config.yaml" 43 | 44 | cat > "${cfg}" << _EOF 45 | config: 46 | backup: true 47 | create: true 48 | dotpath: dotfiles 49 | variables: 50 | var1: "this is some test" 51 | var2: 12 52 | var3: another test 53 | dotfiles: 54 | f_abc: 55 | dst: ${tmpd}/abc 56 | src: abc 57 | profiles: 58 | p1: 59 | dotfiles: 60 | - f_abc 61 | variables: 62 | var1: "this is some sub-test" 63 | p2: 64 | include: 65 | - p1 66 | variables: 67 | var2: 42 68 | _EOF 69 | #cat ${cfg} 70 | 71 | # create the dotfile 72 | echo "{{@@ var1 @@}}" > "${tmps}"/dotfiles/abc 73 | echo "{{@@ var2 @@}}" >> "${tmps}"/dotfiles/abc 74 | echo "{{@@ var3 @@}}" >> "${tmps}"/dotfiles/abc 75 | echo "test" >> "${tmps}"/dotfiles/abc 76 | 77 | # install 78 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 79 | 80 | cat "${tmpd}"/abc 81 | grep '^this is some sub-test' "${tmpd}"/abc >/dev/null 82 | grep '^12' "${tmpd}"/abc >/dev/null 83 | grep '^another test' "${tmpd}"/abc >/dev/null 84 | 85 | # install 86 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p2 87 | 88 | cat "${tmpd}"/abc 89 | grep '^this is some sub-test' "${tmpd}"/abc >/dev/null 90 | grep '^42' "${tmpd}"/abc >/dev/null 91 | grep '^another test' "${tmpd}"/abc >/dev/null 92 | 93 | #cat ${tmpd}/abc 94 | 95 | echo "OK" 96 | exit 0 97 | -------------------------------------------------------------------------------- /tests-ng/variables-nested.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2023, deadc0de6 4 | # 5 | # test nested variables (see #383) 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | # the dotfile destination 34 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 35 | 36 | clear_on_exit "${tmps}" 37 | clear_on_exit "${tmpd}" 38 | 39 | # create the config file 40 | cfg="${tmps}/config.yaml" 41 | 42 | cat > "${cfg}" << _EOF 43 | config: 44 | backup: true 45 | create: true 46 | dotpath: dotfiles 47 | variables: 48 | hello: 49 | k: "hello1" 50 | wow1: "{{@@ hello.k @@}}" 51 | hello2: "hello2" 52 | z2: 53 | wow2: "{{@@ hello2 @@}}" 54 | a: 55 | suba: 56 | subsuba: "submarine" 57 | b: 58 | subb: 59 | subsubb: 60 | dotfiles: 61 | f_abc: 62 | dst: ${tmpd}/abc 63 | src: abc 64 | profiles: 65 | p1: 66 | dotfiles: 67 | - f_abc 68 | _EOF 69 | #cat ${cfg} 70 | 71 | # create the dotfile 72 | echo "wow1={{@@ wow1 @@}}" > "${tmps}"/dotfiles/abc 73 | echo "wow2={{@@ z2.wow2 @@}}" >> "${tmps}"/dotfiles/abc 74 | echo "subsuba={{@@ a.suba.subsuba @@}}" >> "${tmps}"/dotfiles/abc 75 | echo "subsubb={{@@ b.subb.subsubb @@}}" >> "${tmps}"/dotfiles/abc 76 | 77 | # install 78 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 --verbose 79 | 80 | cat "${tmpd}"/abc 81 | 82 | [ ! -e "${tmpd}"/abc ] && echo "abc not installed" && exit 1 83 | grep '^wow1=hello1' "${tmpd}"/abc >/dev/null 84 | grep '^wow2=hello2' "${tmpd}"/abc >/dev/null 85 | grep '^subsuba=submarine' "${tmpd}"/abc >/dev/null 86 | grep '^subsubb=None' "${tmpd}"/abc >/dev/null 87 | 88 | echo "OK" 89 | exit 0 90 | -------------------------------------------------------------------------------- /tests-ng/variables.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | # 5 | # test variables from yaml file 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # the dotfile source 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | mkdir -p "${tmps}"/dotfiles 33 | #echo "dotfile source: ${tmps}" 34 | # the dotfile destination 35 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 36 | #echo "dotfile destination: ${tmpd}" 37 | 38 | clear_on_exit "${tmps}" 39 | clear_on_exit "${tmpd}" 40 | 41 | # create the config file 42 | cfg="${tmps}/config.yaml" 43 | export dotdrop_test_dst="${tmpd}/def" 44 | 45 | cat > "${cfg}" << _EOF 46 | config: 47 | backup: true 48 | create: true 49 | dotpath: dotfiles 50 | variables: 51 | var1: "this is some test" 52 | var2: 12 53 | var3: another test 54 | vardst: "{{@@ env['dotdrop_test_dst'] @@}}" 55 | dotfiles: 56 | f_abc: 57 | dst: ${tmpd}/abc 58 | src: abc 59 | f_def: 60 | dst: "{{@@ vardst @@}}" 61 | src: def 62 | profiles: 63 | p1: 64 | dotfiles: 65 | - f_abc 66 | - f_def 67 | _EOF 68 | #cat ${cfg} 69 | 70 | # create the dotfile 71 | echo "{{@@ var1 @@}}" > "${tmps}"/dotfiles/abc 72 | echo "{{@@ var2 @@}}" >> "${tmps}"/dotfiles/abc 73 | echo "{{@@ var3 @@}}" >> "${tmps}"/dotfiles/abc 74 | echo "test" >> "${tmps}"/dotfiles/abc 75 | 76 | echo "test_def" > "${tmps}"/dotfiles/def 77 | 78 | # install 79 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 --verbose 80 | 81 | [ ! -e "${tmpd}"/abc ] && echo "abc not installed" && exit 1 82 | grep '^this is some test' "${tmpd}"/abc >/dev/null 83 | grep '^12' "${tmpd}"/abc >/dev/null 84 | grep '^another test' "${tmpd}"/abc >/dev/null 85 | 86 | [ ! -e "${tmpd}"/def ] && echo "def not installed" && exit 1 87 | grep '^test_def' "${tmpd}"/def >/dev/null 88 | 89 | #cat ${tmpd}/abc 90 | 91 | echo "OK" 92 | exit 0 93 | -------------------------------------------------------------------------------- /tests-ng/workers.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2024, deadc0de6 4 | # 5 | # test workers 6 | # returns 1 in case of error 7 | # 8 | 9 | ## start-cookie 10 | set -eu -o errtrace -o pipefail 11 | cur=$(cd "$(dirname "${0}")" && pwd) 12 | ddpath="${cur}/../" 13 | PPATH="{PYTHONPATH:-}" 14 | export PYTHONPATH="${ddpath}:${PPATH}" 15 | altbin="python3 -m dotdrop.dotdrop" 16 | if hash coverage 2>/dev/null; then 17 | mkdir -p coverages/ 18 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" 19 | fi 20 | bin="${DT_BIN:-${altbin}}" 21 | # shellcheck source=tests-ng/helpers 22 | source "${cur}"/helpers 23 | echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" 24 | ## end-cookie 25 | 26 | ################################################################ 27 | # this is the test 28 | ################################################################ 29 | 30 | # dotdrop directory 31 | tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 32 | echo "[+] dotdrop dir: ${tmps}" 33 | echo "[+] dotpath dir: ${tmps}/dotfiles" 34 | 35 | # the dotfile to be imported 36 | tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) 37 | 38 | clear_on_exit "${tmps}" 39 | clear_on_exit "${tmpd}" 40 | 41 | # create the config file 42 | cfg="${tmps}/config.yaml" 43 | create_conf "${cfg}" # sets token 44 | 45 | # single file 46 | echo 'unique' > "${tmpd}"/uniquefile 47 | 48 | # import 49 | echo "import..." 50 | cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/uniquefile 51 | 52 | # install 53 | rm -f "${tmpd}"/uniquefile 54 | echo "install..." 55 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" -w3 56 | 57 | # compare 58 | echo "new content" > "${tmpd}"/uniquefile 59 | echo "compare..." 60 | set +e 61 | cd "${ddpath}" | ${bin} compare -c "${cfg}" -w3 62 | set -e 63 | 64 | # update 65 | echo "update..." 66 | cd "${ddpath}" | ${bin} update -f -c "${cfg}" -w3 "${tmpd}"/uniquefile 67 | 68 | # uninstall 69 | echo "uninstall..." 70 | cd "${ddpath}" | ${bin} uninstall -f -c "${cfg}" 71 | 72 | echo "OK" 73 | exit 0 74 | -------------------------------------------------------------------------------- /tests-requirements.txt: -------------------------------------------------------------------------------- 1 | pycodestyle; python_version > '3.5' 2 | pytest; python_version > '3.5' 3 | coverage; python_version > '3.5' 4 | coveralls; python_version > '3.5' 5 | pyflakes; python_version > '3.5' 6 | pylint; python_version > '3.5' 7 | halo; python_version > '3.5' 8 | distro; python_version > '3.5' 9 | urllib3; python_version > '3.5' -------------------------------------------------------------------------------- /tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # author: deadc0de6 (https://github.com/deadc0de6) 3 | # Copyright (c) 2017, deadc0de6 4 | 5 | # stop on first error 6 | set -eu -o errtrace -o pipefail 7 | 8 | cur=$(cd "$(dirname "${0}")" && pwd) 9 | in_cicd="${GITHUB_WORKFLOW:-}" 10 | 11 | if [ -n "${in_cicd}" ]; then 12 | # patch TERM var in ci/cd 13 | if [ -z "${TERM}" ]; then 14 | export TERM="linux" 15 | fi 16 | fi 17 | 18 | # make sure both version.py and manpage dotdrop.1 are in sync 19 | dotdrop_version=$(grep version dotdrop/version.py | sed 's/^.*= .\(.*\).$/\1/g') 20 | man_version=$(grep '^\.TH' manpage/dotdrop.1 | sed 's/^.*"dotdrop-\(.*\)\" "Save your.*$/\1/g') 21 | if [ "${dotdrop_version}" != "${man_version}" ]; then 22 | echo "ERROR version.py (${dotdrop_version}) and manpage (${man_version}) differ!" 23 | exit 1 24 | fi 25 | echo "current dotdrop version ${dotdrop_version}" 26 | 27 | echo "=> python version:" 28 | python3 --version 29 | 30 | # test syntax 31 | echo "checking syntax..." 32 | "${cur}"/scripts/check-syntax.sh 33 | 34 | # unittest 35 | echo "unittest..." 36 | "${cur}"/scripts/check-unittests.sh 37 | 38 | # tests-ng 39 | if [ -n "${in_cicd}" ]; then 40 | # in CI/CD 41 | export DOTDROP_WORKERS=1 42 | echo "tests-ng with ${DOTDROP_WORKERS} worker(s)..." 43 | "${cur}"/scripts/check-tests-ng.sh 44 | 45 | export DOTDROP_WORKERS=4 46 | echo "tests-ng with ${DOTDROP_WORKERS} worker(s)..." 47 | "${cur}"/scripts/check-tests-ng.sh 48 | else 49 | echo "tests-ng..." 50 | "${cur}"/scripts/check-tests-ng.sh 51 | fi 52 | 53 | # merge coverage 54 | coverage combine coverages/* 55 | coverage xml 56 | 57 | # test doc 58 | if [ -z "${in_cicd}" ]; then 59 | # not in CI/CD 60 | echo "checking documentation..." 61 | "${cur}"/scripts/check-doc.sh 62 | fi 63 | 64 | ## done 65 | echo "All tests finished successfully" 66 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deadc0de6/dotdrop/55c5869c30679291332af77d987676170c090dbc/tests/__init__.py -------------------------------------------------------------------------------- /tests/dummy.py: -------------------------------------------------------------------------------- 1 | """ 2 | author: deadc0de6 (https://github.com/deadc0de6) 3 | Copyright (c) 2017, deadc0de6 4 | basic unittest for the import function 5 | """ 6 | 7 | 8 | import unittest 9 | import dotdrop 10 | 11 | 12 | class TestDummy(unittest.TestCase): 13 | """test case""" 14 | 15 | dotdrop.main() 16 | 17 | 18 | def main(): 19 | """entry point""" 20 | unittest.main() 21 | 22 | 23 | if __name__ == '__main__': 24 | main() 25 | --------------------------------------------------------------------------------