-
Notifications
You must be signed in to change notification settings - Fork 13
/
vscode.sh
executable file
·154 lines (136 loc) · 4.4 KB
/
vscode.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
#!@BASH@
# shellcheck shell=bash
set -e
shopt -s nullglob
FIRST_RUN="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-first-run"
SDK_UPDATE="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-sdk-update-@SDK_VERSION@"
FLATPAK_IDE_LOGLEVEL="${FLATPAK_IDE_LOGLEVEL:-@DEFAULT_LOGLEVEL@}"
function msg() {
if [ "${FLATPAK_IDE_LOGLEVEL}" -ne 0 ]; then
echo "@PROGRAM_NAME@-wrapper: $*" >&2
fi
}
function exec_vscode() {
exec "@EDITOR_BINARY@" @EDITOR_ARGS@ "$@"
}
if [ -n "${FLATPAK_IDE_ENV}" ]; then
msg "Environment is already set up"
exec_vscode "$@"
fi
declare -A PATH_SUBDIRS
PATH_SUBDIRS[PATH]="bin"
PATH_SUBDIRS[PYTHONPATH]="lib/python@PYTHON_VERSION@/site-packages"
PATH_SUBDIRS[PKG_CONFIG_PATH]="lib/pkgconfig"
PATH_SUBDIRS[GI_TYPELIB_PATH]="lib/girepository-1.0"
function export_path_vars() {
base_dir="$1"
for var_name in "${!PATH_SUBDIRS[@]}"; do
abs_dir="$base_dir/${PATH_SUBDIRS[$var_name]}"
if [ -d "$abs_dir" ]; then
msg "Adding $abs_dir to $var_name"
if [ -z "${!var_name}" ]; then
export "$var_name"="$abs_dir"
else
export "$var_name"="${!var_name}:$abs_dir"
fi
fi
done
}
for tool_dir in /app/tools/*; do
export_path_vars "$tool_dir"
done
if [ "$FLATPAK_ENABLE_SDK_EXT" = "*" ]; then
SDK=()
for d in /usr/lib/sdk/*; do
SDK+=("${d##*/}")
done
else
IFS=',' read -ra SDK <<< "$FLATPAK_ENABLE_SDK_EXT"
fi
for i in "${SDK[@]}"; do
sdk_ext_dir="/usr/lib/sdk/$i"
if [[ -d "$sdk_ext_dir" ]]; then
if [[ -z "$FLATPAK_SDK_EXT_NO_SCRIPTS" && \
-f "$sdk_ext_dir/enable.sh" ]]; then
msg "Evaluating $sdk_ext_dir/enable.sh"
# shellcheck source=/dev/null
. "$sdk_ext_dir/enable.sh"
else
export_path_vars "$sdk_ext_dir"
fi
else
msg "Requested SDK extension \"$i\" is not installed"
fi
done
# Create /etc/shells and add shells from extensions
if [ ! -f /etc/shells ]; then
printf '/usr/bin/%s\n' sh bash > /etc/shells
for ext_etc_shells in /app/tools/*/etc/shells; do
cat >> /etc/shells < "$ext_etc_shells"
done
fi
FLATPAK_PREFER_USER_PACKAGES="${FLATPAK_PREFER_USER_PACKAGES:-0}"
FLATPAK_ISOLATE_PACKAGES="${FLATPAK_ISOLATE_PACKAGES:-1}"
FLATPAK_ISOLATE_NPM="${FLATPAK_ISOLATE_NPM:-${FLATPAK_ISOLATE_PACKAGES}}"
FLATPAK_PREFER_USER_NPM="${FLATPAK_PREFER_USER_NPM:-${FLATPAK_PREFER_USER_PACKAGES}}"
FLATPAK_ISOLATE_CARGO="${FLATPAK_ISOLATE_CARGO:-${FLATPAK_ISOLATE_PACKAGES}}"
FLATPAK_PREFER_USER_CARGO="${FLATPAK_PREFER_USER_CARGO:-${FLATPAK_PREFER_USER_PACKAGES}}"
FLATPAK_ISOLATE_PIP="${FLATPAK_ISOLATE_PIP:-${FLATPAK_ISOLATE_PACKAGES}}"
FLATPAK_PREFER_USER_PIP="${FLATPAK_PREFER_USER_PIP:-${FLATPAK_PREFER_USER_PACKAGES}}"
FLATPAK_ISOLATE_GEM="${FLATPAK_ISOLATE_GEM:-${FLATPAK_ISOLATE_PACKAGES}}"
FLATPAK_PREFER_USER_GEM="${FLATPAK_PREFER_USER_GEM:-${FLATPAK_PREFER_USER_PACKAGES}}"
if [ "${FLATPAK_ISOLATE_NPM}" -ne 0 ]; then
msg "Setting up NPM packages"
export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME/npmrc"
if [ ! -f "$NPM_CONFIG_USERCONFIG" ]; then
cat <<EOF_NPM_CONFIG > "$NPM_CONFIG_USERCONFIG"
prefix=\${XDG_DATA_HOME}/node
init-module=\${XDG_CONFIG_HOME}/npm-init.js
tmp=\${XDG_CACHE_HOME}/tmp
EOF_NPM_CONFIG
fi
if [ "$FLATPAK_PREFER_USER_NPM" -ne 0 ]; then
export PATH="$XDG_DATA_HOME/node/bin:$PATH"
else
export PATH="$PATH:$XDG_DATA_HOME/node/bin"
fi
fi
if [ "${FLATPAK_ISOLATE_CARGO}" -ne 0 ] ; then
msg "Setting up Cargo packages"
export CARGO_INSTALL_ROOT="$XDG_DATA_HOME/cargo"
export CARGO_HOME="$CARGO_INSTALL_ROOT"
if [ "$FLATPAK_PREFER_USER_CARGO" -ne 0 ]; then
export PATH="$CARGO_INSTALL_ROOT/bin:$PATH"
else
export PATH="$PATH:$CARGO_INSTALL_ROOT/bin"
fi
fi
if [ "${FLATPAK_ISOLATE_PIP}" -ne 0 ]; then
msg "Setting up Python packages"
export PYTHONUSERBASE="$XDG_DATA_HOME/python"
if [ "$FLATPAK_PREFER_USER_PIP" -ne 0 ]; then
export PATH="$PYTHONUSERBASE/bin:$PATH"
else
export PATH="$PATH:$PYTHONUSERBASE/bin"
fi
fi
if [ "${FLATPAK_ISOLATE_GEM}" -ne 0 ]; then
msg "Setting up Ruby packages"
GEM_USER_INSTALL="$(ruby <<<'puts Gem.user_dir')"
if [ "$FLATPAK_PREFER_USER_GEM" -ne 0 ]; then
export PATH="$GEM_USER_INSTALL/bin:$PATH"
else
export PATH="$PATH:$GEM_USER_INSTALL/bin"
fi
fi
export FLATPAK_IDE_ENV=1
if [ ! -f "${FIRST_RUN}" ]; then
touch "${FIRST_RUN}"
touch "${SDK_UPDATE}"
exec_vscode "$@" "@FIRST_RUN_README@"
elif [ ! -f "${SDK_UPDATE}" ]; then
touch "${SDK_UPDATE}"
exec_vscode "$@" "@SDK_UPDATE_README@"
else
exec_vscode "$@"
fi