diff options
Diffstat (limited to 'docs/cpt.org')
-rw-r--r-- | docs/cpt.org | 150 |
1 files changed, 138 insertions, 12 deletions
diff --git a/docs/cpt.org b/docs/cpt.org index bff8ac9..dfddc38 100644 --- a/docs/cpt.org +++ b/docs/cpt.org @@ -48,7 +48,9 @@ manual for *Carbs Packaging Tools*. For development logs see [[https://git.carbs - [[#option-parsing][Option parsing]] - [[#message-functions][Message functions]] - [[#text-functions][Text functions]] + - [[#portability-functions][Portability functions]] - [[#system-functions][System Functions]] + - [[#package-functions][Package Functions]] * Copying :PROPERTIES: @@ -890,11 +892,11 @@ Following functions are used to manipulate, check, or interact with text. given string. If the string is inside the list, it will return 0, otherwise 1. #+begin_src sh - # Usage - contains "$LIST" foo +# Usage +contains "$LIST" foo - contains "foo bar" foo # Returns 0 - contains "foo bar" baz # Returns 1 +contains "foo bar" foo # Returns 0 +contains "foo bar" baz # Returns 1 #+end_src *** =regesc()= @@ -906,7 +908,7 @@ given string. If the string is inside the list, it will return 0, otherwise 1. in POSIX BRE. Those characters are, =$=, =.=, =*=, =[=, =\\=, and =^=. #+begin_src sh - regesc '^[$\' # Returns \^\[\$\\ +regesc '^[$\' # Returns \^\[\$\\ #+end_src *** =pop()= @@ -918,13 +920,75 @@ in POSIX BRE. Those characters are, =$=, =.=, =*=, =[=, =\\=, and =^=. call. Word splitting is intentional when using this function. #+begin_src sh - # Usage - pop foo from $LIST +# Usage +pop foo from $LIST - pop foo from foo baz bar # Returns baz bar +pop foo from foo baz bar # Returns baz bar #+end_src -** System Functions +*** =sepchar()= +:PROPERTIES: +:DESCRIPTION: Separate characters from a string +:END: + +This function can be used to separate characters from the given string without +resorting to external resources. + +#+begin_src sh +sepchar mystring +# Prints: +# m +# y +# s +# t +# r +# i +# n +# g +#+end_src + +** Portability functions +:PROPERTIES: +:DESCRIPTION: Functions to replace non-POSIX commands +:END: + +These helper functions are used so that we don't depend on non-POSIX programs for +certain functionality. They are prefixed with the =_= character. + +*** =_seq()= +:PROPERTIES: +:DESCRIPTION: 'seq(1)' but no newline +:END: + +This function is similar to =seq(1)= except that it only takes a single argument +and doesn't print any newlines. It is suitable to be used in =for= loops. + +#+begin_src sh +_seq 5 +# Prints: +# 1 2 3 4 5 +#+end_src + +*** =_stat()= +:PROPERTIES: +:DESCRIPTION: 'stat %U' replacement +:END: + +This function imitates =stat %U=. =stat= isn't defined by POSIX, and this is +also a GNU extension. This function returns the owner of a file. If the owner +cannot be found, it will return =root=. + +*** =_readlinkf()= +:PROPERTIES: +:DESCRIPTION: 'readlink -f' replacement +:END: + +This function was taken from [[https://github.com/ko1nksm/readlinkf][POSIX sh readlinkf library by Koichi Nakashima]]. +=readlink= is also not defined by POSIX, so this function uses =ls= to follow +symbolic links until it reaches the actual file. + +** TODO System Functions +- [ ] Add description *** =as_root()= :PROPERTIES: :DESCRIPTION: Run a command as the root user @@ -935,6 +999,68 @@ environment variable is set, it will call the following arguments as the root user. It supports the following programs for privilege escalation with the following order: -1. =sudo= -2. =doas= -3. =su= +1. =sls= +2. =sudo= +3. =doas= +4. =su= + +** TODO Package Functions +:PROPERTIES: +:DESCRIPTION: Manipulate, or query anything related to packages +:END: + +Obviously, package functions are the most important ones for =cpt-lib=, those +are the ones you will use to build, to query, to manipulate, or to otherwise +interact with packages. + +*** =pkg_owner()= +:PROPERTIES: +:DESCRIPTION: Check which package owns the given file +:END: + +This function can be used to determine the owner of a package. The first +argument is used for flags that will be passed to =grep=, and the second one is +for the file query. Rest of the arguments can be used in order to specify the +manifests to be used, but it is optional. =pkg_owner()= will search for all the +installed packages if no other arguments are given. + +#+begin_src sh +# Example +pkg_owner -lFx /usr/bin/grep # Returns 'busybox' + +# An example call made by `pkg_fix_deps()` to figure out whether the built +# package contains the file it depends. +pkg_owner -l "/${dep#/}\$" "$PWD/manifest" >/dev/null && continue +pkg_owner -l "/${dep#/}\$" "$@" ||: +#+end_src + +*** =pkg_isbuilt()= +:PROPERTIES: +:DESCRIPTION: Check whether the given package is built +:END: + +This function returns with success when the given package has a built tarball +with the matching version and release strings from the repository. + +*** =pkg_lint()= +:PROPERTIES: +:DESCRIPTION: Check whether a package directory fits the standards +:END: + +This function checks whether a given package fits the proper package +specification. This function *does not return with failure, it exits outright* +if it fails. + +*** TODO =pkg_find()= +:PROPERTIES: +:DESCRIPTION: Query package locations +:END: + +=pkg_find()= + +*** TODO =pkg_gentree= +:PROPERTIES: +:DESCRIPTION: Generate a dependency tree for the given package +:END: + +Keep in mind /etc/cpt-base |