From b94aa33b493b50906261aec4df824602d617d1a3 Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Tue, 28 Jan 2020 13:41:10 +0000 Subject: kiss: alternatives: initial working solution FossilOrigin-Name: 2bd207d7de9a96dd1a679d731397a4d5f2e526a91b10a026d01c72f0b5c84f50 --- kiss | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'kiss') diff --git a/kiss b/kiss index a6a013d..a1ba40f 100755 --- a/kiss +++ b/kiss @@ -822,14 +822,47 @@ pkg_conflicts() { } pkg_swap() { + # Swap between package alternatives. + # Check to see if the package is installed. This # will exit with an error if it is not. pkg_list "$1" >/dev/null alt=$(printf %s "$1$2" | sed 's|/|>|g') + cd "$sys_db/../choices" - [ -f "$sys_db/../choices/$alt" ] || + [ -f "$alt" ] || [ -h "$alt" ] || die "Alternative '$1 $2' doesn't exist" + + if [ -f "$2" ]; then + # Figure out which package owns the file we are going to + # swap for another package's. + # + # Print the full path to the manifest file which contains + # the match to our search. + pkg_owns=$(set +f; "$grep" -lFx "$2" "$sys_db/"*/manifest) ||: + + # Extract the package name from the path above. + pkg_owns=${pkg_owns%/*} + pkg_owns=${pkg_owns##*/} + + [ "$pkg_owns" ] || + die "File '$2' exists on filesystem but isn't owned" + + log "Swapping '$2' from '$pkg_owns' to '$1'" + + # Convert the current owner to an alternative and rewrite + # its manifest file to reflect this. + dosu mv -f "'$2'" "'$pkg_owns>${alt#*>}'" + dosu sed -i "'s|$2|$PWD/$pkg_owns>${alt#*>}|'" \ + "'../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. + dosu mv -f "'$alt'" "'$2'" + dosu sed -i "'s|$PWD/$alt|$2|'" \ + "'../installed/$1/manifest'" } pkg_remove() { @@ -1195,7 +1228,7 @@ args() { # Go over each alternative and format the file # name for listing. (pkg_name>usr>bin>ls) for pkg in *; do - [ -f "$pkg" ] && + [ "$pkg" = '*' ] || printf '%s\n' "$pkg" | sed 's|>| /|;s|>|/|g' done fi -- cgit v1.2.3