2023-08-25 10:29:22 -06:00
|
|
|
#!/bin/bash
|
2024-02-14 19:05:41 -06:00
|
|
|
set -eu
|
|
|
|
|
2024-02-14 15:32:17 -06:00
|
|
|
if [[ -z "${HOME_USER}" ]]; then
|
|
|
|
HOME_USER="vscode"
|
|
|
|
fi
|
2024-02-14 15:15:23 -06:00
|
|
|
|
2024-02-14 19:05:41 -06:00
|
|
|
#addgroup nonroot
|
|
|
|
#adduser --disabled-password --gecos "" ${HOME_USER}
|
|
|
|
#echo "${HOME_USER} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
2024-02-14 15:15:23 -06:00
|
|
|
|
|
|
|
# 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)"
|
|
|
|
|
2024-02-15 12:41:29 -06:00
|
|
|
if [ "${HOME_USER-}" ]; then
|
|
|
|
USER="$HOME_USER"
|
|
|
|
if [ "$HOME_USER" != "$(whoami)" ]; then
|
2024-04-08 19:56:06 -06:00
|
|
|
if ! id -u $HOME_USER > /dev/null 2>&1; then
|
|
|
|
sudo adduser --disabled-password --gecos "" ${HOME_USER}
|
|
|
|
sudo echo "$HOME_USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/nopasswd > /dev/null
|
|
|
|
fi
|
2024-04-08 18:21:44 -06:00
|
|
|
|
|
|
|
# Copy environment variables from vscode user to HOME_USER
|
|
|
|
env | grep -v 'HOME_USER' | while read -r line; do
|
|
|
|
sudo su - ${HOME_USER} -c "echo 'export $line' >> ~/.bashrc"
|
|
|
|
done
|
|
|
|
|
2024-04-08 15:31:42 -06:00
|
|
|
sudo -u $HOME_USER -i
|
|
|
|
# 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.
|
2024-04-08 19:04:04 -06:00
|
|
|
# sudo usermod --login "$HOME_USER" vscode
|
|
|
|
# sudo groupmod -n "$HOME_USER" vscode
|
2024-04-08 15:31:42 -06:00
|
|
|
|
2024-04-08 19:56:06 -06:00
|
|
|
# sudo sed -i "/vscode/d" /etc/sudoers.d/nopasswd
|
|
|
|
# sudo cd /home/${HOME_USER}
|
|
|
|
sudo chown -R ${HOME_USER}:${HOME_USER} /home/${HOME_USER}
|
2024-02-14 15:15:23 -06:00
|
|
|
fi
|
2023-08-25 12:20:22 -06:00
|
|
|
fi
|
|
|
|
|
2023-08-25 19:20:38 -06:00
|
|
|
|
2023-08-29 10:11:28 -06:00
|
|
|
#Creating extensions folder
|
2024-04-08 19:56:06 -06:00
|
|
|
if [ ! -d "/home/${HOME_USER}/.config/Code" ]; then
|
|
|
|
sudo mkdir -p /home/${HOME_USER}/.config/Code
|
|
|
|
fi
|
2023-08-29 11:15:51 -06:00
|
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.config/Code
|
2024-04-08 19:56:06 -06:00
|
|
|
|
|
|
|
if [ ! -d "/home/${HOME_USER}/.vscode-server" ]; then
|
|
|
|
sudo mkdir -p /home/${HOME_USER}/.vscode-server
|
|
|
|
fi
|
2023-08-29 10:11:28 -06:00
|
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.vscode-server
|
2024-04-08 19:56:06 -06:00
|
|
|
|
|
|
|
if [ ! -d "/home/${HOME_USER}/.vscode-server-insiders" ]; then
|
|
|
|
sudo mkdir -p /home/${HOME_USER}/.vscode-server-insiders
|
|
|
|
fi
|
2023-08-29 13:39:54 -06:00
|
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.vscode-server-insiders
|
2023-08-29 10:11:28 -06:00
|
|
|
|
2023-08-29 06:56:31 -06:00
|
|
|
# Check if the data.json file exists
|
|
|
|
if [ -f "/home/extensions.json" ]; then
|
|
|
|
# Read the JSON file into a variable
|
|
|
|
jsonExtensions=$(cat /home/extensions.json)
|
|
|
|
|
2023-09-01 11:07:46 -06:00
|
|
|
# Use jq to extract the extension parameter from the JSON array
|
2023-09-01 12:11:04 -06:00
|
|
|
extensions=$(echo $jsonExtensions | jq -r '.[].extensionsGroup.extensions[].uniqueIdentifier')
|
2023-08-29 06:56:31 -06:00
|
|
|
|
|
|
|
# Loop through the extensions and process each element
|
|
|
|
for extension in $extensions; do
|
|
|
|
echo "Installing extension: $extension"
|
2023-08-29 10:17:01 -06:00
|
|
|
sudo su - ${HOME_USER} -c "code --install-extension $extension"
|
2023-08-29 06:56:31 -06:00
|
|
|
done
|
2023-08-29 13:39:54 -06:00
|
|
|
sudo cp -R /home/${HOME_USER}/.vscode/* /home/${HOME_USER}/.vscode-server
|
2023-08-29 21:55:28 -06:00
|
|
|
sudo cp -R /home/${HOME_USER}/.vscode/* /home/${HOME_USER}/.vscode-server-insiders
|
2023-08-29 13:39:54 -06:00
|
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.vscode
|
|
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.vscode-server
|
|
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.vscode-server-insiders
|
2023-08-29 06:56:31 -06:00
|
|
|
else
|
|
|
|
echo "File extensions.json not found"
|
|
|
|
fi
|
|
|
|
|
2023-08-25 12:20:22 -06:00
|
|
|
if [[ -z "${VSCODE_TUNNEL_NAME}" ]]; then
|
2024-04-08 15:31:42 -06:00
|
|
|
sudo su - ${HOME_USER} -c "code tunnel --accept-server-license-terms"
|
2023-08-25 12:20:22 -06:00
|
|
|
else
|
2024-04-08 15:31:42 -06:00
|
|
|
sudo su - ${HOME_USER} -c "code tunnel --accept-server-license-terms --name ${VSCODE_TUNNEL_NAME}"
|
2023-08-25 12:20:22 -06:00
|
|
|
fi
|