summarylogtreecommitdiffstats
path: root/owlry.install
blob: ae8cc6c41680b2108a4df537781f0edd045216d9 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
## owlry .install hook
##
## v2.0 renamed the systemd user units (owlryd.{service,socket} → owlry.{service,socket})
## and consolidated 14 separate packages into one.
##
## 2.0.1 extends this hook with proactive detection of two common upgrade snags:
##   1. Stale ~/.config/systemd/user/owlry{,d}.{service,socket} overrides pointing
##      at a deleted dev-time build path or the removed `owlryd` binary. systemd-user
##      gives precedence to user-level units over /usr/lib/systemd/user/*, so a
##      stale override silently breaks the AUR-shipped unit.
##   2. Compositor configs (Hyprland, Sway, i3, river, niri) with `exec owlryd` /
##      `exec-once = owlryd` lines that won't resolve anymore.
##
## The hook only DETECTS and REPORTS — it never touches user homedirs from a root
## pacman context. Each affected user gets a precise remediation command.

_owlry_for_each_user() {
    # Apply $1 (function name) to each logged-in user's home directory.
    # Falls back silently if loginctl/getent aren't available.
    local fn="$1"
    command -v loginctl >/dev/null 2>&1 || return 0
    command -v getent >/dev/null 2>&1 || return 0
    local user home
    while read -r user; do
        [ -n "$user" ] || continue
        home="$(getent passwd "$user" 2>/dev/null | awk -F: '{print $6}')"
        [ -d "$home" ] || continue
        "$fn" "$user" "$home"
    done < <(loginctl list-users --no-legend 2>/dev/null | awk '{print $2}')
}

_owlry_check_unit() {
    # Inspect a user-level systemd unit; emit a remediation hint if it's stale.
    # Args: $1=user, $2=home, $3=unit-filename (e.g. owlry.service)
    local user="$1" home="$2" unit="$3"
    local svc="$home/.config/systemd/user/$unit"
    [ -f "$svc" ] || return 1
    local exec_line
    exec_line="$(grep -E '^ExecStart=' "$svc" 2>/dev/null | head -1 | sed 's/^ExecStart=//')"
    case "$exec_line" in
        */owlryd|*/owlryd\ *)
            printf '    %s -> references deleted owlryd binary: %s\n' "$svc" "$exec_line"
            return 0
            ;;
        */target/debug/*|*/target/release/*)
            printf '    %s -> points at a dev-time build path: %s\n' "$svc" "$exec_line"
            return 0
            ;;
        */owlry|*/owlry\ *|/usr/bin/owlry|/usr/bin/owlry\ *)
            # If the override matches the canonical /usr/bin/owlry, it's harmless
            # but redundant. Flag it gently.
            printf '    %s -> user-level override (redundant; AUR ships this unit)\n' "$svc"
            return 0
            ;;
        *)
            # Unknown ExecStart — flag it so the user can review.
            printf '    %s -> non-standard ExecStart: %s\n' "$svc" "$exec_line"
            return 0
            ;;
    esac
}

_owlry_check_compositors() {
    # Args: $1=user, $2=home
    local user="$1" home="$2"
    local found=0 f
    # Single-file configs
    for f in \
        "$home/.config/sway/config" \
        "$home/.config/i3/config" \
        "$home/.config/river/init" \
        "$home/.config/niri/config.kdl"; do
        if [ -f "$f" ] && grep -qE '\bowlryd\b' "$f" 2>/dev/null; then
            printf '    %s -> contains `owlryd` reference\n' "$f"
            found=1
        fi
    done
    # Hyprland — main file + include directory
    if [ -d "$home/.config/hypr" ]; then
        while IFS= read -r f; do
            if grep -qE '\bowlryd\b' "$f" 2>/dev/null; then
                printf '    %s -> contains `owlryd` reference\n' "$f"
                found=1
            fi
        done < <(find "$home/.config/hypr" -type f \( -name '*.conf' -o -name '*.hyprlang' \) 2>/dev/null)
    fi
    return $((1 - found))
}

_owlry_per_user_migration_check() {
    local user="$1" home="$2"
    # Collect all check output in one subshell so internal newlines are
    # preserved (only the trailing newline gets stripped by $()).
    local out
    out="$({
        _owlry_check_unit "$user" "$home" owlry.service
        _owlry_check_unit "$user" "$home" owlry.socket
        _owlry_check_unit "$user" "$home" owlryd.service
        _owlry_check_unit "$user" "$home" owlryd.socket
        _owlry_check_compositors "$user" "$home"
    })"

    [ -z "$out" ] && return 0

    echo
    echo "  ── user '$user' ─────────────────────────────────────────────"
    echo "$out"
    echo
    echo "  Suggested cleanup (run as '$user'):"
    echo
    cat <<EOF
      # 1. Drop any user-level systemd overrides:
      rm -f ~/.config/systemd/user/owlry.service ~/.config/systemd/user/owlry.socket
      rm -f ~/.config/systemd/user/owlryd.service ~/.config/systemd/user/owlryd.socket
      systemctl --user daemon-reload
      systemctl --user reenable --now owlry.service
      systemctl --user reset-failed owlry.service 2>/dev/null || true

      # 2. Replace any \`owlryd\` autostart line in your compositor config:
      #      exec-once = owlryd       ->   exec-once = owlry -d
      #      exec       owlryd        ->   exec       owlry -d
      #    (Usually unnecessary now — owlry.service / owlry.socket replace autostart.)
EOF
}

post_upgrade() {
    local old_pkgver="$2"
    case "$old_pkgver" in
        1.*|0.*)
            cat <<'EOF'

  ╭─────────────────────────────────────────────────────────────────╮
  │  owlry 2.0 — the v2 rewrite                                     │
  │                                                                 │
  │  The daemon binary 'owlryd' is gone; owlry now ships as a       │
  │  single binary. Use `owlry -d` (or the systemd service).        │
  │                                                                 │
  │  The systemd user unit was renamed:                             │
  │      owlryd.service  ->  owlry.service                          │
  │      owlryd.socket   ->  owlry.socket                           │
  │                                                                 │
  │  Plugin packages (bookmarks, systemd, clipboard, …) are now     │
  │  built into owlry by default — they were dropped from AUR and   │
  │  replaced via this package.                                     │
  │                                                                 │
  │  Widget providers (weather, media, pomodoro) and bookmarks      │
  │  are not in 2.0; they return in a later 2.x release. See:       │
  │      docs/RESTRUCTURE-V2.md (decisions D20, D22)                │
  ╰─────────────────────────────────────────────────────────────────╯
EOF
            _owlry_for_each_user _owlry_per_user_migration_check
            ;;
        2.0|2.0.0)
            # 2.0.0 → 2.0.1: re-run the migration check; some users may have
            # missed cleanup the first time. Idempotent — only prints when
            # there's still something to flag.
            _owlry_for_each_user _owlry_per_user_migration_check
            ;;
    esac
}

post_install() {
    cat <<'EOF'

  owlry installed. Start the daemon with:
      systemctl --user enable --now owlry.service

  Or run ad-hoc:
      owlry -d &
      owlry

  Configuration: ~/.config/owlry/config.toml
  Diagnostics:   owlry doctor

EOF
}

post_remove() {
    echo "  owlry removed. Configuration in ~/.config/owlry remains intact."
}