-
Notifications
You must be signed in to change notification settings - Fork 8
/
install.sh
executable file
·136 lines (114 loc) · 3.82 KB
/
install.sh
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
#!/bin/bash
set -e
PREFIXES="${NUGETURIPREFIXES:-"https://pkgs.dev.azure.com/"}"
USENET6="${DOTNET6:-"false"}"
ALIAS_DOTNET="${DOTNETALIAS:-"true"}"
ALIAS_NUGET="${NUGETALIAS:-"true"}"
ALIAS_NPM="${NPMALIAS:-"true"}"
ALIAS_YARN="${YARNALIAS:-"true"}"
ALIAS_NPX="${NPXALIAS:-"true"}"
ALIAS_RUSH="${RUSHALIAS:-"true"}"
INSTALL_PIP_HELPER="${PYTHON:-"false"}"
COMMA_SEP_TARGET_FILES="${TARGETFILES:-"DEFAULT"}"
ALIASES_ARR=()
if [ "${ALIAS_DOTNET}" = "true" ]; then
ALIASES_ARR+=('dotnet')
fi
if [ "${ALIAS_NUGET}" = "true" ]; then
ALIASES_ARR+=('nuget')
fi
if [ "${ALIAS_NPM}" = "true" ]; then
ALIASES_ARR+=('npm')
fi
if [ "${ALIAS_YARN}" = "true" ]; then
ALIASES_ARR+=('yarn')
fi
if [ "${ALIAS_NPX}" = "true" ]; then
ALIASES_ARR+=('npx')
fi
if [ "${ALIAS_RUSH}" = "true" ]; then
ALIASES_ARR+=('rush')
ALIASES_ARR+=('rush-pnpm')
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
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 [ "${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 "${ALIASES_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
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