1
0
mirror of https://codeberg.org/kiss-community/kiss synced 2024-12-25 08:30:05 -07:00

kiss: Clean up fixdeps()

This commit is contained in:
Dylan Araps 2020-05-22 12:40:09 +03:00
parent 87cc8c726e
commit a747565ef4
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E

72
kiss
View File

@ -5,7 +5,21 @@
# in KISS Linux (https://k1ss.org). # in KISS Linux (https://k1ss.org).
# #
# [1] Warnings related to word splitting and globbing are disabled. # [1] Warnings related to word splitting and globbing are disabled.
# All word splitting in this script is *safe* and intentional. # All word splitting in this script is *safe* and intentional.
#
# [2] Information is grabbed from 'ls -ld' output.
#
# This is fine _despite_ the usual gaggle about 'ls' and its
# use in scripting. The POSIX specification states that the
# link target must be the exact contents of the link.
#
# The specification:
#
# > If the file is a symbolic link and the -L option is not
# specified, this information shall be about the link
# itself and the <pathname> field shall be of the form:
#
# > "%s -> %s", <pathname of link>, <contents of link>
# #
# Created by Dylan Araps. # Created by Dylan Araps.
@ -60,14 +74,8 @@ as_root() {
} }
file_owner() { file_owner() {
# Grab the owner of the file/directory via 'ls -ld'. This is # Grab the owner of the file/directory via 'ls -ld'
# fine despite the usual gabble about 'ls' and its usage in scripts. # See: [1] and [2] at top of script.
#
# Grabbing permissions, ownership or symlink targets from 'ls -l'
# output is totally fine and doesn't suffer from the disconnect
# between the real and display representation of the information.
#
# Globbing is disabled and word splitting is intentional here.
# shellcheck disable=2046 # shellcheck disable=2046
set -- $(ls -ld "$1"); user=${3:-root} set -- $(ls -ld "$1"); user=${3:-root}
@ -474,49 +482,24 @@ pkg_fixdeps() {
while read -r file; do while read -r file; do
# Run 'ldd' on the file and parse each line. The code then checks to # Run 'ldd' on the file and parse each line. The code then checks to
# see which packages own the linked libraries and it prints the result. # see which packages own the linked 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'. # Resolve path symlinks to find the real location to the library.
[ "${dep##*ldd*}" ] || continue cd -P "${dep%/*}" 2>/dev/null || continue
# Extract the file path from 'ldd' output.
dep=${dep#* => } dep=${dep% *} old_PWD=$PWD
# False positive (we need to modify PWD).
# shellcheck disable=2030
cd -P "${dep%/*}" 2>/dev/null || PWD=${1%/*}
# 'ls' is used to obtain the target of the symlink. # 'ls' is used to obtain the target of the symlink.
# # See: [2] at top of script.
# This is fine _despite_ the usual gaggle about 'ls' and its
# use in scripting. The POSIX specification states that the
# link target must be the exact contents of the link.
#
# The specification:
#
# > If the file is a symbolic link and the -L option is not
# specified, this information shall be about the link
# itself and the <pathname> field shall be of the form:
#
# > "%s -> %s", <pathname of link>, <contents of link>
lso=$(ls -ld "$PWD/${dep##*/}" 2>/dev/null) && lso=$(ls -ld "$PWD/${dep##*/}" 2>/dev/null) &&
case $lso in *' -> '*) case $lso in *' -> '*) lso=${lso##* -> } dep=$PWD/${lso##*/}; esac
lso=${lso##*" -> "} dep=$PWD/${lso##*/}
esac
# We need to go back to where we came from as the old PWD
# stores the name of the current package.
cd "$old_PWD"
# Figure out which package owns the file. # Figure out which package owns the file.
own=$(grep -lFx "${dep##$KISS_ROOT}" "$@") dep=$(grep -lFx "${dep##$KISS_ROOT}" "$@")
own=${own%/*} own=${own##*/} dep=${dep%/*} dep=${dep##*/}
# Skip listing these packages as dependencies. # Skip listing these packages as dependencies.
case $own in musl|gcc|llvm|"${PWD##*/}"|"${PWD##*/}-bin"|"") case $dep in
continue musl|gcc|llvm|"${OLDPWD##*/}"|"${OLDPWD##*/}-bin"|"") ;;
*) printf '%s\n' "$dep"
esac esac
printf '%s\n' "$own"
done ||: done ||:
done >> depends done >> depends
@ -962,6 +945,7 @@ pkg_install_files() {
while read -r line; do while read -r line; do
# Grab the octal permissions so that directory creation # Grab the octal permissions so that directory creation
# preserves permissions. # preserves permissions.
# See: [2] at top of script.
rwx=$(ls -ld "$2/$line") oct='' b='' o=0 rwx=$(ls -ld "$2/$line") oct='' b='' o=0
# Convert the output of 'ls' (rwxrwx---) to octal. This is simply # Convert the output of 'ls' (rwxrwx---) to octal. This is simply