aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt3
-rw-r--r--README.html246
-rw-r--r--README.org19
-rw-r--r--ck.134
-rw-r--r--src/add.c2
-rw-r--r--src/ckutil.c10
-rw-r--r--src/clparser.c2
-rw-r--r--src/clparser.h1
-rw-r--r--src/export.c48
-rw-r--r--src/restore.c2
-rw-r--r--test/export.sh28
-rw-r--r--test/restore.sh4
12 files changed, 303 insertions, 96 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c0700c9..ce41ade 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 3)
+set(ck_PATCH_VERSION 4)
# Feature test macros
set(FEATURE_TEST_MACROS "-D_DEFAULT_SOURCE")
@@ -70,6 +70,7 @@ set(ckLib_src
${SRC_DIR}/restore.c
${SRC_DIR}/search.c
${SRC_DIR}/help.c
+ ${SRC_DIR}/export.c
)
set(ckLib_hdr
diff --git a/README.html b/README.html
index 286583d..6c38c37 100644
--- a/README.html
+++ b/README.html
@@ -3,7 +3,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
-<!-- 2018-11-19 Mon 01:39 -->
+<!-- 2018-11-20 Tue 13:48 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>&lrm;</title>
@@ -232,36 +232,36 @@ for the JavaScript code in this tag.
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
-<li><a href="#org501dc95">ck</a>
+<li><a href="#org10db10e">ck</a>
<ul>
-<li><a href="#org34cb767">Technicalities</a></li>
-<li><a href="#org090a724">Download</a></li>
+<li><a href="#orgd5becfe">Technicalities</a></li>
+<li><a href="#org9006d02">Download</a></li>
</ul>
</li>
<li><a href="#build-instructions">build it</a>
<ul>
-<li><a href="#org3638199">requirements</a></li>
-<li><a href="#org73a5d1c">make &amp;&amp; install</a></li>
+<li><a href="#org111dea7">requirements</a></li>
+<li><a href="#org887e970">make &amp;&amp; install</a></li>
</ul>
</li>
-<li><a href="#org88418f5">for devs</a>
+<li><a href="#org90d0470">for devs</a>
<ul>
-<li><a href="#org8949557">CMake options</a></li>
-<li><a href="#orgaf8cc38">compiler</a></li>
-<li><a href="#org336c3ed">tests</a>
+<li><a href="#orgb40d88b">CMake options</a></li>
+<li><a href="#org8004748">compiler</a></li>
+<li><a href="#org206a328">tests</a>
<ul>
-<li><a href="#orgb9b2773">run tests</a></li>
-<li><a href="#org98a43db">test suite</a></li>
+<li><a href="#org9934a6f">run tests</a></li>
+<li><a href="#org91a2119">test suite</a></li>
</ul>
</li>
</ul>
</li>
-<li><a href="#orge6e9f86">ck configuration</a></li>
+<li><a href="#orgc85202a">ck configuration</a></li>
<li><a href="#usage">Usage</a>
<ul>
-<li><a href="#org034a512">Initialize</a></li>
-<li><a href="#orgc8d3141">Add configs</a></li>
-<li><a href="#org5984569">Using the ck actions</a></li>
+<li><a href="#org5123075">Initialize</a></li>
+<li><a href="#orga15fbdd">Add configs</a></li>
+<li><a href="#orgf2b924a">Using the ck actions</a></li>
</ul>
</li>
<li><a href="#manpage">manpage</a></li>
@@ -269,9 +269,9 @@ for the JavaScript code in this tag.
</div>
</div>
<p align="center"><img src="res/logo.png"></p>
-<div id="outline-container-org501dc95" class="outline-2">
-<h2 id="org501dc95">ck</h2>
-<div class="outline-text-2" id="text-org501dc95">
+<div id="outline-container-org10db10e" class="outline-2">
+<h2 id="org10db10e">ck</h2>
+<div class="outline-text-2" id="text-org10db10e">
<p>
<b>The Config Keeper</b>
</p>
@@ -281,7 +281,7 @@ Have you ever wondered:
</p>
<blockquote>
<p>
-"Jeez Luiz, how can I manage all my configs across my desktop and server?"
+"Jeez Luise, how can I manage all my configs across my desktop and server?"
</p>
<p>
@@ -325,11 +325,16 @@ 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).
</p>
+
+<p>
+You can even export all <b>ck</b> data with the <code>export</code> action. This will create a
+<code>.tar.gz</code> file.
+</p>
</div>
-<div id="outline-container-org34cb767" class="outline-3">
-<h3 id="org34cb767">Technicalities</h3>
-<div class="outline-text-3" id="text-org34cb767">
+<div id="outline-container-orgd5becfe" class="outline-3">
+<h3 id="orgd5becfe">Technicalities</h3>
+<div class="outline-text-3" id="text-orgd5becfe">
<p>
Upon adding a config to <b>ck</b>, it moves it to the specified folder and adds a symbolic link
back where it came from (<code>ln -s</code>).
@@ -342,9 +347,9 @@ majority should).
</div>
</div>
-<div id="outline-container-org090a724" class="outline-3">
-<h3 id="org090a724">Download</h3>
-<div class="outline-text-3" id="text-org090a724">
+<div id="outline-container-org9006d02" class="outline-3">
+<h3 id="org9006d02">Download</h3>
+<div class="outline-text-3" id="text-org9006d02">
<p>
Go ahead and download <b>ck</b> and give it a try. It comes with a help sub-command
that explains any inquires you might have.
@@ -362,13 +367,13 @@ You can also read the manpage <a href="#manpage">down below</a>.
</div>
</div>
-<div id="outline-container-org5314b35" class="outline-2">
-<h2 id="build-instructions"><a id="org5314b35"></a>build it</h2>
+<div id="outline-container-org7d912d3" class="outline-2">
+<h2 id="build-instructions"><a id="org7d912d3"></a>build it</h2>
<div class="outline-text-2" id="text-build-instructions">
</div>
-<div id="outline-container-org3638199" class="outline-3">
-<h3 id="org3638199">requirements</h3>
-<div class="outline-text-3" id="text-org3638199">
+<div id="outline-container-org111dea7" class="outline-3">
+<h3 id="org111dea7">requirements</h3>
+<div class="outline-text-3" id="text-org111dea7">
<ul class="org-ul">
<li>cmake</li>
<li>sqlite3-dev</li>
@@ -377,9 +382,9 @@ You can also read the manpage <a href="#manpage">down below</a>.
</div>
</div>
-<div id="outline-container-org73a5d1c" class="outline-3">
-<h3 id="org73a5d1c">make &amp;&amp; install</h3>
-<div class="outline-text-3" id="text-org73a5d1c">
+<div id="outline-container-org887e970" class="outline-3">
+<h3 id="org887e970">make &amp;&amp; install</h3>
+<div class="outline-text-3" id="text-org887e970">
<p>
Use <code>-DCMAKE_INSTALL_PREFIX</code> when running cmake to change the install path.
</p>
@@ -402,16 +407,16 @@ Use <code>-DCMAKE_INSTALL_PREFIX</code> when running cmake to change the install
</div>
</div>
-<div id="outline-container-org88418f5" class="outline-2">
-<h2 id="org88418f5">for devs</h2>
-<div class="outline-text-2" id="text-org88418f5">
+<div id="outline-container-org90d0470" class="outline-2">
+<h2 id="org90d0470">for devs</h2>
+<div class="outline-text-2" id="text-org90d0470">
<p>
Please be <a href="https://www.gnu.org/philosophy/kind-communication.html">kind</a> to each other.
</p>
</div>
-<div id="outline-container-org8949557" class="outline-3">
-<h3 id="org8949557">CMake options</h3>
-<div class="outline-text-3" id="text-org8949557">
+<div id="outline-container-orgb40d88b" class="outline-3">
+<h3 id="orgb40d88b">CMake options</h3>
+<div class="outline-text-3" id="text-orgb40d88b">
<p>
cmake accepts the following options:
</p>
@@ -432,9 +437,9 @@ To use any one of them append it after the cmake command like so:
</div>
</div>
-<div id="outline-container-orgaf8cc38" class="outline-3">
-<h3 id="orgaf8cc38">compiler</h3>
-<div class="outline-text-3" id="text-orgaf8cc38">
+<div id="outline-container-org8004748" class="outline-3">
+<h3 id="org8004748">compiler</h3>
+<div class="outline-text-3" id="text-org8004748">
<p>
Pick your favorite
</p>
@@ -464,9 +469,9 @@ Pick your favorite
</div>
</div>
-<div id="outline-container-org336c3ed" class="outline-3">
-<h3 id="org336c3ed">tests</h3>
-<div class="outline-text-3" id="text-org336c3ed">
+<div id="outline-container-org206a328" class="outline-3">
+<h3 id="org206a328">tests</h3>
+<div class="outline-text-3" id="text-org206a328">
<p>
The testing "suite" is a bash script that runs regression
and unit tests. Regression tests are under the <code>tests/</code> directory
@@ -475,9 +480,9 @@ under <code>unit/</code> directory and test the code.
</p>
</div>
-<div id="outline-container-orgb9b2773" class="outline-4">
-<h4 id="orgb9b2773">run tests</h4>
-<div class="outline-text-4" id="text-orgb9b2773">
+<div id="outline-container-org9934a6f" class="outline-4">
+<h4 id="org9934a6f">run tests</h4>
+<div class="outline-text-4" id="text-org9934a6f">
<p>
First make sure you build ck with the <code>-DCK_TESTS=1</code> option. Then
go to the build directory and type:
@@ -486,12 +491,23 @@ go to the build directory and type:
<pre class="src src-sh">$ ./test-ck
</pre>
</div>
+<p>
+Or if you want to run a particular regression test use the filter option
+</p>
+<div class="org-src-container">
+<pre class="src src-sh">$ ./test-ck -f add
+</pre>
+</div>
+<p>
+This will match any test scrits with <code>add</code> in their name.
+</p>
</div>
</div>
-<div id="outline-container-org98a43db" class="outline-4">
-<h4 id="org98a43db">test suite</h4>
-<div class="outline-text-4" id="text-org98a43db">
+
+<div id="outline-container-org91a2119" class="outline-4">
+<h4 id="org91a2119">test suite</h4>
+<div class="outline-text-4" id="text-org91a2119">
<div class="org-src-container">
<pre class="src src-sh">$ ./test-ck -h
ck test suite
@@ -500,8 +516,10 @@ 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
</pre>
</div>
@@ -509,17 +527,17 @@ flags:
</div>
</div>
</div>
-<div id="outline-container-orge6e9f86" class="outline-2">
-<h2 id="orge6e9f86">ck configuration</h2>
-<div class="outline-text-2" id="text-orge6e9f86">
+<div id="outline-container-orgc85202a" class="outline-2">
+<h2 id="orgc85202a">ck configuration</h2>
+<div class="outline-text-2" id="text-orgc85202a">
<p>
See the <a href="#manpage">manpage</a> below.
</p>
</div>
</div>
-<div id="outline-container-orgd582e7c" class="outline-2">
-<h2 id="usage"><a id="orgd582e7c"></a>Usage</h2>
+<div id="outline-container-org0ed22f1" class="outline-2">
+<h2 id="usage"><a id="org0ed22f1"></a>Usage</h2>
<div class="outline-text-2" id="text-usage">
<p>
ck's goal is to assist with the configuration file management.
@@ -529,9 +547,9 @@ ck's goal is to assist with the configuration file management.
This section is an example usage.
</p>
</div>
-<div id="outline-container-org034a512" class="outline-3">
-<h3 id="org034a512">Initialize</h3>
-<div class="outline-text-3" id="text-org034a512">
+<div id="outline-container-org5123075" class="outline-3">
+<h3 id="org5123075">Initialize</h3>
+<div class="outline-text-3" id="text-org5123075">
<div class="org-src-container">
<pre class="src src-sh"><span style="color: #528fd1;">cd</span> ~
<span style="color: #656565;"># </span><span style="color: #757575;">make the directories for the configs</span>
@@ -544,9 +562,9 @@ $ ck init configs/vc configs/sec
</div>
</div>
-<div id="outline-container-orgc8d3141" class="outline-3">
-<h3 id="orgc8d3141">Add configs</h3>
-<div class="outline-text-3" id="text-orgc8d3141">
+<div id="outline-container-orga15fbdd" class="outline-3">
+<h3 id="orga15fbdd">Add configs</h3>
+<div class="outline-text-3" id="text-orga15fbdd">
<div class="org-src-container">
<pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">add emacs configs</span>
<span style="color: #656565;">## </span><span style="color: #757575;">primary config</span>
@@ -574,9 +592,9 @@ $ sudo ck -c /home/ckuser add ssh /etc/ssh/sshd_config -s
</div>
</div>
-<div id="outline-container-org5984569" class="outline-3">
-<h3 id="org5984569">Using the ck actions</h3>
-<div class="outline-text-3" id="text-org5984569">
+<div id="outline-container-orgf2b924a" class="outline-3">
+<h3 id="orgf2b924a">Using the ck actions</h3>
+<div class="outline-text-3" id="text-orgf2b924a">
<div class="org-src-container">
<pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">list the configs in a treelike structure with basename only</span>
$ ck list tree -b
@@ -628,11 +646,11 @@ $ ck --help e
</div>
</div>
-<div id="outline-container-org6aa4382" class="outline-2">
-<h2 id="manpage"><a id="org6aa4382"></a>manpage</h2>
+<div id="outline-container-org4efb467" class="outline-2">
+<h2 id="manpage"><a id="org4efb467"></a>manpage</h2>
<div class="outline-text-2" id="text-manpage">
<!-- Creator : groff version 1.22.3 -->
-<!-- CreationDate: Mon Nov 19 01:39:46 2018 -->
+<!-- CreationDate: Tue Nov 20 13:48:12 2018 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
@@ -722,7 +740,8 @@ manage configuration across the system</p>
<td width="82%">
-<p><b>init</b> <i>VERSION_CONTROL_DIR SECRET_DIR</i></p></td>
+<p><b>init</b> <i>VERSION_CONTROL_DIR</i>
+[<i>SECRET_DIR</i>]</p> </td>
<td width="3%">
</td></tr>
<tr valign="top" align="left">
@@ -892,6 +911,19 @@ manage configuration across the system</p>
<p><b>help&nbsp;</b><i>action</i></p></td>
<td width="3%">
</td></tr>
+<tr valign="top" align="left">
+<td width="11%"></td>
+<td width="3%">
+
+
+<p><b>ck</b></p></td>
+<td width="1%"></td>
+<td width="82%">
+
+
+<p><b>export</b></p></td>
+<td width="3%">
+</td></tr>
</table>
<h2>DESCRIPTION
@@ -899,8 +931,7 @@ manage configuration across the system</p>
</h2>
-
-<p style="margin-left:11%; margin-top: 1em"><i><b>ck</b></i>
+<p style="margin-left:11%; margin-top: 1em"><b>ck</b>
manages configuration files in a Linux system. To that end
it provides an <b>action</b> based command line
interface.</p>
@@ -908,10 +939,10 @@ interface.</p>
<p style="margin-left:11%; margin-top: 1em"><b>ck</b> needs
a database and an rc file to run. It also needs two
directories (stored in the rc file), the
-<i>VERSION_CONRTOL_DIR</i> and the <i>SECRET_DIR</i>. This
-is where the configurations will end up after they are added
-to <b>ck</b>. The <b>init</b> action takes care of them. For
-more details see the
+<i>VERSION_CONRTOL_DIR</i> and (optionally) the
+<i>SECRET_DIR</i>. This is where the configurations will end
+up after they are added to <b>ck</b>. The <b>init</b> action
+takes care of them. For more details see the
<b>ACTIONS&nbsp;</b>and&nbsp;<b>FILES</b> sections
below.</p>
@@ -1003,7 +1034,10 @@ section above.</p>
<br>
Create the <b>ck</b> database (<i>ckdb</i>) and initialize
it. Create the ck config file (<i>ckrc</i>) and add the
-directory paths to it. <b><br>
+directory paths to it. If <i>SECRET_DIR</i> is not passed,
+the <b>&minus;s</b> flag will be disabled in the <b>add</b>
+action, and this <b>ck</b> instance won&rsquo;t be able to
+store secret configs. <b><br>
USAGE</b></p>
<table width="100%" border="0" rules="none" frame="void"
@@ -1015,11 +1049,12 @@ USAGE</b></p>
<p><b>ck</b></p></td>
<td width="1%"></td>
-<td width="54%">
+<td width="57%">
-<p><b>init</b> <i>VERSION_CONTROL_DIR SECRET_DIR</i></p></td>
-<td width="28%">
+<p><b>init</b> <i>VERSION_CONTROL_DIR</i>
+[<i>SECRET_DIR</i>]</p> </td>
+<td width="25%">
</td></tr>
</table>
@@ -1062,7 +1097,8 @@ exist</b>.</p> </td></tr>
<p style="margin-left:11%;"><b>EXAMPLES</b></p>
<pre style="margin-left:14%;">$ ck init /home/ckuser/configs/vc home/ckuser/configs/sec
-$ ck i configs/vc configs/sec</pre>
+$ ck i configs/vc configs/sec
+$ ck i ~/scripts # no secret dir provided</pre>
<p style="margin-left:11%; margin-top: 1em"><b>ADD
@@ -1776,6 +1812,52 @@ $ ck h d
$ ck --help ls</pre>
+<p style="margin-left:11%; margin-top: 1em"><b>EXPORT
+CONFIGS <br>
+ck</b> can export the config files it tracks as well as the
+<i>ckrc</i> and <i>ckdb</i> files into a tar.gz archive. The
+file is named ck.tar.gz <b><br>
+USAGE</b></p>
+
+<table width="100%" border="0" rules="none" frame="void"
+ cellspacing="0" cellpadding="0">
+<tr valign="top" align="left">
+<td width="14%"></td>
+<td width="3%">
+
+
+<p><b>ck</b></p></td>
+<td width="1%"></td>
+<td width="10%">
+
+
+<p><b>export</b></p></td>
+<td width="72%">
+</td></tr>
+</table>
+
+<p style="margin-left:11%;"><b>ALIASES</b></p>
+
+
+<p style="margin-left:14%;"><b>export</b>,&nbsp;<b>&minus;&minus;export</b>,&nbsp;<b>&minus;ex</b></p>
+
+<p style="margin-left:11%;"><b>ARGUMENTS</b></p>
+
+<table width="100%" border="0" rules="none" frame="void"
+ cellspacing="0" cellpadding="0">
+<tr valign="top" align="left">
+<td width="14%"></td>
+<td width="8%">
+
+
+<p>None.</p></td>
+<td width="78%">
+</td></tr>
+</table>
+
+<p style="margin-left:11%;"><b>EXAMPLES</b></p>
+<pre style="margin-left:14%;">$ ck export</pre>
+
<h2>EXIT STATUS
<a name="EXIT STATUS"></a>
</h2>
@@ -1854,7 +1936,7 @@ flags</b>: @CMAKE_C_FLAGS@</p>
</div>
</div>
<div id="postamble" class="status">
-<p class="date">Created: 2018-11-19 Mon 01:39</p>
+<p class="date">Created: 2018-11-20 Tue 13:48</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
diff --git a/README.org b/README.org
index 756ed3a..fb15d30 100644
--- a/README.org
+++ b/README.org
@@ -5,16 +5,16 @@
Have you ever wondered:
#+BEGIN_QUOTE
- "Jeez Luiz, how can I manage all my configs across my desktop and server?"
+ "Jeez Luise, how can I manage all my configs across my desktop and server?"
- -- You
+ -- You
#+END_QUOTE
or maybe:
#+BEGIN_QUOTE
"How can I possibly keep all my configs in sync across computers?"
- -- You again
+ -- You again
#+END_QUOTE
*ck* is the solution you've been looking for all your life.
@@ -33,6 +33,9 @@ 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=).
@@ -126,6 +129,12 @@ go to the build directory and type:
#+BEGIN_SRC sh
$ ./test-ck
#+END_SRC
+Or if you want to run a particular regression test use the filter option
+#+BEGIN_SRC sh
+$ ./test-ck -f add
+#+END_SRC
+This will match any test scrits with =add= in their name.
+
*** test suite
#+BEGIN_SRC sh
@@ -136,8 +145,10 @@ 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
+ use if the tests crush unexpectedly
+ -v, --verbose verbose test output
-h, --help, * print this
#+END_SRC
* ck configuration
diff --git a/ck.1 b/ck.1
index 9944b3f..020242d 100644
--- a/ck.1
+++ b/ck.1
@@ -91,6 +91,10 @@ ck \- manage configuration across the system
.SY ck
.BI help \ action
.YS
+\" Export
+.SY ck
+.B export
+.YS
.SH DESCRIPTION
.B ck
manages configuration files in a Linux system. To that end it provides an
@@ -774,6 +778,36 @@ $ ck help add
$ ck h d
$ ck --help ls
.EE
+.SS "EXPORT CONFIGS"
+.B ck
+can export the config files it tracks as well as the
+.I ckrc
+and
+.I ckdb
+files into a tar.gz archive. The file is named ck.tar.gz
+.TP 2
+.B USAGE
+.ns
+.RS 2
+.SY ck
+.B export
+.YS
+.RE
+.TP 2
+.B ALIASES
+.BR export , \ \-\-export , \ \-ex
+.TP 2
+.B ARGUMENTS
+.ns
+.RS 2
+.TP 21
+None.
+.RE
+.TP 2
+.B EXAMPLES
+.EX
+$ ck export
+.EE
.SH EXIT STATUS
.B ck
shall return 0 if the action was completed without an error, -1 otherwise
diff --git a/src/add.c b/src/add.c
index 79227d1..c38db24 100644
--- a/src/add.c
+++ b/src/add.c
@@ -246,7 +246,7 @@ static AddOpt add_make_options(cklist *args, DB *db) {
addOpt.err = ADD_ERR_WRONG_CONFIG;
return addOpt;
}
- if (!util_is_file_link(addOpt.confPath)) {
+ if (util_is_file_link(addOpt.confPath)) {
addOpt.err = ADD_ERR_LINK_CONFIG;
return addOpt;
}
diff --git a/src/ckutil.c b/src/ckutil.c
index bc86c02..9eed9a5 100644
--- a/src/ckutil.c
+++ b/src/ckutil.c
@@ -34,7 +34,7 @@ int util_is_dir(const char *path) {
}
int util_file_exists(const char* path, char *absPath) {
- if (!path || !absPath) {
+ if (!path) {
return 0;
}
struct stat st = {0};
@@ -61,12 +61,12 @@ int util_is_file_link(const char *path) {
if (!path) {
return 0;
}
+ if (!util_file_exists(path, NULL)) {
+ return 0;
+ }
struct stat buf;
lstat(path, &buf);
- if (S_ISLNK(buf.st_mode)) {
- return 0;
- }
- return 1;
+ return S_ISLNK(buf.st_mode);
}
void util_mkdir(const char *name) {
diff --git a/src/clparser.c b/src/clparser.c
index 5b0852b..3a2a9a6 100644
--- a/src/clparser.c
+++ b/src/clparser.c
@@ -25,6 +25,7 @@ const char* const strLIST[] = {"5", "list", "ls", "l", "-l", "-ls"};
const char* const strSEARCH[] = {"4", "search", "grep", "s", "-s"};
const char* const strHELP[] = {"5", "help", "h", "-?", "-h", "--help"};
const char* const strRESTORE[] = {"3", "restore","r", "-r"};
+const char* const strEXPORT[] = {"3", "export", "ex", "--export"};
const char* const strConfDir[] = {"2", "--config", "-c"};
const char* const strVerbose1[] = {"2", "--verbose", "-v"};
const char* const strVersion[] = {"2", "version", "--version"};
@@ -276,6 +277,7 @@ static void print_parser_help() {
ckhelp("List\t%s", get_possible_action_strings(names, CKA_LIST));
ckhelp("Search\t%s", get_possible_action_strings(names, CKA_SEARCH));
ckhelp("Restore\t%s", get_possible_action_strings(names, CKA_RESTORE));
+ ckhelp("Export\t%s", get_possible_action_strings(names, CKA_EXPORT));
ckhelp("Help\t%s", get_possible_action_strings(names, CKA_HELP));
report_help();
}
diff --git a/src/clparser.h b/src/clparser.h
index afb6260..6e4cbea 100644
--- a/src/clparser.h
+++ b/src/clparser.h
@@ -29,6 +29,7 @@
X(LIST, 1, 6) \
X(SEARCH, 1, 1) \
X(RESTORE, 1, 2) \
+ X(EXPORT, 0, 0) \
X(HELP, 1, 1)
enum ParseErrors {
diff --git a/src/export.c b/src/export.c
new file mode 100644
index 0000000..b9f6aa3
--- /dev/null
+++ b/src/export.c
@@ -0,0 +1,48 @@
+/* export.c - the export action ---------------------------------------*- C -*-
+ *
+ * This file is part of ck, the config keeper
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * Copyright (C) 2018 Anastasis Grammenos
+ * GPLv3 (see LICENCE for the full notice)
+ *
+ * -------------------------------------------------------------------------- */
+#include <libgen.h>
+
+#include "dblayer.h"
+#include "ckerrlog.h"
+
+ERRLOG(export);
+
+int run_EXPORT(UserOpt *opt, Conf *conf) {
+ if (system("which tar > /dev/null 2>&1") != 0) {
+ ERR("No tar avaliable. Please make sure you have tar installed.");
+ return -1;
+ }
+
+ char cmd[STR_L] = "tar -zcvf ck.tar.gz";
+ if(conf->scrt_dir) {
+ strcat(cmd, " -C ");
+ strcat(cmd, conf->scrt_dir);
+ strcat(cmd, " ../");
+ strcat(cmd, basename(conf->scrt_dir));
+ }
+ strcat(cmd, " -C ");
+ strcat(cmd, conf->vc_dir);
+ strcat(cmd, " ../");
+ strcat(cmd, basename(conf->vc_dir));
+ strcat(cmd, " -C ");
+ strcat(cmd, opt->confDir);
+ strcat(cmd, " ckrc -C ");
+ strcat(cmd, opt->confDir);
+ strcat(cmd, " ckdb");
+
+ hLOG("Running: %s", cmd);
+ strcat(cmd, " > /dev/null 2>&1");
+ return system(cmd);
+}
+
+void print_EXPORT_help() {
+ HELP("ck export");
+}
diff --git a/src/restore.c b/src/restore.c
index 3aff790..a18f906 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -23,7 +23,7 @@ static int restore_make_links(cklist *from, cklist *to) {
&& list_size(from) == list_size(to)) {
do {
if (util_file_exists(list_get(to), NULL)
- || !util_is_file_link(list_get(to))) {
+ || util_is_file_link(list_get(to))) {
ERR("File %s already exists.", list_get(to));
sERR("No links were created.");
return -1;
diff --git a/test/export.sh b/test/export.sh
new file mode 100644
index 0000000..8daf76a
--- /dev/null
+++ b/test/export.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+init export
+
+# add configs to ck
+path1=$BIN/test1.conf
+path2=$BIN/test2.conf
+path3=$BIN/test3.conf
+path4=$BIN/test4.conf
+path5=$BIN/test5.conf
+
+add_config prog1 $path1
+add_config prog1 $path2
+add_config prog2 $path3
+add_config prog2 $path4
+add_config prog3 $path5
+
+# export
+exec $BIN/ck -c $BIN export >&${V} &
+wait $!
+
+if [ ! -f $BIN/ck.tar.gz ]; then
+ err "tar.gz was not created"
+fi
+
+rm $BIN/ck.tar.gz
+clear_tests
+echo -e $PASS
diff --git a/test/restore.sh b/test/restore.sh
index 2d60cb9..ba131e4 100644
--- a/test/restore.sh
+++ b/test/restore.sh
@@ -23,7 +23,7 @@ wait $!
for i in $($BIN/ck -c $BIN list -p prog1); do
if [[ ! -L "$i" ]]; then
- err "Couldn't restore path $i"
+ err "Couldn't restore path $i from -p prog1"
exit 1
fi
done
@@ -37,7 +37,7 @@ wait $!
for i in $($BIN/ck -c $BIN list paths); do
if [[ ! -L "$i" ]]; then
- err "Couldn't restore path $i"
+ err "Couldn't restore path $i from all"
exit 1
fi
done