aboutsummaryrefslogtreecommitdiffstats
path: root/del-service
diff options
context:
space:
mode:
authorColin Guthrie <colin@mageia.org>2012-09-30 14:42:51 +0000
committerColin Guthrie <colin@mageia.org>2012-09-30 14:42:51 +0000
commit16af0931257c829a42d1f97495fa4ee4e26dbfdd (patch)
treeb90632e85d0a2af50cb8298803d01d531ecb2e80 /del-service
parent6f12178282416be7811bc75566fdcf928a68b157 (diff)
downloadrpm-helper-16af0931257c829a42d1f97495fa4ee4e26dbfdd.tar
rpm-helper-16af0931257c829a42d1f97495fa4ee4e26dbfdd.tar.gz
rpm-helper-16af0931257c829a42d1f97495fa4ee4e26dbfdd.tar.bz2
rpm-helper-16af0931257c829a42d1f97495fa4ee4e26dbfdd.tar.xz
rpm-helper-16af0931257c829a42d1f97495fa4ee4e26dbfdd.zip
Sync del-service unit finding code with add-service.
This is actually where the non-relative symlinks in chroots might occur as technically all packges will only include relative symlinks.
Diffstat (limited to 'del-service')
-rwxr-xr-xdel-service52
1 files changed, 34 insertions, 18 deletions
diff --git a/del-service b/del-service
index e23aa0f..e40a1cb 100755
--- a/del-service
+++ b/del-service
@@ -40,30 +40,46 @@ else
fi
units="$*" # systemd units
+USERUNITDIR=/etc/systemd/system
+RUNTIMEUNITDIR=/run/systemd/system
+SYSTEMUNITDIR=/lib/systemd/system
+
+find_unit() {
+ unit=$(basename $1)
+
+ # We need to normalise the systemd unit name as the native unit may not have
+ # the same filename (sans it's .service suffix) as sysvinit script.
+ # In this case, symlinks are used to mask the sysvinit file, but for enabling
+ # and disabling units we must use the official name.
+
+ searchunit=
+ if [ -L "$USERUNITDIR/$unit" ]; then
+ searchunit=$(/usr/bin/readlink -m "$USERUNITDIR/$unit")
+ elif [ -e "$USERUNITDIR/$unit" ]; then
+ searchunit="$USERUNITDIR/$unit"
+ elif [ -L "$RUNTIMEUNITDIR/$unit" ]; then
+ searchunit=$(/usr/bin/readlink -m "$RUNTIMEUNITDIR/$unit")
+ else [ -e "$RUNTIMEUNITDIR/$unit" ]; then
+ searchunit="$RUNTIMEUNITDIR/$unit"
+ elif [ -L "$SYSTEMUNITDIR/$unit" ]; then
+ searchunit=$(/usr/bin/readlink -m "$SYSTEMUNITDIR/$unit")
+ elif [ -e "$SYSTEMUNITDIR/$unit" ]; then
+ searchunit="$SYSTEMUNITDIR/$unit"
+ fi
+ if [ -n "$searchunit" ]; then
+ echo -n $searchunit
+ fi
+}
+
+
# If only a sysvinit service is given, then deal with a systemd unit of the same
# name. Specific specs can enable specific unit names as needed but this should
# catch the most common usage.
if [ -z "$units" ]; then
units="$srv.service"
-
- # We need to normalise the systemd unit name as the native unit may not have
- # the same filename (sans it's .service suffix) as sysvinit script.
- # In this case, symlinks are used to mask the sysvinit file, but for enabling
- # and disabling units we must use the official name.
- SYSTEMUNITDIR=/lib/systemd/system
- USERUNITDIR=/etc/systemd/system
- RUNTIMEUNITDIR=/run/systemd/system
-
- searchunit=
- if [ -f "$SYSTEMUNITDIR/$units" ]; then
- searchunit=$(/usr/bin/readlink "$SYSTEMUNITDIR/$units")
- elif [ -f "$USERUNITDIR/$units" ]; then
- searchunit=$(/usr/bin/readlink "$USERUNITDIR/$units")
- elif [ -f "$RUNTIMEUNITDIR/$units" ]; then
- searchunit=$(/usr/bin/readlink "$RUNTIMEUNITDIR/$units")
- fi
+ searchunit=$(find_unit $units)
if [ -n "$searchunit" ]; then
- units=$searchunit
+ units=$(basename $searchunit)
fi
fi