sudo-cwd.sh: drop the all 'sof_' prefixes and references

This script is now generic. This was not done earlier to be gentle on
git blame.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
This commit is contained in:
Marc Herbert 2022-10-05 22:34:38 -07:00 committed by Liam Girdwood
parent 027be98371
commit 0a4b1d62d5
1 changed files with 15 additions and 18 deletions

View File

@ -27,46 +27,43 @@
set -e
set -x
# TODO: rename the "sof_" bits
main()
{
sof_uid="$(stat --printf='%u' .)"
cwd_uid="$(stat --printf='%u' .)"
local current_uid; current_uid="$(id -u)"
if test "$current_uid" = "$sof_uid"; then
if test "$current_uid" = "$cwd_uid"; then
exec "$@"
else
exec_as_sof_uid "$@"
exec_as_cwd_uid "$@"
fi
}
exec_as_sof_uid()
exec_as_cwd_uid()
{
# Add new container user matching the host user owning the SOF
# checkout
local sof_user; sof_user="$(id "$sof_uid")" || {
sof_user=sof_zephyr_docker_builder
# If missing, add new user owning the current directory
local cwd_user; cwd_user="$(id "$cwd_uid")" || {
cwd_user='cwd_user'
local sof_guid; sof_guid="$(stat --printf='%g' .)"
local cwd_guid; cwd_guid="$(stat --printf='%g' .)"
getent group "$sof_guid" ||
sudo groupadd -g "$sof_guid" sof_zephyr_docker_group
getent group "$cwd_guid" ||
sudo groupadd -g "$cwd_guid" 'cwd_group'
sudo useradd -m -u "$sof_uid" -g "$sof_guid" "$sof_user"
sudo useradd -m -u "$cwd_uid" -g "$cwd_guid" "$cwd_user"
local current_user; current_user="$(id -un)"
# Copy sudo permissions just in case the build needs it
sudo sed -e "s/$current_user/$sof_user/" /etc/sudoers.d/"$current_user" |
sudo tee -a /etc/sudoers.d/"$sof_user"
sudo sed -e "s/$current_user/$cwd_user/" /etc/sudoers.d/"$current_user" |
sudo tee -a /etc/sudoers.d/"$cwd_user"
sudo chmod --reference=/etc/sudoers.d/"$current_user" \
/etc/sudoers.d/"$sof_user"
/etc/sudoers.d/"$cwd_user"
}
# Double sudo to work around some funny restriction in
# zephyr-build:/etc/sudoers: 'user' can do anything but... only as
# root.
sudo sudo -u "$sof_user" REAL_CC="$REAL_CC" "$@"
sudo sudo -u "$cwd_user" REAL_CC="$REAL_CC" "$@"
exit "$?"
}