github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docker/custom-scripts/setup-user.sh (about)

     1  #!/usr/bin/env bash
     2  #
     3  # Copyright 2021 The Dapr Authors
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  # Unless required by applicable law or agreed to in writing, software
     9  # distributed under the License is distributed on an "AS IS" BASIS,
    10  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  # See the License for the specific language governing permissions and
    12  # limitations under the License.
    13  #
    14  #
    15  # Syntax: ./setup-user.sh [USERNAME] [SECURE_PATH_BASE]
    16  
    17  USERNAME=${1:-"kubeblocks"}
    18  SECURE_PATH_BASE=${2:-$PATH}
    19  
    20  set -e
    21  
    22  if [ "$(id -u)" -ne 0 ]; then
    23      echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
    24      exit 1
    25  fi
    26  
    27  # Update the secure_path base
    28  echo "Defaults secure_path=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin:${SECURE_PATH_BASE}\"" >> /etc/sudoers.d/secure_path
    29  
    30  # Create the ~/.local/bin folder
    31  sudo -u ${USERNAME} mkdir -p /home/${USERNAME}/.local/bin