aboutsummaryrefslogtreecommitdiff
path: root/cpt.texi
blob: 3868330c560e6f903fd1a6c410768e40e4644740 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
@c TODO add extending the package manager
@node Package Manager
@chapter Package Manager

Carbs Linux uses its own package managing toolchain named @code{cpt}. It is a
fork of the @url{https://github.com/kisslinux/kiss, kiss} package manager. Unlike
@command{kiss}, however, its main goal is being easily extendable. Instead of being
a single file package manager, it revolves around the shell library @command{cpt-lib},
and many tools that wrap around it.


@node Usage
@section Usage
@command{cpt} is formed of many tools combined in a single environment, similar
to @command{git}. When you run @command{cpt} without any arguments, it will show
all available tools and their explanations. Here is an example call with extra
scripts on my system:

@example
-> Carbs Packaging Tool
-> add               Commit the current directory as a new package
-> alternatives      List and swap to alternatives
-> build             Build a package
-> bump              Commit the current directory as a version bump
-> cargo-urlgen      Create static cargo sources for Rust packages
-> cargolock-urlgen  Convert the given Cargo.lock file to sources
-> cat               Concatanate package files in the installed package database
-> changelog         Print the git log of the specific package
-> chbuild           Create/destroy temporary chroots
-> checkmissing      Verify package manifests
-> checksum          Generate checksums
-> chroot            Enter a chroot
-> commit            Commit a package without the prefix of 'package:'
-> depends           Display a package's dependencies
-> download          Download sources for the given package
-> exec              Execute a command inside the alternatives system
-> export            Turn an installed package into a CPT tarball
-> fetch             Fetch repositories
-> fork              Fork a package to the current directory
-> getchoice         Prints the full path to a file in the alternatives system.
-> install           Install a package
-> link              Link a forked package's files to the other repository
-> list              List installed packages
-> maintainer        Find the maintainer of a package
-> manifest          Display all files owned by a package
-> manifest-tree     Display all files owned by a package with a tree view
-> new               Create a boilerplate CPT package
-> orphans           List orphaned packages
-> owns              Check which package owns a file
-> rel               Bump the release number of a package
-> remove            Remove a package
-> repodepends       Display a package's dependencies in the repository
-> reporevdepends    Display packages on the repository which depend on package
-> reset             Remove all packages except for the base
-> revdepends        Display packages which depend on package
-> search            Search for a package
-> size              Show the size on disk for a package
-> source            Extract sources of a given package to the current directory
-> update            Check for updates
@end example

@node @command{cpt-alternatives}
@subsection @command{cpt-alternatives}

You can list and swap to alternatives using @command{cpt-alternatives}, or
@command{cpt a} for short. When run without alternatives, it will list
alternatives. It can read from standard input if @option{-} is given as an
argument.

@subsubsection Examples

List alternatives

@example
$ cpt-alternatives
ncurses /usr/bin/clear
ncurses /usr/bin/reset
@end example

Swap to @command{clear} from @command{ncurses}.

@example
$ cpt-alternatives ncurses /usr/bin/clear
-> Swapping '/usr/bin/clear' from 'busybox' to 'ncurses'
@end example

Swap in bulk (all of sbase).

@example
$ cpt a | grep ^sbase | cpt a -
@end example

@node @command{cpt-build}
@subsection @command{cpt-build}

cpt-build will build given packages and their dependencies. If multiple packages
are specified, it will ask to install the packages as well.

@subsubsection Options
@command{cpt-build} will accept the following options:

@itemize
@item
@option{-y}, @option{--no-prompt} -- Do not prompt for confirmation
@item
@option{}
@end itemize

@node Packaging System
@section Packaging System

A package is formed of several files, these are:
@itemize
@item
@file{build}
@item
@file{sources}
@item
@file{checksums}
@item
@file{version}
@item
@file{depends}
@item
@file{post-install}
@item
@file{message}
@item
@file{test}
@end itemize

Any other file can be added to the package directory at the discretion of the
package maintainer. Everything in the package directory will also be added to the
package database that is located on '/var/db/cpt/installed'. These can be
patches, configuration files, etc.

@subsection @file{build}

Typically @file{build} files are shell scripts that run commands to prepare the source
code to be installed on the target system. Even though we will be assuming that
the @file{build} file is a POSIX shell script (for portability's sake), @file{build}
files can be any executable program from binary programs to @command{perl} scripts.

The contents of a build script do not need to follow a certain rule for the
package manager, except for the fact that the user needs the permission to
execute the file.

An important advice is to append an '-e' to the shebang (#!/bin/sh -e) so that
the build script exits on compilation error.

Build is run with three arguments (@env{$#})

@enumerate
@item
Location of the package directory (DESTDIR)
@item
Package version
@item
System architecture
@end enumerate

@subsection @file{sources}

@file{sources} file is a list of files and sources that will be put to the build
directory during the build process. Those can be remote sources (such as tarballs),
git repositories, and files that reside on the package directory.

The syntax is pretty simple for the @file{soures} file; @verb{|src dest|}. The
@env{dest} parameter is optional. It is the directory that the source will be
placed in. Here is the @file{sources} file for the @command{gst-plugins} package:

@example
https://gstreamer.freedesktop.org/src/gst-plugins-good/gst-plugins-good-1.16.2.tar.xz good
https://gstreamer.freedesktop.org/src/gst-plugins-bad/gst-plugins-bad-1.16.2.tar.xz   bad
https://gstreamer.freedesktop.org/src/gst-plugins-ugly/gst-plugins-ugly-1.16.2.tar.xz ugly
https://gstreamer.freedesktop.org/src/gst-libav/gst-libav-1.16.2.tar.xz               libav
@end example

This file is read from the package manager as space seperated. Files that begin
with a '#' comment are ignored. The first value points to the location of the
source.

If it starts with a protcol url, (such as ftp:// http:// https://) it will be
downloaded with @command{curl}.

If the source is a git repository, it shall be prefixed with a @verb{|git+|} git(1) will
be used to do a shallow clone of the repository. If the commit is suffixed by a
history pointer, git will checkout the relevant revision. So,

@table @indicateurl
@item git+git://example.com/pub/repo#v1.2.3
will checkout the tag named 'v1.2.3'
@item git+git://example.com/pub/repo#development
will checkout the branch named 'development'
@item git+git://example.com/pub/repo#1a314s87
will checkout the commit named '1a314s87'
@end table

Other files are assumed to be residing in the package directory. They should be
added with their paths relative to the package directory.


@subsection @file{checksums}

checksums file is generated by the @file{cpt c pkg command}. It is generated
according to the order of the sources file. That's why you shouldn't be editing
it manually. The checksums file is created with the digests of the files using
the sha256 algorithm.

@subsection @file{version}

The version file includes the version of the software and the release number of
of the package on a space seperated format. The contents of the file should look
like below.

@example
1.3.2 1
@end example

The version should always match to the number of the upstream release. For
drastic changes that require a rebuild Those can be,

@itemize
@item
update of libraries that forces the package to be relinked
@item
change in the build scripts that affect the output of the package
@end itemize

When a version bump occurs, the release should be reset to 1.

@subsection @file{depends}

This is a list of dependencies that must be installed before a package build. You
can append ``make'' after a dependency to mark a package is only required during
the build process of a package. Packages marked as a make dependency can be
removed after the build. There are also ``test'' dependencies. These dependencies
are only installed if either the @env{CPT_TEST} is set to 1, or the build is run
with the @option{-t} or @option{--test} options. So, a package package could have
the following @file{depends} file:

@example
linux-headers make
python        test
zlib
@end example

@subsection @file{post-install}

@file{post-install} files have the same requirements as the build script. They
will be run after the package is installed as root (or as the user if the user
has write permissions on @env{CPT_ROOT}).

@subsection @file{message}

This plaintext file will be outputted with @command{cat} after every package is
installed.

@subsection @file{test}

Test files are mainly for the repository maintainer to test the packages, and
will only run if the user has the @env{CPT_TEST} variable set, or the build is
run with the @option{-t} or @option{--test} options. This script is run on the
build directory. It is run right after the build script is finished.

@node Rsync Repositories
@section Rsync Repositories

Rsync repositories are simple to serve and simple to use. In the repository
directory, there needs to be a '.rsync' file that points to the remote of the
repository. This is used in order to fetch changes from the upstream. '.rsync'
file looks like this for the core repository:

@example
rsync://carbslinux.org/repo/core
@end example

Rsync repositories have some few distinctions when it comes to fetching them.
They can be either synced individually or as a ``root''. There are 2 important
files, those are @file{.rsync} and @file{.rsync_root}. Here is the Carbs Linux
rsync repository structure.

@example
           /
   -----------------
  |                |
.rsync           core/
          ----------------
          |              |
        .rsync      .rsync_root
@end example

Unlike git repositories, they don't have a defined ``root'' directory. This is
both an advantage and a disadvantage. This way, we can sync individual
repositories, but that also means we need extra files to define root directories
and repository locations. Here is the content for each of these files:

@example
/.rsync:           rsync://carbslinux.org/repo
/core/.rsync:      rsync://carbslinux.org/repo/core
/core/.rsync_root: ..
@end example

The @file{.rsync_root} file on the core repository points to the upper directory.
If a @file{.rsync} file exists on the upper directory, this means that is the whole
repository and will sync the entire repository instead of each individual repository.

If the upper directory doesn't have this @file{.rsync} file, this means that this
is an individual repository, and the package manager will fetch accordingly.

@node Setting up an rsync repository for distribution
@subsection Setting up an rsync repository for distribution

Carbs Linux repositories automatically sync from the git repostitories and serve
it through the rsync daemon. Here is a sample shell script that I use in order to
sync repositories. Feel free to customize for your own use.

@verbatim
    #!/bin/sh
    HOSTNAME="rsync://carbslinux.org/repo"
    GITDIR="/pub/git/repo"
    SHAREDIR="/pub/share/repo"
    git -C "$GITDIR" pull

    rsync -avcC --delete --include=core --exclude=.rsync,.rsync_root "$GITDIR/." "$SHAREDIR"

    printf '%s\n' "$HOSTNAME" > "$GITDIR/.rsync"
    for dir in "$GITDIR/"*; do
        [ -d "$dir" ] || continue
        [ -f "$dir/.rsync" ] ||
        printf '%s/%s\n' "$HOSTNAME" "${dir##*/}" > "$dir/.rsync"
        printf '..\n' > "$dir/.rsync_root"
    done
@end verbatim

You can then create an @strong{rsync} user for serving the repositories.

@example
$ adduser -SD rsync
@end example

Create @file{/etc/rsyncd.conf} and a service configuration as well.

@verbatim

    uid = rsync
    gid = rsync
    address = example.com
    max connections = 10
    use chroot = yes

    [repo]
        path = /pub/share/repo
        comment = My repository
@end verbatim

Create a service file at @file{/etc/sv/rsync/run} (runit):

@example
#!/bin/sh
exec rsync --daemon --no-detach
@end example