1+ #! /usr/bin/env bash
2+ # -------------------------------------------------------------------------------------------------------------
3+ # Copyright (c) Microsoft Corporation. All rights reserved.
4+ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
5+ # -------------------------------------------------------------------------------------------------------------
6+
7+ set -e
8+
9+ USERNAME=${1:- " vscode" }
10+
11+ . /etc/os-release
12+
13+ # Add to bashrc/zshrc files for all users.
14+ updaterc () {
15+ echo " Updating /etc/bash.bashrc and /etc/zsh/zshrc..."
16+ if [[ " $( cat /etc/bash.bashrc) " != * " $1 " * ]]; then
17+ echo -e " $1 " >> /etc/bash.bashrc
18+ fi
19+ if [ -f " /etc/zsh/zshrc" ] && [[ " $( cat /etc/zsh/zshrc) " != * " $1 " * ]]; then
20+ echo -e " $1 " >> /etc/zsh/zshrc
21+ fi
22+ }
23+
24+ # Run apt-get if needed.
25+ apt_get_update_if_needed () {
26+ if [ ! -d " /var/lib/apt/lists" ] || [ " $( ls /var/lib/apt/lists/ | wc -l) " = " 0" ]; then
27+ echo " Running apt-get update..."
28+ apt-get update
29+ else
30+ echo " Skipping apt-get update."
31+ fi
32+ }
33+
34+ # Check if packages are installed and installs them if not.
35+ check_packages () {
36+ if ! dpkg -s " $@ " > /dev/null 2>&1 ; then
37+ apt_get_update_if_needed
38+ apt-get -y install --no-install-recommends " $@ "
39+ fi
40+ }
41+
42+ export DEBIAN_FRONTEND=noninteractive
43+ export VCPKG_FORCE_SYSTEM_BINARIES=1
44+
45+ # Install additional packages needed by vcpkg: https://github.com/microsoft/vcpkg/blob/master/README.md#installing-linux-developer-tools
46+ check_packages build-essential tar curl zip unzip pkg-config bash-completion ninja-build
47+
48+ # Setup group and add user
49+ umask 0002
50+ if ! cat /etc/group | grep -e " ^vcpkg:" > /dev/null 2>&1 ; then
51+ groupadd -r " vcpkg"
52+ fi
53+ usermod -a -G " vcpkg" " ${USERNAME} "
54+
55+ # Start Installation
56+ # Clone repository with ports and installer
57+ mkdir -p " ${VCPKG_ROOT} "
58+ mkdir -p " ${VCPKG_DOWNLOADS} "
59+ git clone --depth=1 \
60+ -c core.eol=lf \
61+ -c core.autocrlf=false \
62+ -c fsck.zeroPaddedFilemode=ignore \
63+ -c fetch.fsck.zeroPaddedFilemode=ignore \
64+ -c receive.fsck.zeroPaddedFilemode=ignore \
65+ https://github.com/microsoft/vcpkg " ${VCPKG_ROOT} "
66+
67+ # # Run installer to get latest stable vcpkg binary
68+ # # https://github.com/microsoft/vcpkg/blob/7e7dad5fe20cdc085731343e0e197a7ae655555b/scripts/bootstrap.sh#L126-L144
69+ " ${VCPKG_ROOT} " /bootstrap-vcpkg.sh
70+
71+ # Add vcpkg to PATH
72+ updaterc " $( cat << EOF
73+ export VCPKG_ROOT="${VCPKG_ROOT} "
74+ if [[ "\$ {PATH}" != *"\$ {VCPKG_ROOT}"* ]]; then export PATH="\$ {PATH}:\$ {VCPKG_ROOT}"; fi
75+ EOF
76+ ) "
77+
78+ # Give read/write permissions to the user group.
79+ chown -R " :vcpkg" " ${VCPKG_ROOT} " " ${VCPKG_DOWNLOADS} "
80+ chmod g+r+w+s " ${VCPKG_ROOT} " " ${VCPKG_DOWNLOADS} "
81+ chmod -R g+r+w " ${VCPKG_ROOT} " " ${VCPKG_DOWNLOADS} "
82+
83+ # Enable tab completion for bash and zsh
84+ VCPKG_FORCE_SYSTEM_BINARIES=1 su " ${USERNAME} " -c " ${VCPKG_ROOT} /vcpkg integrate bash"
85+ VCPKG_FORCE_SYSTEM_BINARIES=1 su " ${USERNAME} " -c " ${VCPKG_ROOT} /vcpkg integrate zsh"
0 commit comments