mirror of
https://github.com/aleleba/aleleba-vscode-dockerfile-configuration.git
synced 2025-01-09 13:16:48 -06:00
139 lines
4.4 KiB
Bash
Executable File
139 lines
4.4 KiB
Bash
Executable File
#!/bin/bash
|
|
set -eu
|
|
|
|
if [[ -z "${HOME_USER-}" ]]; then
|
|
HOME_USER="vscode"
|
|
fi
|
|
|
|
if ! grep -q "HOME_USER=" /etc/environment; then
|
|
sudo bash -c "echo HOME_USER=$HOME_USER >> /etc/environment"
|
|
fi
|
|
|
|
if [[ -v VSCODE_TUNNEL_NAME && -n "${VSCODE_TUNNEL_NAME}" ]]; then
|
|
if ! grep -q "VSCODE_TUNNEL_NAME=" /etc/environment; then
|
|
sudo bash -c "echo VSCODE_TUNNEL_NAME=$VSCODE_TUNNEL_NAME >> /etc/environment"
|
|
fi
|
|
fi
|
|
|
|
# List all environment variables
|
|
sudo env |
|
|
|
|
# Filter variables that start with GLOBAL_ENV_
|
|
grep -E '^GLOBAL_ENV_' |
|
|
|
|
# Exclude GLOBAL_ENV_HOME_USER and GLOBAL_ENV_VSCODE_TUNNEL_NAME
|
|
grep -vE '^(GLOBAL_ENV_HOME_USER|GLOBAL_ENV_VSCODE_TUNNEL_NAME)=' |
|
|
|
|
# Remove the GLOBAL_ENV_ prefix
|
|
sed 's/^GLOBAL_ENV_//' |
|
|
|
|
# Append the result to /etc/environment if not already present
|
|
while IFS= read -r line
|
|
do
|
|
if ! grep -q "^${line%=*}=" /etc/environment; then
|
|
echo "export $line" | sudo tee -a /etc/environment
|
|
fi
|
|
done
|
|
|
|
USER="$HOME_USER"
|
|
if ! id -u $HOME_USER > /dev/null 2>&1; then
|
|
sudo adduser --disabled-password --gecos "" --uid 1000 ${HOME_USER}
|
|
sudo echo "$HOME_USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/nopasswd > /dev/null
|
|
|
|
# Check if the .bashrc file exists, if not, create it
|
|
#if [ ! -f /home/${HOME_USER}/.bashrc ]; then
|
|
#sudo touch /home/${HOME_USER}/.bashrc
|
|
#fi
|
|
|
|
# Change the ownership of the .bashrc file
|
|
#sudo chown ${HOME_USER} /home/${HOME_USER}/.bashrc
|
|
|
|
# List all environment variables
|
|
#sudo env |
|
|
|
|
# Filter variables that start with USER_ENV_
|
|
#grep -E '^USER_ENV_' |
|
|
|
|
# Remove the USER_ENV_ prefix
|
|
#sed 's/^USER_ENV_//' |
|
|
|
|
# Append the result to /home/${HOME_USER}/.bashrc
|
|
#while IFS= read -r line
|
|
#do
|
|
#echo "export $line" | sudo -u ${HOME_USER} tee -a /home/${HOME_USER}/.bashrc
|
|
#done
|
|
|
|
# Creating .vscode folder if it doesn't exist
|
|
if [ ! -d "/home/${HOME_USER}/.vscode" ]; then
|
|
sudo mkdir -p /home/${HOME_USER}/.vscode
|
|
fi
|
|
|
|
# Changing the property of the directory /home/${HOME_USER}/.vscode
|
|
sudo chown -R ${HOME_USER} /home/${HOME_USER}/.vscode
|
|
fi
|
|
|
|
# Then execute entrypoint.sh
|
|
if [ "$HOME_USER" != "$(whoami)" ]; then
|
|
exec sudo -u $HOME_USER bash -c "source /etc/environment; /usr/bin/entrypoint.sh"
|
|
else
|
|
sudo chown -R 1000 /home/${HOME_USER}
|
|
fi
|
|
|
|
# Find .sh files in /usr/bin/custom-scripts and execute them in order
|
|
for script in $(find /usr/bin/custom-scripts -name "*.sh" | sort); do
|
|
chmod +x $script
|
|
sudo -u $HOME_USER bash -c "source /etc/environment; $script"
|
|
done
|
|
|
|
# Move the .bashrc file to the user's home directory
|
|
sudo mv /usr/bin/.bashrc /home/${HOME_USER}/.bashrc
|
|
sudo chown ${HOME_USER} /home/${HOME_USER}/.bashrc
|
|
|
|
# Move the .profile file to the user's home directory
|
|
sudo mv /usr/bin/.profile /home/${HOME_USER}/.profile
|
|
sudo chown ${HOME_USER} /home/${HOME_USER}/.profile
|
|
|
|
#Creating extensions folder
|
|
if [ ! -d "/home/${HOME_USER}/.config/Code" ]; then
|
|
sudo mkdir -p /home/${HOME_USER}/.config/Code
|
|
fi
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.config/Code
|
|
|
|
if [ ! -d "/home/${HOME_USER}/.vscode-server" ]; then
|
|
sudo mkdir -p /home/${HOME_USER}/.vscode-server
|
|
fi
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.vscode-server
|
|
|
|
if [ ! -d "/home/${HOME_USER}/.vscode-server-insiders" ]; then
|
|
sudo mkdir -p /home/${HOME_USER}/.vscode-server-insiders
|
|
fi
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.vscode-server-insiders
|
|
|
|
# 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)
|
|
|
|
# Use jq to extract the extension parameter from the JSON array
|
|
extensions=$(echo $jsonExtensions | jq -r '.[].extensionsGroup.extensions[].uniqueIdentifier')
|
|
|
|
# Loop through the extensions and process each element
|
|
for extension in $extensions; do
|
|
echo "Installing extension: $extension"
|
|
sudo su ${HOME_USER} -c "code --install-extension $extension"
|
|
done
|
|
sudo cp -R /home/${HOME_USER}/.vscode/* /home/${HOME_USER}/.vscode-server
|
|
sudo cp -R /home/${HOME_USER}/.vscode/* /home/${HOME_USER}/.vscode-server-insiders
|
|
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
|
|
else
|
|
echo "File extensions.json not found"
|
|
fi
|
|
|
|
if [[ -v VSCODE_TUNNEL_NAME && -n "${VSCODE_TUNNEL_NAME}" ]]; then
|
|
sudo su ${HOME_USER} -c "code tunnel --accept-server-license-terms --name ${VSCODE_TUNNEL_NAME}"
|
|
else
|
|
sudo su ${HOME_USER} -c "code tunnel --accept-server-license-terms"
|
|
fi
|