forked from kiss-community/kiss
kiss: Merge kiss-utils and kiss
This commit is contained in:
parent
2347c22bf8
commit
49cfb7cac2
14
README.md
14
README.md
@ -134,4 +134,16 @@ export MAKEFLAGS=
|
||||
|
||||
## Extending the package manager
|
||||
|
||||
See: https://github.com/kisslinux/kiss-utils
|
||||
The `contrib` directory contains a set of simple scripts to extend the package manager.
|
||||
|
||||
- `kiss-chroot`: Enter a KISS `chroot`.
|
||||
- `kiss-depends-finder`: Find missing dependencies by parsing 'ldd'.
|
||||
- `kiss-depends`: Display a package's dependencies.
|
||||
- `kiss-export`: Turn an installed package into a KISS tarball.
|
||||
- `kiss-manifest-tree`: Display all files as tree owned by a package.
|
||||
- `kiss-manifest`: Display all files owned by a package.
|
||||
- `kiss-maintainer`: Display the package maintainers.
|
||||
- `kiss-orphans`: List orphaned packages.
|
||||
- `kiss-owns`: Check which package owns a file.
|
||||
- `kiss-revdepends`: Display packages which depend on package.
|
||||
- `kiss-size`: Show the size on disk for an installed package.
|
||||
|
58
contrib/kiss-chroot
Executable file
58
contrib/kiss-chroot
Executable file
@ -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 "$@"
|
13
contrib/kiss-depends
Executable file
13
contrib/kiss-depends
Executable file
@ -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"
|
46
contrib/kiss-depends-finder
Executable file
46
contrib/kiss-depends-finder
Executable file
@ -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"
|
17
contrib/kiss-export
Executable file
17
contrib/kiss-export
Executable file
@ -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"
|
||||
)
|
8
contrib/kiss-maintainer
Executable file
8
contrib/kiss-maintainer
Executable file
@ -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
|
||||
}
|
13
contrib/kiss-manifest
Executable file
13
contrib/kiss-manifest
Executable file
@ -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"
|
14
contrib/kiss-manifest-tree
Executable file
14
contrib/kiss-manifest-tree
Executable file
@ -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
|
17
contrib/kiss-orphans
Executable file
17
contrib/kiss-orphans
Executable file
@ -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
|
25
contrib/kiss-owns
Executable file
25
contrib/kiss-owns
Executable file
@ -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'"
|
8
contrib/kiss-repodepends
Executable file
8
contrib/kiss-repodepends
Executable file
@ -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
|
10
contrib/kiss-revdepends
Executable file
10
contrib/kiss-revdepends
Executable file
@ -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
|
21
contrib/kiss-size
Executable file
21
contrib/kiss-size
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user