summarylogtreecommitdiffstats
path: root/systemd-netns-git.install
blob: 16129b5cd338439096f83175875349b2ffcd0100 (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
# systemd-netns-git.install

# This function runs after the package is successfully installed for the first time.
post_install() {
  /usr/bin/netns-update
}

# This function runs after the package is successfully upgraded.
# The argument $1 contains the new package version.
# The argument $2 contains the old package version.
post_upgrade() {
  /usr/bin/netns-update
}

post_remove() {
  local shopt_state
  shopt_state=$(shopt -p nullglob)      # Save the current nullglob state.
  shopt -s nullglob                     # Enable nullglob.

  # Define the exact regex pattern we need to match within the file content.
  local pattern='^# For each NSTYPE this file needs to be copied AS-IS to /etc/systemd/system/netns(_outside)?-NSTYPE@\.service$'

  for f in /etc/systemd/system/netns*; do
    if [[ -f "$f" ]] && grep -q -E "$pattern" "$f"; then
      rm -f "$f"
    fi
  done

  eval "$shopt_state"                   # Restore the original nullglob setting.
}