forked from kiss-community/kiss
kiss: alternatives: initial working solution
This commit is contained in:
parent
596c64d447
commit
f63e1acb64
37
kiss
37
kiss
@ -822,14 +822,47 @@ pkg_conflicts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pkg_swap() {
|
pkg_swap() {
|
||||||
|
# Swap between package alternatives.
|
||||||
|
|
||||||
# Check to see if the package is installed. This
|
# Check to see if the package is installed. This
|
||||||
# will exit with an error if it is not.
|
# will exit with an error if it is not.
|
||||||
pkg_list "$1" >/dev/null
|
pkg_list "$1" >/dev/null
|
||||||
|
|
||||||
alt=$(printf %s "$1$2" | sed 's|/|>|g')
|
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"
|
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() {
|
pkg_remove() {
|
||||||
@ -1195,7 +1228,7 @@ args() {
|
|||||||
# Go over each alternative and format the file
|
# Go over each alternative and format the file
|
||||||
# name for listing. (pkg_name>usr>bin>ls)
|
# name for listing. (pkg_name>usr>bin>ls)
|
||||||
for pkg in *; do
|
for pkg in *; do
|
||||||
[ -f "$pkg" ] &&
|
[ "$pkg" = '*' ] ||
|
||||||
printf '%s\n' "$pkg" | sed 's|>| /|;s|>|/|g'
|
printf '%s\n' "$pkg" | sed 's|>| /|;s|>|/|g'
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user