From 14354b96301e252f52b5315e63b43f44dbac5314 Mon Sep 17 00:00:00 2001 From: Harald Pfeiffer Date: Sun, 16 Jun 2024 13:07:26 +0200 Subject: InComm --- README.md | 33 +++ fs/usr/lib/lirion/ln-initfunctions | 104 +++++++++ nfpm/.gitignore | 1 + nfpm/Makefile | 12 + nfpm/nfpm.yaml | 34 +++ nfpm/nfpm.yaml.skel | 461 +++++++++++++++++++++++++++++++++++++ 6 files changed, 645 insertions(+) create mode 100644 README.md create mode 100755 fs/usr/lib/lirion/ln-initfunctions create mode 100644 nfpm/.gitignore create mode 100644 nfpm/Makefile create mode 100644 nfpm/nfpm.yaml create mode 100644 nfpm/nfpm.yaml.skel diff --git a/README.md b/README.md new file mode 100644 index 0000000..3280ad4 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# Content + +## Modules + +### initfunctions + +A script that gives you status messages in the vein of classical SysV init functions. +I myself have migrated to systemd (stripped of what I don't need ofc, mostly using the resource +manager only), but I still like this classical output for many of my scripts. + +## Files / Folders + +### /fs + +This reflects actual system folders, so here you'll find the actual scripts and +libraries in the folders you'd put them into on your system. + +### /Makefile + +Only use this if you want to install the files underneath `fs` directly. +No common target, either use tab completion of `make` or read the Makefile yourself. + +### /nfpm + +Stuff I use for building packages you would install on a target OS if you do not +want to care about distribution yourself. + +Currently I am using [nfpm](https://github.com/goreleaser/nfpm) for this. It can build +debs, rpms, and even apks - I don't care about other OSes now and I *especially* don't care +about broken OSes that never were built for proper mass administration in the first place +(i.e. Windows/MSI). Most of my stuff is not built for that anyway. + +Right now, nfpm quickly suited my needs. Should I change this, this doc will also change. diff --git a/fs/usr/lib/lirion/ln-initfunctions b/fs/usr/lib/lirion/ln-initfunctions new file mode 100755 index 0000000..81d74e6 --- /dev/null +++ b/fs/usr/lib/lirion/ln-initfunctions @@ -0,0 +1,104 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2119,SC2120 + +# This serves as an alternative to "init functions". So the objective is to display +# an abstract about what a script is doing in the background and delivering a status. +# E.g.: +# - lnbegin "Doing awesome stuff" +# - do-something -q 2>/dev/null +# - case "$?" in +# 0) lnok ;; +# 255) lnwarn "Something uncritical went wrong" ;; +# *) lnfail "kaboom!" 101;; +# esac +# +# This script uses unicode characters. A "legacy" variant where we fall back +# to having e.g. "[ OK ]" instead of a checkmark is planned. (Earlier versions had that, too.) +# +# For a demo of the looks, use SCRIPTNAME -d. +# +# LICENCE: LGPLv3 +# AUTHOR: coding æt lirion dot de + +declare -x LNINITMSG + +function lnbegin { + printf "[⏲] %b\\033[s..." "$1" + export LNINITMSG="$1" +} +function lnok { + printf "\\r\\033[92m[✔] %b\\033[u\\033[K" "$LNINITMSG" + [ -n "$1" ]&&printf " \\033[37m(%b)\\033[0m" "$1" + printf "\\033[92m.\033[0m\\n" + unset LNINITMSG +} +function lnsucc { + lnok "$1" +} +function lninfo { + printf "\\r[ℹ]\\033[u\\033[K" + [ -n "$1" ]&&printf ": %b" "$1" + printf ".\\n" + unset LNINITMSG +} +function lnwarn { + printf "\\r\\033[33m[\\033[1m⚠\\033[0m\\033[33m] %b\\033[u\\033[K" "$LNINITMSG" + [ -n "$1" ]&&printf " \\033[37m(%b)\\033[0m" "$1" + printf "\\033[33m.\\033[0m\\n" + unset LNINITMSG + return 255 +} +function lnfail { + printf "\\r\\033[31m[✖] \\033[31m%b\\033[u\\033[K" "$LNINITMSG" # was 91m before + [ -n "$1" ]&&printf " \\033[37m(%b)\\033[0m" "$1" + printf "\\033[31m.\\033[0m\\n" + unset LNINITMSG + [ -n "$2" ]&&return "$2"||return 1 +} +function lnskip { + printf "\\r\\033[37m[↪] %b\\033[u\\033[K" "$LNINITMSG" + [ -n "$1" ]&&printf " \\033[37m(%b)\\033[0m" "$1" + printf "\\033[37m.\033[0m\\n" + unset LNINITMSG +} +function lnretry { + printf "\\r\\033[36m[↻] %b\\033[u\\033[K" "$LNINITMSG" + [ -n "$1" ]&&printf " \\033[37m(%b)\\033[0m" "$1" + printf "\\033[36m.\\033[0m\\n" + unset LNINITMSG +} +function lnquit { + printf "\\r\\033[34m[⏻] %b\\033[u\\033[K" "$LNINITMSG" + [ -n "$1" ]&&printf " \\033[37m(%b)\\033[0m" "$1" + printf "\\033[34m.\\033[0m\\n" + unset LNINITMSG +} +function lnprog { + # here, we neither have a newline at the end of the function nor do we + # remove the LNINITMSG variable. It is designated for additional + # information _during execution_. + [ -z "$1" ] && return 0 + printf "\\033[u\\033[K \\033[38;5;237m(%b)\\033[0m" "$1" +} +function lnsmil { + printf "\\r\\033[35m[☺] %b\\033[u\\033[K" "$LNINITMSG" + [ -n "$1" ]&&printf " \\033[37m(%b)\\033[0m" "$1" + printf "\\033[35m.\\033[0m\\n" + unset LNINITMSG +} +function demo { + lnbegin "Progress message";sleep 0.31337;lnprog "additional progress message (does not terminate)";printf -- " -- \\n" + lnbegin "OK message";sleep 0.31337;lnok "additional success message" + lnbegin "Info message";sleep 0.31337;lninfo "information without further steps / return value" + lnbegin "Warning message";sleep 0.31337;lnwarn "additional warning info" + lnbegin "Failure message";sleep 0.31337;lnfail "additional failure info" + lnbegin "Skip message";sleep 0.31337;lnskip "additional skip reason" + lnbegin "Retry message";sleep 0.31337;lnretry "additional reason for new run" + lnbegin "Quit message";sleep 0.31337;lnquit "additional quit information" + lnbegin "Lulz";sleep 0.31337;lnsmil + unset LNINITMSG +} +if [ "$1" == "-d" ] || [ "$1" == "--demo" ];then + demo + exit 0 +fi diff --git a/nfpm/.gitignore b/nfpm/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/nfpm/.gitignore @@ -0,0 +1 @@ +/build diff --git a/nfpm/Makefile b/nfpm/Makefile new file mode 100644 index 0000000..0224e8a --- /dev/null +++ b/nfpm/Makefile @@ -0,0 +1,12 @@ +all: skel build + +skel: + @grep -vP '^[\t\ ]*#' nfpm.yaml.skel | tr -s '\n' > nfpm.yaml + +build: build-deb build-rpm + +build-deb: + @nfpm pkg --packager deb --target ./build/ + +build-rpm: + @nfpm pkg --packager rpm --target ./build/ diff --git a/nfpm/nfpm.yaml b/nfpm/nfpm.yaml new file mode 100644 index 0000000..2f1d8b1 --- /dev/null +++ b/nfpm/nfpm.yaml @@ -0,0 +1,34 @@ +name: ln-initscripts +arch: all +platform: linux +version: 1.0.0 +version_schema: semver +epoch: 1 +prerelease: wtf1 +version_metadata: git +release: 1 +section: admin +priority: optional +maintainer: No env variable was set +description: An alternative to initscript-like status messages from lirion.de +vendor: lirion.de +homepage: https://git.lirion.de/lirion-initfunctions/ +license: LGLPv3 +mtime: "2024-06-16T12:30:00Z" +changelog: "changelog.yaml" +disable_globbing: false +depends: + - bash +contents: + - src: ../fs/usr/lib/lirion + dst: /usr/lib/lirion + type: tree +umask: 0o022 +rpm: + signature: + key_id: 99a00d948c6e71b599e986ad5421594bf1ab46f4 +deb: + signature: + method: dpkg-sig + type: origin + key_id: 99a00d948c6e71b599e986ad5421594bf1ab46f4 diff --git a/nfpm/nfpm.yaml.skel b/nfpm/nfpm.yaml.skel new file mode 100644 index 0000000..9581300 --- /dev/null +++ b/nfpm/nfpm.yaml.skel @@ -0,0 +1,461 @@ +# Name. (required) +name: ln-initscripts + +# Architecture. (required) +# This will expand any env var you set in the field, e.g. version: ${GOARCH} +# The architecture is specified using Go nomenclature (GOARCH) and translated +# to the platform specific equivalent. In order to manually set the architecture +# to a platform specific value, use deb_arch, rpm_arch and apk_arch. +# Examples: `all`, `amd64`, `386`, `arm5`, `arm6`, `arm7`, `arm64`, `mips`, +# `mipsle`, `mips64le`, `ppc64le`, `s390` +arch: all + +# Platform. +# This will expand any env var you set in the field, e.g. version: ${GOOS} +# This is only used by the rpm and deb packagers. +# Examples: `linux` (default), `darwin` +platform: linux + +# Version. (required) +# This will expand any env var you set in the field, e.g. version: ${SEMVER} +# Some package managers, like deb, require the version to start with a digit. +# Hence, you should not prefix the version with 'v'. +version: 1.0.0 + +# Version Schema allows you to specify how to parse the version string. +# Default is `semver` +# `semver` attempt to parse the version string as a valid semver version. +# The parser is lenient; it will strip a `v` prefix and will accept +# versions with fewer than 3 components, like `v1.2`. +# If parsing succeeds, then the version will be molded into a format +# compatible with the specific packager used. +# If parsing fails, then the version is used as-is. +# `none` skip trying to parse the version string and just use what is passed in +version_schema: semver + +# Version Epoch. +# A package with a higher version epoch will always be considered newer. +# See: https://www.debian.org/doc/debian-policy/ch-controlfields.html#epochs-should-be-used-sparingly +epoch: 1 + +# Version Prerelease. +# Default is extracted from `version` if it is semver compatible. +# This is appended to the `version`, e.g. `1.2.3+beta1`. If the `version` is +# semver compatible, then this replaces the prerelease component of the semver. +prerelease: wtf1 + +# Version Metadata (previously deb.metadata). +# Default is extracted from `version` if it is semver compatible. +# Setting metadata might interfere with version comparisons depending on the +# packager. If the `version` is semver compatible, then this replaces the +# version metadata component of the semver. +version_metadata: git + +# Version Release, aka revision. +# This will expand any env var you set in the field, e.g. release: ${VERSION_RELEASE} +# This is appended to the `version` after `prerelease`. This should be +# incremented if you release an updated package of the same upstream version, +# and it should reset to 1 when bumping the version. +release: 1 + +# Section. +# This is only used by the deb packager. +# See: https://www.debian.org/doc/debian-policy/ch-archive.html#sections +section: admin + +# Priority. +# Defaults to `optional` on deb +# Defaults to empty on rpm and apk +# See: https://www.debian.org/doc/debian-policy/ch-archive.html#priorities +priority: optional + +# Maintainer. (required) +# This will expand any env var you set in the field, e.g. maintainer: ${GIT_COMMITTER_NAME} <${GIT_COMMITTER_EMAIL}> +# Defaults to empty on rpm and apk +# Leaving the 'maintainer' field unset will not be allowed in a future version +maintainer: No env variable was set + +# Description. +# Defaults to `no description given`. +# Most packagers call for a one-line synopsis of the package. Some (like deb) +# also call for a multi-line description starting on the second line. +description: An alternative to initscript-like status messages from lirion.de + +# Vendor. +# This will expand any env var you set in the field, e.g. vendor: ${VENDOR} +# This is only used by the rpm packager. +vendor: lirion.de + +# Package's homepage. +# This will expand any env var you set in the field, e.g. homepage: ${CI_PROJECT_URL} +homepage: https://git.lirion.de/lirion-initfunctions/ + +# License. +license: LGLPv3 + +# Date to be used as mtime on internal files. +# +# Default is the value of $SOURCE_DATE_EPOCH (which should be an Unix time), +# or the current time. +# Read more about SOURCE_DATE_EPOCH at https://reproducible-builds.org/docs/source-date-epoch/ +mtime: "2024-06-16T12:30:00Z" + +# Changelog YAML file, see: https://github.com/goreleaser/chglog +changelog: "changelog.yaml" + +# Disables globbing for files, config_files, etc. +disable_globbing: false + +# Packages it replaces. (overridable) +# This will expand any env var you set in the field, e.g. ${REPLACE_BLA} +# the env var approach can be used to account for differences in platforms +#replaces: +# - foobar +# - ${REPLACE_BLA} + +# Packages it provides. (overridable) +# This will expand any env var you set in the field, e.g. ${PROVIDES_BLA} +# the env var approach can be used to account for differences in platforms +#provides: +# - bar +# - ${PROVIDES_BLA} + +# Dependencies. (overridable) +# This will expand any env var you set in the field, e.g. ${DEPENDS_NGINX} +# the env var approach can be used to account for differences in platforms +# e.g. rhel needs nginx >= 1:1.18 and deb needs nginx (>= 1.18.0) +depends: + - bash +# - ${DEPENDS_NGINX} + +# Recommended packages. (overridable) +# This will expand any env var you set in the field, e.g. ${RECOMMENDS_BLA} +# the env var approach can be used to account for differences in platforms +#recommends: +# - golang +# - ${RECOMMENDS_BLA} + +# Suggested packages. (overridable) +# This will expand any env var you set in the field, e.g. ${SUGGESTS_BLA} +# the env var approach can be used to account for differences in platforms +#suggests: +# - bzr + +# Packages it conflicts with. (overridable) +# This will expand any env var you set in the field, e.g. ${CONFLICTS_BLA} +# the env var approach can be used to account for differences in platforms +#conflicts: +# - mercurial +# - ${CONFLICTS_BLA} + +# Contents to add to the package +# This can be binaries or any other files. +contents: + # Basic file that applies to all packagers +# - src: ../fs/usr/lib/lirion/ln-initfunctions +# dst: /usr/lib/lirion/initfunctions + + # This will add all files in some/directory or in subdirectories at the + # same level under the directory /etc. This means the tree structure in + # some/directory will not be replicated. +# - src: ../fs/usr/lib/lirion +# dst: /usr/lib/lirion + + # This will replicate the directory structure under some/directory at /etc. + - src: ../fs/usr/lib/lirion + dst: /usr/lib/lirion + type: tree + + # Simple config file +# - src: path/to/local/foo.conf +# dst: /etc/foo.conf +# type: config + + # Select files with a glob (doesn't work if you set disable_globbing: true). + # If `src` is a glob, then the `dst` will be treated like a directory - even + # if it doesn't end with `/`, and even if the glob only matches one file. +# - src: path/to/local/*.1.gz +# dst: /usr/share/man/man1/ + + # Simple symlink at /usr/bin/foo which points to /sbin/foo, which is + # the same behaviour as `ln -s /sbin/foo /usr/bin/foo`. + # + # This also means that both "src" and "dst" are paths inside the package (or + # rather paths in the file system where the package will be installed) and + # not in the build environment. This is different from regular files where + # "src" is a path in the build environment. However, this convention results + # in "dst" always being the file that is created when installing the + # package. +# - src: /actual/path/to/foo +# dst: /usr/bin/foo +# type: symlink + + # Corresponds to `%config(noreplace)` if the packager is rpm, otherwise it + # is just a config file +# - src: path/to/local/bar.conf +# dst: /etc/bar.conf +# type: config|noreplace + + # These files are not actually present in the package, but the file names + # are added to the package header. From the RPM directives documentation: + # + # "There are times when a file should be owned by the package but not + # installed - log files and state files are good examples of cases you might + # desire this to happen." + # + # "The way to achieve this is to use the %ghost directive. By adding this + # directive to the line containing a file, RPM will know about the ghosted + # file, but will not add it to the package." + # + # For non rpm packages ghost files are ignored at this time. +# - dst: /etc/casper.conf +# type: ghost +# - dst: /var/log/boo.log +# type: ghost + + # You can use the packager field to add files that are unique to a specific + # packager +# - src: path/to/rpm/file.conf +# dst: /etc/file.conf +# type: config|noreplace +# packager: rpm +# - src: path/to/deb/file.conf +# dst: /etc/file.conf +# type: config|noreplace +# packager: deb +# - src: path/to/apk/file.conf +# dst: /etc/file.conf +# type: config|noreplace +# packager: apk + + # Sometimes it is important to be able to set the mtime, mode, owner, or group for a file + # that differs from what is on the local build system at build time. The owner (if different + # than 'root') has to be always specified manually in 'file_info' as it will not be copied + # from the 'src' file. +# - src: path/to/foo +# dst: /usr/share/foo +# file_info: +# # Make sure that the mode is specified in octal, e.g. 0644 instead of 644. +# mode: 0644 +# mtime: 2008-01-02T15:04:05Z +# owner: notRoot +# group: notRoot + + # Using the type 'dir', empty directories can be created. When building RPMs, however, this + # type has another important purpose: Claiming ownership of that folder. This is important + # because when upgrading or removing an RPM package, only the directories for which it has + # claimed ownership are removed. However, you should not claim ownership of a folder that + # is created by the distro or a dependency of your package. + # A directory in the build environment can optionally be provided in the 'src' field in + # order copy mtime and mode from that directory without having to specify it manually. +# - dst: /some/dir +# type: dir +# file_info: +# mode: 0700 + + # Using `expand: true`, environment variables will be expanded in both + # src and dst. +# - dst: /usr/local/bin/${NAME} +# src: "${NAME}" +# expand: true + +# Umask to be used on files without explicit mode set. +# +# By default, nFPM will inherit the mode of the original file that's being +# added. +# This may lead to issues if these files are checkout out in Git, for example, +# as it won't keep all the permissions on fresh checkouts, or if the local +# system has a problematic umask setting. +# +# This setting allows to set the umask for all files that are added to the +# package without a specific file_info.mode set. +# +# Default: 0o002 (will remove world-writable permissions) +umask: 0o022 + +# Scripts to run at specific stages. (overridable) +#scripts: +# preinstall: ./scripts/preinstall.sh +# postinstall: ./scripts/postinstall.sh +# preremove: ./scripts/preremove.sh +# postremove: ./scripts/postremove.sh + +# All fields above marked as `overridable` can be overridden for a given +# package format in this section. +#overrides: +# # The depends override can for example be used to provide version +# # constraints for dependencies where different package formats use different +# # versions or for dependencies that are named differently. +# deb: +# depends: +# - baz (>= 1.2.3-0) +# - some-lib-dev +# # ... +# rpm: +# depends: +# - baz >= 1.2.3-0 +# - some-lib-devel +# # ... +# apk: +# # ... +# archlinux: +# depends: +# - baz +# - some-lib + +# Custom configuration applied only to the RPM packager. +rpm: +# # rpm specific architecture name that overrides "arch" without performing any +# # replacements. +# rpm_arch: ia64 +# +# # RPM specific scripts. +# scripts: +# # The pretrans script runs before all RPM package transactions / stages. +# pretrans: ./scripts/pretrans.sh +# # The posttrans script runs after all RPM package transactions / stages. +# posttrans: ./scripts/posttrans.sh +# # The verify script runs when verifying packages using `rpm -V`. +# verify: ./scripts/verify.sh + +# # The package group. This option is deprecated by most distros +# # but required by old distros like CentOS 5 / EL 5 and earlier. +# group: Unspecified + +# # The package summary. This is, by default, the first line of the +# # description, but can be explicitly provided here. +# summary: Explicit summary for the package + + # The packager is used to identify the organization that actually packaged + # the software, as opposed to the author of the software. + # `maintainer` will be used as fallback if not specified. + # This will expand any env var you set in the field, e.g. packager: ${PACKAGER} +# packager: GoReleaser + + # Compression algorithm (gzip (default), zstd, lzma or xz). +# compression: zstd + +# # Prefixes for relocatable packages. +# prefixes: +# - /usr/bin + + # The package is signed if a key_file is set + signature: + # PGP secret key (can also be ASCII-armored), the passphrase is taken + # from the environment variable $NFPM_RPM_PASSPHRASE with a fallback + # to $NFPM_PASSPHRASE. + # This will expand any env var you set in the field, e.g. key_file: ${SIGNING_KEY_FILE} +# key_file: key.gpg + + # PGP secret key id in hex format, if it is not set it will select the first subkey + # that has the signing flag set. You may need to set this if you want to use the primary key as the signing key + # or to support older versions of RPM < 4.13.0 which cannot validate a signed RPM that used a subkey to sign + # This will expand any env var you set in the field, e.g. key_id: ${RPM_SIGNING_KEY_ID} + key_id: 99a00d948c6e71b599e986ad5421594bf1ab46f4 + +# Custom configuration applied only to the Deb packager. +deb: + # deb specific architecture name that overrides "arch" without performing any replacements. +# deb_arch: arm + + # Custom deb special files. +# scripts: +# # Deb rules script. +# rules: foo.sh + + # Deb templates file, when using debconf. +# templates: templates + + # Deb config maintainer script for asking questions when using debconf. +# config: config + + # Custom deb triggers +# triggers: +# # register interest on a trigger activated by another package +# # (also available: interest_await, interest_noawait) +# interest: +# - some-trigger-name +# +# # activate a trigger for another package +# # (also available: activate_await, activate_noawait) +# activate: +# - another-trigger-name +# + # Packages which would break if this package would be installed. + # The installation of this package is blocked if `some-package` + # is already installed. +# breaks: +# - some-package + + # Compression algorithm (gzip (default), zstd, xz or none). +# compression: zstd + + # The package is signed if a key_file is set + signature: + # Signature method, either "dpkg-sig" or "debsign". + # Defaults to "debsign" + method: dpkg-sig + + # PGP secret key (can also be ASCII-armored). The passphrase is taken + # from the environment variable $NFPM_DEB_PASSPHRASE with a fallback + # to $NFPM_PASSPHRASE. + # This will expand any env var you set in the field, e.g. key_file: ${SIGNING_KEY_FILE} +# key_file: key.gpg + + # The type describes the signers role, possible values are "origin", + # "maint" and "archive". If unset, the type defaults to "origin". + type: origin + + # PGP secret key id in hex format, if it is not set it will select the first subkey + # that has the signing flag set. You may need to set this if you want to use the primary key as the signing key + # This will expand any env var you set in the field, e.g. key_id: ${DEB_SIGNING_KEY_ID} + key_id: 99a00d948c6e71b599e986ad5421594bf1ab46f4 + + # Additional fields for the control file. Empty fields are ignored. + # This will expand any env vars you set in the field values, e.g. Vcs-Browser: ${CI_PROJECT_URL} +# fields: +# Bugs: https://github.com/goreleaser/nfpm/issues + + # The Debian-specific "predepends" field can be used to ensure the complete installation of a list of + # packages (including unpacking, pre- and post installation scripts) prior to the installation of the + # built package. +# predepends: +# - baz (>= 1.2.3-0) + +#apk: +# # apk specific architecture name that overrides "arch" without performing any replacements. +# apk_arch: armhf +# +# # The package is signed if a key_file is set +# signature: +# # RSA private key in the PEM format. The passphrase is taken from +# # the environment variable $NFPM_APK_PASSPHRASE with a fallback +# # to $NFPM_PASSPHRASE. +# # This will expand any env var you set in the field, e.g. key_file: ${SIGNING_KEY_FILE} +# key_file: key.gpg +# +# # The name of the signing key. When verifying a package, the signature +# # is matched to the public key store in /etc/apk/keys/.rsa.pub. +# # If unset, it defaults to the maintainer email address. +# key_name: origin +# +# # APK does not use pgp keys, so the key_id field is ignored. +# key_id: ignored +# +#archlinux: +# # This value is used to specify the name used to refer to a group +# # of packages when building a split package. Defaults to name +# # See: https://wiki.archlinux.org/title/PKGBUILD#pkgbase +# pkgbase: bar +# +# # The packager identifies the organization packaging the software +# # rather than the developer. Defaults to "Unknown Packager". +# packager: GoReleaser +# +# # Arch Linux specific scripts. +# scripts: +# # The preupgrade script runs before pacman upgrades the package +# preupgrade: ./scripts/preupgrade.sh +# +# # The postupgrade script runs after pacman upgrades the package +# postupgrade: ./scripts/postupgrade.sh -- cgit v1.2.3