Skip to content
Snippets Groups Projects
Commit aaf33e41 authored by lcappelli's avatar lcappelli
Browse files

Improove the creation of vscode user

To create the vscode user, the provide_user.sh script is used. With this script the comand line appearance is improved with colors and branch informations
parent 9c06dad7
No related branches found
No related tags found
1 merge request!19Resolve "Remove dependency from storm2/build project"
Pipeline #72477 passed
......@@ -6,18 +6,20 @@ FROM centos:7
# Allow customization of build user ID and name
ARG VSCODE_USER=vscode
ARG VSCODE_USER_UID=1000
ARG VSCODE_GID=${VSCODE_USER_UID}
ENV VSCODE_USER $VSCODE_USER
ENV VSCODE_USER_UID $VSCODE_USER_UID
ENV VSCODE_GID=${VSCODE_USER_UID}
COPY assets/provide-user.sh /docker/
RUN sh /docker/provide-user.sh ${VSCODE_USER} ${VSCODE_USER_UID} ${VSCODE_GID}
RUN echo "include_only=.garr.it,.cern.ch" >> /etc/yum/pluginconf.d/fastestmirror.conf && \
yum clean all && \
yum install -y hostname epel-release && \
yum -y update && \
yum -y install which wget tar sudo file && \
echo '%wheel ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
adduser --uid ${VSCODE_USER_UID} ${VSCODE_USER} && \
usermod -a -G wheel ${VSCODE_USER} && \
yum clean all && \
rm -rf /var/cache/yum
......
#!/usr/bin/env bash
# Copyright 2018-2022 Istituto Nazionale di Fisica Nucleare
# SPDX-License-Identifier: EUPL-1.2
USERNAME=${1}
USER_UID=${2}
USER_GID=${3}
set -e
if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi
groupadd --gid $USER_GID $USERNAME
useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
yum install -y sudo
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME
chmod 0440 /etc/sudoers.d/$USERNAME
CODESPACES_BASH="$(cat \
<<'EOF'
# Codespaces bash prompt theme
__bash_prompt() {
local userpart='`export XIT=$? \
&& [ ! -z "${GITHUB_USER}" ] && echo -n "\[\033[0;32m\]@${GITHUB_USER} " || echo -n "\[\033[0;32m\]\u " \
&& [ "$XIT" -ne "0" ] && echo -n "\[\033[1;31m\]➜" || echo -n "\[\033[0m\]➜"`'
local gitbranch='`\
export BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null); \
if [ "${BRANCH}" = "HEAD" ]; then \
export BRANCH=$(git describe --contains --all HEAD 2>/dev/null); \
fi; \
if [ "${BRANCH}" != "" ]; then \
echo -n "\[\033[0;36m\](\[\033[1;31m\]${BRANCH}" \
&& if git ls-files --error-unmatch -m --directory --no-empty-directory -o --exclude-standard ":/*" > /dev/null 2>&1; then \
echo -n " \[\033[1;33m\]✗"; \
fi \
&& echo -n "\[\033[0;36m\]) "; \
fi`'
local lightblue='\[\033[1;34m\]'
local removecolor='\[\033[0m\]'
PS1="${userpart} ${lightblue}\w ${gitbranch}${removecolor}\$ "
unset -f __bash_prompt
}
__bash_prompt
EOF
)"
USER_RC_PATH="/home/${USERNAME}"
echo "${CODESPACES_BASH}" >> "${USER_RC_PATH}/.bashrc"
chown ${USERNAME}:${USERNAME} "${USER_RC_PATH}/.bashrc"
echo "Done!"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment