diff options
author | dylan.araps@gmail.com <dylan.araps@gmail.com> | 2019-06-26 16:27:36 +0000 |
---|---|---|
committer | dylan.araps@gmail.com <dylan.araps@gmail.com> | 2019-06-26 16:27:36 +0000 |
commit | 447861b03f128a79fd10f356157f1b47e5446103 (patch) | |
tree | c94c4c292263f5656f1e92ed2e95dfcc63acac11 | |
parent | be6762000d20259440247b4b2db51ab583179b7d (diff) | |
download | cpt-447861b03f128a79fd10f356157f1b47e5446103.tar.gz |
kiss: Fix package installation bugs.
FossilOrigin-Name: e97870b69f3501416be502fd67556007ed214ea30ff95e45e063e6b502f42ad2
-rwxr-xr-x | kiss | 47 |
1 files changed, 38 insertions, 9 deletions
@@ -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." |