Use rcm to deploy the configuration to any folder.

    Hello again. A week (this article is about a very long time marinated in backlog)Some time ago, I explained how to use rcm for normal configuration management . We have a puppet module in our company that distributes the user's personal settings across all hosts for which he has access. Accordingly, I want the following:

    • Have your own settings for everything I use (vim, zsh, git, etc ..)
    • Update them as you update the dotfiles repository
    • All this - without unnecessary gestures


    All that is needed is already used by me, namely:

    • rcm
    • git
    • tar

    The format used for uploading files to hosts

    There is nothing tricky here: we deploy tar-balls by unpacking their contents on hosts. Only files and directories from a specific list are managed, completely frayed with each crown each time. Accordingly, if the tarball has changed, then everything is rewritten in $HOMEthe list. If not, the contents of $ HOME remain unchanged. A separate script is responsible for (re) packing the source file of personal files, it looks rather trivial:

    #!/bin/bash -e# Repack each personal directory into a tarball, use gtar on mac/*BSD and tar on linux
    TAR=$(command -v gtar tar | head -1)
    cd"$(dirname "$0")"for file in *; doif [ -d "${file}" ]; thenprintf'\033[0;32mArchiving of \033[1;33m%s\033[0m\n'"$file"# to avoid differences in an archive because of different mtime# hard coded 2003-01-01 CET
        XZ_OPT=-e9 $TAR --mtime="@1041375600" -cJf "${file}.tar.xz""${file}"fidone

    How to create a new tar-ball by commit

    Deploy dotfiles not in $ HOME

    Since I already have a tool with which I deploy configs to different hosts, then obviously I will use it. You just need to fix something and make rcmcopy files to where I need to. However, rcm always installs dot files in $ HOME, there are no command line arguments to change this behavior.

    After some experiments and picking the source code, I realized that you can change $ HOME directly, then the behavior of the utilities of all the commands rcm will change as follows: each of the utilities lsrc, mkrc, rcdn, rsupwill read ${HOME}/.rcrcand use ${HOME}/.dotfilesthe default. Accordingly, it is enough to create the one ${HOME}/.rcrcwith all the necessary parameters.

    The easiest way is to make a "blank" home folder and fill it from scratch with each commit. An example of how it looks can be seen in the repository . This folder is ignored on all hosts without the personal tag , respectively, will not interfere with the basic configuration. One single .rcrc file contains all the parameters for the file copying logic, I will do only some remarks:

    • Without $SYMLINK_DIRSrcupworking out hopelessly long, creating a complete list of files that need to be copied. With this option in conjunction with the $COPY_ALWAYSutility simply copies the entire folder as cp -rwithout much hassle
    • Obviously, a lot of things are not needed on remote servers, everything is listed in $EXCLUDES(with the exception of vim plugins, they have to be deleted in the hook, because they are used $SYMLINK_DIRS)
    • Since it ${HOME}/.dotfilesstops working for obvious reasons, you must also override$DOTFILES_DIRS

    That's all. Now you can copy the tag-personal folder anywhere, override it for a while ${HOME}and executercup

    cp -r "${WORK_DIR}""${HOME}"
    rcup -v

    Great! But you want something else ...

    Automate the deployment of configs to $ HOME custom

    To do this "something" is simple, git in this place will help your hooks. There is an executable file of the .git/hooks/post-commitfollowing content:

    #!/bin/shset -e
    HOME="${HOME}/some/long/custom/path/final_directory/USERNAME"# Some unnecessary and very heavy plugins
    EXCLUDED_VIM_PLUGINS='YouCompleteMe vimtex'
    rm -rf "${HOME}"
    cp -r "${WORK_DIR}""${HOME}"
    rcdn -v
    rcup -v
    for plugin in${EXCLUDED_VIM_PLUGINS}; do
      rm -rf "${HOME}/.vim/plugged/${plugin}"done# cleanup for .git dirs, compiled py and pictures
    find "${HOME}" \( \
        \( -type d -iname '.git' \) -o \
        \( -type f \
          \( -iname '*.pyc' -o -iname '*.gif' -o -iname '*.png' \) \
        \) \
      \) -exec rm -rf {} +
    # final repack for files"${HOME}/../"

    Now, after each commit to the repository with the dot-files, this script will be launched.

    Everything, after that, it remains to make a commit + push in the repository with personal data and wait until the automation magic takes my configs to the working hosts.

    Why complicate things like that?

    The fact is that while the company had no tools for deploying personal configuration to hosts, there was no need for such a body kit. But as soon as the opportunity arises, the appetite grows instantly. Some of my colleagues who was satisfied with the fact that the hosts brought on the three I've found, for example, .vimrc .bashrc .gitconfig. However, for quite a long time I had been lovingly sharpening, correcting and polishing a whole variety of different tools. Only one folder ~/.vimafter installing all the plugins weighs 427MB (yes, 218 of them are YCM, and I don’t drag him to the servers, and after cleaning and packaging it all loses weight up to 3MB).

    Probably, it will seem to someone that this is somehow too much and could be done with his hands. Perhaps not everyone will agree.

    I hope that someone else has an almost physical need to feel comfortable at workstations, almost at home, and this tool allows him. Use on health and be with us automation!

    Also popular now: