summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 259b663a22894d4ea2107dab0d9b72194172df2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Maintainer: FirstAirBender <noblechuk5 [at] web [dot] de>

pkgname=systemd-removed-services-hook
pkgver=1.3.3
pkgrel=1
pkgdesc='Notifies you of uninstalled systemd services along with the command to disable them'
arch=('any')
url='https://gitlab.com/firstairbender/systemd-removed-services-hook'
license=('Unlicense')
makedepends=('pacutils')
depends=('systemd')

build() {
  {
  	cat <<-'EOF'
		# https://jlk.fjfi.cvut.cz/arch/manpages/man/alpm-hooks.5

		[Trigger]
		Operation = Remove
		Type      = Path
	EOF

  	for p in $(systemd-analyze --global unit-paths; systemd-analyze unit-paths); do 
  		p=${p#"$(pacconf RootDir)"}
  		echo "Target    = $p/*.service"
  	done | sort

  	cat <<-'EOF'

		[Action]
		Description = Systemd commands to disable uninstalled services
		When        = PreTransaction
		Depends     = systemd
		Exec        = /bin/bash -c 'echo; cat | while read -r f; do service="${f##*/}"; if [ "${f/*\/system\/*/system}" = "system" ] && systemctl --quiet is-enabled "$service" 2> /dev/null; then echo -e " ► systemctl disable $service"; elif [ "${f/*\/user\/*/user}" = "user" ] && systemctl --quiet --global is-enabled "$service" 2> /dev/null; then echo -e " ► systemctl disable --global $service"; fi; done'
		NeedsTargets
	EOF

  } > '20-systemd-removed-services.hook'
}

package() {
    install -Dm 0644 ./* --target-directory="$pkgdir/$(pacconf HookDir)"
}