* Refinements

* Git LFS script

* GH CLI script

* Go script

* Java script

* kubectl / helm script

* PowerShell script

* Rust script

* Test refinements

* Bug fix

* Script to build git from source

* Output "Done!" when script has finished
This commit is contained in:
Chuck Lantz 2020-08-18 17:37:16 -07:00 коммит произвёл GitHub
Родитель fa6da4a49d
Коммит f6a820ec21
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
21 изменённых файлов: 524 добавлений и 91 удалений

Просмотреть файл

@ -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!"

Просмотреть файл

@ -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!"

Просмотреть файл

@ -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!"

Просмотреть файл

@ -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!"

Просмотреть файл

@ -4,7 +4,7 @@
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
# Syntax: ./docker-debian.sh <enable non-root docker socket access flag> <source socket> <target socket> <non-root user>
# 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!"

Просмотреть файл

@ -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!"

Просмотреть файл

@ -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!"

Просмотреть файл

@ -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!"

Просмотреть файл

@ -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!"

116
script-library/go-debian.sh Normal file
Просмотреть файл

@ -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 <<EOF
set -e
echo "Downloading Go ${TARGET_GO_VERSION}..."
curl -sSL -o /tmp/go.tar.gz "https://golang.org/dl/go${TARGET_GO_VERSION}.linux-amd64.tar.gz"
echo "Extracting Go ${TARGET_GO_VERSION}..."
tar -xzf /tmp/go.tar.gz -C "${TARGET_GOROOT}" --strip-components=1
rm -f /tmp/go.tar.gz
EOF
)"
if ! type go > /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

Просмотреть файл

@ -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!"

Просмотреть файл

@ -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

Просмотреть файл

@ -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!"

Просмотреть файл

@ -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!"

Просмотреть файл

@ -4,7 +4,7 @@
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
# Syntax: ./node-debian.sh <directory to install nvm> <node version to install (use "none" to skip)> <non-root user>
# 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}
# Set up non-root user if applicable
if [ "${USERNAME}" != "root" ] && id -u $USERNAME > /dev/null 2>&1; 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 \
<<EOF
export NVM_DIR="${NVM_DIR}"
[ -s "\$NVM_DIR/nvm.sh" ] && . "\$NVM_DIR/nvm.sh"
[ -s "\$NVM_DIR/bash_completion" ] && . "\$NVM_DIR/bash_completion"
if [ "\$(stat -c '%U' \$NVM_DIR)" != "${USERNAME}" ]; then
sudo chown -R ${USERNAME}:root \$NVM_DIR
fi
NVM_INIT=$(cat <<EOF
export NVM_DIR="${NVM_DIR}"
[ -s "\$NVM_DIR/nvm.sh" ] && . "\$NVM_DIR/nvm.sh"
[ -s "\$NVM_DIR/bash_completion" ] && . "\$NVM_DIR/bash_completion"
if [ "\$(stat -c '%U' \$NVM_DIR)" != "${USERNAME}" ]; then
sudo chown -R ${USERNAME}:root \$NVM_DIR
fi
EOF
# Update ownership
)
echo "${NVM_INIT}" | tee -a /root/.bashrc /root/.zshrc >> /etc/skel/.bashrc
# Set up non-root user if applicable
if [ "${USERNAME}" != "root" ]; then
# Add NVM init and add code to update NVM ownership if UID/GID changes
echo "${NVM_INIT}" | tee -a /home/${USERNAME}/.bashrc >> /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!"

Просмотреть файл

@ -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!"

Просмотреть файл

@ -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

Просмотреть файл

@ -45,4 +45,4 @@ if [ "${TFLINT_VERSION}" != "none" ]; then
fi
rm -rf /tmp/tf-downloads
echo "Done."
echo "Done!"

Просмотреть файл

@ -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" ]

Просмотреть файл

@ -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,

Просмотреть файл

@ -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