diff options
author | dylan.araps@gmail.com <dylan.araps@gmail.com> | 2019-10-30 10:51:47 +0000 |
---|---|---|
committer | dylan.araps@gmail.com <dylan.araps@gmail.com> | 2019-10-30 10:51:47 +0000 |
commit | b1bede47810652d3fe72fba66d9a1afce391eef7 (patch) | |
tree | 78758763038103e56fa956f9579d2cbd237078d3 /contrib | |
parent | 7b1b13cfbf82f38cc7bb1a587c579230bd3c659d (diff) | |
download | cpt-b1bede47810652d3fe72fba66d9a1afce391eef7.tar.gz |
kiss: Merge kiss-utils and kiss
FossilOrigin-Name: 6cabd29074b5abe15dd342797d3fc9b0c0271b3e001f388b360a3ee91b4a40ba
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/kiss-chroot | 58 | ||||
-rwxr-xr-x | contrib/kiss-depends | 13 | ||||
-rwxr-xr-x | contrib/kiss-depends-finder | 46 | ||||
-rwxr-xr-x | contrib/kiss-export | 17 | ||||
-rwxr-xr-x | contrib/kiss-maintainer | 8 | ||||
-rwxr-xr-x | contrib/kiss-manifest | 13 | ||||
-rwxr-xr-x | contrib/kiss-manifest-tree | 14 | ||||
-rwxr-xr-x | contrib/kiss-orphans | 17 | ||||
-rwxr-xr-x | contrib/kiss-owns | 25 | ||||
-rwxr-xr-x | contrib/kiss-repodepends | 8 | ||||
-rwxr-xr-x | contrib/kiss-revdepends | 10 | ||||
-rwxr-xr-x | contrib/kiss-size | 21 |
12 files changed, 250 insertions, 0 deletions
diff --git a/contrib/kiss-chroot b/contrib/kiss-chroot new file mode 100755 index 0000000..372ef0a --- /dev/null +++ b/contrib/kiss-chroot @@ -0,0 +1,58 @@ +#!/bin/sh -e +# +# kiss-chroot: Enter a chroot. + +log() { + printf '\033[32m->\033[m %s.\n' "$*" +} + +die() { + log "$*" >&2 + exit 1 +} + +clean() { + log Unmounting /dev, /proc and /sys from chroot; { + umount "$1/dev" ||: + umount "$1/proc" ||: + umount "$1/sys" ||: + } + + log Cleaning leftover host files; { + rm -f "$1/root/.ash_history" + rm -f "$1/etc/resolv.conf" + } +} + +main() { + [ -z "$1" ] && die Need a path to the chroot + [ -d "$1" ] || die Given path does not exist + [ "$(id -u)" = 0 ] || die Script needs to be run as root + + trap 'clean "$1"' EXIT INT + + log Mounting /dev, /proc and /sys from host; { + mountpoint -q "$1/dev" || mount -o bind /dev "$1/dev" + mountpoint -q "$1/proc" || mount -t proc proc "$1/proc" + mountpoint -q "$1/sys" || mount -t sysfs sys "$1/sys" + + } + + log Copying /etc/resolv.conf from host; { + cp /etc/resolv.conf "$1/etc" + } + + log Entering chroot; { + chroot "$1" /usr/bin/env -i \ + HOME=/root \ + TERM="$TERM" \ + SHELL=/bin/sh \ + USER=root \ + CFLAGS="-march=x86-64 -mtune=generic -pipe -Os" \ + CXXFLAGS="-march=x86-64 -mtune=generic -pipe -Os" \ + MAKEFLAGS="-j$(nproc 2>/dev/null || echo 1)" \ + /bin/sh -l + } +} + +main "$@" diff --git a/contrib/kiss-depends b/contrib/kiss-depends new file mode 100755 index 0000000..22a1d4e --- /dev/null +++ b/contrib/kiss-depends @@ -0,0 +1,13 @@ +#!/bin/sh -ef +# +# kiss-depends - Display a package's dependencies. + +db_dir=$KISS_ROOT/var/db/kiss/installed/${1-null} + +# Check if package is installed and exit if it is not. +[ -d "$db_dir" ] || { + printf '%s\n' "error: '$1' not installed." >&2 + exit 1 +} + +[ -f "$db_dir/depends" ] && cat "$db_dir/depends" diff --git a/contrib/kiss-depends-finder b/contrib/kiss-depends-finder new file mode 100755 index 0000000..3a7f88b --- /dev/null +++ b/contrib/kiss-depends-finder @@ -0,0 +1,46 @@ +#!/bin/sh -e +# +# Find missing dependencies by parsing 'ldd'. + +db_dir=$KISS_ROOT/var/db/kiss/installed + +# Check if package is installed and exit if it is not. +[ -d "$db_dir/${1-null}" ] || { + printf '%s\n' "error: '$1' not installed." >&2 + exit 1 +} + +printf '%s\n' "=> Detected dependencies:" + +while read -r file; do + # Skip directories. + [ -d "$KISS_ROOT/$file" ] && continue + + ldd "$KISS_ROOT/$file" 2>/dev/null | while read -r dep; do + # Skip lines containing 'ldd'. + [ "${dep##*ldd*}" ] || continue + + # Extract the file path from 'ldd' output. + dep=${dep#* => } + dep=${dep% *} + + # Traverse symlinks to get the true path to the file. + pkg=$(readlink -f "$KISS_ROOT/${dep##$KISS_ROOT}") + + # Figure out which package owns the file. + pkg=$(grep -lFx "${pkg##$KISS_ROOT}" "$db_dir/"*/manifest) + pkg=${pkg%/*} + pkg=${pkg##*/} + + case $pkg in + # Skip listing these packages as dependencies. + musl|gcc|$1) ;; + *) printf '%s\n' "$pkg" ;; + esac + done & +done < "$db_dir/$1/manifest" | sort | uniq + +printf '\n%s\n' "=> Package dependencies:" + +[ -f "$db_dir/$1/depends" ] && + cat "$db_dir/$1/depends" diff --git a/contrib/kiss-export b/contrib/kiss-export new file mode 100755 index 0000000..e8da80f --- /dev/null +++ b/contrib/kiss-export @@ -0,0 +1,17 @@ +#!/bin/sh -ef +# +# kiss-export - Turn an installed package into a KISS tarball. + +read -r ver rel 2>/dev/null < "$KISS_ROOT/var/db/kiss/installed/$1/version" || { + printf '%s\n' "error: '$1' is not installed." >&2 + exit 1 +} + +# This warning is safe to ignore as globs are disabled and +# word splitting is intentional. +# shellcheck disable=2046 +tar czvf "$1#$ver-$rel.tar.gz" -C / -- $( + while read -r file; do + [ -d "$KISS_ROOT/$file" ] || printf '%s\n' ".$file" + done < "$KISS_ROOT/var/db/kiss/installed/$1/manifest" +) diff --git a/contrib/kiss-maintainer b/contrib/kiss-maintainer new file mode 100755 index 0000000..a8bc19c --- /dev/null +++ b/contrib/kiss-maintainer @@ -0,0 +1,8 @@ +#!/bin/sh -e +# +# kiss-maintainer - find the maintainer of a package. + +kiss s "$1" >/dev/null && { + cd "$(kiss s "$1")" + git log . 2>/dev/null | grep -F Author: | sort -u +} diff --git a/contrib/kiss-manifest b/contrib/kiss-manifest new file mode 100755 index 0000000..74cd380 --- /dev/null +++ b/contrib/kiss-manifest @@ -0,0 +1,13 @@ +#!/bin/sh -ef +# +# kiss-manifest - Display all files owned by a package. + +db_dir=$KISS_ROOT/var/db/kiss/installed/${1-null} + +# Check if package is installed and exit if it is not. +[ -d "$db_dir" ] || { + printf '%s\n' "error: '$1' not installed." >&2 + exit 1 +} + +cat "$db_dir/manifest" diff --git a/contrib/kiss-manifest-tree b/contrib/kiss-manifest-tree new file mode 100755 index 0000000..995af9d --- /dev/null +++ b/contrib/kiss-manifest-tree @@ -0,0 +1,14 @@ +#!/bin/sh -ef +# +# kiss-manifest-tree - Display all files owned by a package. + +db_dir=$KISS_ROOT/var/db/kiss/installed/${1-null} + +# Check if package is installed and exit if it is not. +[ -d "$db_dir" ] || { + printf '%s\n' "error: '$1' not installed." >&2 + exit 1 +} + +printf '%s\n' "[$1]:" +tree -C --fromfile "$db_dir/manifest" | tail -n +2 diff --git a/contrib/kiss-orphans b/contrib/kiss-orphans new file mode 100755 index 0000000..a1f0894 --- /dev/null +++ b/contrib/kiss-orphans @@ -0,0 +1,17 @@ +#!/bin/sh -e +# +# kiss-orphans - List orphaned packages. + +cd "$KISS_ROOT/var/db/kiss/installed/" + +for pkg in *; do + # Skip these packages. + case $pkg in + baseinit|baselayout|gcc|pkgconf|e2fsprogs|\ + make|busybox|bzip2|grub|automake) + continue + ;; + esac + + grep -q "^$pkg$" ./*/depends || printf '%s\n' "$pkg" +done diff --git a/contrib/kiss-owns b/contrib/kiss-owns new file mode 100755 index 0000000..249c52c --- /dev/null +++ b/contrib/kiss-owns @@ -0,0 +1,25 @@ +#!/bin/sh -e +# +# kiss-owns - Check which package owns a file. + +# Strip 'KISS_ROOT' from the file path if passed and +# follow symlinks. +file=$(readlink -f "$KISS_ROOT/${1##$KISS_ROOT}") + +# Check if the file exists and exit if it is not. +[ -f "$file" ] || { + printf '%s\n' "error: file '$1' doesn't exist." >&2 + exit 1 +} + +# Print the full path to the manifest file which contains +# the match to our search. +pkg_owns=$(grep -lFx "${file##$KISS_ROOT}" \ + "$KISS_ROOT/var/db/kiss/installed/"*/manifest) + + +# Extract the package name from the path above. +pkg_owns=${pkg_owns%/*} +pkg_owns=${pkg_owns##*/} + +printf '%s\n' "[$pkg_owns] owns '$1'" diff --git a/contrib/kiss-repodepends b/contrib/kiss-repodepends new file mode 100755 index 0000000..f56c2cb --- /dev/null +++ b/contrib/kiss-repodepends @@ -0,0 +1,8 @@ +#!/bin/sh +# +# kiss-repodepends + +# Disable this warning as the output +# from 'kiss s' is intended to be split. +# shellcheck disable=2046 +cat $(kiss s "$1")/depends 2>/dev/null diff --git a/contrib/kiss-revdepends b/contrib/kiss-revdepends new file mode 100755 index 0000000..5a181e5 --- /dev/null +++ b/contrib/kiss-revdepends @@ -0,0 +1,10 @@ +#!/bin/sh -e +# +# kiss-revdepends - Display packages which depend on package. + +# 'cd' to the database directory as a simple way of +# stripping the path and performing a 'basename'. +cd "$KISS_ROOT/var/db/kiss/installed" + +# Use a simple 'grep' to display packages depending on '$1'. +grep "^$1" -- */depends diff --git a/contrib/kiss-size b/contrib/kiss-size new file mode 100755 index 0000000..72365a4 --- /dev/null +++ b/contrib/kiss-size @@ -0,0 +1,21 @@ +#!/bin/sh -ef +# +# kiss-size - Show the size on disk for a package. + +db_dir=$KISS_ROOT/var/db/kiss/installed/${1-null} + +# Check if package is installed and exit if it is not. +[ -d "$db_dir" ] || { + printf '%s\n' "error: '$1' not installed." >&2 + exit 1 +} + +# Filter directories from manifest and leave only files. +# Directories in the manifest end in a trailing '/'. +files=$(sed 's|.*/$||' "$db_dir/manifest") + +# Send the file list to 'du'. +# This unquoted variable is safe as word splitting is intended +# and globbing is globally disabled in this script. +# shellcheck disable=2086 +du -shc -- $files 2>/dev/null |