forked from microsoft/codespace-features
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·171 lines (145 loc) · 5.52 KB
/
install.sh
File metadata and controls
executable file
·171 lines (145 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
set -e
PREFIXES="${NUGETURIPREFIXES:-"https://pkgs.dev.azure.com/"}"
USENET6="${DOTNET6:-"false"}"
WRAPPERTYPE="${WRAPPERTYPE:-"SHELL_FUNCTION"}"
ALIAS_DOTNET="${DOTNETALIAS:-"true"}"
ALIAS_NUGET="${NUGETALIAS:-"true"}"
ALIAS_NPM="${NPMALIAS:-"true"}"
ALIAS_YARN="${YARNALIAS:-"true"}"
ALIAS_NPX="${NPXALIAS:-"true"}"
ALIAS_RUSH="${RUSHALIAS:-"true"}"
ALIAS_PNPM="${PNPMALIAS:-"true"}"
INSTALL_PIP_HELPER="${PYTHON:-"false"}"
COMMA_SEP_TARGET_FILES="${TARGETFILES:-"DEFAULT"}"
# Destination to install wrappers for the `EXECUTABLE` wrapper type.
# This path must take precedence over /usr/local/bin and the original tools,
# which is ensured via `containerEnv.PATH` in devcontainer-feature.json.
EXECUTABLES_TARGET_DIR='/usr/local/share/codespace-features'
WRAPPED_BINS_ARR=()
if [ "${ALIAS_DOTNET}" = "true" ]; then
WRAPPED_BINS_ARR+=('dotnet')
fi
if [ "${ALIAS_NUGET}" = "true" ]; then
WRAPPED_BINS_ARR+=('nuget')
fi
if [ "${ALIAS_NPM}" = "true" ]; then
WRAPPED_BINS_ARR+=('npm')
fi
if [ "${ALIAS_YARN}" = "true" ]; then
WRAPPED_BINS_ARR+=('yarn')
fi
if [ "${ALIAS_NPX}" = "true" ]; then
WRAPPED_BINS_ARR+=('npx')
fi
if [ "${ALIAS_RUSH}" = "true" ]; then
WRAPPED_BINS_ARR+=('rush')
WRAPPED_BINS_ARR+=('rush-pnpm')
fi
if [ "${ALIAS_PNPM}" = "true" ]; then
WRAPPED_BINS_ARR+=('pnpm')
WRAPPED_BINS_ARR+=('pnpx')
fi
# Source /etc/os-release to get OS info
. /etc/os-release
if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi
apt_get_update() {
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update -y
fi
}
# Checks if packages are installed and installs them if not
check_packages() {
if ! dpkg -s "$@" > /dev/null 2>&1; then
apt_get_update
apt-get -y install --no-install-recommends "$@"
rm -rf /var/lib/apt/lists/*
fi
}
export DEBIAN_FRONTEND=noninteractive
if [ "${ID}" = "mariner" ]; then
tdnf install -y wget ca-certificates
tdnf clean all
else
check_packages wget ca-certificates
fi
# Change to the directory where this script is located
cd "$(dirname "$0")"
cp ./scripts/install-provider.sh /tmp
chmod +rx /tmp/install-provider.sh
cp ./scripts/install-python-keyring.sh /tmp
chmod +rx /tmp/install-python-keyring.sh
sed "s|REPLACE_WITH_AZURE_DEVOPS_NUGET_FEED_URL_PREFIX|${PREFIXES}|g" ./scripts/run-dotnet.sh > /usr/local/bin/run-dotnet.sh
chmod +rx /usr/local/bin/run-dotnet.sh
sed "s|REPLACE_WITH_AZURE_DEVOPS_NUGET_FEED_URL_PREFIX|${PREFIXES}|g" ./scripts/run-nuget.sh > /usr/local/bin/run-nuget.sh
chmod +rx /usr/local/bin/run-nuget.sh
cp ./scripts/run-npm.sh /usr/local/bin/run-npm.sh
chmod +rx /usr/local/bin/run-npm.sh
cp ./scripts/run-yarn.sh /usr/local/bin/run-yarn.sh
chmod +rx /usr/local/bin/run-yarn.sh
cp ./scripts/write-npm.sh /usr/local/bin/write-npm.sh
chmod +rx /usr/local/bin/write-npm.sh
cp ./scripts/run-npx.sh /usr/local/bin/run-npx.sh
chmod +rx /usr/local/bin/run-npx.sh
cp ./scripts/run-rush.sh /usr/local/bin/run-rush.sh
chmod +rx /usr/local/bin/run-rush.sh
cp ./scripts/run-rush-pnpm.sh /usr/local/bin/run-rush-pnpm.sh
chmod +rx /usr/local/bin/run-rush-pnpm.sh
cp ./scripts/run-pnpm.sh /usr/local/bin/run-pnpm.sh
chmod +rx /usr/local/bin/run-pnpm.sh
cp ./scripts/run-pnpx.sh /usr/local/bin/run-pnpx.sh
chmod +rx /usr/local/bin/run-pnpx.sh
if [ "${INSTALL_PIP_HELPER}" = "true" ]; then
USER="${_REMOTE_USER}" /tmp/install-python-keyring.sh
rm /tmp/install-python-keyring.sh
fi
INSTALL_WITH_SUDO="false"
if command -v sudo >/dev/null 2>&1; then
if [ "root" != "$_REMOTE_USER" ]; then
INSTALL_WITH_SUDO="true"
fi
fi
if [ "$WRAPPERTYPE" = "SHELL_FUNCTION" ]; then
echo "Installing shell functions for wrapped commands."
if [ "${COMMA_SEP_TARGET_FILES}" = "DEFAULT" ]; then
if [ "${INSTALL_WITH_SUDO}" = "true" ]; then
COMMA_SEP_TARGET_FILES="~/.bashrc,~/.zshrc"
else
COMMA_SEP_TARGET_FILES="/etc/bash.bashrc,/etc/zsh/zshrc"
fi
fi
IFS=',' read -r -a TARGET_FILES_ARR <<< "$COMMA_SEP_TARGET_FILES"
for ALIAS in "${WRAPPED_BINS_ARR[@]}"; do
for TARGET_FILE in "${TARGET_FILES_ARR[@]}"; do
CMD="$ALIAS() { /usr/local/bin/run-$ALIAS.sh \"\$@\"; }"
if [ "${INSTALL_WITH_SUDO}" = "true" ]; then
sudo -u ${_REMOTE_USER} bash -c "echo '$CMD' >> $TARGET_FILE"
else
echo $CMD >> $TARGET_FILE || true
fi
done
done
elif [ "$WRAPPERTYPE" = "EXECUTABLE" ]; then
echo "Installing executable scripts for wrapped commands."
sudo mkdir -p "${EXECUTABLES_TARGET_DIR}"
for ALIAS in "${WRAPPED_BINS_ARR[@]}"; do
TARGET_EXECUTABLE_PATH="${EXECUTABLES_TARGET_DIR}/$ALIAS"
TARGET_WRAPPER_PATH="/usr/local/bin/run-$ALIAS.sh"
TARGET_WRAPPER_EXE_ENV_VAR_NAME=$(sed "s|-|_|g" <<<"${ALIAS}_EXE" | tr '[:lower:]' '[:upper:]')
cp ./scripts/executable-wrapper-template.sh "$TARGET_EXECUTABLE_PATH"
sed -i "s|SUBST_TARGET_WRAPPER_PATH|$TARGET_WRAPPER_PATH|g; s|SUBST_TARGET_BIN_NAME|$ALIAS|g; s|SUBST_EXE_ENV_VAR|$TARGET_WRAPPER_EXE_ENV_VAR_NAME|g" "$TARGET_EXECUTABLE_PATH"
chmod +x "$TARGET_EXECUTABLE_PATH"
done
else
echo "Invalid WRAPPERTYPE specified: $WRAPPERTYPE. Must be one of SHELL_FUNCTION or EXECUTABLE."
exit 1
fi
if [ "${INSTALL_WITH_SUDO}" = "true" ]; then
sudo -u ${_REMOTE_USER} bash -c "/tmp/install-provider.sh ${USENET6}"
fi
rm /tmp/install-provider.sh
exit 0