Skip to content

Commit

Permalink
Clean up systemd unit disable logic (#721)
Browse files Browse the repository at this point in the history
* Fix #638
  • Loading branch information
Eeems committed Dec 10, 2023
1 parent 0979c66 commit 9e481a5
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 84 deletions.
10 changes: 4 additions & 6 deletions package/display/package
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ timestamp=2023-08-27T02:39:10Z
maintainer="raisjn <[email protected]>"
license=MIT
url="https://github.com/ddvk/remarkable2-framebuffer"
pkgver=1:0.0.32-1
pkgver=1:0.0.32-2
_release="${pkgver%-*}"
_release="v${_release#*:}"
_libver=1.0.1
Expand Down Expand Up @@ -66,13 +66,13 @@ display() {
systemctl daemon-reload
if systemctl enable rm2fb --now; then
# Restart xochitl if it's running
if systemctl --quiet is-active xochitl; then
if is-active xochitl; then
# Reset the crash count so we don't trigger remarkable-fail
echo "0" > /tmp/crashnum
systemctl restart xochitl
fi
else
systemctl disable rm2fb --now
disable-unit rm2fb.service
echo "Failed to start rm2fb. Keeping it disabled for now."
echo "Please check the logs and open an issue:"
echo " https://github.com/toltec-dev/toltec/issues/new"
Expand All @@ -83,9 +83,7 @@ display() {

preremove() {
if [[ $arch = rm2 ]]; then
if systemctl list-units --full -all | grep -Fq 'rm2fb.service'; then
systemctl disable rm2fb --now
fi
disable-unit rm2fb.service
echo -n "make sure "
if ! is-enabled xochitl.service; then
echo "to re-enable xochitl with 'systemctl enable xochitl --now'"
Expand Down
7 changes: 2 additions & 5 deletions package/draft/package
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pkgnames=(draft)
pkgdesc="Launcher which wraps around the standard interface"
url=https://github.com/dixonary/draft-reMarkable
pkgver=0.2.0-21
pkgver=0.2.0-22
timestamp=2020-07-20T10:23Z
section="launchers"
maintainer="Mattéo Delabre <[email protected]>"
Expand Down Expand Up @@ -60,10 +60,7 @@ configure() {
}

preremove() {
if systemctl list-units --full -all | grep -Fq "$pkgname.service"; then
echo "Disabling $pkgname"
systemctl disable --now "$pkgname"
fi
disable-unit "$pkgname.service"
}

postremove() {
Expand Down
12 changes: 2 additions & 10 deletions package/koreader/package
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pkgnames=(koreader)
pkgdesc="Ebook reader supporting PDF, DjVu, EPUB, FB2 and many more formats"
url=https://github.com/koreader/koreader
pkgver=2023.10-1
pkgver=2023.10-2
timestamp=2023-10-30T17:19:28Z
section="readers"
maintainer="raisjn <[email protected]>"
Expand Down Expand Up @@ -62,15 +62,7 @@ MSG
}

preremove() {
if is-active "$pkgname"; then
echo "Stopping $pkgname"
systemctl stop "$pkgname"
fi

if is-enabled "$pkgname"; then
echo "Disabling $pkgname"
systemctl disable "$pkgname"
fi
disable-unit "$pkgname.service"
}

postremove() {
Expand Down
11 changes: 2 additions & 9 deletions package/oxide/package
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

pkgnames=(erode fret oxide rot tarnish decay corrupt anxiety oxide-utils inject_evdev liboxide libsentry)
_oxidever=2.6
pkgver=$_oxidever-2
pkgver=$_oxidever-3
_sentryver=0.5.0
timestamp=2023-06-05T23:27:53Z
maintainer="Eeems <[email protected]>"
Expand Down Expand Up @@ -98,14 +98,7 @@ tarnish() {
fi
}
preremove() {
if is-active tarnish; then
echo "Stopping tarnish"
systemctl stop tarnish
fi
if is-enabled tarnish; then
echo "Disabling tarnish"
systemctl disable tarnish
fi
disable-unit tarnish.service
}
postremove() {
systemctl daemon-reload
Expand Down
11 changes: 2 additions & 9 deletions package/reboot-guard/package
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pkgnames=(reboot-guard)
pkgdesc="Block systemd-initiated poweroff/reboot/halt until configurable condition checks pass"
url=https://github.com/stephanritscher/reboot-guard
pkgver=1.0.1-7
pkgver=1.0.1-8
timestamp=2020-05-04T06:16Z
section="devel"
maintainer="Eeems <[email protected]>"
Expand Down Expand Up @@ -34,14 +34,7 @@ configure() {
}

preremove() {
if is-active rguard.service; then
echo "Stopping rguard.service"
systemctl stop rguard.service
fi
if is-enabled rguard.service; then
echo "Disabling rguard.service"
systemctl disable rguard.service
fi
disable-unit rguard.service
}

postremove() {
Expand Down
4 changes: 2 additions & 2 deletions package/rmfakecloud-proxy/package
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pkgdesc="Connect Xochitl to a rmfakecloud server"
_url=https://github.com/ddvk/rmfakecloud-proxy
url="$_url"
_upver=0.0.3
pkgver="$_upver-3"
pkgver="$_upver-4"
timestamp=2022-02-26T22:59Z
section="utils"
maintainer="Mattéo Delabre <[email protected]>"
Expand Down Expand Up @@ -55,7 +55,7 @@ configure() {
install-hosts
else
uninstall-certificates
systemctl disable --now rmfakecloud-proxy
disable-unit rmfakecloud-proxy.service
uninstall-hosts
fi

Expand Down
10 changes: 4 additions & 6 deletions package/rmkit/package
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dumbskull() {
genie() {
pkgdesc="Gesture engine that connects commands to gestures"
url="https://rmkit.dev/apps/genie"
pkgver=0.1.6-2
pkgver=0.1.6-3
section="utils"

package() {
Expand All @@ -67,8 +67,7 @@ genie() {
}

preremove() {
echo "Disabling $pkgname"
systemctl disable --now "$pkgname"
disable-unit "$pkgname.service"
}

postremove() {
Expand Down Expand Up @@ -146,7 +145,7 @@ nao() {
remux() {
pkgdesc="Launcher that supports multi-tasking applications"
url="https://rmkit.dev/apps/remux"
pkgver=0.2.4-1
pkgver=0.2.4-2
section="launchers"

package() {
Expand All @@ -166,8 +165,7 @@ remux() {
}

preremove() {
echo "Disabling $pkgname"
systemctl disable --now "$pkgname"
disable-unit "$pkgname.service"
}

postremove() {
Expand Down
12 changes: 2 additions & 10 deletions package/tailscale-systemd/package
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pkgnames=(tailscale-systemd)
pkgdesc="SystemD configuration for tailscale"
url=https://tailscale.com
pkgver=0.0.0-1
pkgver=0.0.0-2
section="utils"
timestamp=2023-07-12T00:00Z
maintainer="Kai <[email protected]>"
Expand All @@ -30,15 +30,7 @@ configure() {
}

preremove() {
if is-active tailscaled; then
echo "Stopping tailscaled"
systemctl stop tailscaled
fi

if is-enabled tailscaled; then
echo "Disabling tailscaled"
systemctl disable tailscaled
fi
disable-unit "tailscaled.service"
}

postremove() {
Expand Down
8 changes: 3 additions & 5 deletions package/toltec-base/package
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ archs=(rm1 rm2)
pkgnames=(toltec-base)
pkgdesc="Metapackage defining the base set of packages in a Toltec install"
url=https://toltec-dev.org/
pkgver=1.2-2
pkgver=1.2-3
timestamp=2023-05-08T19:31Z
section="utils"
maintainer="Eeems <[email protected]>"
Expand All @@ -29,10 +29,8 @@ configure() {
sed -i \
-e 's|^export TERM=xterm|if \[ -z "$TERM" \];then export TERM=xterm;fi|' \
/opt/etc/profile
if is-enabled "update-engine.service"; then
echo "Disabling automatic update"
systemctl disable --now update-engine
fi
echo "Disabling automatic update"
disable-unit update-engine.service
if [[ "$arch" == "rm1" ]] && ! is-masked sys-subsystem-net-devices-usb1.device; then
echo "Disabling usb1 network device to avoid long boots"
systemctl mask sys-subsystem-net-devices-usb1.device
Expand Down
11 changes: 2 additions & 9 deletions package/webinterface-onboot/package
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _pkgname='webinterface-onboot'
pkgnames=("$_pkgname")
pkgdesc="Start the web interface without the cable, on boot."
url="https://github.com/rM-self-serve/$_pkgname"
pkgver=1.2.2-1
pkgver=1.2.2-2
timestamp=2023-12-03T11:43:00Z
section="utils"
maintainer="rM-self-serve <[email protected]>"
Expand Down Expand Up @@ -73,14 +73,7 @@ _restore() {
}

preremove() {
if is-active "$pkgname"; then
echo "Stopping $pkgname"
systemctl stop "$pkgname"
fi
if is-enabled "$pkgname"; then
echo "Disabling $pkgname"
systemctl disable "$pkgname"
fi
disable-unit "$pkgname.service"
_restore
}

Expand Down
11 changes: 2 additions & 9 deletions package/webinterface-wifi/package
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _pkgname="webinterface-wifi"
pkgnames=("$_pkgname")
pkgdesc="View the web interface if running, over wifi"
url="https://github.com/rM-self-serve/$_pkgname"
pkgver=2.0.0-1
pkgver=2.0.0-2
timestamp=2023-11-26T00:02:11Z
section="utils"
maintainer="rM-self-serve <[email protected]>"
Expand Down Expand Up @@ -72,14 +72,7 @@ configure() {
}

preremove() {
if is-active "$pkgname"; then
echo "Stopping $pkgname"
systemctl stop "$pkgname"
fi
if is-enabled "$pkgname"; then
echo "Disabling $pkgname"
systemctl disable "$pkgname"
fi
disable-unit "$pkgname.service"
}

postremove() {
Expand Down
6 changes: 2 additions & 4 deletions package/xochitl/package
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pkgnames=(xochitl)
pkgdesc="Read documents and take notes"
url=https://remarkable.com
pkgver=0.0.0-16
pkgver=0.0.0-17
timestamp=2022-11-07T20:19:57Z
section="readers"
maintainer="Mattéo Delabre <[email protected]>"
Expand Down Expand Up @@ -83,9 +83,7 @@ configure() {
}

preremove() {
if is-active manual-sync.service; then
systemctl disable --now manual-sync.service
fi
disable-unit manual-sync.service
}

postremove() {
Expand Down
28 changes: 28 additions & 0 deletions scripts/install-lib
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,31 @@ remove-bind-mount() {
rm "$unit_path"
systemctl daemon-reload
}

# Check to see if a systemd unit exists
#
# Arguments:
#
# $1 - Full name of the systemd unit, e.g. "draft.service"
unit-exists() {
[ "$(systemctl --quiet list-unit-files "${1}" | grep -c "${1}")" -eq 1 ]
}

# Stops and disabled a unit
#
# Arguments:
#
# $1 - Full name of the systemd unit, e.g. "draft.service"
disable-unit() {
if ! unit-exists "${1}"; then
return
fi
if is-active "$1"; then
echo "Stopping ${1}"
systemctl stop "${1}"
fi
if is-enabled "${1}"; then
echo "Disabling ${1}"
systemctl disable "${1}"
fi
}

0 comments on commit 9e481a5

Please sign in to comment.