Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit 5970e01

Browse files
author
CI
committed
Automated update for script library changes
1 parent d03737f commit 5970e01

File tree

45 files changed

+1918
-1308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1918
-1308
lines changed

containers/alpine/.devcontainer/library-scripts/common-alpine.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
# Syntax: ./common-alpine.sh <install zsh flag> <username> <user UID> <user GID>
88

9-
set -e
10-
119
INSTALL_ZSH=${1:-"true"}
1210
USERNAME=${2:-"$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)"}
1311
USER_UID=${3:-1000}
1412
USER_GID=${4:-1000}
1513

14+
set -e
15+
1616
if [ "$(id -u)" -ne 0 ]; then
17-
echo 'Script must be run a root. Use sudo or set "USER root" before running the script.'
17+
echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
1818
exit 1
1919
fi
2020

containers/azure-ansible/.devcontainer/library-scripts/common-debian.sh

Lines changed: 110 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
55
#-------------------------------------------------------------------------------------------------------------
66

7-
# Syntax: ./common-debian.sh <install zsh flag> <username> <user UID> <user GID> <upgrade packages flag>
8-
9-
set -e
7+
# Syntax: ./common-debian.sh [install zsh flag] [username] [user UID] [user GID] [upgrade packages flag]
108

119
INSTALL_ZSH=${1:-"true"}
12-
USERNAME=${2:-"$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)"}
10+
USERNAME=${2:-"vscode"}
1311
USER_UID=${3:-1000}
1412
USER_GID=${4:-1000}
1513
UPGRADE_PACKAGES=${5:-"true"}
1614

15+
set -e
16+
1717
if [ "$(id -u)" -ne 0 ]; then
18-
echo 'Script must be run a root. Use sudo or set "USER root" before running the script.'
18+
echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
1919
exit 1
2020
fi
2121

@@ -26,63 +26,94 @@ if [ "${USERNAME}" = "none" ] || [ "${USERNAME}" = "root" ]; then
2626
USER_GID=0
2727
fi
2828

29+
# Load markers to see which steps have already run
30+
MARKER_FILE="/usr/local/etc/vscode-dev-containers/common"
31+
if [ -f "${MARKER_FILE}" ]; then
32+
echo "Marker file found:"
33+
cat "${MARKER_FILE}"
34+
source "${MARKER_FILE}"
35+
fi
36+
2937
# Ensure apt is in non-interactive to avoid prompts
3038
export DEBIAN_FRONTEND=noninteractive
3139

32-
# Install apt-utils to avoid debconf warning
33-
apt-get -y install --no-install-recommends apt-utils 2> >( grep -v 'debconf: delaying package configuration, since apt-utils is not installed' >&2 )
40+
# Function to call apt-get if needed
41+
apt-get-update-if-needed()
42+
{
43+
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
44+
echo "Running apt-get update..."
45+
apt-get update
46+
else
47+
echo "Skipping apt-get update."
48+
fi
49+
}
50+
51+
# Run install apt-utils to avoid debconf warning then verify presence of other common developer tools and dependencies
52+
if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then
53+
apt-get-update-if-needed
54+
55+
PACKAGE_LIST="apt-utils \
56+
git \
57+
openssh-client \
58+
less \
59+
iproute2 \
60+
procps \
61+
curl \
62+
wget \
63+
unzip \
64+
nano \
65+
jq \
66+
lsb-release \
67+
ca-certificates \
68+
apt-transport-https \
69+
dialog \
70+
gnupg2 \
71+
libc6 \
72+
libgcc1 \
73+
libgssapi-krb5-2 \
74+
libicu[0-9][0-9] \
75+
liblttng-ust0 \
76+
libstdc++6 \
77+
zlib1g \
78+
locales \
79+
sudo"
80+
81+
# Install libssl1.1 if available
82+
if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then
83+
PACKAGE_LIST="${PACKAGE_LIST} libssl1.1"
84+
fi
85+
86+
# Install appropriate version of libssl1.0.x if available
87+
LIBSSL=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '')
88+
if [ "$(echo "$LIBSSL" | grep -o 'libssl1\.0\.[0-9]:' | uniq | sort | wc -l)" -eq 0 ]; then
89+
if [[ ! -z $(apt-cache --names-only search ^libssl1.0.2$) ]]; then
90+
# Debian 9
91+
PACKAGE_LIST="${PACKAGE_LIST} libssl1.0.2"
92+
elif [[ ! -z $(apt-cache --names-only search ^libssl1.0.0$) ]]; then
93+
# Ubuntu 18.04, 16.04, earlier
94+
PACKAGE_LIST="${PACKAGE_LIST} libssl1.0.0"
95+
fi
96+
fi
97+
98+
echo "Packages to verify are installed: ${PACKAGE_LIST}"
99+
apt-get -y install --no-install-recommends ${PACKAGE_LIST} 2> >( grep -v 'debconf: delaying package configuration, since apt-utils is not installed' >&2 )
100+
101+
PACKAGES_ALREADY_INSTALLED="true"
102+
fi
34103

35104
# Get to latest versions of all packages
36105
if [ "${UPGRADE_PACKAGES}" = "true" ]; then
106+
apt-get-update-if-needed
37107
apt-get -y upgrade --no-install-recommends
108+
apt-get autoremove -y
38109
fi
39110

40-
# Install common developer tools and dependencies
41-
apt-get -y install --no-install-recommends \
42-
git \
43-
openssh-client \
44-
less \
45-
iproute2 \
46-
procps \
47-
curl \
48-
wget \
49-
unzip \
50-
nano \
51-
jq \
52-
lsb-release \
53-
ca-certificates \
54-
apt-transport-https \
55-
dialog \
56-
gnupg2 \
57-
libc6 \
58-
libgcc1 \
59-
libgssapi-krb5-2 \
60-
libicu[0-9][0-9] \
61-
liblttng-ust0 \
62-
libstdc++6 \
63-
zlib1g \
64-
locales
65-
66111
# Ensure at least the en_US.UTF-8 UTF-8 locale is available.
67112
# Common need for both applications and things like the agnoster ZSH theme.
68-
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
69-
locale-gen
70-
71-
# Install libssl1.1 if available
72-
if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then
73-
apt-get -y install --no-install-recommends libssl1.1
74-
fi
75-
76-
# Install appropriate version of libssl1.0.x if available
77-
LIBSSL=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '')
78-
if [ "$(echo "$LIBSSL" | grep -o 'libssl1\.0\.[0-9]:' | uniq | sort | wc -l)" -eq 0 ]; then
79-
if [[ ! -z $(apt-cache --names-only search ^libssl1.0.2$) ]]; then
80-
# Debian 9
81-
apt-get -y install --no-install-recommends libssl1.0.2
82-
elif [[ ! -z $(apt-cache --names-only search ^libssl1.0.0$) ]]; then
83-
# Ubuntu 18.04, 16.04, earlier
84-
apt-get -y install --no-install-recommends libssl1.0.0
85-
fi
113+
if [ "${LOCALE_ALREADY_SET}" != "true" ]; then
114+
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
115+
locale-gen
116+
LOCALE_ALREADY_SET="true"
86117
fi
87118

88119
# Create or update a non-root user to match UID/GID - see https://aka.ms/vscode-remote/containers/non-root-user.
@@ -102,22 +133,39 @@ else
102133
fi
103134

104135
# Add add sudo support for non-root user
105-
apt-get install -y sudo
106-
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME
107-
chmod 0440 /etc/sudoers.d/$USERNAME
136+
if [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then
137+
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME
138+
chmod 0440 /etc/sudoers.d/$USERNAME
139+
EXISTING_NON_ROOT_USER="${USERNAME}"
140+
fi
108141

109142
# Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later)
110-
echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc
111-
chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc
143+
if [ "${DOT_LOCAL_ALREADY_ADDED}" != "true" ]; then
144+
echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc
145+
chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc
146+
DOT_LOCAL_ALREADY_ADDED="true"
147+
fi
112148

113149
# Optionally install and configure zsh
114-
if [ "$INSTALL_ZSH" = "true" ] && [ ! -d "/root/.oh-my-zsh" ]; then
150+
if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALREADY_INSTALLED}" != "true" ]; then
151+
apt-get-update-if-needed
115152
apt-get install -y zsh
116-
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
153+
curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash 2>&1
117154
echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc
118-
cp -R /root/.oh-my-zsh /home/$USERNAME
119-
cp /root/.zshrc /home/$USERNAME
120-
sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc
121-
chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc
155+
if [ "${USERNAME}" != "root" ]; then
156+
cp -fR /root/.oh-my-zsh /home/$USERNAME
157+
cp -f /root/.zshrc /home/$USERNAME
158+
sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc
159+
chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc
160+
fi
161+
ZSH_ALREADY_INSTALLED="true"
122162
fi
123163

164+
# Write marker file
165+
mkdir -p "$(dirname "${MARKER_FILE}")"
166+
echo -e "\
167+
PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\
168+
LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\
169+
EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\
170+
DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\
171+
ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}"

containers/azure-ansible/.devcontainer/library-scripts/docker-debian.sh

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,79 @@
66

77
# Syntax: ./docker-debian.sh <enable non-root docker socket access flag> <source socket> <target socket> <non-root user>
88

9-
set -e
10-
119
ENABLE_NONROOT_DOCKER=${1:-"true"}
1210
SOURCE_SOCKET=${2:-"/var/run/docker-host.sock"}
1311
TARGET_SOCKET=${3:-"/var/run/docker.sock"}
14-
NONROOT_USER=${4:-"vscode"}
12+
USERNAME=${4:-"vscode"}
13+
14+
set -e
1515

1616
if [ "$(id -u)" -ne 0 ]; then
17-
echo 'Script must be run a root. Use sudo or set "USER root" before running the script.'
17+
echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
1818
exit 1
1919
fi
2020

2121
# Ensure apt is in non-interactive to avoid prompts
2222
export DEBIAN_FRONTEND=noninteractive
2323

24-
# Install Docker CLI
25-
apt-get -y install --no-install-recommends apt-transport-https ca-certificates curl gnupg2 lsb-release
26-
curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | (OUT=$(apt-key add - 2>&1) || echo $OUT)
27-
echo "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list
28-
apt-get update
29-
apt-get -y install --no-install-recommends docker-ce-cli
24+
# Function to run apt-get if needed
25+
apt-get-update-if-needed()
26+
{
27+
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
28+
echo "Running apt-get update..."
29+
apt-get update
30+
else
31+
echo "Skipping apt-get update."
32+
fi
33+
}
3034

31-
# Install Docker Compose
32-
LATEST_COMPOSE_VERSION=$(curl -sSL "https://api.github.com/repos/docker/compose/releases/latest" | grep -o -P '(?<="tag_name": ").+(?=")')
33-
curl -sSL "https://github.com/docker/compose/releases/download/${LATEST_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
34-
chmod +x /usr/local/bin/docker-compose \
35+
# Install Docker CLI if not already installed
36+
if type docker > /dev/null 2>&1; then
37+
echo "Docker CLI already installed."
38+
else
39+
if ! type curl > /dev/null 2>&1; then
40+
apt-get-update-if-needed
41+
apt-get -y install --no-install-recommends apt-transport-https ca-certificates curl gnupg2 lsb-release
42+
fi
43+
curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | (OUT=$(apt-key add - 2>&1) || echo $OUT)
44+
echo "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list
45+
apt-get update
46+
apt-get -y install --no-install-recommends docker-ce-cli
47+
fi
48+
49+
# Install Docker Compose if not already installed
50+
if type docker-compose > /dev/null 2>&1; then
51+
echo "Docker Compose already installed."
52+
else
53+
LATEST_COMPOSE_VERSION=$(curl -sSL "https://api.github.com/repos/docker/compose/releases/latest" | grep -o -P '(?<="tag_name": ").+(?=")')
54+
curl -sSL "https://github.com/docker/compose/releases/download/${LATEST_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
55+
chmod +x /usr/local/bin/docker-compose
56+
fi
57+
58+
# If init file already exists, exit
59+
if [ -f "/usr/local/share/docker-init.sh" ]; then
60+
exit 0
61+
fi
3562

3663
# By default, make the source and target sockets the same
3764
if [ "${SOURCE_SOCKET}" != "${TARGET_SOCKET}" ]; then
3865
touch "${SOURCE_SOCKET}"
3966
ln -s "${SOURCE_SOCKET}" "${TARGET_SOCKET}"
40-
chown -h "${NONROOT_USER}" "${TARGET_SOCKET}"
4167
fi
4268

43-
# If enabling non-root access, setup socat
44-
if [ "${ENABLE_NONROOT_DOCKER}" = "true" ]; then
45-
apt-get -y install socat
46-
tee /usr/local/share/docker-init.sh << EOF
69+
# Add a stub if not adding non-root user access, user is root, or the specified user does not exist
70+
if [ "${ENABLE_NONROOT_DOCKER}" = "false" ] || [ "${USERNAME}" = "root" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
71+
echo '/usr/bin/env bash -c "\$@"' > /usr/local/share/docker-init.sh
72+
chmod +x /usr/local/share/docker-init.sh
73+
exit 0
74+
fi
75+
76+
# If enabling non-root access and specified user is found, setup socat and add script
77+
chown -h "${USERNAME}":root "${TARGET_SOCKET}"
78+
apt-get-update-if-needed
79+
apt-get -y install socat
80+
tee /usr/local/share/docker-init.sh > /dev/null \
81+
<< EOF
4782
#!/usr/bin/env bash
4883
#-------------------------------------------------------------------------------------------------------------
4984
# Copyright (c) Microsoft Corporation. All rights reserved.
@@ -73,29 +108,29 @@ log()
73108
}
74109
75110
echo -e "\n** \$(date) **" | sudoIf tee -a \${SOCAT_LOG} > /dev/null
76-
log "Ensuring ${NONROOT_USER} has access to ${SOURCE_SOCKET} via ${TARGET_SOCKET}"
111+
log "Ensuring ${USERNAME} has access to ${SOURCE_SOCKET} via ${TARGET_SOCKET}"
77112
78113
# If enabled, try to add a docker group with the right GID. If the group is root,
79114
# fall back on using socat to forward the docker socket to another unix socket so
80115
# that we can set permissions on it without affecting the host.
81-
if [ "${ENABLE_NONROOT_DOCKER}" = "true" ] && [ "${SOURCE_SOCKET}" != "${TARGET_SOCKET}" ] && [ "${NONROOT_USER}" != "root" ] && [ "${NONROOT_USER}" != "0" ]; then
116+
if [ "${ENABLE_NONROOT_DOCKER}" = "true" ] && [ "${SOURCE_SOCKET}" != "${TARGET_SOCKET}" ] && [ "${USERNAME}" != "root" ] && [ "${USERNAME}" != "0" ]; then
82117
SOCKET_GID=\$(stat -c '%g' ${SOURCE_SOCKET})
83118
if [ "\${SOCKET_GID}" != "0" ]; then
84119
log "Adding user to group with GID \${SOCKET_GID}."
85120
if [ "\$(cat /etc/group | grep :\${SOCKET_GID}:)" = "" ]; then
86121
sudoIf groupadd --gid \${SOCKET_GID} docker-host
87122
fi
88123
# Add user to group if not already in it
89-
if [ "\$(id ${NONROOT_USER} | grep -E 'groups=.+\${SOCKET_GID}\(')" = "" ]; then
90-
sudoIf usermod -aG \${SOCKET_GID} ${NONROOT_USER}
124+
if [ "\$(id ${USERNAME} | grep -E 'groups=.+\${SOCKET_GID}\(')" = "" ]; then
125+
sudoIf usermod -aG \${SOCKET_GID} ${USERNAME}
91126
fi
92127
else
93128
# Enable proxy if not already running
94129
if [ ! -f "\${SOCAT_PID}" ] || ! ps -p \$(cat \${SOCAT_PID}) > /dev/null; then
95130
log "Enabling socket proxy."
96131
log "Proxying ${SOURCE_SOCKET} to ${TARGET_SOCKET} for vscode"
97132
sudoIf rm -rf ${TARGET_SOCKET}
98-
(sudoIf socat UNIX-LISTEN:${TARGET_SOCKET},fork,mode=660,user=${NONROOT_USER} UNIX-CONNECT:${SOURCE_SOCKET} 2>&1 | sudoIf tee -a \${SOCAT_LOG} > /dev/null & echo "\$!" | sudoIf tee \${SOCAT_PID} > /dev/null)
133+
(sudoIf socat UNIX-LISTEN:${TARGET_SOCKET},fork,mode=660,user=${USERNAME} UNIX-CONNECT:${SOURCE_SOCKET} 2>&1 | sudoIf tee -a \${SOCAT_LOG} > /dev/null & echo "\$!" | sudoIf tee \${SOCAT_PID} > /dev/null)
99134
else
100135
log "Socket proxy already running."
101136
fi
@@ -108,7 +143,5 @@ fi
108143
set +e
109144
"\$@"
110145
EOF
111-
else
112-
echo '/usr/bin/env bash -c "\$@"' > /usr/local/share/docker-init.sh
113-
fi
114146
chmod +x /usr/local/share/docker-init.sh
147+
chown ${USERNAME}:root /usr/local/share/docker-init.sh

0 commit comments

Comments
 (0)