Files
pmaports-rtwo/main/postmarketos-usb-moded/rootfs-usr-lib-systemd-system-generators-umtprd-config-generator
T
Clayton CraftandDylan Van Assche 5971d0f226 main/postmarketos-usb-moded: use a generator to configure UID/GID for umtprd
MTP transfers write files to the home folder of the user.
If no GID and UID are specified, uMTP-responder will use the GID/UID
under which it is running at the time of the file transfer.
This causes users to not be able to access the files on the device after transfering.

This patch adds a systemd generator that:

1) reads /etc/default_user, and appends config to
   /etc/umtprd/umtprd.conf to set the MTP default user/group. If this
   file doesn't exist, 10000:10000 is the fallback uid:gid.
2) installs this config to /run/umtprd/umptrd.conf
3) adds a unit override to /run for umtprd.service that runs the daemon
   with this modified config

The generator is used instead of hardcoding a uid and gid in umtprd.conf
so that this can support immutable installs or situations where the
default UID/GID is not 10000.

Co-authored-by: Dylan Van Assche <dylan@postmarketos.org>
Signed-off-by: Clayton Craft <craftyguy@postmarketos.org>
Part-of: <https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/7658>
2026-01-05 10:15:18 +00:00

40 lines
886 B
Bash

#!/bin/sh
# systemd generator for uMTP-Responder configuration
# Generates config with user UID/GID in /run
set -e
late_dir="$3"
# fallback UID/GID
uid=10000
gid=10000
user_file="/etc/default_user"
if [ -f "$user_file" ]; then
user=$(cat "$user_file")
if [ -n "$user" ]; then
# Get UID/GID, fall back to defaults on failure
uid=$(id -u "$user" 2>/dev/null || echo 10000)
gid=$(id -g "$user" 2>/dev/null || echo 10000)
fi
fi
mkdir -p /run/umtprd
cat /etc/umtprd/umtprd.conf > /run/umtprd/umtprd.conf
cat << EOF >> /run/umtprd/umtprd.conf
# GID/UID for file operations (generated)
default_uid $uid
default_gid $gid
EOF
# unit override to use generated config
mkdir -p "${late_dir}/umtprd.service.d"
cat << EOF > "${late_dir}/umtprd.service.d/10-config-path.conf"
[Service]
ExecStart=
ExecStart=/usr/bin/umtprd -conf /run/umtprd/umtprd.conf
EOF