1
0
mirror of https://codeberg.org/kiss-community/kiss synced 2024-11-04 22:15:36 -07:00
kiss/contrib/kiss-link

47 lines
1.3 KiB
Plaintext
Raw Normal View History

2020-03-13 07:43:54 -06:00
#!/bin/sh -ef
2020-05-01 00:07:20 -06:00
# Link a repository file to another repository
2020-03-13 07:43:54 -06:00
[ "$1" ] || {
printf 'usage: kiss-link file\n'
exit 1
}
[ -f "${file:=$1}" ] || {
printf 'file %s does not exist in the current directory\n' "$1"
exit 1
}
oPWD=$PWD
# Check if the package exists in a repository and error out here
# if it does not. The error message from the package manager will
# be displayed.
kiss s "${PWD##*/}" >/dev/null
# Disable this warning as globbing is disabled and word splitting
# is intentional. This grabs the location of the package's files.
# shellcheck disable=2046
{
# Generate a list of repositories in which the package
# exists. Then 'cd' to the first found directory to do a
# comparison.
set -- $(kiss s "${PWD##*/}"); cd "$1"
# Error if the package exists nowhere but the current
# directory and this script would create a broken symlink.
[ -z "$2" ] && [ "$PWD" = "$oPWD" ] && {
printf 'error: cannot symlink file to itself\n'
exit 1
}
# If the first repository in '$KISS_PATH' is the current
# directory, use the second repository in the list.
[ "$PWD" = "$oPWD" ] && shift
# Finally, make the link to the file in whatever repository
# it was found in.
2020-09-03 01:17:29 -06:00
ln -sf "$1/$file" "$oPWD/$file"
2020-03-13 07:43:54 -06:00
}
printf 'linked %s to %s\n' "$file" "$1"