Files
my-dev-server/entrypoint.sh
mol 74f74bf8f8
All checks were successful
continuous-integration/drone/push Build is passing
更新 entrypoint.sh
2024-02-25 06:12:50 +00:00

63 lines
1.9 KiB
Bash

#!/bin/bash
set -eu
# if [ -n "$ROOT_PASSWD" ]; then
# echo "root:${ROOT_PASSWD}" | chpasswd
# echo "密码设置完毕" >> /root/info.log
# fi
# 初始化
if [ "${DOCKER_USER-}" ]; then
USER="$DOCKER_USER"
USER_HOME="$(id -un 1000)"
if [ "$DOCKER_USER" != "$USER_HOME" ]; then
# 无密码sudo
echo "$DOCKER_USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/nopasswd > /dev/null
# Unfortunately we cannot change $HOME as we cannot move any bind mounts
# nor can we bind mount $HOME into a new home as that requires a privileged container.
sudo usermod --login "$DOCKER_USER" "$USER_HOME"
sudo groupmod -n "$DOCKER_USER" "$USER_HOME"
#sudo printf "user: $DOCKER_USER\ngroup: $DOCKER_USER\n" > /etc/fixuid/config.yml
if [ -e "/home/coder/.gitconfig" ]; then
echo "git配置文件已存在"
else
touch /home/coder/.gitconfig
echo "git配置文件已创建"
fi
# git使用openssh的shh程序
su "$(id -un 1000)" -c "git config --global core.sshCommand /usr/bin/ssh"
if [ -n "$GIT_USER" ] && [ -n "$GIT_EMAIL" ]; then
su "$(id -un 1000)" -c "git config --global user.name '$GIT_USER'"
su "$(id -un 1000)" -c "git config --global user.email '$GIT_EMAIL'"
echo "git 用户已设置完毕"
fi
sudo chown -R "$DOCKER_USER":999 /home/coder
# 移除无密码sudo
sudo sed -i "/coder/d" /etc/sudoers.d/nopasswd
fi
fi
service ssh start
ssh-agent bash
# We do this first to ensure sudo works below when renaming the user.
# Otherwise the current container UID may not exist in the passwd database.
# eval "$(fixuid -q)"
# Allow users to have scripts run on container startup to prepare workspace.
# https://github.com/coder/code-server/issues/5177
if [ -d "${ENTRYPOINTD}" ]; then
find "${ENTRYPOINTD}" -type f -executable -print -exec {} \;
fi
su "$(id -un 1000)" -c "exec dumb-init /usr/bin/code-server '$@'"