Repository navigation
Expand file tree
/
Copy pathAppRun
More file actions
executable file
·147 lines (125 loc) · 5.44 KB
/
Copy pathAppRun
File metadata and controls
executable file
·147 lines (125 loc) · 5.44 KB
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
#!/bin/bash
APPDIR="$(dirname "$(readlink -f "${0}")")"
export PATH="${APPDIR}/usr/bin:${PATH}"
# Install a launcher into the user's applications directory so the desktop
# shell can associate our window with an app entry and offer "Add to
# Favorites"/pinning. An AppImage installs nothing on its own, so without this
# there is no entry to pin and the shell falls back to a window-backed app:
# generic icon, no launcher actions.
#
# Two details are load-bearing:
# * Exec= must be an absolute, resolvable path. GLib silently discards any
# entry whose Exec program is not found in $PATH, so the bundled desktop
# file's `Exec=nim_status_client` is rewritten to point at the AppImage.
# * StartupWMClass (shipped in nim-status.desktop) must match the WM_CLASS
# instance name Qt sets, so the shell can map a running window back here.
#
# Rewritten on every run, which keeps the entry correct when the AppImage is
# moved or replaced by a newer version.
install_desktop_entry() {
[[ -n "${APPIMAGE:-}" ]] || return 0 # not running as an AppImage
[[ "${STATUS_NO_DESKTOP_INTEGRATION:-}" == "1" ]] && return 0
local data_dir="${XDG_DATA_HOME:-${HOME}/.local/share}"
local apps_dir="${data_dir}/applications"
local icons_dir="${data_dir}/icons/hicolor/512x512/apps"
local entry="${apps_dir}/nim-status.desktop"
local template="${APPDIR}/nim-status.desktop"
[[ -f "${template}" ]] || return 0
mkdir -p "${apps_dir}" "${icons_dir}" || return 0
cp -f "${APPDIR}/status.png" "${icons_dir}/status.png" 2>/dev/null
local line contents=""
while IFS= read -r line || [[ -n "${line}" ]]; do
[[ "${line}" == Exec=* ]] && continue
contents+="${line}"$'\n'
done <"${template}"
contents+="Exec=\"${APPIMAGE}\""$'\n'
# Only write when the entry would actually change; every write wakes the
# desktop shell's file monitor.
[[ "$(cat "${entry}" 2>/dev/null)" == "${contents%$'\n'}" ]] && return 0
# Write via a temp file: the destination may be a symlink (developers often
# link it at a checkout), and redirecting into it would clobber the target.
local tmp="${entry}.tmp.$$"
printf '%s' "${contents}" >"${tmp}" 2>/dev/null || { rm -f "${tmp}"; return 0; }
mv -f "${tmp}" "${entry}" 2>/dev/null || { rm -f "${tmp}"; return 0; }
if command -v update-desktop-database >/dev/null 2>&1; then
update-desktop-database "${apps_dir}" 2>/dev/null
fi
return 0
}
install_desktop_entry
export GST_PLUGIN_SCANNER="${APPDIR}/usr/lib/gstreamer1.0/gstreamer-1.0/gst-plugin-scanner"
export GST_PLUGIN_PATH="${APPDIR}/usr/lib/gstreamer-1.0"
export GST_PLUGIN_PATH_1_0="${APPDIR}/usr/lib/gstreamer-1.0"
export GST_PLUGIN_SYSTEM_PATH="${APPDIR}/usr/lib/gstreamer-1.0"
export GST_PLUGIN_SYSTEM_PATH_1_0="${APPDIR}/usr/lib/gstreamer-1.0"
export LD_LIBRARY_PATH="${APPDIR}/usr/lib/:${APPDIR}/usr/lib/nss:${LD_LIBRARY_PATH}"
export QT_QPA_PLATFORM="xcb"
# Set Qt WebEngine resources path for V8 snapshot files
# The resources are copied to usr/libexec/ during build
export QTWEBENGINE_RESOURCES_PATH="${APPDIR}/usr/libexec"
# Set up pcsc-lite environment
export PCSC_DRIVERS_DIR="${APPDIR}/usr/lib/pcsc/drivers"
export PCSCLITE_CONFIG_DIR="${APPDIR}/etc/reader.conf.d"
# Start pcscd
# warning: needs to be same as ipcdir/usbdropdir in ci/Dockerfile
# https://salsa.debian.org/rousseau/PCSC/-/blob/master/meson.options?ref_type=heads#L36
PCSCD_RUN_DIR="/tmp/pcscd/run"
PCSCD_DRIVERS_DIR="/tmp/pcscd/drivers"
PCSCD_SOCKET="${PCSCD_RUN_DIR}/pcscd.comm"
PCSCD_PIDFILE="/tmp/pcscd/pcscd.pid"
mkdir -p "$(dirname "$PCSCD_PIDFILE")"
# Kill any orphan pcscd from previous runs using saved PID
if [ -f "$PCSCD_PIDFILE" ]; then
OLD_PID=$(cat "$PCSCD_PIDFILE" 2>/dev/null)
if [ -n "$OLD_PID" ] && kill -0 "$OLD_PID" 2>/dev/null; then
echo "Killing orphan pcscd process $OLD_PID"
kill -9 "$OLD_PID" 2>/dev/null || true
sleep 0.2
fi
rm -f "$PCSCD_PIDFILE"
fi
# kill any pcscd processes by name as fallback
pkill -9 pcscd 2>/dev/null || true
sleep 0.1
rm -rf "${PCSCD_RUN_DIR}" "${PCSCD_DRIVERS_DIR}"
mkdir -p "${PCSCD_RUN_DIR}" "${PCSCD_DRIVERS_DIR}"
# pcscd usbdropdir is compile-time /tmp/pcscd/drivers; the AppImage mount path is random.
if [ -d "${APPDIR}/usr/lib/pcsc/drivers" ]; then
cp -a "${APPDIR}/usr/lib/pcsc/drivers/." "${PCSCD_DRIVERS_DIR}/"
fi
cleanup_pcscd() {
if [ -n "$PCSCD_PID" ] && kill -0 "$PCSCD_PID" 2>/dev/null; then
echo "Killing pcscd process $PCSCD_PID"
kill "$PCSCD_PID" 2>/dev/null
wait "$PCSCD_PID" 2>/dev/null
fi
rm -f "$PCSCD_PIDFILE"
}
trap cleanup_pcscd EXIT TERM INT
# Poll until the predicate succeeds or the timeout elapses; poll interval =
# timeout/20. Timeout is non-fatal (callers tolerate it), hence WARN.
# $1=desc $2=timeout-secs $3...=command.
wait_for() {
local desc="$1" timeout="$2"; shift 2
local deadline=$(( SECONDS + timeout ))
local ms=$(( timeout * 1000 / 20 )) interval
printf -v interval '%d.%03d' $(( ms / 1000 )) $(( ms % 1000 ))
while ! "$@"; do
if (( SECONDS >= deadline )); then
echo "WARN: timed out after ${timeout}s waiting for ${desc}" >&2
return 1
fi
sleep "$interval"
done
}
echo "starting pcscd with ${APPDIR}/usr/bin/pcscd --foreground --auto-exit &"
"${APPDIR}/usr/bin/pcscd" --foreground --auto-exit &
PCSCD_PID=$!
echo "$PCSCD_PID" >"$PCSCD_PIDFILE"
wait_for "pcscd socket ${PCSCD_SOCKET}" 5 \
bash -c "[[ -S '${PCSCD_SOCKET}' ]]" || true
DEFAULT_LANG=en_US.UTF-8
if [[ "$LANG" == "C.UTF-8" ]]; then
export LANG=$DEFAULT_LANG
fi
exec "${APPDIR}/usr/bin/nim_status_client" "$@"