aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2020-05-14 10:45:18 +0000
committermerakor <cem@ckyln.com>2020-05-14 10:45:18 +0000
commit0f9b1f4c75317680989aa4a44a32e6efe256dd56 (patch)
treee3c39e9b358982229fb0cffd7643f48644fa78a4
parent6a4e02766624574ddbafe87472afd1a47de8e090 (diff)
downloadcpt-0f9b1f4c75317680989aa4a44a32e6efe256dd56.tar.gz
kiss: don't elevate permissions if it isn't required, KISS_ROOT fix
Co-authored-by: Dylan Araps <dylan.araps@gmail.com> FossilOrigin-Name: d111e5f22b95c4688390daf2dc7c24cdc1316648e991a7c5be9e6de1d12ab184
-rwxr-xr-xkiss22
1 files changed, 12 insertions, 10 deletions
diff --git a/kiss b/kiss
index 6a61ea5..39aea51 100755
--- a/kiss
+++ b/kiss
@@ -800,9 +800,10 @@ pkg_conflicts() {
# (/bin/ls -> /usr/bin/ls).
while read -r file; do
case $file in */) continue; esac
+ dirname="$(kiss-readlink "$KISS_ROOT/${file%/*}" 2>/dev/null)"
printf '%s/%s\n' \
- "$(kiss-readlink "$KISS_ROOT/${file%/*}" 2>/dev/null)" \
+ "${dirname#$KISS_ROOT}" \
"${file##*/}"
done < "$tar_dir/$1/$pkg_db/$1/manifest" > "$KISS_TMPDIR/$pid-m"
@@ -928,16 +929,16 @@ pkg_swap() {
# Convert the current owner to an alternative and rewrite
# its manifest file to reflect this. We then resort this file
# so no issues arise when removing packages.
- cp -Pf "$2" "$pkg_owns>${alt#*>}"
- sed "s#^$2#$PWD/$pkg_owns>${alt#*>}#" \
+ cp -Pf "$KISS_ROOT/$2" "$pkg_owns>${alt#*>}"
+ sed "s#^$2#${PWD#$KISS_ROOT}/$pkg_owns>${alt#*>}#" \
"../installed/$pkg_owns/manifest" |
sort -r -o "../installed/$pkg_owns/manifest"
fi
# Convert the desired alternative to a real file and rewrite
# the manifest file to reflect this. The reverse of above.
- mv -f "$alt" "$2"
- sed "s#^$PWD/$alt#$2#" "../installed/$1/manifest" |
+ mv -f "$alt" "$KISS_ROOT/$2"
+ sed "s#^${PWD#$KISS_ROOT}/$alt#$2#" "../installed/$1/manifest" |
sort -r -o "../installed/$1/manifest"
}
@@ -1117,7 +1118,7 @@ pkg_install() {
# This is repeated multiple times. Better to make it a function.
pkg_rsync() {
- rsync --chown=root:root --chmod=Du-s,Dg-s,Do-s \
+ rsync "--chown=$USER:$USER" --chmod=Du-s,Dg-s,Do-s \
-WhHKa --no-compress --exclude /etc "${1:---}" \
"$tar_dir/$pkg_name/" "$KISS_ROOT/"
}
@@ -1363,16 +1364,17 @@ args() {
a|alternatives)
# Rerun the script with 'su' if the user isn't root.
# Cheeky but 'su' can't be used on shell functions themselves.
- [ -z "$1" ] || [ "$uid" = 0 ] || {
+ [ -z "$1" ] || [ -w "$KISS_ROOT/" ] || [ "$uid" = 0 ] || {
as_root "$0" "$action" "$@"
return
}
;;
i|install|r|remove)
- # Rerun the script with 'su' if the user isn't root.
- # Cheeky but 'su' can't be used on shell functions themselves.
- [ "$uid" = 0 ] || {
+ # Rerun the script with 'su' if the user does not have write
+ # permissions for the root. Cheeky but 'su' can't be used on
+ # shell functions themselves.
+ [ -w "$KISS_ROOT/" ] || [ "$uid" = 0 ] || {
KISS_FORCE="$KISS_FORCE" as_root "$0" "$action" "$@"
return
}