8 changed files with 107 additions and 16 deletions
@ -0,0 +1,4 @@
|
||||
#!/bin/sh -e |
||||
|
||||
update-alternatives --display "$__object_id" 2>/dev/null \ |
||||
| awk -F ' - ' '/priority [0-9]+$/ { print $1 }' |
@ -0,0 +1,40 @@
|
||||
#!/bin/sh -e |
||||
|
||||
# fedora's (update-)alternatives --display output doesn't have |
||||
# "link <name> is <path>" line, but debian does. so, let's find |
||||
# out how they store this information. |
||||
# |
||||
# debian and friends: |
||||
# https://salsa.debian.org/dpkg-team/dpkg/-/blob/master/utils/update-alternatives.c |
||||
# see calls to altdb_print_line function |
||||
# |
||||
# fedora and friends: |
||||
# https://github.com/fedora-sysv/chkconfig/blob/master/alternatives.c |
||||
# see calls to parseLine function |
||||
# |
||||
# conclusion: it is safe to assume that (master) link is on second line |
||||
|
||||
for altdir in \ |
||||
/var/lib/dpkg/alternatives \ |
||||
/var/lib/alternatives |
||||
do |
||||
if [ ! -f "$altdir/$__object_id" ] |
||||
then |
||||
continue |
||||
fi |
||||
|
||||
link="$( awk 'NR==2' "$altdir/$__object_id" )" |
||||
|
||||
if [ -n "$link" ] |
||||
then |
||||
break |
||||
fi |
||||
done |
||||
|
||||
if [ -z "$link" ] |
||||
then |
||||
echo "unable to get link for $__object_id" >&2 |
||||
exit 1 |
||||
fi |
||||
|
||||
echo "$link" |
@ -0,0 +1,12 @@
|
||||
#!/bin/sh -e |
||||
|
||||
path_is="$( update-alternatives --display "$__object_id" 2>/dev/null \ |
||||
| awk '/link currently points to/ {print $5}' )" |
||||
|
||||
if [ -z "$path_is" ] |
||||
then |
||||
echo "unable to get current path for $__object_id" >&2 |
||||
exit 1 |
||||
fi |
||||
|
||||
echo "$path_is" |
@ -0,0 +1,8 @@
|
||||
#!/bin/sh -e |
||||
|
||||
if [ -f "$( cat "$__object/parameter/path" )" ] |
||||
then |
||||
echo 'present' |
||||
else |
||||
echo 'absent' |
||||
fi |
@ -1,8 +0,0 @@
|
||||
#!/bin/sh -e |
||||
path="$(cat "$__object/parameter/path")" |
||||
name="$__object_id" |
||||
link="$(readlink "/etc/alternatives/$name")" |
||||
if [ "$path" = "$link" ] |
||||
then echo present |
||||
else echo absent |
||||
fi |
Loading…
Reference in new issue