Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions docker/root/init
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
#!/bin/bash
#!/bin/sh

# SPDX-License-Identifier: MIT
# Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com

get_attribs() {
local file_stats file_to_test useful_attribs
if file_to_test=$(realpath "$1") && [[ $2 =~ ^[0-9]+$ ]] ; then
useful_attribs=$(stat "$file_to_test" -t)
read -r -a file_stats <<< "${useful_attribs#"$file_to_test"}"
echo "${file_stats["$2"]}"
else
return 1
fi
}

get_build_uid() {
get_attribs /build 3
stat -c '%u' /build
}

get_build_gid() {
get_attribs /build 4
stat -c '%g' /build
}

if NEW_GID=$(get_build_gid) && NEW_UID=$(get_build_uid); then
# bypass everything if podman is remapping the id to root
if [ "${NEW_UID}" == "0" ]; then
if [ "$(id -u)" == "0" ]; then
if [ "${NEW_UID}" = "0" ]; then
if [ "$(id -u)" = "0" ]; then
exec dumb-init -- "$@"
else
echo "Unable to resolve ns mapping!"
Expand All @@ -39,7 +28,7 @@ else
echo "Not able to detect UID/GID for remapping!"
fi

if [ "$(id -u)" == "$(id -u abc)" ]; then
if [ "$(id -u)" = "$(id -u abc)" ]; then
exec dumb-init -- "$@"
else
exec dumb-init -- su-exec abc:abc "$@"
Expand Down