From bd85acf6a408674bcdcb5116963fe4fea2247280 Mon Sep 17 00:00:00 2001 From: gramanas Date: Tue, 20 Nov 2018 20:21:29 +0200 Subject: Simplyfy restore arguments --- CMakeLists.txt | 2 +- README.html | 253 +++++++++++++++++++++++++++++++++++++------------------ README.org | 55 +++++++++++- ck.1 | 14 +-- src/clparser.h | 2 +- src/confparser.c | 2 +- src/restore.c | 37 +++----- test/restore.sh | 4 +- 8 files changed, 245 insertions(+), 124 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce41ade..8dcf30a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ project(ck C) # version set(ck_MAJOR_VERSION 0) set(ck_MINOR_VERSION 9) -set(ck_PATCH_VERSION 4) +set(ck_PATCH_VERSION 5) # Feature test macros set(FEATURE_TEST_MACROS "-D_DEFAULT_SOURCE") diff --git a/README.html b/README.html index 6c38c37..215584d 100644 --- a/README.html +++ b/README.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + @@ -232,36 +232,37 @@ for the JavaScript code in this tag.

Table of Contents

-
-

ck

-
+
+

ck

+

The Config Keeper

@@ -332,9 +333,9 @@ You can even export all ck data with the export action. This

-
-

Technicalities

-
+
+

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). @@ -347,9 +348,9 @@ majority should).

-
-

Download

-
+
+

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. @@ -367,13 +368,13 @@ You can also read the manpage down below.

-
-

build it

+
+

build it

-
-

requirements

-
+
+

requirements

+
  • cmake
  • sqlite3-dev
  • @@ -382,9 +383,9 @@ You can also read the manpage down below.
-
-

make && install

-
+
+

make && install

+

Use -DCMAKE_INSTALL_PREFIX when running cmake to change the install path.

@@ -394,7 +395,7 @@ Use -DCMAKE_INSTALL_PREFIX when running cmake to change the install # make a build directory and enter it > mkdir ~/ck_build; cd ~/ck_build; # run cmake -> cmake ~/code/ck +> cmake ~/code/ck # run make > make # install it @@ -407,16 +408,16 @@ Use -DCMAKE_INSTALL_PREFIX when running cmake to change the install
-
-

for devs

-
+
+

for devs

+

Please be kind to each other.

-
-

CMake options

-
+
+

CMake options

+

cmake accepts the following options:

@@ -437,9 +438,9 @@ To use any one of them append it after the cmake command like so:
-
-

compiler

-
+
+

compiler

+

Pick your favorite

@@ -469,9 +470,9 @@ Pick your favorite
-
-

tests

-
+
+

tests

+

The testing "suite" is a bash script that runs regression and unit tests. Regression tests are under the tests/ directory @@ -480,9 +481,9 @@ under unit/ directory and test the code.

-
-

run tests

-
+
+

run tests

+

First make sure you build ck with the -DCK_TESTS=1 option. Then go to the build directory and type: @@ -505,9 +506,9 @@ This will match any test scrits with add in their name.

-
-

test suite

-
+
+

test suite

+
$ ./test-ck -h
 ck test suite
@@ -527,17 +528,17 @@ flags:
 
-
-

ck configuration

-
+
+

ck configuration

+

See the manpage below.

-
-

Usage

+
+

Usage

ck's goal is to assist with the configuration file management. @@ -547,9 +548,9 @@ ck's goal is to assist with the configuration file management. This section is an example usage.

-
-

Initialize

-
+
+

Initialize

+
cd ~
 # make the directories for the configs
@@ -562,9 +563,9 @@ $ ck init configs/vc configs/sec
 
-
-

Add configs

-
+
+

Add configs

+
# add emacs configs
 ## primary config
@@ -592,9 +593,9 @@ $ sudo ck -c /home/ckuser add ssh /etc/ssh/sshd_config -s
 
-
-

Using the ck actions

-
+
+

Using the ck actions

+
# list the configs in a treelike structure with basename only
 $ ck list tree -b
@@ -633,9 +634,9 @@ $ ck delete emacs
 $ ck del emacs init.el
 
 # restore all links (on a new instalation)
-$ ck restore all
+$ ck restore --all
 # restore a program's links
-$ ck r -p emacs
+$ ck r emacs
 
 # get help for an action
 $ ck h add
@@ -644,13 +645,99 @@ $ 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

+
+

manpage

- + @@ -882,7 +969,7 @@ manage configuration across the system

-

restore −p PROGRAM_NAME

+

restore PROGRAM_NAME

@@ -895,7 +982,7 @@ manage configuration across the system

-

restore all

+

restore −−all

@@ -1700,11 +1787,11 @@ USAGE

ck

- + -

restore −p PROGRAM_NAME

- +

restore PROGRAM_NAME

+ @@ -1713,11 +1800,11 @@ USAGE

ck

- + -

restore all

- +

restore −−all

+ @@ -1746,7 +1833,7 @@ USAGE

-

all

+

--all

@@ -1756,8 +1843,8 @@ USAGE

EXAMPLES

-
$ ck restore all
-$ ck restore -p emacs
+
$ ck restore --all
+$ ck restore emacs

GET HELP @@ -1936,7 +2023,7 @@ flags: @CMAKE_C_FLAGS@

-

Created: 2018-11-20 Tue 13:48

+

Created: 2018-11-20 Tue 20:21

Validate

diff --git a/README.org b/README.org index fb15d30..ce1f4e9 100644 --- a/README.org +++ b/README.org @@ -69,7 +69,7 @@ Use =-DCMAKE_INSTALL_PREFIX= when running cmake to change the install path. # make a build directory and enter it > mkdir ~/ck_build; cd ~/ck_build; # run cmake - > cmake ~/code/ck + > cmake ~/code/ck # run make > make # install it @@ -235,15 +235,64 @@ This section is an example usage. $ ck del emacs init.el # restore all links (on a new instalation) - $ ck restore all + $ ck restore --all # restore a program's links - $ ck r -p emacs + $ ck r emacs # get help for an action $ ck h add $ ck --help e #+END_SRC +** 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 +#+BEGIN_SRC sh + you@desktop -> ck export +#+END_SRC + +**** Copy the resulting tar file to the server +#+BEGIN_SRC sh + you@desktop -> scp ck.tar.gz ckuser@server:/home/ckuser +#+END_SRC + +**** Now we ssh to the server +#+BEGIN_SRC sh + you@desktop -> ssh ckuser@server +#+END_SRC + +**** Start by untaring the archive & installing ck +#+BEGIN_SRC sh + ckuser@server -> tar zxf ck.tar.gz +#+END_SRC + +**** 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. + #+BEGIN_SRC sh + ckuser@server -> export CK_CONFIG=/where/you/have/ckrc/and/ckdb + #+END_SRC + + 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 +#+BEGIN_SRC sh + ckuser@server -> ck restore zsh + ckuser@server -> ck restore emacs +#+END_SRC + * manpage :PROPERTIES: :CUSTOM_ID: manpage diff --git a/ck.1 b/ck.1 index 020242d..827b7ce 100644 --- a/ck.1 +++ b/ck.1 @@ -80,12 +80,12 @@ ck \- manage configuration across the system .YS \" Restore .SY ck -.B restore \-p +.B restore .I PROGRAM_NAME .YS .ns .SY ck -.B restore all +.B restore \-\-all .YS \" Help .SY ck @@ -714,12 +714,12 @@ take care of the already created links, if that's the case. .ns .RS 2 .SY ck -.B restore \-p +.B restore .I PROGRAM_NAME .YS .ns .SY ck -.B restore all +.B restore \-\-all .YS .RE .TP 2 @@ -735,7 +735,7 @@ The name of the .B program to be restored. .TP 21 -.B all +.B --all Restore all .B programs ck keeps track of. @@ -743,8 +743,8 @@ keeps track of. .TP 2 .B EXAMPLES .EX -$ ck restore all -$ ck restore -p emacs +$ ck restore --all +$ ck restore emacs .EE .SS "GET HELP" Get help for any given diff --git a/src/clparser.h b/src/clparser.h index 6e4cbea..1ba6d00 100644 --- a/src/clparser.h +++ b/src/clparser.h @@ -28,7 +28,7 @@ X(EDIT, 1, 5) \ X(LIST, 1, 6) \ X(SEARCH, 1, 1) \ - X(RESTORE, 1, 2) \ + X(RESTORE, 1, 1) \ X(EXPORT, 0, 0) \ X(HELP, 1, 1) diff --git a/src/confparser.c b/src/confparser.c index 48f0c71..f7b6268 100644 --- a/src/confparser.c +++ b/src/confparser.c @@ -88,7 +88,7 @@ int find_config(UserOpt *opt) { return 0; } } - LOG("$XDG_CONFIG_HOME not avaliable."); + ERR("No config found."); return -1; } diff --git a/src/restore.c b/src/restore.c index a18f906..426e803 100644 --- a/src/restore.c +++ b/src/restore.c @@ -129,44 +129,29 @@ int run_RESTORE(UserOpt *opt, Conf *conf) { cklist *from = list_make_new(); cklist *to = list_make_new(); int err_flag = 0; - if (strcmp(list_get(opt->args), "-p") == 0) { - if (list_next(opt->args)) { - if (program_exists(&db, list_get(opt->args))) { - if (restore_configs_exists(&db, conf, list_get(opt->args), from, to)) { - hLOG("Restoring links for %s...", list_get(opt->args)); - } - else { - err_flag = 1; - } + char *arg = list_get(opt->args); + if (strcmp(arg, "--all") != 0) { + if (program_exists(&db, arg)) { + if (restore_configs_exists(&db, conf, arg, from, to)) { + hLOG("Restoring links for %s...", arg); } else { - ERR("Program %s does not exist", list_get(opt->args)); err_flag = 1; } } else { - sERR("-p needs a program name"); + ERR("Program %s does not exist", arg); err_flag = 1; } } - else if (strcmp(list_get(opt->args), "all") == 0) { - if (!list_next(opt->args)) { - if (restore_all_exist(&db, conf, from, to)) { - hLOG("Restoring all links..."); - } - else { - err_flag = 1; - } + else { + if (restore_all_exist(&db, conf, from, to)) { + hLOG("Restoring all links..."); } else { - sERR("Wrong argument"); err_flag = 1; } } - else { - sERR("Wrong argument"); - err_flag = 1; - } close_DB(&db); int rc = -1; if (!err_flag) { @@ -181,7 +166,7 @@ int run_RESTORE(UserOpt *opt, Conf *conf) { } void print_RESTORE_help() { - ckhelp("ck restore -p PROGRAM_NAME"); - ckhelp("ck restore all"); + ckhelp("ck restore PROGRAM_NAME"); + ckhelp("ck restore --all"); report_help(); } diff --git a/test/restore.sh b/test/restore.sh index ba131e4..3730fb2 100644 --- a/test/restore.sh +++ b/test/restore.sh @@ -18,7 +18,7 @@ add_config prog2 $path4 rm "$path1" "$path2" # restore them -exec $BIN/ck -c $BIN restore -p prog1 >&${V} & +exec $BIN/ck -c $BIN restore prog1 >&${V} & wait $! for i in $($BIN/ck -c $BIN list -p prog1); do @@ -32,7 +32,7 @@ done rm "$path1" "$path2" "$path3" "$path4" # restore all -exec $BIN/ck -c $BIN restore all >&${V} & +exec $BIN/ck -c $BIN restore --all >&${V} & wait $! for i in $($BIN/ck -c $BIN list paths); do -- cgit v1.2.3