thin-edge.io installation with deb files need getent
Closed this issue · 7 comments
Describe the bug
The installation of thin-edge.io with the Debian Packages need getent
. This command is not available on busybox.
To Reproduce
Try to install tedge.deb on a target that runs with busybox.
Expected behavior
Avoid getent use grep for example to check if a group or user exists.
Environment (please complete the following information):
- OS
Custom Yocto Linux - Hardware [incl. revision]
Phoenix Contact Controller AXC F 2152 - System-Architecture [e.g. result of "uname -a"]
Linux axcf2152 5.4.257-rt87-pxc SMP PREEMPT_RT Thu Nov 16 06:49:45 UTC 2023 armv7l armv7l armv7l GNU/Linux - thin-edge.io version
v1.1.1
Additional context
root@axcf2152# dpkg -i -D=2 /opt/plcnext/apps/60002172000584/images/tedge/arm/tedge.deb
(Reading database ... 32 files and directories currently installed.)
Preparing to unpack .../images/tedge/arm/tedge.deb ...
/var/lib/dpkg/tmp.ci/preinst: line 9: getent: command not found
groupadd: group 'tedge' already exists
dpkg: error processing archive /opt/plcnext/apps/60002172000584/images/tedge/arm/tedge.deb (--install):
new tedge:armhf package pre-installation script subprocess returned error exit status 9
Errors were encountered while processing:
/opt/plcnext/apps/60002172000584/images/tedge/arm/tedge.deb
We would have to avoid doing a manual grep on /etc/passwd
and /etc/group
as this doesn't work if the OS uses custom user/groups controlled by NSS, namely Fedora IoT does not store the values under aforementioned files during installation due to its usage of rpm-ostree (to enable rolling back of packages etc.).
@bjoernsauer I think thin-edge.io can switch to use checks with id
(for both user and group), and this should work in busybox as id is included in the busy-box list of commands
Hi @reubenmiller, yes id
would be available. Maybe check for getent
and prefere to use it if it is available and fall back to a alternative implementation with id
or something else.
We'll see what makes more sense, we generally want to try to avoid too many different ways of doing things as it makes the script a bit more difficult to read and maintain, however only if we can be 100% sure that using id
"works everywhere"
Below are the proposed commands to use to check if existence of the tedge user and group:
# Check if user
if ! id -u tedge >/dev/null 2>&1; then
echo "tedge user does not exist"
fi
# Check if group exists
if ! id -g tedge >/dev/null 2>&1; then
echo "tedge group does not exist"
fi
Though I guess we could do some simple wrapper functions which have some fallback logic to ensure maximum compatibility:
group_exists() {
name="$1"
if command_exists id; then
id -g "$name" >/dev/null 2>&1
elif command_exists getent; then
getent group "$name" >/dev/null 2>&1
else
# Fallback to plain grep, as busybox does not have getent
grep -q "^${name}:" /etc/group
fi
}
user_exists() {
name="$1"
if command_exists id; then
id -u "$name" >/dev/null 2>&1
elif command_exists getent; then
getent passwd "$name" >/dev/null 2>&1
else
# Fallback to plain grep, as busybox does not have getent
grep -q "^${name}:" /etc/passwd
fi
}
I can confirm that the proposed solution works for my target system.
There is already a PR in the works, #2942
@bjoernsauer The feature is already merged, so you can try out the published packages from the tedge-main channel from cloudsmith.io.
Or if you're using the install convenience script, you can use an argument to use the main channel:
wget -O thin-edge.io/install.sh | sh -s -- --channel main