kiss: simplify logs

This commit is contained in:
Dylan Araps 2019-08-19 18:02:18 +00:00
parent dbfb18d2ed
commit d122fdfcd5

86
kiss
View File

@ -39,15 +39,15 @@ log() {
pkg_lint() { pkg_lint() {
# Check that each mandatory file in the package entry exists. # Check that each mandatory file in the package entry exists.
log "[$1]: Checking repository files" log "[$1] Checking repository files"
# Figure out *where* the repository entry for the package is located. # Figure out *where* the repository entry for the package is located.
repo_dir=$(pkg_search "$1") repo_dir=$(pkg_search "$1")
cd "$repo_dir" || die "'$repo_dir' not accessible" cd "$repo_dir" || die "'$repo_dir' not accessible"
[ -f sources ] || die "[$1]: Sources file not found" [ -f sources ] || die "[$1] Sources file not found"
[ -x build ] || die "[$1]: Build file not found or not executable" [ -x build ] || die "[$1] Build file not found or not executable"
[ -s version ] || die "[$1]: Version file not found or empty" [ -s version ] || die "[$1] Version file not found or empty"
# Ensure that the release field in the version file is set # Ensure that the release field in the version file is set
# to something. The above test checks for the version field inclusively. # to something. The above test checks for the version field inclusively.
@ -120,7 +120,7 @@ pkg_list() {
pkg_sources() { pkg_sources() {
# Download any remote package sources. The existence of local # Download any remote package sources. The existence of local
# files is also checked. # files is also checked.
log "[$1]: Downloading sources" log "[$1] Downloading sources"
# Store each downloaded source in named after the package it # Store each downloaded source in named after the package it
# belongs to. This avoid conflicts between two packages having a # belongs to. This avoid conflicts between two packages having a
@ -143,22 +143,22 @@ pkg_sources() {
# Remote source. # Remote source.
*://*) *://*)
[ -f "${src##*/}" ] && { [ -f "${src##*/}" ] && {
log "[$1]: Found cached source '${src##*/}'" log "[$1] Found cached source '${src##*/}'"
continue continue
} }
wget "$src" || { wget "$src" || {
rm -f "${src##*/}" rm -f "${src##*/}"
die "[$1]: Failed to download $src" die "[$1] Failed to download $src"
} }
;; ;;
# Local files (Any source that is non-remote is assumed to be local). # Local files (Any source that is non-remote is assumed to be local).
*) *)
[ -f "$repo_dir/$src" ] || [ -f "$repo_dir/$src" ] ||
die "[$1]: No local file '$src'" die "[$1] No local file '$src'"
log "[$1]: Found local file '$src'" log "[$1] Found local file '$src'"
;; ;;
esac esac
done < "$repo_dir/sources" done < "$repo_dir/sources"
@ -167,7 +167,7 @@ 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 local repository files. # any local repository files.
log "[$1]: Extracting sources" log "[$1] Extracting sources"
# Store each downloaded source in named after the package it # Store each downloaded source in named after the package it
# belongs to. This avoid conflicts between two packages having a # belongs to. This avoid conflicts between two packages having a
@ -193,7 +193,7 @@ pkg_extract() {
*://*.tar*|*://*.tgz) *://*.tar*|*://*.tgz)
tar xf "$src_dir/$1/${src##*/}" -C "./$dest" \ tar xf "$src_dir/$1/${src##*/}" -C "./$dest" \
--strip-components 1 \ --strip-components 1 \
|| die "[$1]: Couldn't extract ${src##*/}" || die "[$1] Couldn't extract ${src##*/}"
;; ;;
# Local files (Any source that is non-remote is assumed to be local). # Local files (Any source that is non-remote is assumed to be local).
@ -205,7 +205,7 @@ pkg_extract() {
cp -f "$src_dir/$1/${src##*/}" "./$dest" cp -f "$src_dir/$1/${src##*/}" "./$dest"
else else
die "[$1]: Local file $src not found" die "[$1] Local file $src not found"
fi fi
;; ;;
esac esac
@ -258,7 +258,7 @@ pkg_verify() {
# Compare the checksums using 'cmp'. # Compare the checksums using 'cmp'.
cmp -s "$cac_dir/c-$1" "$repo_dir/checksums" || { cmp -s "$cac_dir/c-$1" "$repo_dir/checksums" || {
log "[$1]: Checksum mismatch" log "[$1] Checksum mismatch"
# Instead of dying above, log it to the terminal. Also define a # Instead of dying above, log it to the terminal. Also define a
# variable so we *can* die after all checksum files have been # variable so we *can* die after all checksum files have been
@ -279,7 +279,7 @@ pkg_strip() {
# Package has stripping disabled, stop here. # Package has stripping disabled, stop here.
[ -f "$repo_dir/nostrip" ] && return [ -f "$repo_dir/nostrip" ] && return
log "[$1]: Stripping binaries and libraries" log "[$1] Stripping binaries and libraries"
# Strip only files matching the below mime-types from the package # Strip only files matching the below mime-types from the package
# directory. No alternative to 'file' here sadly. # directory. No alternative to 'file' here sadly.
@ -311,7 +311,7 @@ pkg_fixdeps() {
# redefines the argument list. # redefines the argument list.
pkg_name=$1 pkg_name=$1
log "[$1]: Checking 'ldd' for missing dependencies" log "[$1] Checking 'ldd' for missing dependencies"
# Go to the directory containing the built package to # Go to the directory containing the built package to
# simplify path building. # simplify path building.
@ -376,7 +376,7 @@ pkg_manifest() (
# Generate the package's manifest file. This is a list of each file # Generate the package's manifest file. This is a list of each file
# and directory inside the package. The file is used when uninstalling # and directory inside the package. The file is used when uninstalling
# packages, checking for package conflicts and for general debugging. # packages, checking for package conflicts and for general debugging.
log "[$1]: Generating manifest" log "[$1] Generating manifest"
# This funcion runs as a sub-shell to avoid having to 'cd' back to the # This funcion runs as a sub-shell to avoid having to 'cd' back to the
# prior directory before being able to continue. # prior directory before being able to continue.
@ -388,13 +388,13 @@ pkg_manifest() (
find . -mindepth 1 -type d -exec printf '%s/\n' {} + -or -print | find . -mindepth 1 -type d -exec printf '%s/\n' {} + -or -print |
sort -r | sed -e ss.ss > "$pkg_dir/$1/$pkg_db/$1/manifest" sort -r | sed -e ss.ss > "$pkg_dir/$1/$pkg_db/$1/manifest"
log "[$1]: Generated manifest" log "[$1] Generated manifest"
) )
pkg_tar() { pkg_tar() {
# Create a tar-ball from the built package's files. # Create a tar-ball from the built package's files.
# This tar-ball also contains the package's database entry. # This tar-ball also contains the package's database entry.
log "[$1]: Creating tar-ball" log "[$1] Creating tar-ball"
# Find the package's repository files. This needs to keep # Find the package's repository files. This needs to keep
# happening as we can't store this data in any kind of data # happening as we can't store this data in any kind of data
@ -408,9 +408,9 @@ pkg_tar() {
# is used here to correct issues with file ownership. # is used here to correct issues with file ownership.
fakeroot \ fakeroot \
tar zpcf "$bin_dir/$1#$version-$release.tar.gz" -C "$pkg_dir/$1" . || tar zpcf "$bin_dir/$1#$version-$release.tar.gz" -C "$pkg_dir/$1" . ||
die "[$1]: Failed to create tar-ball" die "[$1] Failed to create tar-ball"
log "[$1]: Successfully created tar-ball" log "[$1] Successfully created tar-ball"
} }
pkg_build() { pkg_build() {
@ -490,7 +490,7 @@ pkg_build() {
# This calls 'args' to inherit a root check and call # This calls 'args' to inherit a root check and call
# to 'sudo' to elevate permissions. # to 'sudo' to elevate permissions.
[ -f "$bin_dir/$pkg#$version-$release.tar.gz" ] && { [ -f "$bin_dir/$pkg#$version-$release.tar.gz" ] && {
log "[$pkg]: Found pre-built binary, installing" log "[$pkg] Found pre-built binary, installing"
args i "$bin_dir/$pkg#$version-$release.tar.gz" args i "$bin_dir/$pkg#$version-$release.tar.gz"
continue continue
} }
@ -509,7 +509,7 @@ pkg_build() {
# Ensure that checksums exist prior to building the package. # Ensure that checksums exist prior to building the package.
[ -f "$repo_dir/checksums" ] || { [ -f "$repo_dir/checksums" ] || {
log "[$pkg]: Checksums are missing" log "[$pkg] Checksums are missing"
# Instead of dying above, log it to the terminal. Also define a # Instead of dying above, log it to the terminal. Also define a
# variable so we *can* die after all checksum files have been # variable so we *can* die after all checksum files have been
@ -546,13 +546,13 @@ pkg_build() {
# Move to the build directory and call the build script. # Move to the build directory and call the build script.
cd "$mak_dir/$pkg" cd "$mak_dir/$pkg"
fakeroot "$repo_dir/build" "$pkg_dir/$pkg" || fakeroot "$repo_dir/build" "$pkg_dir/$pkg" ||
die "[$pkg]: Build failed" die "[$pkg] Build failed"
# Copy the repository files to the package directory. # Copy the repository files to the package directory.
# This acts as the database entry. # This acts as the database entry.
cp -Rf "$repo_dir" "$pkg_dir/$pkg/$pkg_db/" cp -Rf "$repo_dir" "$pkg_dir/$pkg/$pkg_db/"
log "[$pkg]: Successfully built package" log "[$pkg] Successfully built package"
# Create the manifest file early and make it empty. # Create the manifest file early and make it empty.
# This ensure that the manifest is added to the manifest... # This ensure that the manifest is added to the manifest...
@ -617,12 +617,12 @@ pkg_checksums() {
# Die here if source for some reason, doesn't exist. # Die here if source for some reason, doesn't exist.
[ "$src_path" ] || [ "$src_path" ] ||
die "[$1]: Couldn't find source '$src'" die "[$1] Couldn't find source '$src'"
# An easy way to get 'sha256sum' to print with the 'basename' # An easy way to get 'sha256sum' to print with the 'basename'
# of files is to 'cd' to the file's directory beforehand. # of files is to 'cd' to the file's directory beforehand.
(cd "$src_path" && sha256sum "${src##*/}") || (cd "$src_path" && sha256sum "${src##*/}") ||
die "[$1]: Failed to generate checksums" die "[$1] Failed to generate checksums"
# Unset this variable so it isn't used again on a failed # Unset this variable so it isn't used again on a failed
# source. There's no 'local' keyword in POSIX sh. # source. There's no 'local' keyword in POSIX sh.
@ -635,7 +635,7 @@ pkg_checksums() {
pkg_conflicts() { pkg_conflicts() {
# Check to see if a package conflicts with another. # Check to see if a package conflicts with another.
# This function takes a path to a KISS tar-ball as an argument. # This function takes a path to a KISS tar-ball as an argument.
log "[$2]: Checking for package conflicts" log "[$2] Checking for package conflicts"
# Extract manifest from the tar-ball and only extract files entries. # Extract manifest from the tar-ball and only extract files entries.
tar xf "$1" -O "./$pkg_db/$2/manifest" | tar xf "$1" -O "./$pkg_db/$2/manifest" |
@ -669,7 +669,7 @@ pkg_remove() {
# The package is not installed, don't do anything. # The package is not installed, don't do anything.
pkg_list "$1" >/dev/null || { pkg_list "$1" >/dev/null || {
log "[$1]: Not installed" log "[$1] Not installed"
return return
} }
@ -688,8 +688,8 @@ pkg_remove() {
set -f set -f
[ "$required_by" ] && [ "$required_by" ] &&
die "[$1]: Package is required by ${required_by%, }" \ die "[$1] Package is required by ${required_by%, }" \
"[$1]: Aborting here..." "[$1] Aborting here..."
# 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
@ -705,7 +705,7 @@ pkg_remove() {
rmdir "$KISS_ROOT/$file" 2>/dev/null || continue rmdir "$KISS_ROOT/$file" 2>/dev/null || continue
else else
rm -f -- "$KISS_ROOT/$file" || rm -f -- "$KISS_ROOT/$file" ||
log "[$1]: Failed to remove '$file'" log "[$1] Failed to remove '$file'"
fi fi
done < "$KISS_ROOT/$pkg_db/$1/manifest" done < "$KISS_ROOT/$pkg_db/$1/manifest"
@ -713,7 +713,7 @@ pkg_remove() {
# we no longer need to block 'Ctrl+C'. # we no longer need to block 'Ctrl+C'.
trap pkg_clean EXIT INT trap pkg_clean EXIT INT
log "[$1]: Removed successfully" log "[$1] Removed successfully"
} }
pkg_install() { pkg_install() {
@ -759,9 +759,9 @@ pkg_install() {
# Extract the tar-ball to catch any errors before installation begins. # Extract the tar-ball to catch any errors before installation begins.
tar pxf "$tar_file" -C "$tar_dir/$pkg_name" || tar pxf "$tar_file" -C "$tar_dir/$pkg_name" ||
die "[$pkg_name]: Failed to extract tar-ball" die "[$pkg_name] Failed to extract tar-ball"
log "[$pkg_name]: Checking that all dependencies are installed" log "[$pkg_name] Checking that all dependencies are installed"
# Make sure that all run-time dependencies are installed prior to # Make sure that all run-time dependencies are installed prior to
# installing the package. # installing the package.
@ -773,10 +773,10 @@ pkg_install() {
done < "$tar_dir/$pkg_name/$pkg_db/$pkg_name/depends" done < "$tar_dir/$pkg_name/$pkg_db/$pkg_name/depends"
[ "$required_install" ] && [ "$required_install" ] &&
die "[$1]: Package requires ${required_install%, }" \ die "[$1] Package requires ${required_install%, }" \
"[$1]: Aborting here" "[$1]: Aborting here"
log "[$pkg_name]: Installing package" log "[$pkg_name] Installing package"
# Block being able to abort the script with 'Ctrl+C' during installation. # Block being able to abort the script with 'Ctrl+C' during installation.
# Removes all risk of the user aborting a package installation leaving # Removes all risk of the user aborting a package installation leaving
@ -830,11 +830,11 @@ pkg_install() {
# Run the post install script and suppress errors. If it exists, # Run the post install script and suppress errors. If it exists,
# it will run, else nothing will happen. # it will run, else nothing will happen.
[ -x "$KISS_ROOT/$pkg_db/$pkg_name/post-install" ] && { [ -x "$KISS_ROOT/$pkg_db/$pkg_name/post-install" ] && {
log "[$pkg_name]: Running post-install script" log "[$pkg_name] Running post-install script"
"$KISS_ROOT/$pkg_db/$pkg_name/post-install" ||: "$KISS_ROOT/$pkg_db/$pkg_name/post-install" ||:
} }
log "[$pkg_name]: Installed successfully" log "[$pkg_name] Installed successfully"
done done
} }
@ -857,7 +857,7 @@ pkg_updates() {
cd "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null ||: cd "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null ||:
[ -d .git ] || { [ -d .git ] || {
log "[$repo]: Not a git repository, skipping" log "[$repo] Not a git repository, skipping"
continue continue
} }
@ -867,12 +867,12 @@ pkg_updates() {
*) *)
repos="$repos $PWD " repos="$repos $PWD "
log "[$PWD]: Updating repository" log "[$PWD] Updating repository"
if [ -w "$PWD" ]; then if [ -w "$PWD" ]; then
git pull git pull
else else
log "[$PWD]: Need root to update" log "[$PWD] Need root to update"
sudo git pull sudo git pull
fi fi
;; ;;
@ -975,7 +975,7 @@ args() {
for pkg; do for pkg; do
pkg_checksums "$pkg" > "$(pkg_search "$pkg")/checksums" pkg_checksums "$pkg" > "$(pkg_search "$pkg")/checksums"
log "[$pkg]: Generated checksums" log "[$pkg] Generated checksums"
done done
;; ;;
@ -1040,7 +1040,7 @@ args() {
for pkg in $remove_pkgs; do for pkg in $remove_pkgs; do
pkg_list "$pkg" >/dev/null || pkg_list "$pkg" >/dev/null ||
die "[$pkg]: Not installed" die "[$pkg] Not installed"
pkg_remove "$pkg" check pkg_remove "$pkg" check
done done