Table of Contents
ck
The Config Keeper
Have you ever wondered:
"Jeez Luise, how can I manage all my configs across my desktop and server?"
– You
or maybe:
"How can I possibly keep all my configs in sync across computers?"
– You again
ck is the solution you've been looking for all your life.
With it you can keep track of all the configs you cherish and love, and store them neat and tidy in a folder you can later sync using your favorite sync solution (git, nextcloud, rsync). You can even gift your precious data to Google and use GDrive (not recommended!!).
After you create your local config db you can list them, edit them and even search in them, all within the comforting hands of ck, your faithful companion.
You can also use ck to store sensitive configurations (with passwords, etc) and instruct it to save them in a different folder, so they won't be in the same place with the normal ones (in the event you want to share your configs with the rest of us).
You can even export all ck data with the export
action. This will create a
.tar.gz
file.
Technicalities
Upon adding a config to ck, it moves it to the specified folder and adds a symbolic link
back where it came from (ln -s
).
Make sure that the target program can read it's configuration from a symlink (the vast majority should).
Download
Go ahead and download ck and give it a try. It comes with a help sub-command that explains any inquires you might have.
Grab the latest zip/tarball from the tag section in the repo and proceed to the build section.
You can also read the manpage down below.
build it
requirements
- cmake
- sqlite3-dev
- build tools (gcc/llvm, make…)
make && install
Use -DCMAKE_INSTALL_PREFIX
when running cmake to change the install path.
# clone the repo > cd ~/code; git clone https://gitlab.com/grm-grm/ck # make a build directory and enter it > mkdir ~/ck_build; cd ~/ck_build; # run cmake > cmake ~/code/ck # run make > make # install it > make install # run ck > ck
for devs
Please be kind to each other.
CMake options
cmake accepts the following options:
option(CK_DEBUG "Build with debug symbols, asan and warnings") option(CK_TESTS "Make the tests") option(CK_SHARED "Build with shared lib")
To use any one of them append it after the cmake command like so:
cmake -DCK_DEBUG=1 -DCK_TESTS=1 ~/code/ck
compiler
Pick your favorite
> export CC=clang # or > export CC=gcc
# clone the repo > cd ~/code; git clone https://gitlab.com/grm-grm/ck # make a build directory and enter it > mkdir ~/ck_build; cd ~/ck_build; # run cmake > cmake -DCK_DEBUG=1 -DCK_TESTS=1 ~/code/ck # run make > make # check ck > ./test-ck # run ck > ./ck
tests
The testing "suite" is a bash script that runs regression
and unit tests. Regression tests are under the tests/
directory
and are bash scripts that test ck
functionality. Unit tests reside
under unit/
directory and test the code.
run tests
First make sure you build ck with the -DCK_TESTS=1
option. Then
go to the build directory and type:
$ ./test-ck
Or if you want to run a particular regression test use the filter option
$ ./test-ck -f add
This will match any test scrits with add
in their name.
test suite
$ ./test-ck -h ck test suite use without flags to run all tests flags: -u, --unit run only the unit tests -r, --regression run only the regression tests -f, --filter run regression test matching the argument -c, --clear remove test files use if the tests crush unexpectedly -v, --verbose verbose test output -h, --help, * print this
ck configuration
See the manpage below.
Usage
ck's goal is to assist with the configuration file management.
This section is an example usage.
Initialize
cd ~ # make the directories for the configs $ mkdir -p configs/vc configs/sec # initialize new ck $ ck init configs/vc configs/sec
Add configs
# add emacs configs ## primary config $ ck add emacs .emacs.d/orgconf.org -p ## secret config, with passwords and naughty words $ ck add emacs .emacs.d/accounts.org -s ## and another one for emacs $ ck add emacs .emacs.d/init.el # add tmux config $ ck add tmux .tmux.conf -p # add X configs $ ck add X .xinitrc $ ck add X .Xresources # add ssh configs (secret) $ ck add ssh .ssh/config -s -p $ ck add ssh .ssh/authorized_keys -s # When running with sudo, we need to specify the ck config # location. $ sudo ck -c /home/ckuser add ssh /etc/ssh/sshd_config -s
Using the ck actions
# list the configs in a treelike structure with basename only $ ck list tree -b # or with the full path & attributes $ ck list tree -a # list only the paths in python or lisp like lists $ ck list paths -t lisp $ ck list programs -t python -b -a # list emacs configs $ ck list -p emacs # search the configs $ ck search Hostname $ ck search "search term with spaces" # escape symbols $ ck search \( # edit the primary config of emacs wiht $EDITOR $ ck edit emacs # or with vi $ ck e emacs --editor vi # run the command cat to it $ ck edit emacs --command cat # or a complex editor call $ ck edit emacs --command "emacsclient -a \"\" -t" # edit a non-primary config of ssh $ ck e emacs init.el # edit a root config $ ck e ssh -s # delete a program with all the configs $ ck delete emacs # or a specific config $ ck del emacs init.el # restore all links (on a new instalation) $ ck restore --all # restore a program's links $ ck r emacs # get help for an action $ ck h add $ ck --help e
Copying configs to a different linux system
Using the method described below one can use ck to copy the configs to a different linux system. In this example we assume we have the ck instance we created above and we want to copy some configs to our new VPS.
We will also assume that the VPS' username is different
that the one on our desktop (ckuser
in our example).
- Start at the desktop by exporting the ck files
you@desktop -> ck export
- Copy the resulting tar file to the server
you@desktop -> scp ck.tar.gz ckuser@server:/home/ckuser
- Now we ssh to the server
you@desktop -> ssh ckuser@server
- Start by untaring the archive & installing ck
ckuser@server -> tar zxf ck.tar.gz
- Move the version_control_dir and secer_dir to where you want them to be
- Move the ckrc and ckdb files where you want ck config home to be
- Edit ckrc and change the home_dir to /home/ckuser
- Also change secret_dir and version_control_dir to where you placed them before
- Make sure ck will find your config by default by setting the $CK_CONFIG environment variable
Edit bashrc to make this permanent.
ckuser@server -> export CK_CONFIG=/where/you/have/ckrc/and/ckdb
Note, you might not have to use this if you use one of the default config locations. ck will first check $XDG_CONFIG_HOME/ck and then $HOME/.ck so using either one of these will do.
- Remove any existing conflicting configs
- Restore your configs
ckuser@server -> ck restore zsh ckuser@server -> ck restore emacs
manpage
ck
NAMESYNOPSIS
DESCRIPTION
CONFIGURATION
OPTIONS
ACTIONS
EXIT STATUS
FILES
BUILD VALUES
VERSION
AUTHOR
NAME
ck − manage configuration across the system
SYNOPSIS
ck |
[−v|−−verbose] [−c|−−config DIR] action [...] |
|||
ck |
[version|−−version] |
|||
ck |
init VERSION_CONTROL_DIR [SECRET_DIR] |
|||
ck |
add PROGRAM_NAME CONFIG_PATH [−p] [−s] |
|||
ck |
delete PROGRAM_NAME [CONFIG_BASENAME] |
|||
ck |
list tree [−a] [−b] |
|||
ck |
list −p PROGRAM_NAME [−t list-type] [−a] [−b] |
|||
ck |
list programs [−t list-type] [−a] [−b] |
|||
ck |
list paths [−t list-type] [−a] [−b] |
|||
ck |
list ckconf |
|||
ck |
edit PROGRAM_NAME [CONFIG_BASENAME] [−−editor EDITOR] [−−command COMMAND] [−s] |
|||
ck |
search SEARCH_TERM |
|||
ck |
restore PROGRAM_NAME |
|||
ck |
restore −−all |
|||
ck |
help action |
|||
ck |
export |
DESCRIPTION
ck manages configuration files in a Linux system. To that end it provides an action based command line interface.
ck needs a database and an rc file to run. It also needs two directories (stored in the rc file), the VERSION_CONRTOL_DIR and (optionally) the SECRET_DIR. This is where the configurations will end up after they are added to ck. The init action takes care of them. For more details see the ACTIONS and FILES sections below.
In ck terms a program is an entity that has one or more configs attached to it. Each program can have exactly one primary config. Upon adding a config to ck, it is moved to the appropriate directory, and then symbolically linked back to it’s original place (ln -s).
In a later time you can sync the VERSION_CONTROL_DIR and SECRET_DIR. You can also restore the links given these two directories and the corresponding rc file and database.
CONFIGURATION
ck uses sqlite to index the configuration files. The init action by default creates a directory in witch the ckrc and ckdb files reside. See the FILES section for more details.
ck will first search for the configuration in the folder shown by the $CK_CONFIG environment variable. If it is set it will use the ckrc and ckdb inside this directory. Else it will use $XDG_CONFIG_HOME/ck and if that is not set as well it will fall back to $HOME/.ck.
One can have multiple config directories with different configurations each. Using the config or −c option one can set the path in which ck will search for ckrc and ckdb. Using this will ignore any environment variables. See the OPTIONS section for more details.
OPTIONS
Change
ck behavior using the following options. They must be
present before any action.
−−verbose, −v
[WIP]
Currently prints the log. Must be the first argument in
order to work.
−−config DIR, −c DIR
Use ckdb and ckrc residing in DIR.
−−version, version
Print version and license information, and quit.
ACTIONS
Each action has several aliases. The selected action must be after the OPTIONS if any. All available actions can be seen in the SYNOPSIS section above.
Each action takes a number of arguments and flags.
INITIALIZE
Create the ck database (ckdb) and initialize
it. Create the ck config file (ckrc) and add the
directory paths to it. If SECRET_DIR is not passed,
the −s flag will be disabled in the add
action, and this ck instance won’t be able to
store secret configs.
USAGE
ck |
init VERSION_CONTROL_DIR [SECRET_DIR] |
ALIASES
init, i, −i
ARGUMENTS
VERSION_CONTROL_DIR |
The directory where configs will be stored by default. File must exist. | ||
SECRET_DIR |
The directory where configs will be stored when using the −s flag in add. File must exist. |
EXAMPLES
$ ck init /home/ckuser/configs/vc home/ckuser/configs/sec $ ck i configs/vc configs/sec $ ck i ~/scripts # no secret dir provided
ADD
CONFIG
Add a config to the database (ckdb). Each
config belongs to a program. Every
program can have multiple configs under it and
one of them can be primary. The edit action
will open the primary config by default.
USAGE
ck |
add PROGRAM_NAME CONFIG_PATH [−p] [−s] |
ALIASES
add, a, −a
ARGUMENTS
PROGRAM_NAME |
The name of the program the config belongs at. | ||
CONFIG_PATH |
Path to the config. Can be relative. |
FLAGS
−s |
Mark the config as secret. It will be stored on the SECRET_DIR. | ||
−p |
Mark the config as primary. The edit action will open this by default. |
EXAMPLES
# add emacs configs ## primary config $ ck add emacs ~/.emacs.d/orgconf.org -p ## secret config, with passwords $ ck add emacs ~/.emacs.d/accounts.org -s ## another one for emacs $ ck add emacs ~/.emacs.d/init.el
DELETE
CONFIG
Delete a config or a program from the database
(ckdb). This will not touch the actual file and link.
It is up to the user to handle it.
USAGE
ck |
delete PROGRAM_NAME [CONFIG_BASENAME] |
ALIASES
delete, del, d, −d
ARGUMENTS
PROGRAM_NAME |
Delete the program and all it’s configs. | ||
CONFIG_BASENAME |
The basename of the config file to be deleted. It has to follow the PROGRAM_NAME. |
EXAMPLES
$ ck delete emacs $ ck del emacs init.el
LIST
VALUES
List programs, configs and ck configuration values.
USAGE
ck |
list tree [−a] [−b] |
|||
ck |
list −p PROGRAM_NAME [−t list-type] [−a] [−b] |
|||
ck |
list programs [−t list-type] [−a] [−b] |
|||
ck |
list paths [−t list-type] [−a] [−b] |
|||
ck |
list ckconf |
ALIASES
list, ls, l, -ls, −l
ARGUMENTS
tree |
List programs with their configs in a tree like structure. | ||
paths |
List all the config paths ck keeps track of. | ||
programs |
List all the programs ck keeps track of. | ||
−c PROGRAM_NAME |
List all the configs of PROGRAM_NAME. | ||
ckconf |
List the ck configuration values, like the VERSION_CONTROL_DIR and SECRET_DIR. |
FLAGS
−t type |
Set the type of the list. Can be either plain (the default) a simple list, python to print it like a python array or lisp to print it like a lisp list. | ||
−a |
Show attributes to the listing (when applicable). These are [s] for secret, [p] for primary and [root] if the file is owned by the root user. | ||
−b |
Print the config basename instead of the full path. |
EXAMPLES
$ ck list tree -a $ ck list paths -t lisp $ ck list programs -t python $ ck list -p emacs
EDIT
CONFIGS
Edit a config stored in ck with the
$EDITOR. Edit will open the primary
config of the program. If there is no primary
config but the program only has one
config, edit will open that. Whenever there is
ambiguity, a list of possible configs will be shown.
USAGE
ck |
edit PROGRAM_NAME [CONFIG_BASENAME] [−−editor EDITOR] [−−command COMMAND] [−s] |
ALIASES
edit, e, −e
ARGUMENTS
PROGRAM_NAME |
The name of the program to be edited. If the program has only one config or you want to edit the primary one, no further action is required. | ||
CONFIG_BASENAME |
The basename of the config to be edited. This has to follow the PROGRAM_NAME name. It is only needed when editing a config other than the primary one. |
FLAGS
−−editor EDITOR |
Use EDITOR to edit the config. | ||
−−command COMMAND |
The COMMAND string will be used instead of an editor. | ||
−−s |
Prepend the whole command with sudo, should you want to edit a config belonging to root. |
EXAMPLES
$ ck edit emacs $ ck edit emacs --command cat $ ck edit emacs --command "emacsclient -a $ ck e tmux .tmux.conf $ ck e tmux .tmux.conf --editor vi $ ck e ssh -s
SEARCH
CONFIGS
Grep through the configs. This action is equivalent
to this:
$ ck ls paths | xargs grep -H -n "search term"
Thus for more advanced search
through the configs one can use other programs and
replace grep in the command above.
USAGE
ck |
search SEARCH_TERM |
ALIASES
search, grep, s, −s
ARGUMENTS
SEARCH_TERM |
The term you wish to search for. If it’s a phrase enclose it in "". If it’s a special character you can escape it with \ (backslash). |
EXAMPLES
$ ck search "search term" $ ck search "\(require"
RESTORE
CONFIGS
Given a working ck instance (ckdb +
ckrc + directories in ckrc with
configs), restore shall recreate the
links from the config directories in ckrc back
to their corresponding position when added to ck. It
is useful for copying configs to a new linux
installation or restoring deleted links. It can
either restore a specific program or all of
them.
NOTE: If ck tracks configs that are owned by root, simply running
$ ck restore ...
will fail due to permissions. To remedy this, ck will alter the owner and group of a link to match the one in the original config file. Thus, running
$ sudo ck -c /home/ckuser/.ck restore ...
will restore the root user’s links as it should and the user links will have the user as the owner instead of the root.
ck
checks that the configs exist and that the location
for the link is available before making any links. However,
in the even that symlink fails for some other reason,
the process will stop as is. The user will have to take care
of the already created links, if that’s the case.
USAGE
ck |
restore PROGRAM_NAME |
|||
ck |
restore −−all |
ALIASES
restore, r, −r
ARGUMENTS
PROGRAM_NAME |
The name of the program to be restored. | ||
--all |
Restore all programs ck keeps track of. |
EXAMPLES
$ ck restore --all $ ck restore emacs
GET HELP
Get help for any given action from the command line.
USAGE
ck |
help action |
ALIASES
help, h, −−help, -h, −?
ARGUMENTS
action |
Any action alias you wish to get help for. |
EXAMPLES
$ ck help add $ ck h d $ ck --help ls
EXPORT
CONFIGS
ck can export the config files it tracks as well as the
ckrc and ckdb files into a tar.gz archive. The
file is named ck.tar.gz
USAGE
ck |
export |
ALIASES
export, −−export, −ex
ARGUMENTS
None. |
EXAMPLES
$ ck export
EXIT STATUS
ck shall return 0 if the action was completed without an error, -1 otherwise
FILES
By default ck will store it’s files in $CK_CONFIG > $XDG_CONFIG_HOME/ck > $HOME/.ck. Using the −c|−−config one can change this.
ck generated
files
~/.ck/ckrc
Store the configuration values (VERSION_CONTROL_DIR and SECRET_DIR).
~/.ck/ckdb
SQLite3 database.
User
files
VERSION_CONTROL_DIR
This is where the configuration files will end up by default. It’s value is set with the init action, but can be changed by editing ckrc.
SECRET_DIR
This is where the configuration files will end up when adding them with the -s flag. It’s value is set with the init action, but can be changed by editing ckrc.
BUILD VALUES
compiler:
@CMAKE_C_COMPILER@
flags: @CMAKE_C_FLAGS@
VERSION
ck version @ck_MAJOR_VERSION@.@ck_MINOR_VERSION@.@ck_PATCH_VERSION@
AUTHOR
gramanas
Created: 2018-11-20 Tue 20:21