This commit is contained in:
@ -1,58 +1,61 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
# if [ -n "$ROOT_PASSWD" ]; then
|
# if [ -n "$ROOT_PASSWD" ]; then
|
||||||
# echo "root:${ROOT_PASSWD}" | chpasswd
|
# echo "root:${ROOT_PASSWD}" | chpasswd
|
||||||
# echo "密码设置完毕" >> /root/info.log
|
# echo "密码设置完毕" >> /root/info.log
|
||||||
# fi
|
# fi
|
||||||
|
|
||||||
if [ -e "/home/coder/.gitconfig" ]; then
|
# 初始化
|
||||||
echo "git配置文件已存在" >> /tmp/log/info.log
|
if [ "${DOCKER_USER-}" ]; then
|
||||||
else
|
USER="$DOCKER_USER"
|
||||||
touch /home/coder/.gitconfig
|
if [ "$DOCKER_USER" != "$(id -un 1000)" ]; then
|
||||||
echo "git配置文件已创建" >> /tmp/log/info.log
|
# 无密码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" "$(id -un 1000)"
|
||||||
|
sudo groupmod -n "$DOCKER_USER" "$(id -un 1000)"
|
||||||
|
|
||||||
|
sudo chown -R "$DOCKER_USER":999 /home/coder
|
||||||
|
|
||||||
|
|
||||||
|
if [ -e "/home/coder/.gitconfig" ]; then
|
||||||
|
echo "git配置文件已存在"
|
||||||
|
else
|
||||||
|
touch /home/coder/.gitconfig
|
||||||
|
echo "git配置文件已创建"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# git使用openssh的shh程序
|
||||||
|
git config --global core.sshCommand "/usr/bin/ssh"
|
||||||
|
|
||||||
|
if [ -n "$GIT_USER" ] && [ -n "$GIT_EMAIL" ]; then
|
||||||
|
git config --global user.name "$GIT_USER"
|
||||||
|
git config --global user.email "$GIT_EMAIL"
|
||||||
|
echo "git 用户已设置完毕"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$DOCKER_USER" ] && [ -n "$DOCKER_PASSWD" ]; then
|
||||||
|
docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWD"
|
||||||
|
echo "docker 用户登录完成"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 移除无密码sudo
|
||||||
|
sudo sed -i "/coder/d" /etc/sudoers.d/nopasswd
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# git使用openssh的shh程序
|
service ssh start
|
||||||
git config --global core.sshCommand "/usr/bin/ssh"
|
ssh-agent bash
|
||||||
|
|
||||||
if [ -n "$GIT_USER" ] && [ -n "$GIT_EMAIL" ]; then
|
|
||||||
git config --global user.name "$GIT_USER"
|
|
||||||
git config --global user.email "$GIT_EMAIL"
|
|
||||||
echo "git 用户已设置完毕" >> /tmp/log/info.log
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$DOCKER_USER" ] && [ -n "$DOCKER_PASSWD" ]; then
|
|
||||||
docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWD"
|
|
||||||
echo "docker 用户登录完成" >> /tmp/log/info.log
|
|
||||||
fi
|
|
||||||
|
|
||||||
service ssh start >> /tmp/log/info.log
|
|
||||||
ssh-agent bash >> /tmp/log/info.log
|
|
||||||
|
|
||||||
cat /tmp/log/info.log
|
|
||||||
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
# We do this first to ensure sudo works below when renaming the user.
|
# 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.
|
# Otherwise the current container UID may not exist in the passwd database.
|
||||||
eval "$(fixuid -q)"
|
eval "$(fixuid -q)"
|
||||||
|
|
||||||
su "$(id -un 1000)"
|
su "$(id -un 1000)"
|
||||||
if [ "${DOCKER_USER-}" ]; then
|
|
||||||
USER="$DOCKER_USER"
|
|
||||||
if [ "$DOCKER_USER" != "$(whoami)" ]; then
|
|
||||||
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 useradd -d /home/coder coder
|
|
||||||
sudo usermod --login "$DOCKER_USER" "$(id -un 1000)"
|
|
||||||
sudo groupmod -n "$DOCKER_USER" "$(id -un 1000)"
|
|
||||||
|
|
||||||
sudo sed -i "/coder/d" /etc/sudoers.d/nopasswd
|
|
||||||
|
|
||||||
chown -R "$DOCKER_USER":999 /home/coder
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Allow users to have scripts run on container startup to prepare workspace.
|
# Allow users to have scripts run on container startup to prepare workspace.
|
||||||
# https://github.com/coder/code-server/issues/5177
|
# https://github.com/coder/code-server/issues/5177
|
||||||
|
Reference in New Issue
Block a user