qi-content.texi 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. @c -*-texinfo-*-
  2. @c qi-content.texi
  3. @c This is part of the Qi user guide.
  4. @c Copyright (C) 2019-2022 Matias Fonzo, <selk@dragora.org>.
  5. @c See the file qi-header.texi for copying conditions.
  6. @c
  7. @c If something is modified here, be aware of the increase of VERSION in
  8. @c qi-header.texi, this will produce the result of the manual: qi.info
  9. @node Introduction to Qi
  10. @chapter Introduction to Qi
  11. @cindex introduction to qi
  12. Qi is a simple but well-integrated package manager. It can create,
  13. install, remove, and upgrade software packages. Qi produces binary
  14. packages using recipes, which are files containing specific instructions
  15. to build each package from source. Qi can manage multiple packages
  16. under a single directory hierarchy. This method allows to maintain a set
  17. of packages and multiple versions of them. This means that Qi could be
  18. used as the main package manager or complement the existing one.
  19. Qi offers a friendly command line interface, a global configuration
  20. file, a simple recipe layout to deploy software packages; also works
  21. with binary packages in parallel, speeding up installations and packages
  22. in production. The format used for packages is a simplified and safer
  23. variant of POSIX pax archive compressed in lzip format.
  24. Qi is a modern (POSIX-compliant) shell script released under the
  25. terms of the GNU General Public License. There are only two major
  26. dependencies for the magic: graft(1) and tarlz(1), the rest is expected
  27. to be found in any Unix-like system.
  28. @node Invoking qi
  29. @chapter Invoking qi
  30. @cindex invocation
  31. This chapter describes the synopsis for invoking Qi.
  32. @example
  33. Usage: qi COMMAND [@var{OPTION}...] [@var{FILE}]...
  34. @end example
  35. @noindent
  36. One mandatory command specifies the operation that @samp{qi} should
  37. perform, options are meant to detail how this operation should be
  38. performed during or after the process.
  39. @noindent
  40. Qi supports the following commands:
  41. @table @code
  42. @item warn
  43. Warn about files that will be installed.
  44. @item install
  45. Install packages.
  46. @item remove
  47. Remove packages.
  48. @item upgrade
  49. Upgrade packages.
  50. @item extract
  51. Extract packages for debugging purposes.
  52. @item create
  53. Create a .tlz package from directory.
  54. @item build
  55. Build packages using recipe names.
  56. @item order
  57. Resolve build order through .order files
  58. @end table
  59. @noindent
  60. Options when installing, removing, or upgrading software packages:
  61. @table @code
  62. @item -f
  63. @itemx --force
  64. Force upgrade of pre-existing packages.
  65. @item -k
  66. @itemx --keep
  67. Keep directories when build/remove/upgrade.
  68. Keep (don't delete) the package directory when using remove/upgrade command.
  69. This will also try to preserve the directories @samp{$@{srcdir@}} and
  70. @samp{$@{destdir@}} when using build command. Its effect is available in
  71. recipes as @samp{$@{keep_srcdir@}} and @samp{$@{keep_destdir@}}. See
  72. @ref{Recipes, Special variables} for details.
  73. @item -p
  74. @itemx --prune
  75. Prune conflicts.
  76. @item -P
  77. @itemx --packagedir=<dir>
  78. Set directory for package installations.
  79. @item -t
  80. @itemx --targetdir=<dir>
  81. Set target directory for symbolic links.
  82. @item -r
  83. @itemx --rootdir=<dir>
  84. Use the fully qualified named directory as the root directory for all qi
  85. operations.
  86. Note: the target directory and the package directory will be
  87. relative to the specified directory, excepting the graft log file.
  88. @end table
  89. @noindent
  90. Options when building software packages using recipes:
  91. @table @code
  92. @item -a
  93. @itemx --architecture
  94. Set architecture name for the package.
  95. @item -j
  96. @itemx --jobs
  97. Parallel jobs for the compiler.
  98. This option sets the variable @samp{$@{jobs@}}. If not specified, default
  99. sets to 1.
  100. @item -S
  101. @itemx --skip-questions
  102. Skip questions on completed recipes.
  103. @item -1
  104. @itemx --increment
  105. Increment release number (@samp{$@{release@}} + 1).
  106. The effect of this option will be omitted if --no-package is being used.
  107. @item -n
  108. @itemx --no-package
  109. Do not create a .tlz package.
  110. @item -i
  111. @itemx --install
  112. Install package after the build.
  113. @item -u
  114. @itemx --upgrade
  115. Upgrade package after the build.
  116. @item -o
  117. @itemx --outdir=<dir>
  118. Where the packages produced will be written.
  119. This option sets the variable @samp{$@{outdir@}}.
  120. @item -w
  121. @itemx --worktree=<dir>
  122. Where archives, patches, recipes are expected.
  123. This option sets the variable @samp{$@{worktree@}}.
  124. @item -s
  125. @itemx --sourcedir=<dir>
  126. Where compressed sources will be found.
  127. This option sets the variable @samp{$@{tardir@}}.
  128. @end table
  129. @noindent
  130. Other options:
  131. @table @code
  132. @item -v
  133. @itemx --verbose
  134. Be verbose (an extra -v gives more).
  135. It sets the verbosity level, default sets to 0.
  136. The value 1 is used for more verbosity while the value 2 is too detailed.
  137. Although at the moment it is limited to graft(1) verbosity.
  138. @item -N
  139. @itemx --no-rc
  140. Do not read the configuration file.
  141. This will ignore reading the qirc file.
  142. @item -L
  143. @itemx --show-location
  144. Print default directory locations and exit.
  145. This will print the target directory, package directory, working tree,
  146. the directory for sources, and the output directory for the packages
  147. produced.
  148. @item -h
  149. @itemx --help
  150. Display the usage and exit.
  151. @item -V
  152. @itemx --version
  153. This will print the (short) version information and then exit.
  154. The same can be achieved if Qi is invoked as @samp{qi version}.
  155. @end table
  156. When FILE is -, qi can read from the standard input. See examples from
  157. the @ref{Packages} section.
  158. Exit status: 0 for a normal exit, 1 for minor common errors (help usage,
  159. support not available, etc), 2 to indicate a command execution error;
  160. 3 for integrity check error on compressed files, 4 for empty, not
  161. regular, or expected files, 5 for empty or not defined variables,
  162. 6 when a package already exist, 10 for network manager errors.
  163. For more details, see the @ref{Qi exit status} section.
  164. @node The qirc file
  165. @chapter The qirc file
  166. @cindex configuration file
  167. The global @file{qirc} file offers a way to define variables and tools
  168. (such as a download manager) for default use. This file is used by qi
  169. at runtime, e.g., to build, install, remove or upgrade packages.
  170. Variables and their possible values must be declared as any other
  171. variable in the shell.
  172. @noindent
  173. The command line options related to the package directory and target
  174. directory and some of the command line options used for the build command,
  175. have the power to override the values declared on @file{qirc}.
  176. See @ref{Invoking qi}.
  177. @noindent
  178. The order in which qi looks for this file is:
  179. @enumerate
  180. @item
  181. @env{$@{HOME@}/.qirc}
  182. @- Effective user.
  183. @item
  184. @samp{$@{sysconfdir@}/qirc}
  185. @- System-wide.
  186. @end enumerate
  187. If you intend to run qi as effective user, the file
  188. @samp{$@{sysconfdir@}/qirc} could be copied to @env{$@{HOME@}/.qirc}
  189. setting the paths for @samp{$@{packagedir@}} and @samp{$@{targetdir@}}
  190. according to the @env{$HOME}.
  191. @node Packages
  192. @chapter Packages
  193. @cindex managing packages
  194. A package is a suite of programs usually distributed in binary form
  195. which may also contain manual pages, documentation, or any other file
  196. associated to a specific software.
  197. The package format used by qi is a simplified POSIX pax archive
  198. compressed using lzip@footnote{For more details about tarlz and the
  199. lzip format, visit @url{https://lzip.nongnu.org/tarlz.html}.}. The
  200. file extension for packages ends in @samp{.tlz}.
  201. @noindent
  202. Both package installation and package de-installation are managed using
  203. two important (internal) variables: @samp{$@{packagedir@}} and
  204. @samp{$@{targetdir@}}, these values can be changed in the
  205. configuration file or via options.
  206. @samp{$@{packagedir@}} is a common directory tree where the package
  207. contents will be decompressed (will reside).
  208. @samp{$@{targetdir@}} is a target directory where the links will be
  209. made by graft(1) taking @samp{$@{packagedir@}/package_name} into account.
  210. @noindent
  211. Packages are installed in self-contained directory trees and symbolic
  212. links from a common area are made to the package files. This allows
  213. multiple versions of the same package to coexist on the same system.
  214. @section Package conflicts
  215. @cindex package conflicts
  216. All the links to install or remove a package are handled by graft(1).
  217. Since multiple packages can be installed or removed at the same time,
  218. certain conflicts may arise between the packages.
  219. @noindent
  220. graft@footnote{The official guide for Graft can be found at
  221. @url{https://peters.gormand.com.au/Home/tools/graft/graft.html}.}
  222. defines a CONFLICT as one of the following conditions:
  223. @itemize @bullet
  224. @item
  225. If the package object is a directory and the target object exists but is
  226. not a directory.
  227. @item
  228. If the package object is not a directory and the target object exists
  229. and is not a symbolic link.
  230. @item
  231. If the package object is not a directory and the target object exists
  232. and is a symbolic link to something other than the package object.
  233. @end itemize
  234. @noindent
  235. The default behavior of qi for an incoming package is to ABORT if a
  236. conflict arises. When a package is going to be deleted, qi tells to
  237. graft(1) to remove those parts that are not in conflict, leaving the
  238. links to the belonging package. This behavior can be forced if the
  239. --prune option is given.
  240. @section Installing packages
  241. @cindex package installation
  242. To install a single package, simply type:
  243. @example
  244. qi install coreutils_8.30_i586-1@@tools.tlz
  245. @end example
  246. @noindent
  247. To install multiple packages at once, type:
  248. @example
  249. qi install gcc_8.3.0_i586-1@@devel.tlz rafaela_2.2_i586-1@@legacy.tlz ...
  250. @end example
  251. @noindent
  252. Warn about the files that will be linked:
  253. @example
  254. qi warn bash_5.0_i586-1@@shells.tlz
  255. @end example
  256. This is to verify the content of a package before installing it.
  257. @noindent
  258. See the process of an installation:
  259. @example
  260. qi install --verbose mariana_3.0_i586-1@@woman.tlz
  261. @end example
  262. A second --verbose or -v option gives more (very verbose).
  263. @noindent
  264. Installing package in a different location:
  265. @example
  266. qi install --rootdir=/media/floppy lzip_1.21_i586-1@@compressors.tlz
  267. @end example
  268. Important: the --rootdir option assumes @samp{$@{targetdir@}} and
  269. @samp{$@{packagedir@}}. See the following example:
  270. @example
  271. qi install --rootdir=/home/selk lzip_1.21_i586-1@@compressors.tlz
  272. @end example
  273. The content of "lzip_1.21_i586-1@@compressors.tlz" will be decompressed
  274. into @samp{/home/selk/pkgs/lzip_1.21_i586-1@@compressors}.
  275. Assuming that the main binary for lzip is under
  276. @samp{/home/selk/pkgs/lzip_1.21_i586-1@@compressors/usr/bin/}
  277. the target for "usr/bin" will be created at @samp{/home/selk}. Considering
  278. that you have exported the @env{PATH} as @samp{$@{HOME@}/usr/bin}, now the
  279. system is able to see the recent lzip command.
  280. @noindent
  281. Installing from a list of packages using standard input:
  282. @example
  283. qi install - < PACKAGELIST.txt
  284. @end example
  285. Or in combination with another tool:
  286. @example
  287. sort -u PACKAGELIST.txt | qi install -
  288. @end example
  289. The sort command will read and sorts the list of declared packages,
  290. while trying to have unique entries for each statement. The output
  291. produced is captured by Qi to install each package.
  292. An example of a list containing package names is:
  293. @example
  294. /var/cache/qi/packages/amd64/tcl_8.6.9_amd64-1@@devel.tlz
  295. /var/cache/qi/packages/amd64/tk_8.6.9.1_amd64-1@@devel.tlz
  296. /var/cache/qi/packages/amd64/vala_0.42.3_amd64-1@@devel.tlz
  297. @end example
  298. @section Removing packages
  299. @cindex package de-installation
  300. To remove a package, simply type:
  301. @example
  302. qi remove xz_5.2.4_i586-1@@compressors.tlz
  303. @end example
  304. @noindent
  305. Remove command will match the package name using @samp{$@{packagedir@}} as
  306. prefix. For example, if the value of @samp{$@{packagedir@}} has been
  307. set to /usr/pkg, this will be equal to:
  308. @example
  309. qi remove /usr/pkg/xz_5.2.4_i586-1@@compressors
  310. @end example
  311. @noindent
  312. Detailed output:
  313. @example
  314. qi remove --verbose /usr/pkg/xz_5.2.4_i586-1@@compressors
  315. @end example
  316. A second --verbose or -v option gives more (very verbose).
  317. @noindent
  318. By default the remove command does not preserve a package directory after
  319. removing its links from @samp{$@{targetdir@}}, but this behavior can be
  320. changed if the --keep option is passed:
  321. @example
  322. qi remove --keep /usr/pkg/lzip_1.21_i586-1@@compressors
  323. @end example
  324. This means that the links to the package can be reactivated, later:
  325. @example
  326. cd /usr/pkg && graft -i lzip_1.21_i586-1@@compressors
  327. @end example
  328. @noindent
  329. Removing package from a different location:
  330. @example
  331. qi remove --rootdir=/home/cthulhu xz_5.2.4_i586-1@@compressors
  332. @end example
  333. @noindent
  334. Removing a package using standard input:
  335. @example
  336. echo vala_0.42.3_amd64-1@@devel | qi remove -
  337. @end example
  338. This will match with the package directory.
  339. @section Upgrading packages
  340. @cindex package upgrade
  341. The upgrade command inherits the properties of the installation and removal
  342. process. To make sure that a package is updated, the package is installed
  343. in a temporary directory taking @samp{$@{packagedir@}} into account. Once
  344. the incoming package is pre-installed, qi can proceed to search and delete
  345. packages that have the same name (considered as previous ones). Finally,
  346. the package is re-installed at its final location and the temporary
  347. directory is removed.
  348. Since updating a package can be crucial and so to perform a successful
  349. upgrade, from start to finish, you will want to ignore some important
  350. system signals during the upgrade process, those signals are SIGHUP,
  351. SIGINT, SIGQUIT, SIGABRT, and SIGTERM.
  352. @noindent
  353. To upgrade a package, just type:
  354. @example
  355. qi upgrade gcc_9.0.1_i586-1@@devel.tlz
  356. @end example
  357. This will proceed to upgrade "gcc_9.0.1_i586-1@@devel" removing any other
  358. version of "gcc" (if any).
  359. @noindent
  360. If you want to keep the package directories of versions found during the
  361. upgrade process, just pass:
  362. @example
  363. qi upgrade --keep gcc_9.0.1_i586-1@@devel.tlz
  364. @end example
  365. @noindent
  366. To see the upgrade process:
  367. @example
  368. qi upgrade --verbose gcc_9.0.1_i586-1@@devel.tlz
  369. @end example
  370. A second --verbose or -v option gives more (very verbose).
  371. @noindent
  372. To force the upgrade of an existing package:
  373. @example
  374. qi upgrade --force gcc_9.0.1_i586-1@@devel.tlz
  375. @end example
  376. @subsection Package blacklist
  377. @cindex package blacklist
  378. To implement general package facilities, either to install, remove or
  379. maintain the hierarchy of packages in a clean manner, qi makes use of the
  380. pruning operation via graft(1) by default:
  381. There is a risk if those are crucial packages for the proper functioning
  382. of the system, because it implies the deactivation of symbolic from the
  383. target directory, @emph{especially} when transitioning an incoming package
  384. into its final location during an upgrade.
  385. @noindent
  386. A blacklist of package names has been devised for the case where
  387. a user decides to upgrade all the packages in the system, or
  388. just the crucial ones, such as the C library.
  389. The blacklist is related to the upgrade command only, consists in installing
  390. a package instead of updating it or removing previous versions of it;
  391. the content of the package will be updated over the existing content at
  392. @samp{$@{packagedir@}}, while the existing links from
  393. @samp{$@{targetdir@}} will be preserved. A pruning of links will be
  394. carried out in order to re-link possible differences with the recent
  395. content, this helps to avoid leaving dead links in the target directory.
  396. @noindent
  397. Package names for the blacklist to be declared must be set from the
  398. configuration file. By default, it is declared using the package name,
  399. which is more than enough for critical system packages, but if you want to
  400. be more specific, you can declare a package using:
  401. @samp{$@{pkgname@}_$@{pkgversion@}_$@{arch@}-$@{release@}} where
  402. the package category is avoided for common matching. See
  403. @ref{Recipes, Special variables} for a description of these variables.
  404. @node Recipes
  405. @chapter Recipes
  406. @cindex recipes
  407. A recipe is a file telling qi what to do. Most often, the recipe tells
  408. qi how to build a binary package from a source tarball.
  409. A recipe has two parts: a list of variable definitions and a list of
  410. sections. By convention, the syntax of a section is:
  411. @example
  412. section_name()
  413. @{
  414. section lines
  415. @}
  416. @end example
  417. The section name is followed by parentheses, one newline and an opening
  418. brace. The line finishing the section contains just a closing brace.
  419. The section names or the function names currently recognized are
  420. @samp{build}.
  421. The @samp{build} section (or @strong{shell function}) is an augmented
  422. shell script that contains the main instructions to build software
  423. from source.
  424. If there are other functions defined by the packager, Qi detects them
  425. for later execution.
  426. @section Variables
  427. @cindex variables
  428. A "variable" is a @strong{shell variable} defined either in @file{qirc}
  429. or in a recipe to represent a string of text, called the variable's
  430. "value". These values are substituted by explicit request in the
  431. definitions of other variables or in calls to external commands.
  432. Variables can represent lists of file names, options to pass to
  433. compilers, programs to run, directories to look in for source files,
  434. directories to write output to, or anything else you can imagine.
  435. Definitions of variables in qi have four levels of precedence.
  436. Options which define variables from the command-line override those
  437. specified in the @file{qirc} file, while variables defined in the recipe
  438. override those specified in @file{qirc}, taking priority over those
  439. variables set by command-line options. Finally, the variables have
  440. default values if they are not defined anywhere.
  441. Options that set variables through the command-line can only reference
  442. variables defined in @file{qirc} and variables with default values.
  443. Definitions of variables in @file{qirc} can only reference variables
  444. previously defined in @file{qirc} and variables with default values.
  445. Definitions of variables in the recipe can only reference variables
  446. set by the command-line, variables previously defined in the recipe,
  447. variables defined in @file{qirc}, and variables with default values.
  448. @section Special variables
  449. @cindex special variables
  450. There are variables which can only be set using the command line options or
  451. via @file{qirc}, there are other special variables which can be defined or
  452. redefined in a recipe. See the following definitions:
  453. @samp{outdir} is the directory where the packages produced are written.
  454. This variable can be redefined per-recipe. Default sets to
  455. @samp{/var/cache/qi/packages}.
  456. @samp{worktree} is the working tree where archives, patches, and recipes
  457. are expected. This variable can not be redefined in the recipe. Default
  458. sets to @samp{/usr/src/qi}.
  459. @samp{tardir} is defined in the recipe to the directory where the tarball
  460. containing the source can be found. The full name of the tarball is
  461. composed as @samp{$@{tardir@}/$tarname}. Its value is available in the
  462. recipe as @samp{$@{tardir@}}; a value of . for @samp{tardir} sets it to
  463. the value of CWD (Current Working Directory), this is where the recipe
  464. lives.
  465. @samp{arch} is the architecture to compose the package name. Its value is
  466. available in the recipe as @samp{$@{arch@}}. Default value is the one
  467. that was set in the Qi configuration.
  468. @samp{jobs} is the number of parallel jobs to pass to the compiler. Its
  469. value is available in the recipe as @samp{$@{jobs@}}. The default value
  470. is 1.
  471. The two variables @samp{$@{srcdir@}} and @samp{$@{destdir@}} can be
  472. set in the recipe, as any other variable, but if they are not, qi uses
  473. default values for them when building a package.
  474. @samp{srcdir} contains the source code to be compiled, and defaults to
  475. @samp{$@{program@}-$@{version@}}. @samp{destdir} is the place where the
  476. built package will be installed, and defaults to
  477. @samp{$@{TMPDIR@}/package-$@{program@}}.
  478. If @samp{pkgname} is left undefined, the special variable @samp{program}
  479. is assigned by default. If @samp{pkgversion} is left undefined, the
  480. special variable @samp{version} is assigned by default.
  481. @samp{pkgname} and @samp{pkgversion} along with: @samp{version}, @samp{arch},
  482. @samp{release}, and (optionally) @samp{pkgcategory} are used to produce the
  483. package name in the form:
  484. @samp{$@{pkgname@}_$@{pkgversion@}_$@{arch@}-$@{release@}[@@$@{pkgcategory@}].tlz}
  485. @samp{pkgcategory} is an optional special variable that can be defined on the
  486. recipe to categorize the package name. If it is defined, then the
  487. package output will be composed as
  488. @samp{$@{pkgname@}_$@{pkgversion@}_$@{arch@}-$@{release@}[@@$@{pkgcategory@}.tlz}.
  489. Automatically, the value of @samp{pkgcategory} will be prefixed using the
  490. @samp{@@} (at) symbol which will be added to the last part of the package name.
  491. A special variable called @samp{replace} can be used to declare package names
  492. that will be replaced at installation time.
  493. The special variables @samp{keep_srcdir} and @samp{keep_destdir} are provided
  494. in order to preserve the directories @samp{$@{srcdir@}} or @samp{$@{destdir@}},
  495. if those exists as such. Note: The declaration of these variables are subject
  496. to manual deactivation; its purpose in recipes is to preserve the directories
  497. that relate to the package's build (source) and destination directory, that is
  498. so that another recipe can get a new package (or meta package) from there. For
  499. example, the declarations can be done as:
  500. @example
  501. keep_srcdir=keep_srcdir
  502. keep_destdir=keep_destdir
  503. @end example
  504. Then from another recipe you would proceed to copy the necessary files that
  505. will compose the meta package, from the main function you must deactivate
  506. the variables at the end:
  507. @example
  508. unset -v keep_srcdir keep_destdir
  509. @end example
  510. This will leave the 'keep_srcdir' and 'keep_destdir' variables blank to
  511. continue with the rest of the recipes.
  512. The variable @samp{tarlz_compression_options} can be used to change the
  513. default compression options in tarlz(1), default sets to @samp{-9 --solid}.
  514. For example if the variable is declared as:
  515. @example
  516. tarlz_compression_options="-0 --bsolid"
  517. @end example
  518. It will change the granularity of tarlz(1) by using the @samp{--bsolid}
  519. option @footnote{About the @samp{--bsolid} granularity option of tarlz(1),
  520. @url{https://www.nongnu.org/lzip/manual/tarlz_manual.html#g_t_002d_002dbsolid}.},
  521. as well as increasing the compression speed by lowering the compression
  522. level with @samp{-0}.
  523. This is only recommended for recipes where testing, or faster processing is
  524. desired to create the packaged file more quickly. It is not recommended for
  525. production or general distribution of binary packages.
  526. @noindent
  527. A typical recipe contains the following variables:
  528. @itemize @bullet
  529. @item @samp{program}: Software name.
  530. It matches the source name. It is also used to compose the name of the
  531. package if @samp{$@{pkgname@}} is not specified.
  532. @item @samp{version}: Software version.
  533. It matches the source name. It is also used to compose the version of the
  534. package if @samp{$@{pkgversion@}} is not specified.
  535. @item @samp{arch}: Software architecture.
  536. It is used to compose the architecture of the package in which it is
  537. build.
  538. @item @samp{release}: Release number.
  539. This is used to reflect the release number of the package. It is
  540. recommended to increase this number after any significant change in
  541. the recipe or post-install script.
  542. @item @samp{pkgcategory}: Package category.
  543. Optional but recommended variable to categorize the package name when it is
  544. created.
  545. @end itemize
  546. @noindent
  547. Obtaining sources over the network must be declared in the recipe using
  548. the @samp{fetch} variable.
  549. The variables @samp{netget} and @samp{rsync} can be defined in @file{qirc}
  550. to establish a network downloader in order to get the sources. If they
  551. are not defined, qi uses default values:
  552. @samp{netget} is the general network downloader tool, defaults sets to
  553. @samp{wget2 -c -w1 -t3 --no-check-certificate}.
  554. @samp{rsync} is the network tool for sources containing the prefix for
  555. the RSYNC protocol, default sets to
  556. @samp{rsync -v -a -L -z -i --progress}.
  557. The variable @samp{description} is used to print the package description
  558. when a package is installed.
  559. A description has two parts: a brief description, and a long description.
  560. By convention, the syntax of @samp{description} is:
  561. @example
  562. description="
  563. Brief description.
  564. Long description.
  565. "
  566. @end example
  567. The first line of the value represented is a brief description of the
  568. software (called "blurb"). A blank line separates the @emph{brief
  569. description} from the @emph{long description}, which should contain a more
  570. descriptive description of the software.
  571. @noindent
  572. An example looks like:
  573. @example
  574. description="
  575. The GNU core utilities.
  576. The GNU core utilities are the basic file, shell and text manipulation
  577. utilities of the GNU operating system. These are the core utilities
  578. which are expected to exist on every operating system.
  579. "
  580. @end example
  581. Please consider a length limit of 78 characters as maximum, because the same
  582. one would be used on the meta file creation. See
  583. @ref{Recipes, The meta file} section.
  584. The @samp{homepage} variable is used to declare the main site or home page:
  585. @example
  586. homepage=https://www.gnu.org/software/gcc
  587. @end example
  588. The variable @samp{license} is used for license information@footnote{
  589. The proposal for @samp{license} was made by Richard M. Stallman at
  590. @url{https://lists.gnu.org/archive/html/gnu-linux-libre/2016-05/msg00003.html}.}.
  591. Some code in the program can be covered by license A, license B, or
  592. license C. For "separate licensing" or "heterogeneous licensing", we
  593. suggest using @strong{|} for a disjunction, @strong{&} for a conjunction
  594. (if that ever happens in a significant way), and comma for heterogeneous
  595. licensing. Comma would have lower precedence, plus added special terms.
  596. @example
  597. license="LGPL, GPL | Artistic - added permission"
  598. @end example
  599. @section Writing recipes
  600. @cindex writing recipes
  601. Originally, Qi was designed for the series of Dragora GNU/Linux-Libre 3;
  602. this doesn't mean you can't use it in another distribution, just that if
  603. you do, you'll have to try it out for yourself. To help with this, here
  604. are some references to well-written recipes:
  605. @itemize @bullet
  606. @item @url{https://git.savannah.nongnu.org/cgit/dragora.git/tree/recipes}
  607. @item @url{https://notabug.org/dragora/dragora/src/master/recipes}
  608. @item @url{https://notabug.org/dragora/dragora-extras/src/master/recipes}
  609. @item @url{https://git.savannah.nongnu.org/cgit/dragora/dragora-extras.git/tree/recipes}
  610. @end itemize
  611. @section Building packages
  612. @cindex package build
  613. A recipe is any valid regular file. Qi sets priorities for reading a
  614. recipe, the order in which qi looks for a recipe is:
  615. @enumerate
  616. @item
  617. Current working directory.
  618. @item
  619. If the specified path name does not contain "recipe" as the last
  620. component. Qi will complete it by adding "recipe" to the path name.
  621. @item
  622. If the recipe is not in the current working directory, it will be
  623. searched under @samp{$@{worktree@}/recipes}. The last component will be
  624. completed adding "recipe" to the specified path name.
  625. @end enumerate
  626. @noindent
  627. To build a single package, type:
  628. @example
  629. qi build x-apps/xterm
  630. @end example
  631. @noindent
  632. Multiple jobs can be passed to the compiler to speed up the build process:
  633. @example
  634. qi build --jobs 3 x-apps/xterm
  635. @end example
  636. @noindent
  637. Update or install the produced package (if not already installed) when the
  638. build command ends:
  639. @example
  640. qi build -j3 --upgrade x-apps/xterm
  641. @end example
  642. @noindent
  643. Only process a recipe but do not create the binary package:
  644. @example
  645. qi build --no-package dict/aspell
  646. @end example
  647. The options --install or --upgrade have no effect when --no-package
  648. is given.
  649. @noindent
  650. This is useful to inspect the build process of the above recipe:
  651. qi build --keep --no-package dict/aspell 2>&1 | tee aspell-log.txt
  652. The --keep option could preserve the source directory and the destination
  653. directory for later inspection. A log file of the build process will be
  654. created redirecting both, standard error and standard output to tee(1).
  655. @section Variables from the environment
  656. @cindex environment variables
  657. Qi has environment variables which can be used at build time:
  658. The variable @env{TMPDIR} sets the temporary directory for sources, which is
  659. used for package extractions (see @ref{Examining packages}) and is
  660. prepended to the value of @samp{$@{srcdir@}} and @samp{$@{destdir@}} in
  661. build command. By convention its default value is equal to
  662. @samp{/usr/src/qi/build}.
  663. The variables @env{QICFLAGS}, @env{QICXXFLAGS}, @env{QILDFLAGS}, and
  664. @env{QICPPFLAGS} have no effect by default. The environment variables
  665. such as @env{CFLAGS}, @env{CXXFLAGS}, @env{LDFLAGS}, and @env{CPPFLAGS}
  666. are unset at compile time:
  667. @noindent
  668. Recommended practice is to set variables in the command line of
  669. @samp{configure} or @emph{make(1)} instead of exporting to the
  670. environment. As follows:
  671. @url{https://www.gnu.org/software/make/manual/html_node/Environment.html}
  672. @quotation
  673. It is not wise for makefiles to depend for their functioning on environment
  674. variables set up outside their control, since this would cause different
  675. users to get different results from the same makefile. This is against the
  676. whole purpose of most makefiles.
  677. @end quotation
  678. Setting environment variables for configure is deprecated because running
  679. configure in varying environments can be dangerous.
  680. @url{https://gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Defining-Variables.html}
  681. @quotation
  682. Variables not defined in a site shell script can be set in the environment
  683. passed to configure. However, some packages may run configure again
  684. during the build, and the customized values of these variables may be
  685. lost. In order to avoid this problem, you should set them in the
  686. configure command line, using @samp{VAR=value}. For example:
  687. @code{./configure CC=/usr/local2/bin/gcc}
  688. @end quotation
  689. @url{https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Setting-Output-Variables.html}
  690. @quotation
  691. If for instance the user runs @samp{CC=bizarre-cc ./configure}, then the cache,
  692. config.h, and many other output files depend upon bizarre-cc being the C
  693. compiler. If for some reason the user runs ./configure again, or if it is
  694. run via @samp{./config.status --recheck}, (See Automatic Remaking, and see
  695. config.status Invocation), then the configuration can be inconsistent,
  696. composed of results depending upon two different compilers.
  697. [...]
  698. Indeed, while configure can notice the definition of CC in @samp{./configure
  699. CC=bizarre-cc}, it is impossible to notice it in @samp{CC=bizarre-cc
  700. ./configure}, which, unfortunately, is what most users do.
  701. [...]
  702. configure: error: changes in the environment can compromise the build.
  703. @end quotation
  704. If the @env{SOURCE_DATE_EPOCH} environment variable is set to a UNIX timestamp
  705. (defined as the number of seconds, excluding leap seconds, since 01 Jan 1970
  706. 00:00:00 UTC.); then the given timestamp will be used to overwrite any newer
  707. timestamps on the package contents (when it is created). More information
  708. about this can be found at
  709. @uref{https://reproducible-builds.org/specs/source-date-epoch/}.
  710. @section The meta file
  711. @cindex the meta file
  712. The "meta file" is a regular file created during the build process, it
  713. contains information about the package such as package name, package
  714. version, architecture, release, fetch address, description, and other
  715. minor data extracted from processed recipes. The name of the file is
  716. generated as @samp{$@{full_pkgname@}.tlz.txt}, and its purpose is to
  717. reflect essential information to the user without having to look inside
  718. the package content. The file format is also intended to be used by
  719. other scripts or by common Unix tools.
  720. The content of a meta file looks like:
  721. @example
  722. #
  723. # Pattern scanning and processing language.
  724. #
  725. # The awk utility interprets a special-purpose programming language
  726. # that makes it possible to handle simple data-reformatting jobs
  727. # with just a few lines of code. It is a free version of 'awk'.
  728. #
  729. # GNU awk implements the AWK utility which is part of
  730. # IEEE Std 1003.1 Shell and Utilities (XCU).
  731. #
  732. QICFLAGS="-O2"
  733. QICXXFLAGS="-O2"
  734. QILDFLAGS=""
  735. QICPPFLAGS=""
  736. pkgname=gawk
  737. pkgversion=5.0.1
  738. arch=amd64
  739. release=1
  740. pkgcategory="tools"
  741. full_pkgname=gawk_5.0.1_amd64-1@@tools
  742. blurb="Pattern scanning and processing language."
  743. homepage="https://www.gnu.org/software/gawk"
  744. license="GPLv3+"
  745. fetch="https://ftp.gnu.org/gnu/gawk/gawk-5.0.1.tar.lz"
  746. replace=""
  747. @end example
  748. A package descriptions is extracted from the variable @samp{description}
  749. where each line is interpreted literally and pre-formatted to fit in
  750. (exactly) @strong{80 columns}, plus the character @samp{#} and a blank
  751. space is prefixed to every line (shell comments).
  752. @noindent
  753. In addition to the Special variables, there are implicit variables such as
  754. @samp{blurb}:
  755. The @samp{blurb} variable is related to the special variable
  756. @samp{description}. Its value is made from the first (substantial)
  757. line of @samp{description}, mentioned as the "brief description".
  758. The build flags such as @samp{QICFLAGS}, @samp{QICXXFLAGS},
  759. @samp{QILDFLAGS}, and @samp{QICPPFLAGS} are only added to the meta file
  760. if the declared variable @samp{arch} is not equal to the "noarch" value.
  761. @node Order files
  762. @chapter Order files
  763. @cindex handling build order
  764. The order command has the purpose of resolving the build order through
  765. .order files. An order file contains a list of recipe names, by default
  766. does not perform any action other than to print a resolved list in
  767. descending order. For example, if @strong{a} depends on @strong{b} and
  768. @strong{c}, and @strong{c} depends on @strong{b} as well, the file might
  769. look like:
  770. @example
  771. a: c b
  772. b:
  773. c: b
  774. @end example
  775. Each letter represents a recipe name, complete dependencies for
  776. the first recipe name are listed in descending order, which is
  777. printed from right to left, and removed from left to right:
  778. @sc{Output}
  779. @example
  780. b
  781. c
  782. a
  783. @end example
  784. Blank lines, colons and parentheses are simply ignored. Comment lines
  785. beginning with @samp{#} are allowed.
  786. @noindent
  787. An order file could be used to build a series of packages, for example,
  788. if the content is:
  789. @example
  790. # Image handling libraries
  791. libs/libjpeg-turbo: devel/nasm
  792. x-libs/jasper: libs/libjpeg-turbo
  793. libs/tiff: libs/libjpeg-turbo
  794. @end example
  795. To proceed with each recipe, we can type:
  796. @example
  797. qi order imglibs.order | qi build --install -
  798. @end example
  799. The output of @samp{qi order imglibs.order} tells to qi in which order it
  800. should build the recipes:
  801. @example
  802. devel/nasm
  803. libs/libjpeg-turbo
  804. x-libs/jasper
  805. libs/tiff
  806. @end example
  807. @node Creating packages
  808. @chapter Creating packages
  809. @cindex package creation
  810. The creation command is an internal function of qi to make new Qi
  811. compatible packages. A package is produced using the contents of
  812. the Current Working Directory and the package file is written out.
  813. @example
  814. Usage: qi create [@var{Output/PackageName.tlz}]...
  815. @end example
  816. The argument for the file name to be written must contain a fully
  817. qualified named directory as the output directory where the package
  818. produced will be written. The file name should be composed using the
  819. full name: name-version-architecture-release[@@pkgcategory].tlz
  820. @sc{Example}
  821. @example
  822. cd /usr/pkg
  823. cd claws-mail_3.17.1_amd64-1@@x-apps
  824. qi create /var/cache/qi/packages/claws-mail_3.17.1_amd64-1@@x-apps
  825. @end example
  826. In this case, the package "claws-mail_3.17.1_amd64-1@@x-apps" will be
  827. written into @samp{/var/cache/qi/packages/}.
  828. @noindent
  829. All packages produced are complemented by a checksum file (.sha256).
  830. @node Examining packages
  831. @chapter Examining packages
  832. @cindex package examination
  833. The extraction command serves to examine binary packages for debugging
  834. purposes. It decompresses a package into a single directory, verifying
  835. its integrity and preserving all of its properties (owner and permissions).
  836. @example
  837. Usage: qi extract [@var{packagename.tlz}]...
  838. @end example
  839. @sc{Example}
  840. @example
  841. qi extract mksh_R56c_amd64-1@@shells.tlz
  842. @end example
  843. This action will put the content of "mksh_R56c_amd64-1@@shells.tlz" into a
  844. single directory, this is a private directory for the user who requested
  845. the action, creation operation will be equal to @strong{u=rwx,g=,o= (0700)}.
  846. The package content will reside on this location, default mask to deploy
  847. the content will be equal to @strong{u=rwx,g=rwx,o=rwx (0000)}.
  848. @noindent
  849. Note: the creation of the custom directory is influenced by the value
  850. of the @env{TMPDIR} variable.
  851. @node Qi exit status
  852. @chapter Qi exit status
  853. @cindex exit codes
  854. All the exit codes are described in this chapter.
  855. @table @samp
  856. @item 0
  857. Successful completion (no errors).
  858. @item 1
  859. Minor common errors:
  860. @itemize @bullet
  861. @item Help usage on invalid options or required arguments.
  862. @item Program needed by qi (prerequisite) is not available.
  863. @end itemize
  864. @item 2
  865. Command execution error:
  866. This code is used to return the evaluation of an external command or shell
  867. arguments in case of failure.
  868. @item 3
  869. Integrity check error for compressed files.
  870. Compressed files means:
  871. @itemize @bullet
  872. @item A tarball file from tar(1), typically handled by the GNU tar implementation.
  873. Supported extensions: .tar, .tar.gz, .tgz, .tar.Z, .tar.bz2, .tbz2, .tbz,
  874. .tar.xz, .txz, .tar.zst, .tzst
  875. @item A tarball file from tarlz(1).
  876. Supported extensions: .tar.lz, .tlz
  877. @item Zip files from unzip(1).
  878. Supported extensions: .zip, .ZIP
  879. @item Gzip files from gzip(1).
  880. Supported extensions: .gz, .Z
  881. @item Bzip2 files from bzip2(1).
  882. Supported extension: .bz2
  883. @item Lzip files from lzip(1).
  884. Supported extension: .lz
  885. @item Xz files from xz(1).
  886. Supported extension: .xz
  887. @item Zstd files from zstd(1).
  888. Supported extension: .zst
  889. @end itemize
  890. @item 4
  891. File empty, not regular, or expected.
  892. It's commonly expected:
  893. @itemize @bullet
  894. @item An argument for giving commands.
  895. @item A regular file or readable directory.
  896. @item An expected extension: .tlz, .sha256, .order.
  897. @item A protocol supported by the network downloader tool.
  898. @end itemize
  899. @item 5
  900. Empty or not defined variable:
  901. This code is used to report empty or undefined variables (usually
  902. variables coming from a recipe or assigned arrays that are tested).
  903. @item 6
  904. Package already installed:
  905. The package directory for an incoming .tlz package already exists.
  906. @item 10
  907. Network manager error:
  908. This code is used if the network downloader tool fails for some reason.
  909. @end table