From 8ad6cfa33d6a37605599be5673c4acecc7eca5af Mon Sep 17 00:00:00 2001 From: gramanas Date: Sun, 28 Oct 2018 11:41:49 +0200 Subject: Add root attribute in list, finish manpage --- CMakeLists.txt | 2 +- ck.1 | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/ckutil.c | 13 +++++++ src/ckutil.h | 2 + src/dblayer.c | 12 ++++++ 5 files changed, 138 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb03dfb..6e9d9e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ project(ck C) # version set(ck_MAJOR_VERSION 0) set(ck_MINOR_VERSION 8) -set(ck_PATCH_VERSION 1) +set(ck_PATCH_VERSION 2) # Feature test macros set(FEATURE_TEST_MACROS "-D_DEFAULT_SOURCE") diff --git a/ck.1 b/ck.1 index 8ddf4ef..dd45d4f 100644 --- a/ck.1 +++ b/ck.1 @@ -77,7 +77,7 @@ Upon adding a .I config to .BR ck , -it is moved to the appropriate directory, and the symbolically linked +it is moved to the appropriate directory, and then symbolically linked back to it's original place (\fIln -s\fR). .P In a later time you can sync the @@ -271,7 +271,6 @@ This will not touch the actual file and link. It is up to the user to handle it. .P .B USAGE -.br .in +.2i .B ck delete .IR PROGRAM_NAME | \fR{\fB\-c \ \fICONFIG_PATH\fR} @@ -385,10 +384,15 @@ to print it like a lisp list. .in +.2i Add attributes to the listing (when aplicable). The attributes are -.B [\-s] -for secret and -.B [\-p] -for primary. +.B [s] +for +.BR secret , +.B [p] +for +.B primary +and +.B [root] +if the file is owned by the root user. .P .B EXAMPLES .in +.2i @@ -400,6 +404,29 @@ $ ck list programs -t python .br $ ck list -p emacs .SS "Edit configs" +Edit a +.B config +stored in +.B ck +with the +.IR $EDITOR . +.B Edit +will open the +.B primary config +of the +.BR program . +If there is no +.B primary config +but the +.B program +only has one +.BR config , +.B edit +will open that. +Whenever there is ambiguity, a list +of possible +.B configs +will be shown. .P .B USAGE .br @@ -414,6 +441,30 @@ $ ck list -p emacs .P .B ARGUMENTS .in +.2i +.I PROGRAM_NAME +.in +.2i +The name of the +.B program +to be edited. If the +.B program +has only one +.B config +or you want to edit the +.B primary +one, no further action is required. +.P +.in +.2i +.I CONFIG_BASENAME +.in +.2i +The basename of the +.B config +to be edited. This has to follow the +.B program +name. It is only needed when editing a +.B config +other than the +.B primary +one. .P .B EXAMPLES .in +.2i @@ -421,6 +472,15 @@ $ ck edit emacs .br $ ck e tmux .tmux.conf .SS "Search configs" +Grep through the configs. This +.B action +is equivalent to this: +.P +$ ck ls paths | xargs grep -H -n "search term" +.P +Thus for more advanced search through the +.B configs +one can use other programs and replace grep in the command above. .P .B USAGE .br @@ -435,11 +495,35 @@ $ ck e tmux .tmux.conf .P .B ARGUMENTS .in +.2i +.I SEARCH_TERM +.in +.2i +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). .P .B EXAMPLES .in +.2i $ ck search "search term" +$ ck search "\(require" .SS "Restore configs" +Given a working +.B ck +instance (\fIckdb \fR+ \fIckrc\fR + directories in \fIckrc\fR with +.BR configs ), \ restore +shall recreate the links from the +.B config +directories in +.I ckrc +back to their corresponding position when added to +.BR ck . +It is useful for copying +.B configs +to a new linux installation or +.B restoring +deleted links. It can either +.B restore +a specific +.B program +or all of them. .P .B USAGE .br @@ -454,6 +538,18 @@ $ ck search "search term" .P .B ARGUMENTS .in +.2i +.I PROGRAM_NAME +.in +.2i +The name of the +.B program +to be restored. +.P +.in +.2i +.B all +.in +.2i +Restore all +.B programs ck +keeps track of. .P .B EXAMPLES .in +.2i @@ -461,6 +557,9 @@ $ ck restore all .br $ ck restore -p emacs .SS "Get help" +Get help for any given +.B action +from the command line. .P .B USAGE .br @@ -474,6 +573,11 @@ $ ck restore -p emacs .P .B ARGUMENTS .in +.2i +.I action +.in +.2i +Any +.B action alias +you wish to get help for. .P .B EXAMPLES .in +.2i diff --git a/src/ckutil.c b/src/ckutil.c index f292e8e..06d12da 100644 --- a/src/ckutil.c +++ b/src/ckutil.c @@ -180,3 +180,16 @@ int util_own_grp_copy(const char *dest, const char *original) { } return 0; } + +int util_is_link_owned_by_root(const char *link) { + if (!link) { + return 0; + } + struct stat buf; + if (!lstat(link, &buf)) { + if (buf.st_uid == (uid_t)0) { + return 1; + } + } + return 0; +} diff --git a/src/ckutil.h b/src/ckutil.h index d653116..9f3cb39 100644 --- a/src/ckutil.h +++ b/src/ckutil.h @@ -93,4 +93,6 @@ extern int util_symlink_file(const char *path, const char* dest); /* Chnage owner and group of `new` and make it like `old`*/ extern int util_own_grp_copy(const char *new, const char* old); + +extern int util_is_link_owned_by_root(const char *link); #endif // CKUTIL_H diff --git a/src/dblayer.c b/src/dblayer.c index 33e1682..f517dbe 100644 --- a/src/dblayer.c +++ b/src/dblayer.c @@ -526,6 +526,10 @@ int get_program_paths(DB *db, cklist *ckl, const char* pName, int bname, int att if (sqlite3_column_int(stmt, 2)) { strcat(entry, " [p]"); } + /* root */ + if (util_is_link_owned_by_root((char *)sqlite3_column_text(stmt, 0))) { + strcat(entry, " [root]"); + } } list_add(ckl, entry); free(tmp); @@ -560,6 +564,10 @@ int list_get_paths(DB *db, cklist *ckl, int attr) { if (sqlite3_column_int(stmt, 2)) { strcat(path, " [p]"); } + /* root */ + if (util_is_link_owned_by_root((char *)sqlite3_column_text(stmt, 0))) { + strcat(path, " [root]"); + } } list_add(ckl, path); } @@ -640,6 +648,10 @@ int list_get_path_program_tree(DB *db, cklist *ckl, int attr) { if (sqlite3_column_int(stmt2, 2)) { strcat(treePath, " [p]"); } + /* root */ + if (util_is_link_owned_by_root((char *)sqlite3_column_text(stmt2, 0))) { + strcat(treePath, " [root]"); + } } list_add(ckl, treePath); } -- cgit v1.2.3