site

bvnf.space sources
Log | Files | Refs

010-kiss-misc.html (3280B)


      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
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"/>
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
	<title>KISS tips and tricks</title>
	<link rel="icon" href="data:image/gif;base64,R0lGODlhEAAQAPH/AAAAAP//AAD/AP8AACH/C0NSTkcAAAAAMS4wSAAAAAIwPwAAAAJATwAAAAJQXwAAAAJgbwAAAAJwfwAAAAKAjwAAAAKQnwAAAAKgrwAAAAKwvwAAAALAzwAAAALQ3wAAAALg7wAh+QQF//8EACwAAAAAEAAQAAACOJQFqTp9j5p00IApq8X0rTtBSQCQYIeUZGBmh7qyp8fGpGvV8PyqPt9bJUKiBUYT4SBPRMuH0SgAADs="/>
	<link rel="stylesheet" href="/style.css" type="text/css"/>
	<style type="text/css">
	body {font-family: sans-serif;}
	</style>
</head>
<body>
<h1>KISS tips and tricks</h1>
<p>More blogs about <a href="//kisscommunity.bvnf.space/">KISS</a> are good. I hope this will give you some ideas for your system.</p>

<ol>
<h2><li>Hooks</li></h2>
<p>My <code>$KISS_HOOK</code> file begins with:
<code><pre>PKG=$2
DEST=$3
KISS_TMPDIR=${KISS_TMPDIR:-/tmp}

case $1 in</pre></code> as well as a copy of <code>log()</code> from kiss itself.</p>

	<p>Firstly, one to update the man page database after installation. This is quicker than running just plain <code>makewhatis</code> because it only updates entries for the added files.

<code><pre>post-install)
	man="$(kiss-manifest "$PKG" | grep '/usr/share/man/man./.')" || :
	# shellcheck disable=2086
	[ "$man" ] &amp;&amp; {
		log "$PKG" "Updating manpage database"
		makewhatis -d "$KISS_ROOT/usr/share/man" $man
	} || :
;;</pre></code>Note that I call <code>kiss-manifest</code> directly. Calling kiss from within a hook can be bad.</p>

<p>This is probably the most useful one - gives me a shell in the build directory if something goes wrong.
<code><pre>build-fail)
	printf "\a"
	log "$PKG" "Dropped into subshell"
	sh &gt;/dev/tty
;;</pre></code>I also have a patched <code>kiss</code> which can continue and finish a build that was stopped in this way.</p>

	<p>One to set my terminal title, a classic.
<code><pre>queue-status)
	# Set the terminal title
	[ -t 2 ] &amp;&amp; {
		printf '\033]0;kiss: %s (%d/%d)\a' \
			"$PKG" "${3:-?}" "${4:-?}" &gt;&amp;2
	}
;;</pre></code>

And another classic to log the build duration:
<code><pre>pre-build)
	cat /proc/uptime &gt; "$KISS_TMPDIR/_kiss_start"
;;

post-build)
	set +e
	IFS=. read -r _start _ &lt; "$KISS_TMPDIR/_kiss_start"
	IFS=. read -r _end _ &lt; /proc/uptime

	rm -f "$KISS_TMPDIR/_kiss_start"

	(
		_s=$((_end - _start))
		_h=$((_s / 60 / 60 % 24))
		_m=$((_s / 60 % 60))

		[ "$_h" = 0 ] || _u="${_u}${_h}h "
		[ "$_m" = 0 ] || _u="${_u}${_m}m "

		log "$PKG" "Build finished in ${_u:-${_s}s}"
	)
	set -e
;;</pre></code></p>

<p>By the way:
<code><pre>pre-update|post-update)
	# $2 is not $PKG for this hook
	unset PKG
;;</pre></code></p>

<h2><li>Shell functions</li></h2>
<p>To <code>cd</code> into a package directory:
<code><pre>kisscd () {
    _r="$(kiss search "$@" | sed 1q)"
    [ "$_r" ] &amp;&amp; cd "$_r"
    unset _r
}</pre></code></p>
<p>To quickly view a package build file:
<code><pre>kissb () {
    _r="$(kiss search "$1" | sed 1q)"
    shift
    [ "$_r" ] &amp;&amp; less "$@" "$_r/build"
    unset _r
}</pre></code></p>
</ol>

<p>Let me know your own useful functions.</p>

<hr />
<p>written 2024-03-25</p>

<p><a href="../">Home</a></p>
<p><a href="./">Blog home</a></p>
</body>
</html>