dpt-lib.sh(5)

πŸ’– dpt-lib.sh β€” the dpt shell library, bestie edition πŸ’–

okay so welcome to dpt-lib.sh(5), the manual page for the lil shell library that makes dpt subcommands go brrr. section 5, shell library, we're in the file formats zone and honestly? iconic. 🌸


✨ NAME ✨

dpt-lib.sh β€” the dpt shell library, no cap 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

dpt-lib.sh gets sourced by dpt(1) and it's basically a whole collection of shell functions and variables that any dpt subcommand written in shell can just... use. free real estate. πŸ’…

and as a lil side effect (not me doing extra credit 😭), it also sanity-checks that the script is being run from a source package directory that has a .git/ sub directory. vibe check: passed or not.


πŸŽ€ USAGE πŸŽ€

you source this file at the very beginning of your shell script, like:

. "${DPT__SCRIPTS:-/usr/share/pkg-perl-tools}/lib/dpt-lib.sh"

that's it. that's the whole ritual. ✨


πŸ’œ AVAILABLE FUNCTIONS πŸ’œ

die

Parameters: $message

Echos "E: $message" to STDERR and then exits 1. it said what it said and it left. πŸ’€

warn

Parameters: $message

Echos "W: $message" to STDERR. gentle lil heads up, no exit. 🫢

info

Parameters: $message

Echos "I: $message" to STDERR. just passing along the tea. β˜•

Parameters: $title

Outputs $title with an empty line before it and underlined, kind of like a header. it's giving title card, it's giving main character energy. πŸ‘‘

anykey

Tells the user to press any key and then waits for a keypress. dramatic pause, bestie. ⏸️

promptyesno

Parameters: $prompt

Issues a read() request with y/N options, printing $prompt. Returns true if 'y' or 'Y' is pressed, false otherwise. y = slay, N = not today. πŸ’…

is_command

Parameters: $command, $package (optional)

Checks if $command can be executed (it's running command -v under the hood); returns false and outputs a warning otherwise β€” and if you gave it $package, it'll optionally drop a hint to install that package too. so thoughtful. 🎁

is_installed

Parameters: $package_name, $minimum_package_version (optional)

Checks if $package_name is installed, optionally at $minimum_package_version, and returns false with a warning otherwise. no package, no peace. 😀

is_pkg_perl

Checks if debian/control contains the Debian Perl Group email address. are you one of us? 🧚

gitddiff

Offers to show the diff against the last debian/ tag, if there is any. if there's no tag, there's no diff, that's the rules. πŸ”₯

colored

Parameters: $color, $text

Outputs $text in $color β€” unless the NO_COLOR environment variable is set, in which case we behave. πŸ™ˆ

The available colors are (in capital letters): "BLACK", "RED", "GREEN", "YELLOW", "BLUE", "MAGENTA", "CYAN", "WHITE". 🌈

extra_colored

Parameters: $color, $bgcolor, $text

Outputs $text in foreground $color on $bgcolor β€” again, unless the NO_COLOR environment variable is set. double the color, double the slay. ✨

The available colors for both foreground and background are (in capital letters): "BLACK", "RED", "GREEN", "YELLOW", "BLUE", "MAGENTA", "CYAN", "WHITE".


🌟 AVAILABLE VARIABLES 🌟

PKG

Source package name, from debian/changelog. πŸ“¦

VER

Source package version, from debian/changelog. πŸ”’

UVER

Upstream version, i.e. source package version (from debian/changelog) without epoch and Debian revision. stripped down and thriving. πŸ¦‹

DIST

Source package distribution, from debian/changelog. πŸ—ΊοΈ

Colors

Cf. the colored() function above.

For using colors directly, the following variables exist;

"C_BLACK", "C_RED", "C_GREEN", "C_YELLOW", "C_BLUE", "C_MAGENTA", "C_CYAN", "C_WHITE", plus "C_RESET" to go back from coloring. 🎨

For background colors, the same colors exist as "BG_C_foo". πŸ’–


🧚 ENVIRONMENT VARIABLES 🧚

OOT

OOT (as in "out-of-tree"), if set, disables the check if a script is run in a source package directory and a Git repository. yes bestie, the vibe check gets skipped. πŸ™ˆ

Can be used as

OOT=1 . "${DPT__SCRIPTS:-/usr/share/pkg-perl-tools}/lib/dpt-lib.sh"

and is useful for scripts which are run on build results etc. πŸ› οΈ

⚠️ important tea: this also means that the variables derived from debian/changelog are not available. so like, don't go looking for PKG and friends when OOT is on, they ghosted you. 😭

πŸ‘€ SEE ALSO πŸ‘€

dpt-config(5) for discussion of "$DPT__SCRIPTS". go read it, it's the lore. πŸ“–


Copyright 2022-2024 gregor herrmann gregoa@debian.org

Copyright 2022 Damyan Ivanov dmn@debian.org

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's the whole page, bestie!! this is pkg-perl-tools 0.88, dated 2026-04-01, and you read every single word of dpt-lib.sh(5). not me being so proud of you rn 😭🫢 go source that library and be the main character of your own shell script. periodt. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from