-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathinstall.sh
More file actions
143 lines (121 loc) · 4.31 KB
/
install.sh
File metadata and controls
143 lines (121 loc) · 4.31 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
#!/usr/bin/env bash
FISHER=${FISHER:-"true"}
FISHER_PLUGINS=${FISHER_PLUGINS:-""}
USERNAME=${USERNAME:-"automatic"}
source /etc/os-release
cleanup() {
case "${ID}" in
debian|ubuntu)
rm -rf /var/lib/apt/lists/*
;;
esac
}
# Clean up
cleanup
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
# 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() {
case "${ID}" in
debian|ubuntu)
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update -y
fi
;;
esac
}
# Checks if packages are installed and installs them if not
check_packages() {
case "${ID}" in
debian|ubuntu)
if ! dpkg -s "$@" >/dev/null 2>&1; then
apt_get_update
apt-get -y install --no-install-recommends "$@"
fi
;;
alpine)
if ! apk -e info "$@" >/dev/null 2>&1; then
apk add --no-cache "$@"
fi
;;
esac
}
export DEBIAN_FRONTEND=noninteractive
# Install dependencies if missing
check_packages curl ca-certificates
if ! type git > /dev/null 2>&1; then
check_packages git
fi
# Install fish shell
echo "Installing fish shell..."
case "${ID}" in
debian|ubuntu)
if [ "${ID}" = "ubuntu" ]; then
echo "deb https://ppa.launchpadcontent.net/fish-shell/release-3/ubuntu ${UBUNTU_CODENAME} main" > /etc/apt/sources.list.d/shells:fish:release:3.list
curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x59fda1ce1b84b3fad89366c027557f056dc33ca5" | tee -a /etc/apt/trusted.gpg.d/shells_fish_release_3.asc > /dev/null
elif [ "${ID}" = "debian" ]; then
if [ "${VERSION_ID}" = "9" ]; then
echo 'deb http://download.opensuse.org/repositories/shells:/fish:/release:/3/Debian_9.0/ /' | tee /etc/apt/sources.list.d/shells:fish:release:3.list
curl -fsSL "https://download.opensuse.org/repositories/shells:fish:release:3/Debian_9.0/Release.key" | tee /etc/apt/trusted.gpg.d/shells_fish_release_3.asc > /dev/null
else
echo "deb http://download.opensuse.org/repositories/shells:/fish:/release:/3/Debian_${VERSION_ID}/ /" | tee /etc/apt/sources.list.d/shells:fish:release:3.list
curl -fsSL "https://download.opensuse.org/repositories/shells:fish:release:3/Debian_${VERSION_ID}/Release.key" | tee /etc/apt/trusted.gpg.d/shells_fish_release_3.asc > /dev/null
fi
fi
apt-get update -y
apt-get -y install --no-install-recommends fish
;;
alpine)
apk add --no-cache fish
;;
esac
fish -v
# Install Fisher
if [ "${FISHER}" = "true" ]; then
echo "Installing Fisher..."
fish -c 'curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher'
if [ "${USERNAME}" != "root" ]; then
su $USERNAME -c 'fish -c "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher"'
fi
fish -c "fisher -v"
fi
# Install Fisher plugins
if [ -n "${FISHER_PLUGINS}" ]; then
echo "Installing Fisher plugins…"
for plugin in "${FISHER_PLUGINS[@]}"; do
printf "\tInstalling plugin: ${plugin}"
fish -c "fisher install ${FISHER_PLUGINS}"
done
if [ "${USERNAME}" != "root" ]; then
for plugin in "${FISHER_PLUGINS[@]}"; do
printf "\tInstalling plugin: ${plugin}"
su $USERNAME -c "fish -c 'fisher install ${FISHER_PLUGINS}'"
done
fi
fish -c 'fisher list; cat $__fish_config_dir/fish_plugins'
fi
# Clean up
cleanup
echo "Done!"