summarylogtreecommitdiffstats
path: root/send-rebuild-reminder
blob: e2cd753764d599c3f8d372151aec50edab95d814 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#! /usr/bin/bash

# Written by PKGBUILD

declare -r pkgname=
declare -r pkgver=
declare -r pkgrel=

###

broadcast=0
use_environment=0
use_global_config=1

while :; do
  case $1 in
  --broadcast)
    broadcast=1
    ;;
  --use_environment)
    use_environment=1
    ;;
  --skip-global-config)
    use_global_config=0
    ;;
  *)
    break
    ;;
  esac
  shift
done

if ((!use_environment)); then
  app_name=$pkgname
  message="Kwin was updated. It is necessary to rebuild $pkgname."
  icon=update-medium
  urgency=normal
  action="Execute configured function"
else
  eval "$declare_do_rebuild"
fi

if ((use_global_config)); then
  global_config=/etc/$pkgname/reminder.conf

  if [[ -f $global_config ]]; then
    source "$global_config"
  fi
fi

if ((!broadcast)); then
  local_config=$(systemd-path user-configuration --suffix="/$pkgname/reminder.conf")

  if [[ -f $local_config ]]; then
    source "$local_config"
  fi

  if declare -F do_rebuild >/dev/null; then
    show_action=1
  else
    unset show_action
  fi

  eval "$(notify-send --icon="$icon" --app-name="$app_name" "$message" --urgency="$urgency" ${show_action:+--action="do_rebuild=$action"})"
else
  passed_env=(
    --setenv=app_name="$app_name"
    --setenv=message="$message"
    --setenv=icon="$icon"
    --setenv=urgency="$urgency"
    --setenv=action="$action"
    --setenv=declare_do_rebuild="$(declare -pf do_rebuild 2>/dev/null)"
  )

  for user in ${users:-$(who | cut -d " " -f1 | sort -u)}; do
    systemd-run \
      "${passed_env[@]}" \
      --description="${app_name:+$app_name: }send rebuild reminder" \
      --machine="${user}@.host" \
      --user \
      --no-block \
      --quiet \
      "$(realpath "${BASH_SOURCE[0]}")" --use-environment --skip-global-config
  done
fi