kiss: Wrap comments longer

This commit is contained in:
Dylan Araps 2020-05-21 10:38:07 +03:00
parent d99fc72ec1
commit 8a6a6a6ba8
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
1 changed files with 135 additions and 164 deletions

299
kiss
View File

@ -71,17 +71,16 @@ file_owner() {
# shellcheck disable=2046 # shellcheck disable=2046
set -- $(ls -ld "$1"); user=${3:-root} set -- $(ls -ld "$1"); user=${3:-root}
# If the owner's user ID doesn't exist, fallback # If the owner's user ID doesn't exist, fallback to using 'root'.
# to using 'root'. This prevents the code from # This prevents the code from changing the permissions to something
# changing the permissions to something wonky. # wonky.
id -u "$user" >/dev/null 2>&1 || user=root id -u "$user" >/dev/null 2>&1 || user=root
} }
run_hook() { run_hook() {
# Provide a default post-build hook to remove files # Provide a default post-build hook to remove files and directories
# and directories for things we don't support out of # for things we don't support out of the box. One can simply define
# the box. One can simply define their own hook to # their own hook to override this behavior.
# override this behavior.
[ "${KISS_HOOK:-}" ] || { [ "${KISS_HOOK:-}" ] || {
case $1 in post-build) case $1 in post-build)
rm -rf "$3/usr/share/gettext" rm -rf "$3/usr/share/gettext"
@ -144,14 +143,12 @@ pkg_lint() {
} }
pkg_find() { pkg_find() {
# Figure out which repository a package belongs to by # Figure out which repository a package belongs to by searching for
# searching for directories matching the package name # directories matching the package name in $KISS_PATH/*.
# in $KISS_PATH/*.
query=$1 all=$2 what=$3 IFS=:; set -- query=$1 all=$2 what=$3 IFS=:; set --
# Both counts of word-splitting are intentional here. # Both counts of word-splitting are intentional here. Firstly to split
# Firstly to split the repositories and secondly to # the repositories and secondly to allow for the query to be a glob.
# allow for the query to be a glob.
# shellcheck disable=2086 # shellcheck disable=2086
for path in $KISS_PATH "${what:-$sys_db}"; do for path in $KISS_PATH "${what:-$sys_db}"; do
set +f set +f
@ -163,23 +160,22 @@ pkg_find() {
unset IFS unset IFS
# A package may also not be found due to a repository not being # A package may also not be found due to a repository not being readable
# readable by the current user. Either way, we need to die here. # by the current user. Either way, we need to die here.
[ "$1" ] || die "Package '$query' not in any repository" [ "$1" ] || die "Package '$query' not in any repository"
# Show all search results if called from 'kiss search', else # Show all search results if called from 'kiss search', else print only
# print only the first match. # the first match.
[ "$all" ] && printf '%s\n' "$@" || printf '%s\n' "$1" [ "$all" ] && printf '%s\n' "$@" || printf '%s\n' "$1"
} }
pkg_list() { pkg_list() {
# List installed packages. As the format is files and # List installed packages. As the format is files and directories, this
# directories, this just involves a simple for loop and # just involves a simple for loop and file read.
# file read.
cd "$sys_db" 2>/dev/null cd "$sys_db" 2>/dev/null
# Optional arguments can be passed to check for specific # Optional arguments can be passed to check for specific packages. If no
# packages. If no arguments are passed, list all. # arguments are passed, list all.
[ "$1" ] || { set +f; set -f -- *; } [ "$1" ] || { set +f; set -f -- *; }
# Loop over each package and print its name and version. # Loop over each package and print its name and version.
@ -201,8 +197,8 @@ pkg_cache() {
} }
pkg_sources() { pkg_sources() {
# Download any remote package sources. The existence of local # Download any remote package sources. The existence of local files is
# files is also checked. # also checked.
repo_dir=$(pkg_find "$1") repo_dir=$(pkg_find "$1")
# Support packages without sources. Simply do nothing. # Support packages without sources. Simply do nothing.
@ -210,9 +206,9 @@ pkg_sources() {
log "$1" "Downloading sources" log "$1" "Downloading sources"
# Store each downloaded source in a directory named after the # Store each downloaded source in a directory named after the package it
# package it belongs to. This avoid conflicts between two packages # belongs to. This avoid conflicts between two packages having a source
# having a source of the same name. # of the same name.
mkdir -p "$src_dir/$1" && cd "$src_dir/$1" mkdir -p "$src_dir/$1" && cd "$src_dir/$1"
while read -r src dest || [ "$src" ]; do while read -r src dest || [ "$src" ]; do
@ -286,8 +282,8 @@ pkg_sources() {
} }
pkg_extract() { pkg_extract() {
# Extract all source archives to the build directory and copy over # Extract all source archives to the build directory and copy over any
# any local repository files. # local repository files.
repo_dir=$(pkg_find "$1") repo_dir=$(pkg_find "$1")
# Support packages without sources. Simply do nothing. # Support packages without sources. Simply do nothing.
@ -388,9 +384,9 @@ pkg_extract() {
} }
pkg_depends() { pkg_depends() {
# Resolve all dependencies and generate an ordered list. # Resolve all dependencies and generate an ordered list. This does a
# This does a depth-first search. The deepest dependencies are # depth-first search. The deepest dependencies are listed first and then
# listed first and then the parents in reverse order. # the parents in reverse order.
contains "$deps" "$1" || { contains "$deps" "$1" || {
# Filter out non-explicit, aleady installed dependencies. # Filter out non-explicit, aleady installed dependencies.
# Only filter installed if called from 'pkg_build()'. # Only filter installed if called from 'pkg_build()'.
@ -409,9 +405,8 @@ pkg_depends() {
} }
pkg_order() { pkg_order() {
# Order a list of packages based on dependence and # Order a list of packages based on dependence and take into account
# take into account pre-built tarballs if this is # pre-built tarballs if this is to be called from 'kiss i'.
# to be called from 'kiss i'.
order=; redro=; deps= order=; redro=; deps=
for pkg do case $pkg in for pkg do case $pkg in
@ -419,9 +414,8 @@ pkg_order() {
*) pkg_depends "$pkg" raw *) pkg_depends "$pkg" raw
esac done esac done
# Filter the list, only keeping explicit packages. # Filter the list, only keeping explicit packages. The purpose of these
# The purpose of these two loops is to order the # two loops is to order the argument list based on dependence.
# argument list based on dependence.
for pkg in $deps; do contains "$*" "$pkg" && { for pkg in $deps; do contains "$*" "$pkg" && {
order="$order $pkg " order="$order $pkg "
redro=" $pkg $redro" redro=" $pkg $redro"
@ -431,8 +425,8 @@ pkg_order() {
} }
pkg_strip() { pkg_strip() {
# Strip package binaries and libraries. This saves space on the # Strip package binaries and libraries. This saves space on the system as
# system as well as on the tarballs we ship for installation. # well as on the tarballs we ship for installation.
[ -f "$mak_dir/$pkg/nostrip" ] && return [ -f "$mak_dir/$pkg/nostrip" ] && return
log "$1" "Stripping binaries and libraries" log "$1" "Stripping binaries and libraries"
@ -448,9 +442,6 @@ pkg_strip() {
} }
# Strip only files matching the below ELF types. # Strip only files matching the below ELF types.
# NOTE: 'readelf' is used in place of 'file' as
# it allows us to remove 'file' from the
# core repositories altogether.
find "$pkg_dir/$1" -type f | while read -r file; do find "$pkg_dir/$1" -type f | while read -r file; do
case $(readelf -h "$file") in case $(readelf -h "$file") in
*" DYN "*) strip_opt=unneeded ;; *" DYN "*) strip_opt=unneeded ;;
@ -464,10 +455,9 @@ pkg_strip() {
} }
pkg_fixdeps() { pkg_fixdeps() {
# Dynamically look for missing runtime dependencies by checking # Dynamically look for missing runtime dependencies by checking each
# each binary and library with 'ldd'. This catches any extra # binary and library with 'ldd'. This catches any extra libraries and or
# libraries and or dependencies pulled in by the package's # dependencies pulled in by the package's build suite.
# build suite.
log "$1" "Checking for missing dependencies" log "$1" "Checking for missing dependencies"
command -v ldd >/dev/null || { command -v ldd >/dev/null || {
@ -475,15 +465,14 @@ pkg_fixdeps() {
return 0 return 0
} }
# Go to the directory containing the built package to # Go to the built package directory to simplify path building.
# simplify path building.
cd "$pkg_dir/$1/$pkg_db/$1" cd "$pkg_dir/$1/$pkg_db/$1"
# Generate a list of all installed manifests. # Generate a list of all installed manifests.
set +f; set -f -- "$sys_db/"*/manifest set +f; set -f -- "$sys_db/"*/manifest
# Make a copy of the depends file if it exists to have a # Make a copy of the depends file if it exists to have a reference to
# reference to 'diff' against. # 'diff' against.
if [ -f depends ]; then if [ -f depends ]; then
cp -f depends "$mak_dir/d" cp -f depends "$mak_dir/d"
dep_file=$mak_dir/d dep_file=$mak_dir/d
@ -491,15 +480,14 @@ pkg_fixdeps() {
dep_file=/dev/null dep_file=/dev/null
fi fi
# Get a list of binaries and libraries, false files # Get a list of binaries and libraries, false files will be found,
# will be found, however it's faster to get 'ldd' to check # however it's faster to get 'ldd' to check them anyway than to filter
# them anyway than to filter them out. # them out.
find "$pkg_dir/${PWD##*/}/" -type f 2>/dev/null | find "$pkg_dir/${PWD##*/}/" -type f 2>/dev/null |
while read -r file; do while read -r file; do
# Run 'ldd' on the file and parse each line. The code # Run 'ldd' on the file and parse each line. The code then checks to
# then checks to see which packages own the linked # see which packages own the linked libraries and it prints the result.
# libraries and it prints the result.
ldd "$file" 2>/dev/null | while read -r dep; do ldd "$file" 2>/dev/null | while read -r dep; do
# Skip lines containing 'ldd'. # Skip lines containing 'ldd'.
[ "${dep##*ldd*}" ] || continue [ "${dep##*ldd*}" ] || continue
@ -546,9 +534,8 @@ pkg_fixdeps() {
done ||: done ||:
done >> depends done >> depends
# Remove duplicate entries from the new depends file. # Remove duplicate entries from the new depends file. This removes
# This removes duplicate lines looking *only* at the # duplicate lines looking *only* at the first column.
# first column.
sort -uk1,1 -o depends depends 2>/dev/null ||: sort -uk1,1 -o depends depends 2>/dev/null ||:
# Display a 'diff' of the new dependencies against the old ones. # Display a 'diff' of the new dependencies against the old ones.
@ -578,8 +565,8 @@ pkg_manifest() (
) )
pkg_etcsums() ( pkg_etcsums() (
# Generate checksums for each configuration file in the package's # Generate checksums for each configuration file in the package's /etc/
# /etc/ directory for use in "smart" handling of these files. # directory for use in "smart" handling of these files.
log "$1" "Generating etcsums" log "$1" "Generating etcsums"
# This function runs as a sub-shell to avoid having to 'cd' back to the # This function runs as a sub-shell to avoid having to 'cd' back to the
@ -594,15 +581,15 @@ pkg_etcsums() (
) )
pkg_tar() ( pkg_tar() (
# Create a tarball from the built package's files. # Create a tarball from the built package's files. This tarball also
# This tarball also contains the package's database entry. # contains the package's database entry.
log "$1" "Creating tarball" log "$1" "Creating tarball"
# Read the version information to name the package. # Read the version information to name the package.
read -r version release < "$(pkg_find "$1")/version" read -r version release < "$(pkg_find "$1")/version"
# Use 'cd' to avoid needing tar's '-C' flag which may not # Use 'cd' to avoid needing tar's '-C' flag which may not be portable
# be portable across implementations. # across implementations.
cd "$pkg_dir/$1" cd "$pkg_dir/$1"
# Create a tarball from the contents of the built package. # Create a tarball from the contents of the built package.
@ -619,9 +606,7 @@ pkg_tar() (
) )
pkg_build() { pkg_build() {
# Build packages and turn them into packaged tarballs. This function # Build packages and turn them into packaged tarballs.
# also checks checksums, downloads sources and ensure all dependencies
# are installed.
pkg_build=1 pkg_build=1
log "Resolving dependencies" log "Resolving dependencies"
@ -683,21 +668,20 @@ pkg_build() {
pkg_extract "$pkg" pkg_extract "$pkg"
repo_dir=$(pkg_find "$pkg") repo_dir=$(pkg_find "$pkg")
# Install built packages to a directory under the package name # Install built packages to a directory under the package name to
# to avoid collisions with other packages. # avoid collisions with other packages.
mkdir -p "$pkg_dir/$pkg/$pkg_db" "$mak_dir/$pkg" mkdir -p "$pkg_dir/$pkg/$pkg_db" "$mak_dir/$pkg"
cd "$mak_dir/$pkg" cd "$mak_dir/$pkg"
# Log the version so we can pass it to the package build file # Log the version so we can pass it to the package build file.
# for the occasional use.
read -r build_version _ < "$repo_dir/version" read -r build_version _ < "$repo_dir/version"
log "$pkg" "Starting build" log "$pkg" "Starting build"
run_hook pre-build "$pkg" "$pkg_dir/$pkg" run_hook pre-build "$pkg" "$pkg_dir/$pkg"
# Call the build script, log the output to the terminal # Call the build script, log the output to the terminal and to a file.
# and to a file. There's no PIPEFAIL in POSIX shelll so # There's no PIPEFAIL in POSIX shelll so we must resort to tricks like
# we must resort to tricks like killing the script ourselves. # killing the script ourselves.
{ "$repo_dir/build" "$pkg_dir/$pkg" "$build_version" 2>&1 || { { "$repo_dir/build" "$pkg_dir/$pkg" "$build_version" 2>&1 || {
log "$pkg" "Build failed" log "$pkg" "Build failed"
log "$pkg" "Log stored to $log_dir/$pkg-$time-$pid" log "$pkg" "Log stored to $log_dir/$pkg-$time-$pid"
@ -706,29 +690,29 @@ pkg_build() {
kill 0 kill 0
} } | tee "$log_dir/$pkg-$time-$pid" } } | tee "$log_dir/$pkg-$time-$pid"
# Delete the log file if the build succeeded to prevent # Delete the log file if the build succeeded to prevent the directory
# the directory from filling very quickly with useless logs. # from filling very quickly with useless logs.
[ "$KISS_KEEPLOG" = 1 ] || rm -f "$log_dir/$pkg-$time-$pid" [ "$KISS_KEEPLOG" = 1 ] || rm -f "$log_dir/$pkg-$time-$pid"
# Copy the repository files to the package directory. # Copy the repository files to the package directory. This acts as the
# This acts as the database entry. # database entry.
cp -LRf "$repo_dir" "$pkg_dir/$pkg/$pkg_db/" cp -LRf "$repo_dir" "$pkg_dir/$pkg/$pkg_db/"
# We never ever want this. Let's end the endless conflicts # We never ever want this. Let's end the endless conflicts and remove
# and remove it. This will be the only exception for a # it. This will be the only exception for a specific removal of this
# specific removal of this kind. A 'find' is used instead # kind. A 'find' is used instead of 'rm' so as to not hardcode the
# of 'rm' so as to not hardcode the location to this file. # location to this file.
find "$pkg_dir/$pkg" -type f -name charset.alias -exec rm -f {} + find "$pkg_dir/$pkg" -type f -name charset.alias -exec rm -f {} +
log "$pkg" "Successfully built package" log "$pkg" "Successfully built package"
run_hook post-build "$pkg" "$pkg_dir/$pkg" run_hook post-build "$pkg" "$pkg_dir/$pkg"
# Create the manifest file early and make it empty. # Create the manifest file early and make it empty. This ensures that
# This ensures that the manifest is added to the manifest. # the manifest is added to the manifest.
: > "$pkg_dir/$pkg/$pkg_db/$pkg/manifest" : > "$pkg_dir/$pkg/$pkg_db/$pkg/manifest"
# If the package contains '/etc', add a file called # If the package contains '/etc', add a file called 'etcsums' to the
# 'etcsums' to the manifest. See comment directly above. # manifest. See comment directly above.
[ -d "$pkg_dir/$pkg/etc" ] && : > "$pkg_dir/$pkg/$pkg_db/$pkg/etcsums" [ -d "$pkg_dir/$pkg/etc" ] && : > "$pkg_dir/$pkg/$pkg_db/$pkg/etcsums"
pkg_strip "$pkg" pkg_strip "$pkg"
@ -802,9 +786,8 @@ pkg_checksums() {
} }
pkg_verify() { pkg_verify() {
# Verify all package checksums. This is achieved by generating # Verify all package checksums. This is achieved by generating a new set
# a new set of checksums and then comparing those with the old # of checksums and then comparing those with the old set.
# set.
for pkg do repo_dir=$(pkg_find "$pkg") for pkg do repo_dir=$(pkg_find "$pkg")
[ -f "$repo_dir/sources" ] || continue [ -f "$repo_dir/sources" ] || continue
@ -988,9 +971,9 @@ pkg_swap() {
} }
pkg_install_files() { pkg_install_files() {
# Reverse the manifest file so that we start shallow and go # Reverse the manifest file so that we start shallow and go deeper as we
# deeper as we iterate over each item. This is needed so that # iterate over each item. This is needed so that directories are created
# directories are created going down the tree. # going down the tree.
sort "$2/$pkg_db/${2##*/}/manifest" | sort "$2/$pkg_db/${2##*/}/manifest" |
while read -r line; do while read -r line; do
@ -1092,9 +1075,8 @@ pkg_etc() (
) )
pkg_remove() { pkg_remove() {
# Remove a package and all of its files. The '/etc' directory # Remove a package and all of its files. The '/etc' directory is handled
# is handled differently and configuration files are *not* # differently and configuration files are *not* overwritten.
# overwritten.
pkg_list "$1" >/dev/null || return pkg_list "$1" >/dev/null || return
# Make sure that nothing depends on this package. # Make sure that nothing depends on this package.
@ -1106,8 +1088,8 @@ pkg_remove() {
} }
# Block being able to abort the script with 'Ctrl+C' during removal. # Block being able to abort the script with 'Ctrl+C' during removal.
# Removes all risk of the user aborting a package removal leaving # Removes all risk of the user aborting a package removal leaving an
# an incomplete package installed. # incomplete package installed.
trap '' INT trap '' INT
if [ -x "$sys_db/$1/pre-remove" ]; then if [ -x "$sys_db/$1/pre-remove" ]; then
@ -1140,38 +1122,33 @@ pkg_remove() {
pkg_install() { pkg_install() {
# Install a built package tarball. # Install a built package tarball.
# #
# Package installation works similarly to the method used by # Package installation works similarly to the method used by Slackware in
# Slackware in some of their tooling. It's not the obvious # some of their tooling. It's not the obvious solution to the problem,
# solution to the problem, however it is the best solution # however it is the best solution at this given time.
# at this given time.
# #
# When an installation is an update to an existing package, # When an installation is an update to an existing package, instead of
# instead of removing the old version first we do something # removing the old version first we do something different.
# different.
# #
# The new version is installed overwriting any files which # The new version is installed overwriting any files which it has in
# it has in common with the previously installed version of # common with the previously installed version of the package.
# the package.
# #
# A "diff" is then generated between the old and new versions # A "diff" is then generated between the old and new versions and contains
# and contains any files existing in the old version but not # any files existing in the old version but not the new version.
# the new version.
# #
# The package manager then goes and removes these files which # The package manager then goes and removes these files which leaves us
# leaves us with the new package version in the file system # with the new package version in the file system and all traces of the
# and all traces of the old version gone. # old version gone.
# #
# For good measure the package manager will then install the # For good measure the package manager will then install the new package
# new package an additional two times. Firstly to ensure that # an additional time. This is to ensure that the above diff didn't contain
# the above diff didn't contain anything incorrect. And # anything incorrect.
# Secondly to confirm that everything is sane.
# #
# This is the better method as it is "seamless". An update to # This is the better method as it is "seamless". An update to busybox won't
# busybox won't create a window in which there is no access # create a window in which there is no access to all of its utilities to
# to all of its utilities to give an example. # give an example.
# Install can also take the full path to a tarball. # Install can also take the full path to a tarball. We don't need to check
# We don't need to check the repository if this is the case. # the repository if this is the case.
if [ -f "$1" ] && [ -z "${1%%*.tar.*}" ] && [ -z "${1##*/*}" ]; then if [ -f "$1" ] && [ -z "${1%%*.tar.*}" ] && [ -z "${1##*/*}" ]; then
tar_file=$1 pkg_name=${1##*/} pkg_name=${pkg_name%#*} tar_file=$1 pkg_name=${1##*/} pkg_name=${pkg_name%#*}
@ -1185,25 +1162,24 @@ pkg_install() {
mkdir -p "$tar_dir/$pkg_name" mkdir -p "$tar_dir/$pkg_name"
log "$pkg_name" "Extracting $tar_file" log "$pkg_name" "Extracting $tar_file"
# The tarball is extracted to a temporary directory where its # The tarball is extracted to a temporary directory where its contents are
# contents are then "installed" to the filesystem. # then "installed" to the filesystem. Running this step as soon as possible
# # allows us to also check the validity of the tarball and bail out early
# Running this step as soon as possible allows us to also check # if needed.
# the validity of the tarball and bail out early if needed.
( (
cd "$tar_dir/$pkg_name" cd "$tar_dir/$pkg_name"
decompress "$tar_file" | tar xf - decompress "$tar_file" | tar xf -
) )
# Naively assume that the existence of a manifest file is all # Naively assume that the existence of a manifest file is all that
# that determines a valid KISS package from an invalid one. # determines a valid KISS package from an invalid one. This should be a
# This should be a fine assumption to make in 99.99% of cases. # fine assumption to make in 99.99% of cases.
[ -f "$tar_dir/$pkg_name/$pkg_db/$pkg_name/manifest" ] || [ -f "$tar_dir/$pkg_name/$pkg_db/$pkg_name/manifest" ] ||
die "'${tar_file##*/}' is not a valid KISS package" die "'${tar_file##*/}' is not a valid KISS package"
# Ensure that the tarball's manifest is correct by checking that # Ensure that the tarball's manifest is correct by checking that each file
# each file and directory inside of it actually exists. # and directory inside of it actually exists.
[ "$KISS_FORCE" = 1 ] || { [ "$KISS_FORCE" = 1 ] || {
log "$pkg_name" "Checking that manifest is valid" log "$pkg_name" "Checking that manifest is valid"
while read -r line; do while read -r line; do
@ -1285,8 +1261,8 @@ pkg_install() {
log "$pkg_name" "Verifying installation" log "$pkg_name" "Verifying installation"
pkg_install_files -e "$tar_dir/$pkg_name" pkg_install_files -e "$tar_dir/$pkg_name"
# Reset 'trap' to its original value. Installation is done so # Reset 'trap' to its original value. Installation is done so we no longer
# we no longer need to block 'Ctrl+C'. # need to block 'Ctrl+C'.
trap pkg_clean EXIT INT trap pkg_clean EXIT INT
if [ -x "$sys_db/$pkg_name/post-install" ]; then if [ -x "$sys_db/$pkg_name/post-install" ]; then
@ -1310,8 +1286,7 @@ pkg_updates() {
# shellcheck disable=2046,2086 # shellcheck disable=2046,2086
{ IFS=:; set -- $KISS_PATH; unset IFS; } { IFS=:; set -- $KISS_PATH; unset IFS; }
# Update each repository in '$KISS_PATH'. It is assumed that # Update each repository in '$KISS_PATH'.
# each repository is 'git' tracked.
for repo do for repo do
# Go to the root of the repository (if it exists). # Go to the root of the repository (if it exists).
cd "$repo" cd "$repo"
@ -1434,17 +1409,16 @@ pkg_updates() {
} }
pkg_clean() { pkg_clean() {
# Clean up on exit or error. This removes everything related # Clean up on exit or error. This removes everything related to the build.
# to the build.
[ "$KISS_DEBUG" != 1 ] || return [ "$KISS_DEBUG" != 1 ] || return
# Create a list containing the current invocation's temporary # Create a list containing the current invocation's temporary files and
# files and directories. # directories.
set +f -- "$mak_dir" "$pkg_dir" "$tar_dir" \ set +f -- "$mak_dir" "$pkg_dir" "$tar_dir" \
"$cac_dir/$pid-m" "$cac_dir/$pid-c" "$cac_dir/$pid-m" "$cac_dir/$pid-c"
# Go through the cache and add any entries which don't belong # Go through the cache and add any entries which don't belong to a
# to a currently running kiss instance. # currently running kiss instance.
for dir in "$cac_dir/"[bep]*-[0-9]*; do for dir in "$cac_dir/"[bep]*-[0-9]*; do
[ -e "/proc/${dir##*-}" ] || set -- "$@" "$dir" [ -e "/proc/${dir##*-}" ] || set -- "$@" "$dir"
done done
@ -1453,13 +1427,10 @@ pkg_clean() {
} }
args() { args() {
# Parse script arguments manually. This is rather easy to do in # Parse script arguments manually. This is rather easy to do in our case
# our case since the first argument is always an "action" and # since the first argument is always an "action" and the arguments that
# the arguments that follow are all package names. # follow are all package names.
action=$1 action=$1
# 'dash' exits on error here if 'shift' is used and there are zero
# arguments despite trapping the error ('|| :').
shift "$(($# ? 1 : 0))" shift "$(($# ? 1 : 0))"
# Unless this is a search, sanitize the user's input. The call to # Unless this is a search, sanitize the user's input. The call to
@ -1495,8 +1466,8 @@ args() {
} }
esac esac
# Actions can be abbreviated to their first letter. This saves # Actions can be abbreviated to their first letter. This saves keystrokes
# keystrokes once you memorize the commands. # once you memorize the commands.
case $action in case $action in
a|alternatives) a|alternatives)
if [ "$1" = - ]; then if [ "$1" = - ]; then
@ -1607,8 +1578,8 @@ main() {
# Globally disable globbing and enable exit-on-error. # Globally disable globbing and enable exit-on-error.
set -ef set -ef
# Die here if the user has no set KISS_PATH. This is a rare occurance # Die here if the user has no set KISS_PATH. This is a rare occurance as
# as the environment variable should always be defined. # the environment variable should always be defined.
[ "$KISS_PATH" ] || die "\$KISS_PATH needs to be set" [ "$KISS_PATH" ] || die "\$KISS_PATH needs to be set"
# Allow the user to disable colors in output via an environment variable. # Allow the user to disable colors in output via an environment variable.
@ -1633,32 +1604,32 @@ main() {
# up before we die. This occurs on 'Ctrl+C' as well as success and error. # up before we die. This occurs on 'Ctrl+C' as well as success and error.
trap pkg_clean EXIT INT trap pkg_clean EXIT INT
# Figure out which 'sudo' command to use based on the user's choice or # Figure out which 'sudo' command to use based on the user's choice or what
# what is available on the system. # is available on the system.
su=${KISS_SU:-$(command -v sudo || command -v doas)} || su=su su=${KISS_SU:-$(command -v sudo || command -v doas)} || su=su
# Store the date and time of script invocation to be used as the name # Store the date and time of script invocation to be used as the name of
# of the log files the package manager creates uring builds. # the log files the package manager creates uring builds.
time=$(date '+%Y-%m-%d-%H:%M') time=$(date '+%Y-%m-%d-%H:%M')
# Make note of the user's current ID to do root checks later on. # Make note of the user's current ID to do root checks later on.
# This is used enough to warrant a place here. # This is used enough to warrant a place here.
uid=$(id -u) uid=$(id -u)
# Make sure that the KISS_ROOT doesn't end with a '/'. This might # Make sure that the KISS_ROOT doesn't end with a '/'. This might break
# break some operations. # some operations if left unchecked.
KISS_ROOT=${KISS_ROOT%/} KISS_ROOT=${KISS_ROOT%/}
# Define this variable but don't create its directory structure from # Define this variable but don't create its directory structure from the
# the get go. It will be created as needed by package installation. # get go. It will be created as needed by package installation.
sys_db=$KISS_ROOT/$pkg_db sys_db=$KISS_ROOT/$pkg_db
# This allows for automatic setup of a KISS chroot and will # This allows for automatic setup of a KISS chroot and will
# do nothing on a normal system. # do nothing on a normal system.
mkdir -p "$KISS_ROOT/" 2>/dev/null ||: mkdir -p "$KISS_ROOT/" 2>/dev/null ||:
# Create the required temporary directories and set the variables # Create the required temporary directories and set the variables which
# which point to them. # point to them.
mkdir -p "${cac_dir:=${XDG_CACHE_HOME:-$HOME/.cache}/kiss}" \ mkdir -p "${cac_dir:=${XDG_CACHE_HOME:-$HOME/.cache}/kiss}" \
"${mak_dir:=${KISS_TMPDIR:-$cac_dir}/build-$pid}" \ "${mak_dir:=${KISS_TMPDIR:-$cac_dir}/build-$pid}" \
"${pkg_dir:=${KISS_TMPDIR:-$cac_dir}/pkg-$pid}" \ "${pkg_dir:=${KISS_TMPDIR:-$cac_dir}/pkg-$pid}" \