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:
All that is needed is already used by me, namely:
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 fraying on every crown with each delay. Accordingly, if the tarball has changed, then everything is rubbed into the $HOME
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 *; do if [ -d "${file}" ]; then printf '\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}" fi done
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 rcm
copy the files to the place I need. 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 rcm commands changes as follows: each of the lsrc, mkrc, rcdn, rsup
will read ${HOME}/.rcrc
and use ${HOME}/.dotfiles
by default. Accordingly, it is enough to create the same ${HOME}/.rcrc
with 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:
$SYMLINK_DIRS
rcup
works hopelessly long, creating a complete list of files that need to be copied. With this option in conjunction with the $COPY_ALWAYS
utility simply copies the entire folder as cp -r
without unnecessary trouble.$EXCLUDES
(with the exception of vim plugins, they have to be deleted in the hook because $SYMLINK_DIRS
)${HOME}/.dotfiles
stops working for obvious reasons, you must also override $DOTFILES_DIRS
That's all. Now you can copy the tag-personal folder anywhere, redefine for a time ${HOME}
and execute rcup
WORK_DIR="${HOME}/.dotfiles/tag-personal" _OLD_HOME=$HOME HOME="${HOME}/some/long/custom/path" cp -r "${WORK_DIR}" "${HOME}" rcup -v HOME=$_OLD_HOME
Great! But you want something else ...
To do this "something" is simple, git in this place will help your hooks. There is an executable .git/hooks/post-commit
file with the following content:
#!/bin/sh set -e WORK_DIR="tag-personal" 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}/../repack.sh"
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.
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 were satisfied with the fact that I brought three files to the hosts, say, .vimrc .bashrc .gitconfig
. However, for quite a long time I had been lovingly sharpening, correcting and polishing a whole variety of different tools. Only the ~/.vim
after 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 to 3MB).
Probably, it will seem to someone that this is somehow too much and could have been 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!
Source: https://habr.com/ru/post/435706/
All Articles