-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·180 lines (161 loc) · 6.66 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
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
172
173
174
175
176
177
178
179
180
#!/bin/bash
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
FONT_VERSION="${VERSION:-"latest"}"
INSTALL_FONTCONFIG="${INSTALLFONTCONFIG:-"true"}"
FONT_VARIABLE_TTF="${INSTALLVARIABLETTF:-"false"}"
FONT_VARIABLE_WOFF2="${INSTALLVARIABLEWOFF2:-"false"}"
FONT_STATIC_TTF="${INSTALLSTATICTTF:-"true"}"
FONT_STATIC_OTF="${INSTALLSTATICOTF:-"false"}"
FONT_STATIC_WOFF2="${INSTALLSTATICWOFF2:-"false"}"
set -e
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
# Bring in ID, ID_LIKE, VERSION_ID, VERSION_CODENAME
# shellcheck source=/dev/null
. /etc/os-release
# Get an adjusted ID independent of distro variants
MAJOR_VERSION_ID=$(echo "${VERSION_ID}" | cut -d . -f 1)
if [ "${ID}" = "debian" ] || [ "${ID_LIKE}" = "debian" ]; then
ADJUSTED_ID="debian"
elif [[ "${ID}" = "rhel" || "${ID}" = "fedora" || "${ID}" = "mariner" || "${ID_LIKE}" = *"rhel"* || "${ID_LIKE}" = *"fedora"* || "${ID_LIKE}" = *"mariner"* ]]; then
ADJUSTED_ID="rhel"
if [[ "${ID}" = "rhel" ]] || [[ "${ID}" = *"alma"* ]] || [[ "${ID}" = *"rocky"* ]]; then
VERSION_CODENAME="rhel${MAJOR_VERSION_ID}"
else
# shellcheck disable=SC2034 # Unused variables left for readability
VERSION_CODENAME="${ID}${MAJOR_VERSION_ID}"
fi
else
echo "Linux distro ${ID} not supported."
exit 1
fi
# Ensure that login shells get the correct path if the user updated the PATH using ENV.
rm -f /etc/profile.d/00-restore-env.sh
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" >/etc/profile.d/00-restore-env.sh
chmod +x /etc/profile.d/00-restore-env.sh
# Determine the appropriate non-root user
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
USERNAME=""
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
if id -u "${CURRENT_USER}" >/dev/null 2>&1; then
USERNAME=${CURRENT_USER}
break
fi
done
if [ "${USERNAME}" = "" ]; then
USERNAME=root
fi
elif [ "${USERNAME}" = "none" ] || ! id -u "${USERNAME}" >/dev/null 2>&1; then
USERNAME=root
fi
apt_get_update() {
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update -y
fi
}
yum_update() {
if [ "$(find /var/cache/yum/* | wc -l)" = "0" ]; then
echo "Running yum update..."
yum makecache fast
fi
}
check_packages() {
case $ADJUSTED_ID in
debian)
if ! dpkg -s "$@" > /dev/null 2>&1; then
apt_get_update
export DEBIAN_FRONTEND=noninteractive
apt-get -y install --no-install-recommends "$@"
fi
;;
rhel)
if ! rpm -q "$@" > /dev/null 2>&1; then
yum_update
yum -y install "$@"
fi
;;
esac
}
# Install required packages
check_packages ca-certificates curl jq unzip
# Install fontconfig if it is not already installed
if [ "${INSTALL_FONTCONFIG}" = "true" ]; then
check_packages fontconfig
fi
# Install Cascadia Code
if [ "${USERNAME}" = "root" ]; then
FONT_BASE_DIR="/usr/share/fonts"
else
FONT_BASE_DIR="/home/${USERNAME}/.local/share/fonts"
fi
if [ ! -d "${FONT_BASE_DIR}" ] || [ -z "$(find "${FONT_BASE_DIR}" -type d -name "cascadia-code" -print -quit)" ]; then
mkdir -p "${FONT_BASE_DIR}"
if [ "${USERNAME}" != "root" ]; then
chown "${USERNAME}":"${USERNAME}" "${FONT_BASE_DIR}"
chown "${USERNAME}":"${USERNAME}" "${FONT_BASE_DIR%/*}"
chown "${USERNAME}":"${USERNAME}" "${FONT_BASE_DIR%/*/*}"
fi
if [ "${FONT_VERSION}" = "latest" ]; then
FONT_VERSION=$(curl -fsSL "https://api.github.com/repos/microsoft/cascadia-code/releases/latest" | jq -r '.tag_name')
fi
FONT_URL="https://github.com/microsoft/cascadia-code/releases/download/${FONT_VERSION}/CascadiaCode-${FONT_VERSION#v}.zip"
curl -fsSL "${FONT_URL}" -o "/tmp/CascadiaCode-${FONT_VERSION}.zip"
unzip -q "/tmp/CascadiaCode-${FONT_VERSION}.zip" -d "/tmp/CascadiaCode-${FONT_VERSION}"
if [ "${FONT_VARIABLE_TTF}" = "true" ]; then
FONT_DIR="${FONT_BASE_DIR}/truetype/cascadia-code"
mkdir -p "${FONT_DIR}"
find "/tmp/CascadiaCode-${FONT_VERSION}/ttf/" -maxdepth 1 -name "*.ttf" -exec cp -fv {} "${FONT_DIR}" \;
chown -R "${USERNAME}":"${USERNAME}" "${FONT_DIR}"
chown "${USERNAME}":"${USERNAME}" "${FONT_DIR%/*}"
echo "Cascadia Code (Variable TTF) installed."
fi
if [ "${FONT_VARIABLE_WOFF2}" = "true" ]; then
FONT_DIR="${FONT_BASE_DIR}/woff2/cascadia-code"
mkdir -p "${FONT_DIR}"
find "/tmp/CascadiaCode-${FONT_VERSION}/woff2/" -maxdepth 1 -name "*.woff2" -exec cp -fv {} "${FONT_DIR}" \;
chown -R "${USERNAME}":"${USERNAME}" "${FONT_DIR}"
chown "${USERNAME}":"${USERNAME}" "${FONT_DIR%/*}"
echo "Cascadia Code (Variable WOFF2) installed."
fi
if [ "${FONT_STATIC_TTF}" = "true" ]; then
FONT_DIR="${FONT_BASE_DIR}/truetype/cascadia-code"
mkdir -p "${FONT_DIR}"
find "/tmp/CascadiaCode-${FONT_VERSION}/ttf/static/" -maxdepth 1 -name "*.ttf" -exec cp -fv {} "${FONT_DIR}" \;
chown -R "${USERNAME}":"${USERNAME}" "${FONT_DIR}"
chown "${USERNAME}":"${USERNAME}" "${FONT_DIR%/*}"
echo "Cascadia Code (Static TTF) installed."
fi
if [ "${FONT_STATIC_OTF}" = "true" ]; then
FONT_DIR="${FONT_BASE_DIR}/otf/cascadia-code"
mkdir -p "${FONT_DIR}"
find "/tmp/CascadiaCode-${FONT_VERSION}/otf/static/" -maxdepth 1 -name "*.otf" -exec cp -fv {} "${FONT_DIR}" \;
chown -R "${USERNAME}":"${USERNAME}" "${FONT_DIR}"
chown "${USERNAME}":"${USERNAME}" "${FONT_DIR%/*}"
echo "Cascadia Code (Static OTF) installed."
fi
if [ "${FONT_STATIC_WOFF2}" = "true" ]; then
FONT_DIR="${FONT_BASE_DIR}/woff2/cascadia-code"
mkdir -p "${FONT_DIR}"
find "/tmp/CascadiaCode-${FONT_VERSION}/woff2/static/" -maxdepth 1 -name "*.woff2" -exec cp -fv {} "${FONT_DIR}" \;
chown -R "${USERNAME}":"${USERNAME}" "${FONT_DIR}"
chown "${USERNAME}":"${USERNAME}" "${FONT_DIR%/*}"
echo "Cascadia Code (Static WOFF2) installed."
fi
# Cleanup
rm -rf "/tmp/CascadiaCode-${FONT_VERSION}.zip" "/tmp/CascadiaCode-${FONT_VERSION}"
# Update font cache
if command -v fc-cache >/dev/null 2>&1; then
if [ "${USERNAME}" = "root" ]; then
fc-cache -v "${FONT_BASE_DIR}"
else
su "${USERNAME}" -c "fc-cache -v ${FONT_BASE_DIR}"
fi
fi
else
echo "Cascadia Code is already installed."
fi
echo "Done!"