From fa40f51a4910dabeaff579f80777da920feb6b0c Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 26 Jun 2019 19:27:36 +0300 Subject: [PATCH 1/7] kiss: Fix package installation bugs. --- kiss | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/kiss b/kiss index a31e9e4..6dc8cb8 100755 --- a/kiss +++ b/kiss @@ -20,8 +20,9 @@ source_type() { } pkg_clean() { - rm -rf -- "$mak_dir" "$pkg_dir" \ - "$cac_dir/manifest-$$" "$cac_dir/tar" "$cac_dir/checksums-$$" + rm -rf -- "$mak_dir" "$pkg_dir" "$tar_dir" \ + "$cac_dir/manifest-$$" "$cac_dir/checksums-$$" \ + "$cac_dir/mv" "$cac_dir/mkdir" "$cac_dir/find" } pkg_search() { @@ -154,8 +155,13 @@ pkg_conflicts() { # Extract manifest from tarball and strip directories. tar xf "$bin_dir/$pkg" -O "./var/db/$kiss/$name/manifest" | while read -r line; do - [ "${line%%*/}" ] && printf '%s\n' "$line" >> "$cac_dir/manifest-$$" - done + [ "${line%%*/}" ] && { + printf '%s\n' "$line" >> "$cac_dir/manifest-$$" + continue + } + + [ ! -f "$sys_dir$line" ] || die "Conflict: $line already exists." + done || die "Found file conflicts." # Compare extracted manifest to all installed manifests. # If there are matching lines (files) there's a package @@ -173,14 +179,34 @@ pkg_install() { pkg_conflicts - # Create a backup of 'tar' so it isn't removed during - # package installation. - cp "$(command -v tar)" "$cac_dir" + # Create a backup of 'mv', 'mkdir' and 'find' so they aren't removed + # during package removal. + cp "$(command -v mv)" "$cac_dir" + cp "$(command -v mkdir)" "$cac_dir" + cp "$(command -v find)" "$cac_dir" log "Removing previous version of package if it exists." pkg_remove - "$cac_dir/tar" kpxf "$bin_dir/$pkg" -C "$sys_dir/" 2>/dev/null + tar pxf "$bin_dir/$pkg" -C "$tar_dir/" + + cd "$tar_dir" || die "Aborting due to tar error." + + find ./ -mindepth 1 -type d | while read -r dir; do + mkdir -p "$sys_dir/${dir#./}" + done + + find ./ -mindepth 1 -not -type d | while read -r file; do + rpath=${file#.} + + case $rpath in + /etc/*) [ -f "$sys_dir${rpath%/*}" ] || mv=1 ;; + *) mv=1 ;; + esac + + [ "$mv" ] && mv "$file" "$sys_dir${rpath%/*}" ;mv= + done + "$sys_db/$name/post-install" 2>/dev/null log "Installed ${pkg%.tar.gz}" @@ -201,11 +227,13 @@ pkg_remove() { "$cac_dir/rmdir" "$sys_dir$file" 2>/dev/null || continue else "$cac_dir/rm" -f -- "$sys_dir$file" || log "Failed to remove $file." - fi && log "Removed $file" + fi done < "$sys_db/${1:-$name}/manifest" # Use the backup of 'rm' to remove 'rmdir' and itself. "$cac_dir/rm" "$cac_dir/rmdir" "$cac_dir/rm" + + log "Removed ${pkg%.tar.gz}" } pkg_updates() { @@ -285,6 +313,7 @@ main() { mkdir -p "${cac_dir:=${XDG_CACHE_HOME:=$HOME/.cache}/$kiss}" \ "${mak_dir:=$cac_dir/build-$$}" \ "${bin_dir:=$cac_dir/bin}" \ + "${tar_dir:=$cac_dir/extract-$$}" \ "${pkg_db:=${pkg_dir:=$cac_dir/pkg-$$}/var/db/$kiss}" || die "Couldn't create directories." From 2560ba5128ab62451e9c0e8498c808cf5606a859 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 26 Jun 2019 19:43:14 +0300 Subject: [PATCH 2/7] kiss: Fix /etc exclusion. --- kiss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kiss b/kiss index 6dc8cb8..d47abbc 100755 --- a/kiss +++ b/kiss @@ -200,7 +200,7 @@ pkg_install() { rpath=${file#.} case $rpath in - /etc/*) [ -f "$sys_dir${rpath%/*}" ] || mv=1 ;; + /etc/*) [ -f "$sys_dir${rpath%/*}/${file##*/}" ] || mv=1 ;; *) mv=1 ;; esac @@ -221,7 +221,7 @@ pkg_remove() { cp "$(command -v rmdir)" "$cac_dir" while read -r file; do - [ "${file%/*}" = /etc ] && continue + [ "${file##/etc/*}" ] || continue if [ -d "$sys_dir$file" ]; then "$cac_dir/rmdir" "$sys_dir$file" 2>/dev/null || continue From ee95bc1e1c5d9c6b850224a0409733be311c3653 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 26 Jun 2019 20:34:44 +0300 Subject: [PATCH 3/7] kiss: Optimize directory installation. --- kiss | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kiss b/kiss index d47abbc..67731e9 100755 --- a/kiss +++ b/kiss @@ -192,7 +192,8 @@ pkg_install() { cd "$tar_dir" || die "Aborting due to tar error." - find ./ -mindepth 1 -type d | while read -r dir; do + # Optimization: Only find the deepest directories. + find . -type d -links -3 -prune | while read -r dir; do mkdir -p "$sys_dir/${dir#./}" done @@ -258,7 +259,7 @@ pkg_list() { } args() { - [ -w "$KISS_ROOT/" ] || case $1 in + [ -w "$sys_dir/" ] || case $1 in i*|r*) die "No write permissions to \$KISS_ROOT." esac From d67048d4f8454f1ecb2a182fb6bfe9849e204254 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 26 Jun 2019 20:38:41 +0300 Subject: [PATCH 4/7] kiss: Remove tarball earlier. --- kiss | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kiss b/kiss index 67731e9..7580078 100755 --- a/kiss +++ b/kiss @@ -178,6 +178,7 @@ pkg_install() { [ -f "$bin_dir/$pkg" ] || args b "$name" pkg_conflicts + tar pxf "$bin_dir/$pkg" -C "$tar_dir/" || die "Failed to extract tarball." # Create a backup of 'mv', 'mkdir' and 'find' so they aren't removed # during package removal. @@ -188,8 +189,6 @@ pkg_install() { log "Removing previous version of package if it exists." pkg_remove - tar pxf "$bin_dir/$pkg" -C "$tar_dir/" - cd "$tar_dir" || die "Aborting due to tar error." # Optimization: Only find the deepest directories. @@ -234,7 +233,7 @@ pkg_remove() { # Use the backup of 'rm' to remove 'rmdir' and itself. "$cac_dir/rm" "$cac_dir/rmdir" "$cac_dir/rm" - log "Removed ${pkg%.tar.gz}" + log "Removed ${1:-name}." } pkg_updates() { From 69d79541068978864d9bd7a505cf81e66c5c2f5a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 26 Jun 2019 21:21:42 +0300 Subject: [PATCH 5/7] kiss: clean up --- kiss | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/kiss b/kiss index 7580078..7e38f14 100755 --- a/kiss +++ b/kiss @@ -199,12 +199,10 @@ pkg_install() { find ./ -mindepth 1 -not -type d | while read -r file; do rpath=${file#.} - case $rpath in - /etc/*) [ -f "$sys_dir${rpath%/*}/${file##*/}" ] || mv=1 ;; - *) mv=1 ;; - esac + [ -z "${rpath##/etc/*}" ] && [ -f "$sys_dir${rpath%/*}/${file##*/}" ] && + return - [ "$mv" ] && mv "$file" "$sys_dir${rpath%/*}" ;mv= + mv "$file" "$sys_dir${rpath%/*}" done "$sys_db/$name/post-install" 2>/dev/null @@ -233,7 +231,7 @@ pkg_remove() { # Use the backup of 'rm' to remove 'rmdir' and itself. "$cac_dir/rm" "$cac_dir/rmdir" "$cac_dir/rm" - log "Removed ${1:-name}." + log "Removed ${1:-$name}." } pkg_updates() { From 1260e75fb5f588c6bc3ba84e54f01c94ec0e8e1d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 26 Jun 2019 21:26:33 +0300 Subject: [PATCH 6/7] kiss: Remove file conflict check for now. --- kiss | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/kiss b/kiss index 7e38f14..b86b50d 100755 --- a/kiss +++ b/kiss @@ -155,12 +155,7 @@ pkg_conflicts() { # Extract manifest from tarball and strip directories. tar xf "$bin_dir/$pkg" -O "./var/db/$kiss/$name/manifest" | while read -r line; do - [ "${line%%*/}" ] && { - printf '%s\n' "$line" >> "$cac_dir/manifest-$$" - continue - } - - [ ! -f "$sys_dir$line" ] || die "Conflict: $line already exists." + [ "${line%%*/}" ] && printf '%s\n' "$line" >> "$cac_dir/manifest-$$" done || die "Found file conflicts." # Compare extracted manifest to all installed manifests. From d63a52f9d1e9984a71cba92abd60f15ba9555915 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 26 Jun 2019 21:27:28 +0300 Subject: [PATCH 7/7] kiss: Remove file conflict check for now. --- kiss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiss b/kiss index b86b50d..26a7977 100755 --- a/kiss +++ b/kiss @@ -156,7 +156,7 @@ pkg_conflicts() { tar xf "$bin_dir/$pkg" -O "./var/db/$kiss/$name/manifest" | while read -r line; do [ "${line%%*/}" ] && printf '%s\n' "$line" >> "$cac_dir/manifest-$$" - done || die "Found file conflicts." + done # Compare extracted manifest to all installed manifests. # If there are matching lines (files) there's a package