diff --git a/cgmanifest.json b/cgmanifest.json index df0ec42ea3..341ad0df77 100644 --- a/cgmanifest.json +++ b/cgmanifest.json @@ -850,6 +850,296 @@ } } }, + { + "Component": { + "Type": "DockerImage", + "DockerImage": { + "Name": "mcr.microsoft.com/dotnet/core/sdk", + "Digest": "sha256:c6d4246852f11785f0459d499d4d5a48b4de05e5685c718137acea294ecf899e", + "Tag": "3.1-bionic" + } + } + }, + { + "Component": { + "Type": "DockerImage", + "DockerImage": { + "Name": "mcr.microsoft.com/dotnet/core/sdk", + "Digest": "sha256:d6ee59a3745deef84a87eda04bc42626033f18b357efd214e0fcc043fd3784de", + "Tag": "2.1-bionic" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: apt-transport-https", + "Version": "1.6.12ubuntu0.1", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/universe/a/apt/apt-transport-https_1.6.12ubuntu0.1_all.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: apt-utils", + "Version": "1.6.12ubuntu0.1", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/a/apt/apt-utils_1.6.12ubuntu0.1_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: ca-certificates", + "Version": "20190110~18.04.1", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/c/ca-certificates/ca-certificates_20190110~18.04.1_all.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: curl", + "Version": "7.58.0-2ubuntu3.9", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/c/curl/curl_7.58.0-2ubuntu3.9_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: dialog", + "Version": "1.3-20171209-1", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/universe/d/dialog/dialog_1.3-20171209-1_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: git", + "Version": "1:2.17.1-1ubuntu0.7", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/g/git/git_2.17.1-1ubuntu0.7_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: gnupg", + "Version": "2.2.4-1ubuntu1.2", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/g/gnupg2/gnupg_2.2.4-1ubuntu1.2_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: iproute2", + "Version": "4.15.0-2ubuntu1.2", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/i/iproute2/iproute2_4.15.0-2ubuntu1.2_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: jq", + "Version": "1.5+dfsg-2", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/universe/j/jq/jq_1.5+dfsg-2_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: less", + "Version": "487-0.1", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/l/less/less_487-0.1_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: libc6", + "Version": "2.27-3ubuntu1.2", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/g/glibc/libc6_2.27-3ubuntu1.2_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: libgcc1", + "Version": "1:8.4.0-1ubuntu1~18.04", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-8/libgcc1_8.4.0-1ubuntu1~18.04_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: libgssapi-krb5-2", + "Version": "1.16-2ubuntu0.1", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/k/krb5/libgssapi-krb5-2_1.16-2ubuntu0.1_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: libicu60", + "Version": "60.2-3ubuntu3.1", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/i/icu/libicu60_60.2-3ubuntu3.1_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: libssl1.1", + "Version": "1.1.1-1ubuntu2.1~18.04.6", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1-1ubuntu2.1~18.04.6_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: libstdc++6", + "Version": "8.4.0-1ubuntu1~18.04", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-8/libstdc++6_8.4.0-1ubuntu1~18.04_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: lsb-release", + "Version": "9.20170808ubuntu1", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/l/lsb/lsb-release_9.20170808ubuntu1_all.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: nano", + "Version": "2.9.3-2", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/n/nano/nano_2.9.3-2_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: openssh-client", + "Version": "1:7.6p1-4ubuntu0.3", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/o/openssh/openssh-client_7.6p1-4ubuntu0.3_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: procps", + "Version": "2:3.3.12-3ubuntu1.2", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/p/procps/procps_3.3.12-3ubuntu1.2_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: sudo", + "Version": "1.8.21p2-3ubuntu1.2", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/s/sudo/sudo_1.8.21p2-3ubuntu1.2_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: unzip", + "Version": "6.0-21ubuntu1", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/u/unzip/unzip_6.0-21ubuntu1_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: wget", + "Version": "1.19.4-1ubuntu2.2", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/w/wget/wget_1.19.4-1ubuntu2.2_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: yarn", + "Version": "1.22.4-1", + "DownloadUrl": "https://dl.yarnpkg.com/debian/pool/main/y/yarn/yarn_1.22.4_all.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: zlib1g", + "Version": "1:1.2.11.dfsg-0ubuntu2", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/z/zlib/zlib1g_1.2.11.dfsg-0ubuntu2_amd64.deb" + } + } + }, + { + "Component": { + "Type": "other", + "Other": { + "Name": "Debian Package: zsh", + "Version": "5.4.2-3ubuntu3.1", + "DownloadUrl": "http://archive.ubuntu.com/ubuntu/pool/main/z/zsh/zsh_5.4.2-3ubuntu3.1_amd64.deb" + } + } + }, + { + "Component": { + "Type": "git", + "git": { + "Name": "Nvm", + "repositoryUrl": "https://github.com/nvm-sh/nvm", + "commitHash": "f355b327d6a2a4e8020e943974086d53f00f9a02" + } + } + }, { "Component": { "Type": "DockerImage", @@ -880,16 +1170,6 @@ } } }, - { - "Component": { - "Type": "other", - "Other": { - "Name": "Debian Package: yarn", - "Version": "1.22.4-1", - "DownloadUrl": "https://dl.yarnpkg.com/debian/pool/main/y/yarn/yarn_1.22.4_all.deb" - } - } - }, { "Component": { "Type": "go", @@ -1099,11 +1379,21 @@ }, { "Component": { - "Type": "git", - "git": { - "Name": "Nvm", - "repositoryUrl": "https://github.com/nvm-sh/nvm", - "commitHash": "f355b327d6a2a4e8020e943974086d53f00f9a02" + "Type": "DockerImage", + "DockerImage": { + "Name": "openjdk", + "Digest": "sha256:39b8040fcb319c3c53e3558cca15a5c0792637ea6c02df9688785b4e7a413b2b", + "Tag": "14-jdk-buster" + } + } + }, + { + "Component": { + "Type": "DockerImage", + "DockerImage": { + "Name": "openjdk", + "Digest": "sha256:aaab9fa95bae5708d979a0035e5c617fa44c94bcd0d3cbbdf90b84f2ac323fad", + "Tag": "11-jdk-buster" } } }, @@ -1172,7 +1462,7 @@ "Type": "DockerImage", "DockerImage": { "Name": "python", - "Digest": "sha256:6ca82c8d96a24523a71f40bb38f5682b18ca74a7a19586927c79e714b1b906c4", + "Digest": "sha256:0bb57c218e452ace5a4d55ee3c56e3c57e29c7f43cf55192acf7289becff4b0e", "Tag": "3.7" } } @@ -1182,7 +1472,7 @@ "Type": "DockerImage", "DockerImage": { "Name": "python", - "Digest": "sha256:4ec64894c98dd0de6804e046359be6ae0820699d89a98ed4b2f62ccbea37f044", + "Digest": "sha256:ed4141f76f901c193856a8946283218c67e8dbfc258480fb6947829982913939", "Tag": "3.6" } } @@ -1273,7 +1563,7 @@ "Type": "Pip", "Pip": { "Name": "virtualenv", - "Version": "20.0.30" + "Version": "20.0.31" } } }, diff --git a/containers/alpine/.devcontainer/library-scripts/common-alpine.sh b/containers/alpine/.devcontainer/library-scripts/common-alpine.sh index 4761044831..7192f0892b 100755 --- a/containers/alpine/.devcontainer/library-scripts/common-alpine.sh +++ b/containers/alpine/.devcontainer/library-scripts/common-alpine.sh @@ -79,3 +79,4 @@ if [ "$INSTALL_ZSH" = "true" ] && [ ! -d "/root/.oh-my-zsh" ]; then sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi +echo "Done!" diff --git a/containers/azure-ansible/.devcontainer/library-scripts/azcli-debian.sh b/containers/azure-ansible/.devcontainer/library-scripts/azcli-debian.sh index b2ac3a8556..cc6baeff95 100644 --- a/containers/azure-ansible/.devcontainer/library-scripts/azcli-debian.sh +++ b/containers/azure-ansible/.devcontainer/library-scripts/azcli-debian.sh @@ -28,3 +28,4 @@ echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_rel curl -sL https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT) apt-get update apt-get install -y azure-cli +echo "Done!" \ No newline at end of file diff --git a/containers/azure-ansible/.devcontainer/library-scripts/common-debian.sh b/containers/azure-ansible/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/azure-ansible/.devcontainer/library-scripts/common-debian.sh +++ b/containers/azure-ansible/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/azure-ansible/.devcontainer/library-scripts/docker-debian.sh b/containers/azure-ansible/.devcontainer/library-scripts/docker-debian.sh index d375ac0778..e711dbd9bf 100644 --- a/containers/azure-ansible/.devcontainer/library-scripts/docker-debian.sh +++ b/containers/azure-ansible/.devcontainer/library-scripts/docker-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./docker-debian.sh +# Syntax: ./docker-debian.sh [enable non-root docker socket access flag] [source socket] [target socket] [non-root user] ENABLE_NONROOT_DOCKER=${1:-"true"} SOURCE_SOCKET=${2:-"/var/run/docker-host.sock"} @@ -145,7 +145,9 @@ fi # Execute whatever commands were passed in (if any). This allows us # to set this script to ENTRYPOINT while still executing the default CMD. +set +e exec "\$@" EOF chmod +x /usr/local/share/docker-init.sh chown ${USERNAME}:root /usr/local/share/docker-init.sh +echo "Done!" \ No newline at end of file diff --git a/containers/azure-ansible/.devcontainer/library-scripts/node-debian.sh b/containers/azure-ansible/.devcontainer/library-scripts/node-debian.sh index 2837fc77b4..99d80cfee0 100644 --- a/containers/azure-ansible/.devcontainer/library-scripts/node-debian.sh +++ b/containers/azure-ansible/.devcontainer/library-scripts/node-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./node-debian.sh +# Syntax: ./node-debian.sh [directory to install nvm] [node version to install (use "none" to skip)] [non-root user] export NVM_DIR=${1:-"/usr/local/share/nvm"} export NODE_VERSION=${2:-"lts/*"} @@ -17,8 +17,8 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi -# Treat a user name of "none" as root -if [ "${USERNAME}" = "none" ]; then +# Treat a user name of "none" or non-existant user as root +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -51,46 +51,40 @@ fi if [ -d "${NVM_DIR}" ]; then echo "NVM already installed." if [ "${NODE_VERSION}" != "" ]; then - suIf "nvm install ${NODE_VERSION}" + su ${USERNAME} -c "nvm install ${NODE_VERSION}" fi exit 0 fi mkdir -p ${NVM_DIR} +NVM_INIT=$(cat <> /etc/skel/.bashrc # Set up non-root user if applicable -if [ "${USERNAME}" != "root" ] && id -u $USERNAME > /dev/null 2>&1; then +if [ "${USERNAME}" != "root" ]; then # Add NVM init and add code to update NVM ownership if UID/GID changes - tee -a /root/.bashrc /root/.zshrc /home/${USERNAME}/.bashrc >> /home/${USERNAME}/.zshrc \ -<> /home/${USERNAME}/.zshrc chown ${USERNAME} ${NVM_DIR} /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ] && id -u ${USERNAME} > /dev/null 2>&1; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} - # Run NVM installer as non-root if needed -suIf "$(cat \ -<< EOF - curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash - if [ "${NODE_VERSION}" != "" ]; then - source $NVM_DIR/nvm.sh - nvm alias default ${NODE_VERSION} - fi +su ${USERNAME} -c "$(cat << EOF + set -e + curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash + if [ "${NODE_VERSION}" != "" ]; then + source $NVM_DIR/nvm.sh + nvm alias default ${NODE_VERSION} + fi EOF )" 2>&1 +echo "Done!" \ No newline at end of file diff --git a/containers/azure-blockchain/.devcontainer/library-scripts/azcli-debian.sh b/containers/azure-blockchain/.devcontainer/library-scripts/azcli-debian.sh index b2ac3a8556..cc6baeff95 100644 --- a/containers/azure-blockchain/.devcontainer/library-scripts/azcli-debian.sh +++ b/containers/azure-blockchain/.devcontainer/library-scripts/azcli-debian.sh @@ -28,3 +28,4 @@ echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_rel curl -sL https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT) apt-get update apt-get install -y azure-cli +echo "Done!" \ No newline at end of file diff --git a/containers/azure-blockchain/.devcontainer/library-scripts/common-debian.sh b/containers/azure-blockchain/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/azure-blockchain/.devcontainer/library-scripts/common-debian.sh +++ b/containers/azure-blockchain/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/azure-blockchain/.devcontainer/library-scripts/node-debian.sh b/containers/azure-blockchain/.devcontainer/library-scripts/node-debian.sh index 2837fc77b4..99d80cfee0 100644 --- a/containers/azure-blockchain/.devcontainer/library-scripts/node-debian.sh +++ b/containers/azure-blockchain/.devcontainer/library-scripts/node-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./node-debian.sh +# Syntax: ./node-debian.sh [directory to install nvm] [node version to install (use "none" to skip)] [non-root user] export NVM_DIR=${1:-"/usr/local/share/nvm"} export NODE_VERSION=${2:-"lts/*"} @@ -17,8 +17,8 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi -# Treat a user name of "none" as root -if [ "${USERNAME}" = "none" ]; then +# Treat a user name of "none" or non-existant user as root +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -51,46 +51,40 @@ fi if [ -d "${NVM_DIR}" ]; then echo "NVM already installed." if [ "${NODE_VERSION}" != "" ]; then - suIf "nvm install ${NODE_VERSION}" + su ${USERNAME} -c "nvm install ${NODE_VERSION}" fi exit 0 fi mkdir -p ${NVM_DIR} +NVM_INIT=$(cat <> /etc/skel/.bashrc # Set up non-root user if applicable -if [ "${USERNAME}" != "root" ] && id -u $USERNAME > /dev/null 2>&1; then +if [ "${USERNAME}" != "root" ]; then # Add NVM init and add code to update NVM ownership if UID/GID changes - tee -a /root/.bashrc /root/.zshrc /home/${USERNAME}/.bashrc >> /home/${USERNAME}/.zshrc \ -<> /home/${USERNAME}/.zshrc chown ${USERNAME} ${NVM_DIR} /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ] && id -u ${USERNAME} > /dev/null 2>&1; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} - # Run NVM installer as non-root if needed -suIf "$(cat \ -<< EOF - curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash - if [ "${NODE_VERSION}" != "" ]; then - source $NVM_DIR/nvm.sh - nvm alias default ${NODE_VERSION} - fi +su ${USERNAME} -c "$(cat << EOF + set -e + curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash + if [ "${NODE_VERSION}" != "" ]; then + source $NVM_DIR/nvm.sh + nvm alias default ${NODE_VERSION} + fi EOF )" 2>&1 +echo "Done!" \ No newline at end of file diff --git a/containers/azure-cli/.devcontainer/library-scripts/azcli-debian.sh b/containers/azure-cli/.devcontainer/library-scripts/azcli-debian.sh index b2ac3a8556..cc6baeff95 100644 --- a/containers/azure-cli/.devcontainer/library-scripts/azcli-debian.sh +++ b/containers/azure-cli/.devcontainer/library-scripts/azcli-debian.sh @@ -28,3 +28,4 @@ echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_rel curl -sL https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT) apt-get update apt-get install -y azure-cli +echo "Done!" \ No newline at end of file diff --git a/containers/azure-cli/.devcontainer/library-scripts/common-debian.sh b/containers/azure-cli/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/azure-cli/.devcontainer/library-scripts/common-debian.sh +++ b/containers/azure-cli/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/azure-functions-dotnetcore-2.1/.devcontainer/library-scripts/common-debian.sh b/containers/azure-functions-dotnetcore-2.1/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/azure-functions-dotnetcore-2.1/.devcontainer/library-scripts/common-debian.sh +++ b/containers/azure-functions-dotnetcore-2.1/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/azure-terraform/.devcontainer/library-scripts/azcli-debian.sh b/containers/azure-terraform/.devcontainer/library-scripts/azcli-debian.sh index b2ac3a8556..cc6baeff95 100644 --- a/containers/azure-terraform/.devcontainer/library-scripts/azcli-debian.sh +++ b/containers/azure-terraform/.devcontainer/library-scripts/azcli-debian.sh @@ -28,3 +28,4 @@ echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_rel curl -sL https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT) apt-get update apt-get install -y azure-cli +echo "Done!" \ No newline at end of file diff --git a/containers/azure-terraform/.devcontainer/library-scripts/common-debian.sh b/containers/azure-terraform/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/azure-terraform/.devcontainer/library-scripts/common-debian.sh +++ b/containers/azure-terraform/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/azure-terraform/.devcontainer/library-scripts/docker-debian.sh b/containers/azure-terraform/.devcontainer/library-scripts/docker-debian.sh index d375ac0778..e711dbd9bf 100644 --- a/containers/azure-terraform/.devcontainer/library-scripts/docker-debian.sh +++ b/containers/azure-terraform/.devcontainer/library-scripts/docker-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./docker-debian.sh +# Syntax: ./docker-debian.sh [enable non-root docker socket access flag] [source socket] [target socket] [non-root user] ENABLE_NONROOT_DOCKER=${1:-"true"} SOURCE_SOCKET=${2:-"/var/run/docker-host.sock"} @@ -145,7 +145,9 @@ fi # Execute whatever commands were passed in (if any). This allows us # to set this script to ENTRYPOINT while still executing the default CMD. +set +e exec "\$@" EOF chmod +x /usr/local/share/docker-init.sh chown ${USERNAME}:root /usr/local/share/docker-init.sh +echo "Done!" \ No newline at end of file diff --git a/containers/azure-terraform/.devcontainer/library-scripts/node-debian.sh b/containers/azure-terraform/.devcontainer/library-scripts/node-debian.sh index 2837fc77b4..99d80cfee0 100644 --- a/containers/azure-terraform/.devcontainer/library-scripts/node-debian.sh +++ b/containers/azure-terraform/.devcontainer/library-scripts/node-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./node-debian.sh +# Syntax: ./node-debian.sh [directory to install nvm] [node version to install (use "none" to skip)] [non-root user] export NVM_DIR=${1:-"/usr/local/share/nvm"} export NODE_VERSION=${2:-"lts/*"} @@ -17,8 +17,8 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi -# Treat a user name of "none" as root -if [ "${USERNAME}" = "none" ]; then +# Treat a user name of "none" or non-existant user as root +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -51,46 +51,40 @@ fi if [ -d "${NVM_DIR}" ]; then echo "NVM already installed." if [ "${NODE_VERSION}" != "" ]; then - suIf "nvm install ${NODE_VERSION}" + su ${USERNAME} -c "nvm install ${NODE_VERSION}" fi exit 0 fi mkdir -p ${NVM_DIR} +NVM_INIT=$(cat <> /etc/skel/.bashrc # Set up non-root user if applicable -if [ "${USERNAME}" != "root" ] && id -u $USERNAME > /dev/null 2>&1; then +if [ "${USERNAME}" != "root" ]; then # Add NVM init and add code to update NVM ownership if UID/GID changes - tee -a /root/.bashrc /root/.zshrc /home/${USERNAME}/.bashrc >> /home/${USERNAME}/.zshrc \ -<> /home/${USERNAME}/.zshrc chown ${USERNAME} ${NVM_DIR} /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ] && id -u ${USERNAME} > /dev/null 2>&1; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} - # Run NVM installer as non-root if needed -suIf "$(cat \ -<< EOF - curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash - if [ "${NODE_VERSION}" != "" ]; then - source $NVM_DIR/nvm.sh - nvm alias default ${NODE_VERSION} - fi +su ${USERNAME} -c "$(cat << EOF + set -e + curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash + if [ "${NODE_VERSION}" != "" ]; then + source $NVM_DIR/nvm.sh + nvm alias default ${NODE_VERSION} + fi EOF )" 2>&1 +echo "Done!" \ No newline at end of file diff --git a/containers/azure-terraform/.devcontainer/library-scripts/terraform-debian.sh b/containers/azure-terraform/.devcontainer/library-scripts/terraform-debian.sh index 4e0db26f70..b3601180f0 100644 --- a/containers/azure-terraform/.devcontainer/library-scripts/terraform-debian.sh +++ b/containers/azure-terraform/.devcontainer/library-scripts/terraform-debian.sh @@ -45,4 +45,4 @@ if [ "${TFLINT_VERSION}" != "none" ]; then fi rm -rf /tmp/tf-downloads -echo "Done." +echo "Done!" diff --git a/containers/bazel/.devcontainer/library-scripts/common-debian.sh b/containers/bazel/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/bazel/.devcontainer/library-scripts/common-debian.sh +++ b/containers/bazel/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/dart/.devcontainer/library-scripts/common-debian.sh b/containers/dart/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/dart/.devcontainer/library-scripts/common-debian.sh +++ b/containers/dart/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/debian/.devcontainer/library-scripts/common-debian.sh b/containers/debian/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/debian/.devcontainer/library-scripts/common-debian.sh +++ b/containers/debian/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/docker-from-docker-compose/.devcontainer/library-scripts/common-debian.sh b/containers/docker-from-docker-compose/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/docker-from-docker-compose/.devcontainer/library-scripts/common-debian.sh +++ b/containers/docker-from-docker-compose/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/docker-from-docker-compose/.devcontainer/library-scripts/docker-debian.sh b/containers/docker-from-docker-compose/.devcontainer/library-scripts/docker-debian.sh index d375ac0778..e711dbd9bf 100644 --- a/containers/docker-from-docker-compose/.devcontainer/library-scripts/docker-debian.sh +++ b/containers/docker-from-docker-compose/.devcontainer/library-scripts/docker-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./docker-debian.sh +# Syntax: ./docker-debian.sh [enable non-root docker socket access flag] [source socket] [target socket] [non-root user] ENABLE_NONROOT_DOCKER=${1:-"true"} SOURCE_SOCKET=${2:-"/var/run/docker-host.sock"} @@ -145,7 +145,9 @@ fi # Execute whatever commands were passed in (if any). This allows us # to set this script to ENTRYPOINT while still executing the default CMD. +set +e exec "\$@" EOF chmod +x /usr/local/share/docker-init.sh chown ${USERNAME}:root /usr/local/share/docker-init.sh +echo "Done!" \ No newline at end of file diff --git a/containers/docker-from-docker/.devcontainer/library-scripts/common-debian.sh b/containers/docker-from-docker/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/docker-from-docker/.devcontainer/library-scripts/common-debian.sh +++ b/containers/docker-from-docker/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/docker-from-docker/.devcontainer/library-scripts/docker-debian.sh b/containers/docker-from-docker/.devcontainer/library-scripts/docker-debian.sh index d375ac0778..e711dbd9bf 100644 --- a/containers/docker-from-docker/.devcontainer/library-scripts/docker-debian.sh +++ b/containers/docker-from-docker/.devcontainer/library-scripts/docker-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./docker-debian.sh +# Syntax: ./docker-debian.sh [enable non-root docker socket access flag] [source socket] [target socket] [non-root user] ENABLE_NONROOT_DOCKER=${1:-"true"} SOURCE_SOCKET=${2:-"/var/run/docker-host.sock"} @@ -145,7 +145,9 @@ fi # Execute whatever commands were passed in (if any). This allows us # to set this script to ENTRYPOINT while still executing the default CMD. +set +e exec "\$@" EOF chmod +x /usr/local/share/docker-init.sh chown ${USERNAME}:root /usr/local/share/docker-init.sh +echo "Done!" \ No newline at end of file diff --git a/containers/dotnetcore/.devcontainer/library-scripts/azcli-debian.sh b/containers/dotnetcore/.devcontainer/library-scripts/azcli-debian.sh index b2ac3a8556..cc6baeff95 100644 --- a/containers/dotnetcore/.devcontainer/library-scripts/azcli-debian.sh +++ b/containers/dotnetcore/.devcontainer/library-scripts/azcli-debian.sh @@ -28,3 +28,4 @@ echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_rel curl -sL https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT) apt-get update apt-get install -y azure-cli +echo "Done!" \ No newline at end of file diff --git a/containers/dotnetcore/.devcontainer/library-scripts/common-debian.sh b/containers/dotnetcore/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/dotnetcore/.devcontainer/library-scripts/common-debian.sh +++ b/containers/dotnetcore/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/dotnetcore/.devcontainer/library-scripts/node-debian.sh b/containers/dotnetcore/.devcontainer/library-scripts/node-debian.sh index 2837fc77b4..99d80cfee0 100644 --- a/containers/dotnetcore/.devcontainer/library-scripts/node-debian.sh +++ b/containers/dotnetcore/.devcontainer/library-scripts/node-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./node-debian.sh +# Syntax: ./node-debian.sh [directory to install nvm] [node version to install (use "none" to skip)] [non-root user] export NVM_DIR=${1:-"/usr/local/share/nvm"} export NODE_VERSION=${2:-"lts/*"} @@ -17,8 +17,8 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi -# Treat a user name of "none" as root -if [ "${USERNAME}" = "none" ]; then +# Treat a user name of "none" or non-existant user as root +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -51,46 +51,40 @@ fi if [ -d "${NVM_DIR}" ]; then echo "NVM already installed." if [ "${NODE_VERSION}" != "" ]; then - suIf "nvm install ${NODE_VERSION}" + su ${USERNAME} -c "nvm install ${NODE_VERSION}" fi exit 0 fi mkdir -p ${NVM_DIR} +NVM_INIT=$(cat <> /etc/skel/.bashrc # Set up non-root user if applicable -if [ "${USERNAME}" != "root" ] && id -u $USERNAME > /dev/null 2>&1; then +if [ "${USERNAME}" != "root" ]; then # Add NVM init and add code to update NVM ownership if UID/GID changes - tee -a /root/.bashrc /root/.zshrc /home/${USERNAME}/.bashrc >> /home/${USERNAME}/.zshrc \ -<> /home/${USERNAME}/.zshrc chown ${USERNAME} ${NVM_DIR} /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ] && id -u ${USERNAME} > /dev/null 2>&1; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} - # Run NVM installer as non-root if needed -suIf "$(cat \ -<< EOF - curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash - if [ "${NODE_VERSION}" != "" ]; then - source $NVM_DIR/nvm.sh - nvm alias default ${NODE_VERSION} - fi +su ${USERNAME} -c "$(cat << EOF + set -e + curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash + if [ "${NODE_VERSION}" != "" ]; then + source $NVM_DIR/nvm.sh + nvm alias default ${NODE_VERSION} + fi EOF )" 2>&1 +echo "Done!" \ No newline at end of file diff --git a/containers/go/.devcontainer/library-scripts/common-debian.sh b/containers/go/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/go/.devcontainer/library-scripts/common-debian.sh +++ b/containers/go/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/go/.devcontainer/library-scripts/node-debian.sh b/containers/go/.devcontainer/library-scripts/node-debian.sh index 2837fc77b4..99d80cfee0 100644 --- a/containers/go/.devcontainer/library-scripts/node-debian.sh +++ b/containers/go/.devcontainer/library-scripts/node-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./node-debian.sh +# Syntax: ./node-debian.sh [directory to install nvm] [node version to install (use "none" to skip)] [non-root user] export NVM_DIR=${1:-"/usr/local/share/nvm"} export NODE_VERSION=${2:-"lts/*"} @@ -17,8 +17,8 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi -# Treat a user name of "none" as root -if [ "${USERNAME}" = "none" ]; then +# Treat a user name of "none" or non-existant user as root +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -51,46 +51,40 @@ fi if [ -d "${NVM_DIR}" ]; then echo "NVM already installed." if [ "${NODE_VERSION}" != "" ]; then - suIf "nvm install ${NODE_VERSION}" + su ${USERNAME} -c "nvm install ${NODE_VERSION}" fi exit 0 fi mkdir -p ${NVM_DIR} +NVM_INIT=$(cat <> /etc/skel/.bashrc # Set up non-root user if applicable -if [ "${USERNAME}" != "root" ] && id -u $USERNAME > /dev/null 2>&1; then +if [ "${USERNAME}" != "root" ]; then # Add NVM init and add code to update NVM ownership if UID/GID changes - tee -a /root/.bashrc /root/.zshrc /home/${USERNAME}/.bashrc >> /home/${USERNAME}/.zshrc \ -<> /home/${USERNAME}/.zshrc chown ${USERNAME} ${NVM_DIR} /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ] && id -u ${USERNAME} > /dev/null 2>&1; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} - # Run NVM installer as non-root if needed -suIf "$(cat \ -<< EOF - curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash - if [ "${NODE_VERSION}" != "" ]; then - source $NVM_DIR/nvm.sh - nvm alias default ${NODE_VERSION} - fi +su ${USERNAME} -c "$(cat << EOF + set -e + curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash + if [ "${NODE_VERSION}" != "" ]; then + source $NVM_DIR/nvm.sh + nvm alias default ${NODE_VERSION} + fi EOF )" 2>&1 +echo "Done!" \ No newline at end of file diff --git a/containers/java/.devcontainer/library-scripts/common-debian.sh b/containers/java/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/java/.devcontainer/library-scripts/common-debian.sh +++ b/containers/java/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/java/.devcontainer/library-scripts/gradle-debian.sh b/containers/java/.devcontainer/library-scripts/gradle-debian.sh index f18cbcec28..8e39b47cbd 100644 --- a/containers/java/.devcontainer/library-scripts/gradle-debian.sh +++ b/containers/java/.devcontainer/library-scripts/gradle-debian.sh @@ -29,7 +29,7 @@ if [ "$(id -u)" -ne 0 ]; then fi # Treat a user name of "none" or non-existant user as root -if [ "${USERNAME}" = "none" ] && ! id -u ${USERNAME} > /dev/null 2>&1; then +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -42,19 +42,11 @@ if ! dpkg -s curl ca-certificates unzip > /dev/null 2>&1; then apt-get -y install --no-install-recommends curl ca-certificates unzip fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ]; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} # Install Gradle echo "Downloading Gradle..." -suIf "$(cat \ -<< EOF +su ${USERNAME} -c "$(cat << EOF + set -e mkdir -p /tmp/downloads curl -sSL --output /tmp/downloads/archive-gradle.zip https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip ([ "${GRADLE_DOWNLOAD_SHA}" = "no-check" ] || echo "${GRADLE_DOWNLOAD_SHA} */tmp/downloads/archive-gradle.zip" | sha256sum --check - ) @@ -65,6 +57,6 @@ mv -f /tmp/downloads/gradle* ${GRADLE_HOME} chown ${USERNAME}:root ${GRADLE_HOME} ln -s ${GRADLE_HOME}/bin/gradle /usr/local/bin/gradle rm -rf /tmp/downloads -echo "Done." +echo "Done!" diff --git a/containers/java/.devcontainer/library-scripts/maven-debian.sh b/containers/java/.devcontainer/library-scripts/maven-debian.sh index 8f6c14e77d..98e8a3bc7c 100644 --- a/containers/java/.devcontainer/library-scripts/maven-debian.sh +++ b/containers/java/.devcontainer/library-scripts/maven-debian.sh @@ -29,7 +29,7 @@ if [ "$(id -u)" -ne 0 ]; then fi # Treat a user name of "none" or non-existant user as root -if [ "${USERNAME}" = "none" ] && ! id -u ${USERNAME} > /dev/null 2>&1; then +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -42,15 +42,6 @@ if ! dpkg -s curl ca-certificates tar > /dev/null 2>&1; then apt-get -y install --no-install-recommends curl ca-certificates tar fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ]; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} - # Creat folder, add maven settings mkdir -p ${MAVEN_HOME} ${MAVEN_HOME}/ref tee ${MAVEN_HOME}/ref/maven-settings.xml > /dev/null \ @@ -63,8 +54,8 @@ chown -R ${USERNAME}:root ${MAVEN_HOME} # Install Maven echo "Downloading Maven..." -suIf "$(cat \ -<< EOF +su ${USERNAME} -c "$(cat << EOF + set -e curl -fsSL -o /tmp/maven.tar.gz https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz ([ "${MAVEN_DOWNLOAD_SHA}" = "no-check" ] || echo "${MAVEN_DOWNLOAD_SHA} */tmp/maven.tar.gz" | sha512sum -c - ) tar -xzf /tmp/maven.tar.gz -C ${MAVEN_HOME} --strip-components=1 @@ -72,4 +63,4 @@ suIf "$(cat \ EOF )" ln -s ${MAVEN_HOME}/bin/mvn /usr/local/bin/mvn -echo "Done." +echo "Done!" diff --git a/containers/java/.devcontainer/library-scripts/node-debian.sh b/containers/java/.devcontainer/library-scripts/node-debian.sh index 2837fc77b4..99d80cfee0 100644 --- a/containers/java/.devcontainer/library-scripts/node-debian.sh +++ b/containers/java/.devcontainer/library-scripts/node-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./node-debian.sh +# Syntax: ./node-debian.sh [directory to install nvm] [node version to install (use "none" to skip)] [non-root user] export NVM_DIR=${1:-"/usr/local/share/nvm"} export NODE_VERSION=${2:-"lts/*"} @@ -17,8 +17,8 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi -# Treat a user name of "none" as root -if [ "${USERNAME}" = "none" ]; then +# Treat a user name of "none" or non-existant user as root +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -51,46 +51,40 @@ fi if [ -d "${NVM_DIR}" ]; then echo "NVM already installed." if [ "${NODE_VERSION}" != "" ]; then - suIf "nvm install ${NODE_VERSION}" + su ${USERNAME} -c "nvm install ${NODE_VERSION}" fi exit 0 fi mkdir -p ${NVM_DIR} +NVM_INIT=$(cat <> /etc/skel/.bashrc # Set up non-root user if applicable -if [ "${USERNAME}" != "root" ] && id -u $USERNAME > /dev/null 2>&1; then +if [ "${USERNAME}" != "root" ]; then # Add NVM init and add code to update NVM ownership if UID/GID changes - tee -a /root/.bashrc /root/.zshrc /home/${USERNAME}/.bashrc >> /home/${USERNAME}/.zshrc \ -<> /home/${USERNAME}/.zshrc chown ${USERNAME} ${NVM_DIR} /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ] && id -u ${USERNAME} > /dev/null 2>&1; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} - # Run NVM installer as non-root if needed -suIf "$(cat \ -<< EOF - curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash - if [ "${NODE_VERSION}" != "" ]; then - source $NVM_DIR/nvm.sh - nvm alias default ${NODE_VERSION} - fi +su ${USERNAME} -c "$(cat << EOF + set -e + curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash + if [ "${NODE_VERSION}" != "" ]; then + source $NVM_DIR/nvm.sh + nvm alias default ${NODE_VERSION} + fi EOF )" 2>&1 +echo "Done!" \ No newline at end of file diff --git a/containers/javascript-node/.devcontainer/library-scripts/common-debian.sh b/containers/javascript-node/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/javascript-node/.devcontainer/library-scripts/common-debian.sh +++ b/containers/javascript-node/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/javascript-node/.devcontainer/library-scripts/node-debian.sh b/containers/javascript-node/.devcontainer/library-scripts/node-debian.sh index 2837fc77b4..99d80cfee0 100644 --- a/containers/javascript-node/.devcontainer/library-scripts/node-debian.sh +++ b/containers/javascript-node/.devcontainer/library-scripts/node-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./node-debian.sh +# Syntax: ./node-debian.sh [directory to install nvm] [node version to install (use "none" to skip)] [non-root user] export NVM_DIR=${1:-"/usr/local/share/nvm"} export NODE_VERSION=${2:-"lts/*"} @@ -17,8 +17,8 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi -# Treat a user name of "none" as root -if [ "${USERNAME}" = "none" ]; then +# Treat a user name of "none" or non-existant user as root +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -51,46 +51,40 @@ fi if [ -d "${NVM_DIR}" ]; then echo "NVM already installed." if [ "${NODE_VERSION}" != "" ]; then - suIf "nvm install ${NODE_VERSION}" + su ${USERNAME} -c "nvm install ${NODE_VERSION}" fi exit 0 fi mkdir -p ${NVM_DIR} +NVM_INIT=$(cat <> /etc/skel/.bashrc # Set up non-root user if applicable -if [ "${USERNAME}" != "root" ] && id -u $USERNAME > /dev/null 2>&1; then +if [ "${USERNAME}" != "root" ]; then # Add NVM init and add code to update NVM ownership if UID/GID changes - tee -a /root/.bashrc /root/.zshrc /home/${USERNAME}/.bashrc >> /home/${USERNAME}/.zshrc \ -<> /home/${USERNAME}/.zshrc chown ${USERNAME} ${NVM_DIR} /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ] && id -u ${USERNAME} > /dev/null 2>&1; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} - # Run NVM installer as non-root if needed -suIf "$(cat \ -<< EOF - curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash - if [ "${NODE_VERSION}" != "" ]; then - source $NVM_DIR/nvm.sh - nvm alias default ${NODE_VERSION} - fi +su ${USERNAME} -c "$(cat << EOF + set -e + curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash + if [ "${NODE_VERSION}" != "" ]; then + source $NVM_DIR/nvm.sh + nvm alias default ${NODE_VERSION} + fi EOF )" 2>&1 +echo "Done!" \ No newline at end of file diff --git a/containers/kubernetes-helm/.devcontainer/library-scripts/common-debian.sh b/containers/kubernetes-helm/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/kubernetes-helm/.devcontainer/library-scripts/common-debian.sh +++ b/containers/kubernetes-helm/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/kubernetes-helm/.devcontainer/library-scripts/docker-debian.sh b/containers/kubernetes-helm/.devcontainer/library-scripts/docker-debian.sh index d375ac0778..e711dbd9bf 100644 --- a/containers/kubernetes-helm/.devcontainer/library-scripts/docker-debian.sh +++ b/containers/kubernetes-helm/.devcontainer/library-scripts/docker-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./docker-debian.sh +# Syntax: ./docker-debian.sh [enable non-root docker socket access flag] [source socket] [target socket] [non-root user] ENABLE_NONROOT_DOCKER=${1:-"true"} SOURCE_SOCKET=${2:-"/var/run/docker-host.sock"} @@ -145,7 +145,9 @@ fi # Execute whatever commands were passed in (if any). This allows us # to set this script to ENTRYPOINT while still executing the default CMD. +set +e exec "\$@" EOF chmod +x /usr/local/share/docker-init.sh chown ${USERNAME}:root /usr/local/share/docker-init.sh +echo "Done!" \ No newline at end of file diff --git a/containers/perl/.devcontainer/library-scripts/common-debian.sh b/containers/perl/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/perl/.devcontainer/library-scripts/common-debian.sh +++ b/containers/perl/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/php/.devcontainer/library-scripts/common-debian.sh b/containers/php/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/php/.devcontainer/library-scripts/common-debian.sh +++ b/containers/php/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/php/.devcontainer/library-scripts/node-debian.sh b/containers/php/.devcontainer/library-scripts/node-debian.sh index 2837fc77b4..99d80cfee0 100644 --- a/containers/php/.devcontainer/library-scripts/node-debian.sh +++ b/containers/php/.devcontainer/library-scripts/node-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./node-debian.sh +# Syntax: ./node-debian.sh [directory to install nvm] [node version to install (use "none" to skip)] [non-root user] export NVM_DIR=${1:-"/usr/local/share/nvm"} export NODE_VERSION=${2:-"lts/*"} @@ -17,8 +17,8 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi -# Treat a user name of "none" as root -if [ "${USERNAME}" = "none" ]; then +# Treat a user name of "none" or non-existant user as root +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -51,46 +51,40 @@ fi if [ -d "${NVM_DIR}" ]; then echo "NVM already installed." if [ "${NODE_VERSION}" != "" ]; then - suIf "nvm install ${NODE_VERSION}" + su ${USERNAME} -c "nvm install ${NODE_VERSION}" fi exit 0 fi mkdir -p ${NVM_DIR} +NVM_INIT=$(cat <> /etc/skel/.bashrc # Set up non-root user if applicable -if [ "${USERNAME}" != "root" ] && id -u $USERNAME > /dev/null 2>&1; then +if [ "${USERNAME}" != "root" ]; then # Add NVM init and add code to update NVM ownership if UID/GID changes - tee -a /root/.bashrc /root/.zshrc /home/${USERNAME}/.bashrc >> /home/${USERNAME}/.zshrc \ -<> /home/${USERNAME}/.zshrc chown ${USERNAME} ${NVM_DIR} /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ] && id -u ${USERNAME} > /dev/null 2>&1; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} - # Run NVM installer as non-root if needed -suIf "$(cat \ -<< EOF - curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash - if [ "${NODE_VERSION}" != "" ]; then - source $NVM_DIR/nvm.sh - nvm alias default ${NODE_VERSION} - fi +su ${USERNAME} -c "$(cat << EOF + set -e + curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash + if [ "${NODE_VERSION}" != "" ]; then + source $NVM_DIR/nvm.sh + nvm alias default ${NODE_VERSION} + fi EOF )" 2>&1 +echo "Done!" \ No newline at end of file diff --git a/containers/powershell/.devcontainer/library-scripts/common-debian.sh b/containers/powershell/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/powershell/.devcontainer/library-scripts/common-debian.sh +++ b/containers/powershell/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/python-3-anaconda/.devcontainer/library-scripts/common-debian.sh b/containers/python-3-anaconda/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/python-3-anaconda/.devcontainer/library-scripts/common-debian.sh +++ b/containers/python-3-anaconda/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/python-3-miniconda/.devcontainer/library-scripts/common-debian.sh b/containers/python-3-miniconda/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/python-3-miniconda/.devcontainer/library-scripts/common-debian.sh +++ b/containers/python-3-miniconda/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/python-3/.devcontainer/library-scripts/common-debian.sh b/containers/python-3/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/python-3/.devcontainer/library-scripts/common-debian.sh +++ b/containers/python-3/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/r/.devcontainer/library-scripts/common-debian.sh b/containers/r/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/r/.devcontainer/library-scripts/common-debian.sh +++ b/containers/r/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/ruby/.devcontainer/library-scripts/common-debian.sh b/containers/ruby/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/ruby/.devcontainer/library-scripts/common-debian.sh +++ b/containers/ruby/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/ruby/.devcontainer/library-scripts/node-debian.sh b/containers/ruby/.devcontainer/library-scripts/node-debian.sh index 2837fc77b4..99d80cfee0 100644 --- a/containers/ruby/.devcontainer/library-scripts/node-debian.sh +++ b/containers/ruby/.devcontainer/library-scripts/node-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./node-debian.sh +# Syntax: ./node-debian.sh [directory to install nvm] [node version to install (use "none" to skip)] [non-root user] export NVM_DIR=${1:-"/usr/local/share/nvm"} export NODE_VERSION=${2:-"lts/*"} @@ -17,8 +17,8 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi -# Treat a user name of "none" as root -if [ "${USERNAME}" = "none" ]; then +# Treat a user name of "none" or non-existant user as root +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -51,46 +51,40 @@ fi if [ -d "${NVM_DIR}" ]; then echo "NVM already installed." if [ "${NODE_VERSION}" != "" ]; then - suIf "nvm install ${NODE_VERSION}" + su ${USERNAME} -c "nvm install ${NODE_VERSION}" fi exit 0 fi mkdir -p ${NVM_DIR} +NVM_INIT=$(cat <> /etc/skel/.bashrc # Set up non-root user if applicable -if [ "${USERNAME}" != "root" ] && id -u $USERNAME > /dev/null 2>&1; then +if [ "${USERNAME}" != "root" ]; then # Add NVM init and add code to update NVM ownership if UID/GID changes - tee -a /root/.bashrc /root/.zshrc /home/${USERNAME}/.bashrc >> /home/${USERNAME}/.zshrc \ -<> /home/${USERNAME}/.zshrc chown ${USERNAME} ${NVM_DIR} /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ] && id -u ${USERNAME} > /dev/null 2>&1; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} - # Run NVM installer as non-root if needed -suIf "$(cat \ -<< EOF - curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash - if [ "${NODE_VERSION}" != "" ]; then - source $NVM_DIR/nvm.sh - nvm alias default ${NODE_VERSION} - fi +su ${USERNAME} -c "$(cat << EOF + set -e + curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash + if [ "${NODE_VERSION}" != "" ]; then + source $NVM_DIR/nvm.sh + nvm alias default ${NODE_VERSION} + fi EOF )" 2>&1 +echo "Done!" \ No newline at end of file diff --git a/containers/rust/.devcontainer/library-scripts/common-debian.sh b/containers/rust/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/rust/.devcontainer/library-scripts/common-debian.sh +++ b/containers/rust/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/swift/.devcontainer/library-scripts/common-debian.sh b/containers/swift/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/swift/.devcontainer/library-scripts/common-debian.sh +++ b/containers/swift/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/containers/swift/.devcontainer/library-scripts/node-debian.sh b/containers/swift/.devcontainer/library-scripts/node-debian.sh index 2837fc77b4..99d80cfee0 100644 --- a/containers/swift/.devcontainer/library-scripts/node-debian.sh +++ b/containers/swift/.devcontainer/library-scripts/node-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./node-debian.sh +# Syntax: ./node-debian.sh [directory to install nvm] [node version to install (use "none" to skip)] [non-root user] export NVM_DIR=${1:-"/usr/local/share/nvm"} export NODE_VERSION=${2:-"lts/*"} @@ -17,8 +17,8 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi -# Treat a user name of "none" as root -if [ "${USERNAME}" = "none" ]; then +# Treat a user name of "none" or non-existant user as root +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -51,46 +51,40 @@ fi if [ -d "${NVM_DIR}" ]; then echo "NVM already installed." if [ "${NODE_VERSION}" != "" ]; then - suIf "nvm install ${NODE_VERSION}" + su ${USERNAME} -c "nvm install ${NODE_VERSION}" fi exit 0 fi mkdir -p ${NVM_DIR} +NVM_INIT=$(cat <> /etc/skel/.bashrc # Set up non-root user if applicable -if [ "${USERNAME}" != "root" ] && id -u $USERNAME > /dev/null 2>&1; then +if [ "${USERNAME}" != "root" ]; then # Add NVM init and add code to update NVM ownership if UID/GID changes - tee -a /root/.bashrc /root/.zshrc /home/${USERNAME}/.bashrc >> /home/${USERNAME}/.zshrc \ -<> /home/${USERNAME}/.zshrc chown ${USERNAME} ${NVM_DIR} /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ] && id -u ${USERNAME} > /dev/null 2>&1; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} - # Run NVM installer as non-root if needed -suIf "$(cat \ -<< EOF - curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash - if [ "${NODE_VERSION}" != "" ]; then - source $NVM_DIR/nvm.sh - nvm alias default ${NODE_VERSION} - fi +su ${USERNAME} -c "$(cat << EOF + set -e + curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash + if [ "${NODE_VERSION}" != "" ]; then + source $NVM_DIR/nvm.sh + nvm alias default ${NODE_VERSION} + fi EOF )" 2>&1 +echo "Done!" \ No newline at end of file diff --git a/containers/ubuntu/.devcontainer/library-scripts/common-debian.sh b/containers/ubuntu/.devcontainer/library-scripts/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/containers/ubuntu/.devcontainer/library-scripts/common-debian.sh +++ b/containers/ubuntu/.devcontainer/library-scripts/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/script-library/azcli-debian.sh b/script-library/azcli-debian.sh index b2ac3a8556..cc6baeff95 100644 --- a/script-library/azcli-debian.sh +++ b/script-library/azcli-debian.sh @@ -28,3 +28,4 @@ echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_rel curl -sL https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT) apt-get update apt-get install -y azure-cli +echo "Done!" \ No newline at end of file diff --git a/script-library/common-alpine.sh b/script-library/common-alpine.sh index 4761044831..7192f0892b 100755 --- a/script-library/common-alpine.sh +++ b/script-library/common-alpine.sh @@ -79,3 +79,4 @@ if [ "$INSTALL_ZSH" = "true" ] && [ ! -d "/root/.oh-my-zsh" ]; then sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi +echo "Done!" diff --git a/script-library/common-debian.sh b/script-library/common-debian.sh index e756809afb..9229a8e89c 100755 --- a/script-library/common-debian.sh +++ b/script-library/common-debian.sh @@ -61,6 +61,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then curl \ wget \ unzip \ + zip \ nano \ jq \ lsb-release \ @@ -133,17 +134,32 @@ else fi # Add add sudo support for non-root user -if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME chmod 0440 /etc/sudoers.d/$USERNAME EXISTING_NON_ROOT_USER="${USERNAME}" fi +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin + +if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then + alias code=code-insiders +fi +EOF +)" + # Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then - echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc - chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc - DOT_LOCAL_ALREADY_ADDED="true" +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc + chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc + fi + RC_SNIPPET_ALREADY_ADDED="true" fi # Optionally install and configure zsh @@ -151,11 +167,12 @@ if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALRE apt-get-update-if-needed apt-get install -y zsh curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1 - echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc + echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc + cp -fR /root/.oh-my-zsh /etc/skel + cp -f /root/.zshrc /etc/skel + sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc if [ "${USERNAME}" != "root" ]; then - cp -fR /root/.oh-my-zsh /home/$USERNAME - cp -f /root/.zshrc /home/$USERNAME - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc + cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi ZSH_ALREADY_INSTALLED="true" @@ -167,5 +184,7 @@ echo -e "\ PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" \ No newline at end of file diff --git a/script-library/common-redhat.sh b/script-library/common-redhat.sh index c724fd6216..bf73da6eaa 100755 --- a/script-library/common-redhat.sh +++ b/script-library/common-redhat.sh @@ -84,4 +84,4 @@ if [ "$INSTALL_ZSH" = "true" ] && [ ! -d "/root/.oh-my-zsh" ]; then sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc fi - +echo "Done!" \ No newline at end of file diff --git a/script-library/docker-debian.sh b/script-library/docker-debian.sh index d375ac0778..e711dbd9bf 100644 --- a/script-library/docker-debian.sh +++ b/script-library/docker-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./docker-debian.sh +# Syntax: ./docker-debian.sh [enable non-root docker socket access flag] [source socket] [target socket] [non-root user] ENABLE_NONROOT_DOCKER=${1:-"true"} SOURCE_SOCKET=${2:-"/var/run/docker-host.sock"} @@ -145,7 +145,9 @@ fi # Execute whatever commands were passed in (if any). This allows us # to set this script to ENTRYPOINT while still executing the default CMD. +set +e exec "\$@" EOF chmod +x /usr/local/share/docker-init.sh chown ${USERNAME}:root /usr/local/share/docker-init.sh +echo "Done!" \ No newline at end of file diff --git a/script-library/docker-redhat.sh b/script-library/docker-redhat.sh index 0b9064b552..713e61719f 100644 --- a/script-library/docker-redhat.sh +++ b/script-library/docker-redhat.sh @@ -125,9 +125,11 @@ fi # Execute whatever commands were passed in (if any). This allows us # to set this script to ENTRYPOINT while still executing the default CMD. +set +e exec "\$@" EOF else echo '/usr/bin/env bash -c "\$@"' > /usr/local/share/docker-init.sh fi chmod +x /usr/local/share/docker-init.sh +echo "Done!" \ No newline at end of file diff --git a/script-library/git-from-src-debian.sh b/script-library/git-from-src-debian.sh new file mode 100644 index 0000000000..ddad53e77a --- /dev/null +++ b/script-library/git-from-src-debian.sh @@ -0,0 +1,27 @@ +# Syntax: ./git-from-src-debian.sh [version] + +GIT_VERSION=${1:-"2.27.0"} + +set -e + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +export DEBIAN_FRONTEND=noninteractive + +# Install required packages to build if missing +if ! dpkg -s build-essential curl ca-certificates tar gettext libssl-dev zlib1g-dev libexpat1-dev> /dev/null 2>&1; then + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + apt-get update + fi + apt-get -y install --no-install-recommends build-essential curl ca-certificates tar gettext libssl-dev zlib1g-dev libcurl?-openssl-dev libexpat1-dev +fi + +echo "Downloading source for ${GIT_VERSION}..." +curl -sL https://github.com/git/git/archive/v${GIT_VERSION}.tar.gz | tar -xzC /tmp +echo "Building..." +(cd /tmp/git-${GIT_VERSION} && make -s prefix=/usr/local all && make -s prefix=/usr/local install) +rm -rf /tmp/git-${GIT_VERSION} +echo "Done!" diff --git a/script-library/git-lfs-debian.sh b/script-library/git-lfs-debian.sh new file mode 100644 index 0000000000..ed000e8d3b --- /dev/null +++ b/script-library/git-lfs-debian.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- + +# Syntax: ./git-lfs-debian.sh + +set -e + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +export DEBIAN_FRONTEND=noninteractive + +# Install git and curl if missing +if ! dpkg -s git curl ca-certificates > /dev/null 2>&1; then + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + apt-get update + fi + apt-get -y install --no-install-recommends git curl ca-certificates +fi + +# Install Git LFS +echo "Downloading Git LFS..." +curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash +echo "Installing Git LFS..." +apt-get install -yq git-lfs +git lfs install +echo "Done!" \ No newline at end of file diff --git a/script-library/github-debian.sh b/script-library/github-debian.sh new file mode 100644 index 0000000000..3bae046848 --- /dev/null +++ b/script-library/github-debian.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- + +# Syntax: ./github-debian.sh [version] + +CLI_VERSION=${1:-"0.11.0"} + +set -e + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +export DEBIAN_FRONTEND=noninteractive + +# Install curl, apt-transport-https or gpg if missing +if ! dpkg -s curl ca-certificates > /dev/null 2>&1; then + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + apt-get update + fi + apt-get -y install --no-install-recommends curl ca-certificates +fi + +# Install the GitHub CLI +echo "Downloading github CLI..." +curl -OsSL https://github.com/cli/cli/releases/download/v${CLI_VERSION}/gh_${CLI_VERSION}_linux_amd64.deb +echo "Installing github CLI..." +apt-get install ./gh_${CLI_VERSION}_linux_amd64.deb +echo "Removing github CLI deb file after installation..." +rm -rf ./gh_${CLI_VERSION}_linux_amd64.deb +echo "Done!" diff --git a/script-library/go-debian.sh b/script-library/go-debian.sh new file mode 100644 index 0000000000..85bda531a8 --- /dev/null +++ b/script-library/go-debian.sh @@ -0,0 +1,116 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- + +# Syntax: ./go-debian.sh [Go version] [Go install path] [GOPATH] [non-root user] [Add GOPATH, GOROOT to rc files flag] [install tools] + +TARGET_GO_VERSION=${1:-"1.15"} +TARGET_GOROOT=${2:-"/usr/local/go"} +TARGET_GOPATH=${3:-"/go"} +USERNAME=${4:-"vscode"} +UPDATE_RC=${5:-"true"} +INSTALL_GO_TOOLS=${6:-"true"} + +set -e + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +# Treat a user name of "none" or non-existant user as root +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then + USERNAME=root +fi + +export DEBIAN_FRONTEND=noninteractive + +# Install curl, tar, git if missing +if ! dpkg -s curl ca-certificates tar git > /dev/null 2>&1; then + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + apt-get update + fi + apt-get -y install --no-install-recommends curl ca-certificates tar git +fi + + +# Install Go +GO_INSTALL_SCRIPT="$(cat < /dev/null 2>&1; then + mkdir -p "${TARGET_GOROOT}" "${TARGET_GOPATH}" + chown ${USERNAME}:root "${TARGET_GOROOT}" "${TARGET_GOPATH}" + su ${USERNAME} -c "${GO_INSTALL_SCRIPT}" +else + echo "Go already installed. Skipping." +fi + +# Install Go tools +GO_TOOLS_WITH_MODULES="\ + golang.org/x/tools/gopls \ + honnef.co/go/tools/... \ + golang.org/x/tools/cmd/gorename \ + golang.org/x/tools/cmd/goimports \ + golang.org/x/tools/cmd/guru \ + golang.org/x/lint/golint \ + github.com/mdempsky/gocode \ + github.com/cweill/gotests/... \ + github.com/haya14busa/goplay/cmd/goplay \ + github.com/sqs/goreturns \ + github.com/josharian/impl \ + github.com/davidrjenni/reftools/cmd/fillstruct \ + github.com/uudashr/gopkgs/v2/cmd/gopkgs \ + github.com/ramya-rao-a/go-outline \ + github.com/acroca/go-symbols \ + github.com/godoctor/godoctor \ + github.com/rogpeppe/godef \ + github.com/zmb3/gogetdoc \ + github.com/fatih/gomodifytags \ + github.com/mgechev/revive \ + github.com/go-delve/delve/cmd/dlv" +if [ "${INSTALL_GO_TOOLS}" = "true" ]; then + echo "Installing common Go tools..." + export PATH=${TARGET_GOROOT}/bin:${PATH} + mkdir -p /tmp/gotools + cd /tmp/gotools + export GOPATH=/tmp/gotools + + # Go tools w/module support + export GO111MODULE=on + (echo "${GO_TOOLS_WITH_MODULES}" | xargs -n 1 go get -v )2>&1 + + # gocode-gomod + export GO111MODULE=auto + go get -v -d github.com/stamblerre/gocode 2>&1 + go build -o gocode-gomod github.com/stamblerre/gocode + + # golangci-lint + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin 2>&1 + + # Move Go tools into path and clean up + mv /tmp/gotools/bin/* /usr/local/bin/ + mv gocode-gomod /usr/local/bin/ + rm -rf /tmp/gotools +fi + +# Add GOPATH variable and bin directory into PATH in bashrc/zshrc files (unless disabled) +if [ "${UPDATE_RC}" = "true" ]; then + RC_SNIPPET="export GOPATH=\"${TARGET_GOPATH}\"\nexport GOROOT=\"${TARGET_GOROOT}\"\nexport PATH=\"\${GOROOT}/bin:\${PATH}\"" + echo -e ${RC_SNIPPET} | tee -a /root/.bashrc /root/.zshrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo -e ${RC_SNIPPET} | tee -a /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc + fi + echo "Done!" +else + echo "Done! Be sure to add ${GO_HOME}/bin to the PATH." +fi + diff --git a/script-library/gradle-debian.sh b/script-library/gradle-debian.sh index f18cbcec28..8e39b47cbd 100644 --- a/script-library/gradle-debian.sh +++ b/script-library/gradle-debian.sh @@ -29,7 +29,7 @@ if [ "$(id -u)" -ne 0 ]; then fi # Treat a user name of "none" or non-existant user as root -if [ "${USERNAME}" = "none" ] && ! id -u ${USERNAME} > /dev/null 2>&1; then +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -42,19 +42,11 @@ if ! dpkg -s curl ca-certificates unzip > /dev/null 2>&1; then apt-get -y install --no-install-recommends curl ca-certificates unzip fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ]; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} # Install Gradle echo "Downloading Gradle..." -suIf "$(cat \ -<< EOF +su ${USERNAME} -c "$(cat << EOF + set -e mkdir -p /tmp/downloads curl -sSL --output /tmp/downloads/archive-gradle.zip https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip ([ "${GRADLE_DOWNLOAD_SHA}" = "no-check" ] || echo "${GRADLE_DOWNLOAD_SHA} */tmp/downloads/archive-gradle.zip" | sha256sum --check - ) @@ -65,6 +57,6 @@ mv -f /tmp/downloads/gradle* ${GRADLE_HOME} chown ${USERNAME}:root ${GRADLE_HOME} ln -s ${GRADLE_HOME}/bin/gradle /usr/local/bin/gradle rm -rf /tmp/downloads -echo "Done." +echo "Done!" diff --git a/script-library/java-debian.sh b/script-library/java-debian.sh new file mode 100644 index 0000000000..8615acc882 --- /dev/null +++ b/script-library/java-debian.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- + +# Syntax: ./java-debian.sh [JDK major version] [JAVA_HOME] [non-root user] [Add JAVA_HOME to rc files flag] + +export JAVA_VERSION=${1:-"11"} +export JAVA_HOME=${2:-"/opt/java/openjdk-${JAVA_VERSION}"} +USERNAME=${3:-"vscode"} +UPDATE_RC=${4:-"true"} + +set -e + +JDK_11_URI="https://github.com/AdoptOpenJDK/openjdk11-upstream-binaries/releases/download/jdk-11.0.8%2B10/OpenJDK11U-jdk_x64_linux_11.0.8_10.tar.gz" +JDK_8_URI="https://github.com/AdoptOpenJDK/openjdk8-upstream-binaries/releases/download/jdk8u265-b01/OpenJDK8U-jdk_x64_linux_8u265b01.tar.gz" + +JAVA_URI_VAR="JDK_${JAVA_VERSION}_URI" +JAVA_URI=${!JAVA_URI_VAR} + +if [ "${JAVA_URI}" = "" ]; then + echo 'Only Java versions 8 and 11 are supported by this script.' + exit 1 +fi + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +# Treat a user name of "none" or non-existant user as root +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then + USERNAME=root +fi + +export DEBIAN_FRONTEND=noninteractive + +# Install curl if missing +if ! dpkg -s curl ca-certificates > /dev/null 2>&1; then + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + apt-get update + fi + apt-get -y install --no-install-recommends curl ca-certificates +fi + +# Install Java +if [ -d "${JAVA_HOME}" ]; then + echo "${JAVA_HOME} already exists. Assuming Java is already installed." + exit 0 +fi + +mkdir -p "${JAVA_HOME}" +chown "${USERNAME}" "${JAVA_HOME}" + + + +su ${USERNAME} -c "$(cat << EOF + set -e + echo "Downloading JDK ${JAVA_VERSION}..." + curl -fsSL -o /tmp/openjdk.tar.gz ${JAVA_URI} + echo "Installing JDK ${JAVA_VERSION}..." + tar -xzf /tmp/openjdk.tar.gz -C ${JAVA_HOME} --strip-components=1 + rm -f /tmp/openjdk.tar.gz +EOF +)" + +# Add JAVA_HOME and bin directory into bashrc/zshrc files (unless disabled) +if [ "${UPDATE_RC}" = "true" ]; then + RC_SNIPPET="export JAVA_HOME=\"${JAVA_HOME}\"\nexport PATH=\"\${JAVA_HOME}/bin:\${PATH}\"" + echo -e ${RC_SNIPPET} | tee -a /root/.bashrc /root/.zshrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo -e ${RC_SNIPPET} | tee -a /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc + fi + echo "Done!" +else + echo "Done! Be sure to add ${JAVA_HOME}/bin to the PATH." +fi \ No newline at end of file diff --git a/script-library/kubectl-helm-debian.sh b/script-library/kubectl-helm-debian.sh new file mode 100644 index 0000000000..3ab295f76a --- /dev/null +++ b/script-library/kubectl-helm-debian.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- + +# Syntax: ./kubectl-helm-debian.sh + +set -e + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +export DEBIAN_FRONTEND=noninteractive + +# Install curl if missing +if ! dpkg -s curl ca-certificates > /dev/null 2>&1; then + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + apt-get update + fi + apt-get -y install --no-install-recommends curl ca-certificates +fi + +# Install the kubectl +echo "Downloading kubectl..." +curl -sSL -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl +chmod +x /usr/local/bin/kubectl +# Install Helm +echo "Installing Helm..." +curl -s https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash - +echo "Done!" \ No newline at end of file diff --git a/script-library/maven-debian.sh b/script-library/maven-debian.sh index 8f6c14e77d..98e8a3bc7c 100644 --- a/script-library/maven-debian.sh +++ b/script-library/maven-debian.sh @@ -29,7 +29,7 @@ if [ "$(id -u)" -ne 0 ]; then fi # Treat a user name of "none" or non-existant user as root -if [ "${USERNAME}" = "none" ] && ! id -u ${USERNAME} > /dev/null 2>&1; then +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -42,15 +42,6 @@ if ! dpkg -s curl ca-certificates tar > /dev/null 2>&1; then apt-get -y install --no-install-recommends curl ca-certificates tar fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ]; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} - # Creat folder, add maven settings mkdir -p ${MAVEN_HOME} ${MAVEN_HOME}/ref tee ${MAVEN_HOME}/ref/maven-settings.xml > /dev/null \ @@ -63,8 +54,8 @@ chown -R ${USERNAME}:root ${MAVEN_HOME} # Install Maven echo "Downloading Maven..." -suIf "$(cat \ -<< EOF +su ${USERNAME} -c "$(cat << EOF + set -e curl -fsSL -o /tmp/maven.tar.gz https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz ([ "${MAVEN_DOWNLOAD_SHA}" = "no-check" ] || echo "${MAVEN_DOWNLOAD_SHA} */tmp/maven.tar.gz" | sha512sum -c - ) tar -xzf /tmp/maven.tar.gz -C ${MAVEN_HOME} --strip-components=1 @@ -72,4 +63,4 @@ suIf "$(cat \ EOF )" ln -s ${MAVEN_HOME}/bin/mvn /usr/local/bin/mvn -echo "Done." +echo "Done!" diff --git a/script-library/node-debian.sh b/script-library/node-debian.sh index 2837fc77b4..99d80cfee0 100644 --- a/script-library/node-debian.sh +++ b/script-library/node-debian.sh @@ -4,7 +4,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -# Syntax: ./node-debian.sh +# Syntax: ./node-debian.sh [directory to install nvm] [node version to install (use "none" to skip)] [non-root user] export NVM_DIR=${1:-"/usr/local/share/nvm"} export NODE_VERSION=${2:-"lts/*"} @@ -17,8 +17,8 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi -# Treat a user name of "none" as root -if [ "${USERNAME}" = "none" ]; then +# Treat a user name of "none" or non-existant user as root +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then USERNAME=root fi @@ -51,46 +51,40 @@ fi if [ -d "${NVM_DIR}" ]; then echo "NVM already installed." if [ "${NODE_VERSION}" != "" ]; then - suIf "nvm install ${NODE_VERSION}" + su ${USERNAME} -c "nvm install ${NODE_VERSION}" fi exit 0 fi mkdir -p ${NVM_DIR} +NVM_INIT=$(cat <> /etc/skel/.bashrc # Set up non-root user if applicable -if [ "${USERNAME}" != "root" ] && id -u $USERNAME > /dev/null 2>&1; then +if [ "${USERNAME}" != "root" ]; then # Add NVM init and add code to update NVM ownership if UID/GID changes - tee -a /root/.bashrc /root/.zshrc /home/${USERNAME}/.bashrc >> /home/${USERNAME}/.zshrc \ -<> /home/${USERNAME}/.zshrc chown ${USERNAME} ${NVM_DIR} /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc fi -# Function to su if user exists and is not root -suIf() { - if [ "${USERNAME}" != "root" ] && id -u ${USERNAME} > /dev/null 2>&1; then - su ${USERNAME} -c "$@" - else - "$@" - fi -} - # Run NVM installer as non-root if needed -suIf "$(cat \ -<< EOF - curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash - if [ "${NODE_VERSION}" != "" ]; then - source $NVM_DIR/nvm.sh - nvm alias default ${NODE_VERSION} - fi +su ${USERNAME} -c "$(cat << EOF + set -e + curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash + if [ "${NODE_VERSION}" != "" ]; then + source $NVM_DIR/nvm.sh + nvm alias default ${NODE_VERSION} + fi EOF )" 2>&1 +echo "Done!" \ No newline at end of file diff --git a/script-library/powershell-debian.sh b/script-library/powershell-debian.sh new file mode 100644 index 0000000000..fac4ca8de5 --- /dev/null +++ b/script-library/powershell-debian.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- + +# Syntax: ./powershell-debian.sh + +set -e + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +export DEBIAN_FRONTEND=noninteractive + +# Install curl, apt-transport-https, lsb-release, or gpg if missing +if ! dpkg -s apt-transport-https curl ca-certificates lsb-release > /dev/null 2>&1 || ! type gpg > /dev/null 2>&1; then + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + apt-get update + fi + apt-get -y install --no-install-recommends apt-transport-https curl ca-certificates lsb-release gnupg2 +fi + +# Use correct source for distro (Ubuntu/Debian) and Codename (stretch, buster, bionic, focal) +DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]') +CODENAME=$(lsb_release -cs) +curl -s https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT) +echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-${DISTRO}-${CODENAME}-prod ${CODENAME} main" > /etc/apt/sources.list.d/microsoft.list +apt-get update -yq +apt-get install -yq powershell +echo "Done!" \ No newline at end of file diff --git a/script-library/rust-debian.sh b/script-library/rust-debian.sh new file mode 100644 index 0000000000..2e2c054046 --- /dev/null +++ b/script-library/rust-debian.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- + +# Syntax: ./rust-debian.sh [CARGO_HOME] [RUSTUP_HOME] [non-root user] [add CARGO/RUSTUP_HOME to rc files flag] + +export CARGO_HOME=${1:-"/usr/local/cargo"} +export RUSTUP_HOME=${2:-"/usr/local/rustup"} +USERNAME=${3:-"vscode"} +UPDATE_RC=${4:-"true"} + +set -e + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +# Treat a user name of "none" or non-existant user as root +if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then + USERNAME=root +fi + +export DEBIAN_FRONTEND=noninteractive + +# Install curl, lldb, python3-minimal if missing +if ! dpkg -s curl ca-certificates lldb python3-minimal > /dev/null 2>&1; then + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + apt-get update + fi + apt-get -y install --no-install-recommends curl ca-certificates + apt-get -y install lldb python3-minimal libpython3.? +fi + +# Install Rust +if ! type rustup > /dev/null 2>&1; then + echo "Installing Rust..." + mkdir -p "${CARGO_HOME}" "${RUSTUP_HOME}" + chown ${USERNAME}:root "${CARGO_HOME}" "${RUSTUP_HOME}" + su ${USERNAME} -c "curl --tlsv1.2 https://sh.rustup.rs -sSf | bash -s -- -y --no-modify-path 2>&1" +else + echo "Rust already installed. Skipping." +fi + +echo "Installing common Rust dependencies..." +su ${USERNAME} -c "$(cat << EOF + set -e + export PATH=${PATH}:${CARGO_HOME}/bin + rustup update 2>&1 + rustup component add rls rust-analysis rust-src rustfmt clippy 2>&1 +EOF +)" + +# Add CARGO_HOME, RUSTUP_HOME and bin directory into bashrc/zshrc files (unless disabled) +if [ "${UPDATE_RC}" = "true" ]; then + RC_SNIPPET="export CARGO_HOME=\"${CARGO_HOME}\"\nexport RUSTUP_HOME=\"${RUSTUP_HOME}\"\nexport PATH=\"\${CARGO_HOME}/bin:\${PATH}\"" + echo -e ${RC_SNIPPET} | tee -a /root/.bashrc /root/.zshrc >> /etc/skel/.bashrc + if [ "${USERNAME}" != "root" ]; then + echo -e ${RC_SNIPPET} | tee -a /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc + fi + echo "Done!" +else + echo "Done! Be sure to add ${CARGO_HOME}/bin to the PATH." +fi + diff --git a/script-library/terraform-debian.sh b/script-library/terraform-debian.sh index 4e0db26f70..b3601180f0 100644 --- a/script-library/terraform-debian.sh +++ b/script-library/terraform-debian.sh @@ -45,4 +45,4 @@ if [ "${TFLINT_VERSION}" != "none" ]; then fi rm -rf /tmp/tf-downloads -echo "Done." +echo "Done!" diff --git a/script-library/test/Dockerfile b/script-library/test/Dockerfile index 5a6c0c0c40..ee3dd431c5 100644 --- a/script-library/test/Dockerfile +++ b/script-library/test/Dockerfile @@ -14,7 +14,9 @@ RUN chmod +x /tmp/*.sh ARG DISTRO="debian" ARG USE_DEFAULTS="true" ARG USERNAME="vscode" -RUN /tmp/run-scripts.sh /tmp ${DISTRO} ${USE_DEFAULTS} ${USERNAME} false false 10 +ARG RUN_COMMON_SCRIPT="true" +ARG UPGRADE_PACKAGES="false" +RUN /tmp/run-scripts.sh /tmp ${DISTRO} ${USE_DEFAULTS} ${USERNAME} ${RUN_COMMON_SCRIPT} ${UPGRADE_PACKAGES} ENTRYPOINT [ "/usr/local/share/docker-init.sh" ] CMD [ "sleep", "infinity" ] diff --git a/script-library/test/debian/.devcontainer.json b/script-library/test/debian/.devcontainer.json index 5ca85d3838..27c25a456a 100644 --- a/script-library/test/debian/.devcontainer.json +++ b/script-library/test/debian/.devcontainer.json @@ -6,11 +6,13 @@ "args": { "IMAGE_TO_TEST": "debian:10", "DISTRO": "debian", - "USERNAME": "tester", - "USE_DEFAULTS": "false" + "USERNAME": "vscode", + "UPGRADE_PACKAGES": "false", + "RUN_COMMON_SCRIPT": "true", + "USE_DEFAULTS": "true" } }, - "remoteUser": "tester", + "remoteUser": "vscode", "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker-host.sock,type=bind" ], "overrideCommand": true, diff --git a/script-library/test/run-scripts.sh b/script-library/test/run-scripts.sh index b6273bb5a7..03eb6945ac 100644 --- a/script-library/test/run-scripts.sh +++ b/script-library/test/run-scripts.sh @@ -1,18 +1,13 @@ #!/bin/sh SCRIPT_DIR=${1-"/tmp"} -DISTRO=${2:-debian} -USE_DEFAULTS=${3:-true} -USERNAME=${4:-vscode} -UPGRADE_PAGKES=${5:-true} -ENABLE_NONROOT=${6:-true} -NODE_VERSION=${7:-"lts/*"} -MAVEN_VERSION=${8:-"3.6.3"} -MAVEN_DOWNLOAD_SHA=${9:-"c35a1803a6e70a126e80b2b3ae33eed961f83ed74d18fcd16909b2d44d7dada3203f1ffe726c17ef8dcca2dcaa9fca676987befeadc9b9f759967a8cb77181c0"} -GRADLE_VERSION=${10:-"5.4.1"} -GRADLE_DOWNLOAD_SHA=${11:-"7bdbad1e4f54f13c8a78abc00c26d44dd8709d4aedb704d913fb1bb78ac025dc"} -TERRAFORM_VERSION=${12:-"0.12.16"} -TFLINT_VERSION=${13:-"0.8.2"} +DISTRO=${2:-"debian"} +USE_DEFAULTS=${3:-"true"} +USERNAME=${4:-"vscode"} +RUN_COMMON_SCRIPT=${5:-"true"} +UPGRADE_PAGKES=${6:-"true"} + +set -e runScript() { @@ -30,13 +25,24 @@ runScript() echo "**** Done! ****\n" } -runScript ${SCRIPT_DIR}/common-${DISTRO}.sh "true ${USERNAME} 1000 1000 ${UPGRADE_PACKAGES}" +if [ "${RUN_COMMON_SCRIPT}" = "true" ]; then + runScript ${SCRIPT_DIR}/common-${DISTRO}.sh "true ${USERNAME} 1000 1000 ${UPGRADE_PACKAGES}" +fi if [ "${DISTRO}" = "debian" ]; then - runScript ${SCRIPT_DIR}/node-${DISTRO}.sh "/usr/local/share/nvm ${NODE_VERSION} ${USERNAME}" - runScript ${SCRIPT_DIR}/maven-${DISTRO}.sh "/usr/local/share/maven ${USERNAME} ${MAVEN_DOWNLOAD_SHA}" "${MAVEN_VERSION}" - runScript ${SCRIPT_DIR}/gradle-${DISTRO}.sh "/usr/local/share/gradle ${USERNAME} ${GRADLE_DOWNLOAD_SHA}" "${GRADLE_VERSION}" - runScript ${SCRIPT_DIR}/terraform-${DISTRO}.sh "${TFLINT_VERSION}" "${TERRAFORM_VERSION}" + runScript ${SCRIPT_DIR}/azcli-${DISTRO}.sh + runScript ${SCRIPT_DIR}/git-from-src-${DISTRO}.sh "2.26.2" + runScript ${SCRIPT_DIR}/git-lfs-${DISTRO}.sh + runScript ${SCRIPT_DIR}/github-${DISTRO}.sh + runScript ${SCRIPT_DIR}/go-${DISTRO}.sh "1.14 /opt/go /go ${USERNAME} false" + runScript ${SCRIPT_DIR}/gradle-${DISTRO}.sh "/usr/local/share/gradle ${USERNAME} 7bdbad1e4f54f13c8a78abc00c26d44dd8709d4aedb704d913fb1bb78ac025dc" "5.4.1" + runScript ${SCRIPT_DIR}/java-${DISTRO}.sh "8 /usr/local/share/java ${USERNAME} false" + runScript ${SCRIPT_DIR}/kubectl-helm-${DISTRO}.sh + runScript ${SCRIPT_DIR}/maven-${DISTRO}.sh "/usr/local/share/maven ${USERNAME} c35a1803a6e70a126e80b2b3ae33eed961f83ed74d18fcd16909b2d44d7dada3203f1ffe726c17ef8dcca2dcaa9fca676987befeadc9b9f759967a8cb77181c0" "3.6.3" + runScript ${SCRIPT_DIR}/node-${DISTRO}.sh "/usr/local/share/nvm 10 ${USERNAME}" + runScript ${SCRIPT_DIR}/powershell-${DISTRO}.sh + runScript ${SCRIPT_DIR}/rust-${DISTRO}.sh "/opt/rust/cargo /opt/rust/rustup ${USERNAME} false" + runScript ${SCRIPT_DIR}/terraform-${DISTRO}.sh "0.12.16" "0.8.2" fi # Run Docker script