|
3 | 3 | # Copyright (c) Microsoft Corporation. All rights reserved.
|
4 | 4 | # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
|
5 | 5 | #-------------------------------------------------------------------------------------------------------------
|
6 |
| -# |
7 |
| -# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/hugo.md |
8 |
| -# Maintainer: The VS Code and Codespaces Teams |
| 6 | + |
9 | 7 |
|
10 | 8 | USERNAME=${USERNAME:-"automatic"}
|
11 | 9 | UPDATE_RC=${UPDATE_RC:-"true"}
|
12 | 10 |
|
13 |
| -set -eux |
| 11 | +MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc" |
| 12 | + |
| 13 | +set -eu |
14 | 14 |
|
15 | 15 | if [ "$(id -u)" -ne 0 ]; then
|
16 | 16 | echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
|
@@ -66,72 +66,89 @@ apt_get_update_if_needed()
|
66 | 66 | check_packages() {
|
67 | 67 | if ! dpkg -s "$@" > /dev/null 2>&1; then
|
68 | 68 | apt_get_update_if_needed
|
69 |
| - DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends "$@" |
| 69 | + apt-get -y install --no-install-recommends "$@" |
70 | 70 | fi
|
71 | 71 | }
|
72 | 72 |
|
73 | 73 | install_dotnet_using_apt() {
|
74 |
| - wget --no-check-certificate https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb |
75 |
| - sudo dpkg -i packages-microsoft-prod.deb |
76 |
| - rm packages-microsoft-prod.deb |
77 |
| - |
78 |
| - rm -rf /var/lib/apt/lists/* |
79 |
| - check_packages apt-transport-https dotnet-sdk-6.0 |
| 74 | + echo "Attempting to auto-install dotnet..." |
| 75 | + install_from_microsoft_feed=false |
| 76 | + apt_get_update_if_needed |
| 77 | + apt-get -yq install dotnet6 || install_from_microsoft_feed="true" |
| 78 | + |
| 79 | + if [ "${install_from_microsoft_feed}" = "true" ]; then |
| 80 | + echo "Attempting install from microsoft apt feed..." |
| 81 | + curl -sSL ${MICROSOFT_GPG_KEYS_URI} | gpg --dearmor > /usr/share/keyrings/microsoft-archive-keyring.gpg |
| 82 | + echo "deb [arch=${architecture} signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/repos/microsoft-${ID}-${VERSION_CODENAME}-prod ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/microsoft.list |
| 83 | + apt-get update -y |
| 84 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE="true" apt-get install -yq dotnet-sdk-6.0 |
| 85 | + fi |
| 86 | + |
| 87 | + echo -e "Finished attempt to install dotnet. Sdks installed:\n" |
| 88 | + dotnet --list-sdks |
80 | 89 | }
|
81 | 90 |
|
| 91 | +# If we don't already have Oryx installed, install it now. |
| 92 | +if oryx --version > /dev/null ; then |
| 93 | + echo "oryx is already installed. Skipping installation." |
| 94 | + exit 0 |
| 95 | +fi |
| 96 | + |
| 97 | +echo "Installing Oryx..." |
| 98 | + |
| 99 | +# Ensure apt is in non-interactive to avoid prompts |
| 100 | +export DEBIAN_FRONTEND=noninteractive |
| 101 | + |
| 102 | +. /etc/os-release |
| 103 | +architecture="$(dpkg --print-architecture)" |
| 104 | + |
82 | 105 | # Install dependencies
|
83 |
| -check_packages git sudo wget ca-certificates |
| 106 | +check_packages git sudo curl ca-certificates apt-transport-https gnupg2 dirmngr libc-bin |
84 | 107 |
|
85 |
| -# If we don't already have Oryx installed, install it now. |
86 |
| -if ! oryx --version > /dev/null ; then |
87 |
| - echo "Installing Oryx..." |
| 108 | +if ! cat /etc/group | grep -e "^oryx:" > /dev/null 2>&1; then |
| 109 | + groupadd -r oryx |
| 110 | +fi |
| 111 | +usermod -a -G oryx "${USERNAME}" |
88 | 112 |
|
89 |
| - if ! cat /etc/group | grep -e "^oryx:" > /dev/null 2>&1; then |
90 |
| - groupadd -r oryx |
91 |
| - fi |
92 |
| - usermod -a -G oryx "${USERNAME}" |
| 113 | +# Install dotnet unless available |
| 114 | +if ! dotnet --version > /dev/null ; then |
| 115 | + echo "'dotnet' was not detected. Attempting to install the latest version of the dotnet sdk to build oryx." |
| 116 | + install_dotnet_using_apt |
93 | 117 |
|
94 |
| - # Install dotnet unless available |
95 | 118 | if ! dotnet --version > /dev/null ; then
|
96 |
| - echo "'dotnet' was not detected. Attempting to install the latest version of the dotnet sdk to build oryx." |
97 |
| - install_dotnet_using_apt |
98 |
| - |
99 |
| - if ! dotnet --version > /dev/null ; then |
100 |
| - echo "Please install Dotnet before installing Oryx" |
101 |
| - exit 1 |
102 |
| - fi |
| 119 | + echo "(!) Please install Dotnet before installing Oryx" |
| 120 | + exit 1 |
103 | 121 | fi
|
| 122 | +fi |
104 | 123 |
|
105 |
| - BUILD_SCRIPT_GENERATOR=/usr/local/buildscriptgen |
106 |
| - ORYX=/usr/local/oryx |
107 |
| - GIT_ORYX=/opt/tmp |
| 124 | +BUILD_SCRIPT_GENERATOR=/usr/local/buildscriptgen |
| 125 | +ORYX=/usr/local/oryx |
| 126 | +GIT_ORYX=/opt/tmp |
108 | 127 |
|
109 |
| - mkdir -p ${BUILD_SCRIPT_GENERATOR} |
110 |
| - mkdir -p ${ORYX} |
| 128 | +mkdir -p ${BUILD_SCRIPT_GENERATOR} |
| 129 | +mkdir -p ${ORYX} |
111 | 130 |
|
112 |
| - git clone --depth=1 https://github.com/microsoft/Oryx $GIT_ORYX |
| 131 | +git clone --depth=1 https://github.com/microsoft/Oryx $GIT_ORYX |
113 | 132 |
|
114 |
| - $GIT_ORYX/build/buildSln.sh |
| 133 | +$GIT_ORYX/build/buildSln.sh |
115 | 134 |
|
116 |
| - dotnet publish -property:ValidateExecutableReferencesMatchSelfContained=false -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildScriptGeneratorCli/BuildScriptGeneratorCli.csproj |
117 |
| - |
118 |
| - dotnet publish -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildServer/BuildServer.csproj |
| 135 | +dotnet publish -property:ValidateExecutableReferencesMatchSelfContained=false -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildScriptGeneratorCli/BuildScriptGeneratorCli.csproj |
| 136 | +dotnet publish -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildServer/BuildServer.csproj |
119 | 137 |
|
120 |
| - chmod a+x ${BUILD_SCRIPT_GENERATOR}/GenerateBuildScript |
| 138 | +chmod a+x ${BUILD_SCRIPT_GENERATOR}/GenerateBuildScript |
121 | 139 |
|
122 |
| - ln -s ${BUILD_SCRIPT_GENERATOR}/GenerateBuildScript ${ORYX}/oryx |
123 |
| - cp -f $GIT_ORYX/images/build/benv.sh ${ORYX}/benv |
| 140 | +ln -s ${BUILD_SCRIPT_GENERATOR}/GenerateBuildScript ${ORYX}/oryx |
| 141 | +cp -f $GIT_ORYX/images/build/benv.sh ${ORYX}/benv |
124 | 142 |
|
125 |
| - ORYX_INSTALL_DIR="/opt" |
126 |
| - mkdir -p "${ORYX_INSTALL_DIR}" |
| 143 | +ORYX_INSTALL_DIR="/opt" |
| 144 | +mkdir -p "${ORYX_INSTALL_DIR}" |
127 | 145 |
|
128 |
| - updaterc "export ORYX_SDK_STORAGE_BASE_URL=https://oryx-cdn.microsoft.io && export ENABLE_DYNAMIC_INSTALL=true && DYNAMIC_INSTALL_ROOT_DIR=$ORYX_INSTALL_DIR && ORYX_PREFER_USER_INSTALLED_SDKS=true && export DEBIAN_FLAVOR=focal-scm" |
129 |
| - |
130 |
| - chown -R "${USERNAME}:oryx" "${ORYX_INSTALL_DIR}" "${BUILD_SCRIPT_GENERATOR}" "${ORYX}" |
131 |
| - chmod -R g+r+w "${ORYX_INSTALL_DIR}" "${BUILD_SCRIPT_GENERATOR}" "${ORYX}" |
132 |
| - find "${ORYX_INSTALL_DIR}" -type d | xargs -n 1 chmod g+s |
133 |
| - find "${BUILD_SCRIPT_GENERATOR}" -type d | xargs -n 1 chmod g+s |
134 |
| - find "${ORYX}" -type d | xargs -n 1 chmod g+s |
135 |
| -fi |
| 146 | +updaterc "export ORYX_SDK_STORAGE_BASE_URL=https://oryx-cdn.microsoft.io && export ENABLE_DYNAMIC_INSTALL=true && DYNAMIC_INSTALL_ROOT_DIR=$ORYX_INSTALL_DIR && ORYX_PREFER_USER_INSTALLED_SDKS=true && export DEBIAN_FLAVOR=focal-scm" |
| 147 | + |
| 148 | +chown -R "${USERNAME}:oryx" "${ORYX_INSTALL_DIR}" "${BUILD_SCRIPT_GENERATOR}" "${ORYX}" |
| 149 | +chmod -R g+r+w "${ORYX_INSTALL_DIR}" "${BUILD_SCRIPT_GENERATOR}" "${ORYX}" |
| 150 | +find "${ORYX_INSTALL_DIR}" -type d | xargs -n 1 chmod g+s |
| 151 | +find "${BUILD_SCRIPT_GENERATOR}" -type d | xargs -n 1 chmod g+s |
| 152 | +find "${ORYX}" -type d | xargs -n 1 chmod g+s |
136 | 153 |
|
137 | 154 | echo "Done!"
|
0 commit comments