2019-05-18 06:43:53 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
2024-02-22 08:47:43 +00:00
|
|
|
[ -n "${UMASK:-}" ] && umask "$UMASK"
|
|
|
|
|
2020-07-14 09:38:59 +00:00
|
|
|
if [ "$(id -u)" = '0' ]; then
|
2022-09-26 11:39:41 +00:00
|
|
|
binary="$1"
|
2024-02-22 08:47:43 +00:00
|
|
|
if [ -z "${PCAP:-}" ]; then
|
2022-09-26 11:39:41 +00:00
|
|
|
# If Syncthing should have no extra capabilities, make sure to remove them
|
|
|
|
# from the binary. This will fail with an error if there are no
|
|
|
|
# capabilities to remove, hence the || true etc.
|
|
|
|
setcap -r "$binary" 2>/dev/null || true
|
|
|
|
else
|
|
|
|
# Set capabilities on the Syncthing binary before launching it.
|
|
|
|
setcap "$PCAP" "$binary"
|
|
|
|
fi
|
|
|
|
|
2023-10-07 02:12:07 +00:00
|
|
|
# Chown may fail, which may cause us to be unable to start; but maybe
|
|
|
|
# it'll work anyway, so we let the error slide.
|
|
|
|
chown "${PUID}:${PGID}" "${HOME}" || true
|
|
|
|
exec su-exec "${PUID}:${PGID}" \
|
2020-07-14 09:38:59 +00:00
|
|
|
env HOME="$HOME" "$@"
|
|
|
|
else
|
|
|
|
exec "$@"
|
|
|
|
fi
|