File: customize_container.sh

package info (click to toggle)
opentelemetry-cpp 1.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,372 kB
  • sloc: cpp: 96,239; sh: 1,766; makefile: 36; python: 31
file content (39 lines) | stat: -rwxr-xr-x 1,137 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

set -eu

if [[ $IS_CONTAINER_BUILD != "true" ]]; then
     echo "This script should only run inside a Docker container."
     exit 1
fi

if [[ -n "$INSTALL_PACKAGES" ]]; then
    packages=($INSTALL_PACKAGES)
    for package in "${packages[@]}"; do
        apt install -y "$package"
    done
fi

if [[ $(id "$USER_NAME" 2>/dev/null) ]]; then
    echo "User '$USER_NAME' already exists. Removing it."
    userdel -rf "$USER_NAME"
elif [[ $(id -u "$USER_UID" 2>/dev/null) ]]; then
    OTHER_USER=$(getent passwd "$USER_UID" | cut -d: -f1)
    echo "User '$OTHER_USER' exists with UID $USER_UID. Removing it."
    userdel -rf "$OTHER_USER"
fi

if [[ ! $(getent group "$USER_GID" 2>/dev/null) ]]; then
    echo "Group '$USER_GID' does not exist. Adding it."
    groupadd -g "$USER_GID" "$USER_NAME"
fi

useradd -m -u "$USER_UID" -g "$USER_GID" -s /bin/bash "$USER_NAME"
echo "Created user '$USER_NAME' (UID: $USER_UID, GID: $USER_GID)."

echo "$USER_NAME ALL=(ALL) NOPASSWD:ALL" | tee /etc/sudoers.d/"$USER_NAME"

echo "User and group setup complete."