-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·259 lines (211 loc) · 5.58 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/bash
set -e
set -o pipefail
export DEBIAN_FRONTEND=noninteractive
C_RESET='\033[0m'
NVIDIA_RUN=NVIDIA-Linux-x86_64-390.77.run
get_user() {
if [ -z "${TARGET_USER-}" ]; then
mapfile -t options < <(find /home/* -maxdepth 0 -printf "%f\\n" -type d)
# if there is only one option just use that user
if [ "${#options[@]}" -eq "1" ]; then
readonly TARGET_USER="${options[0]}"
echo "Using user account: ${TARGET_USER}"
return
fi
# iterate through the user options and print them
PS3='Which user account should be used? '
select opt in "${options[@]}"; do
readonly TARGET_USER=$opt
break
done
fi
}
check_is_sudo() {
local C_RED='\033[0;31m'
if [ "$EUID" -ne 0 ]; then
echo -e "${C_RED}Please run as root.${C_RESET}"
exit
fi
}
setup_sudo() {
get_user
gpasswd -a "$TARGET_USER" sudo
gpasswd -a "$TARGET_USER" systemd-journal
gpasswd -a "$TARGET_USER" systemd-network
groupadd docker
gpasswd -a "$TARGET_USER" docker
{ \
echo -e "${TARGET_USER} ALL=(ALL) NOPASSWD:ALL"; \
echo -e "${TARGET_USER} ALL=NOPASSWD: /sbin/ifconfig, /sbin/ifup, /sbin/ifdown, /sbin/ifquery"; \
} >> /etc/sudoers
}
sources() {
sources_dep
cat <<-EOF > /etc/apt/sources.list
deb http://httpredir.debian.org/debian stretch main contrib non-free
deb-src http://httpredir.debian.org/debian/ stretch main contrib non-free
deb http://httpredir.debian.org/debian/ stretch-updates main contrib non-free
deb-src http://httpredir.debian.org/debian/ stretch-updates main contrib non-free
deb http://security.debian.org/ stretch/updates main contrib non-free
deb-src http://security.debian.org/ stretch/updates main contrib non-free
EOF
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list
echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list
echo "deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian stretch contrib" > /etc/apt/sources.list.d/virtualbox.list
curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
curl -sSL https://www.virtualbox.org/download/oracle_vbox_2016.asc | apt-key add -
curl -sSL https://www.virtualbox.org/download/oracle_vbox.asc | apt-key add -
curl -sSL https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
}
sources_dep() {
mkdir -p /etc/apt/apt.conf.d
echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/99translations
apt update || true
apt install -y \
apt-transport-https \
ca-certificates \
curl \
dirmngr \
QQvgnupg2 \
lsb-release \
linux-headers-amd64 \
--no-install-recommends
}
prepare_nvidia() {
dpkg --add-architecture i386
apt update || true
apt install -y \
build-essential \
gcc-multilib \
libstdc++6:i386 \
libgcc1:i386 \
libncurses5:i386 \
rpm \
zlib1g:i386 \
--no-install-recommends
mkdir -p nvidia
curl https://us.download.nvidia.com/XFree86/Linux-x86_64/390.77/"${NVIDIA_RUN}" -o nvidia/"${NVIDIA_RUN}"
chmod +x nvidia/"${NVIDIA_RUN}"
}
firmware() {
apt update || true
apt install -y \
firmware-iwlwifi \
firmware-realtek \
--no-install-recommends
modprobe -r iwlwifi
modprobe iwlwifi
}
install_golang() {
export GO_VERSION
GO_VERSION=$(curl -sSL "https://golang.org/VERSION?m=text")
export GO_SRC=/usr/local/go
if [[ -d "$GO_SRC" ]]; then
sudo rm -rf "$GO_SRC"
sudo rm -rf "$GOPATH"
fi
GO_VERSION=${GO_VERSION#go}
# subshell
(
kernel=$(uname -s | tr '[:upper:]' '[:lower:]')
curl -sSL "https://storage.googleapis.com/golang/go${GO_VERSION}.${kernel}-amd64.tar.gz" | tar -v -C /tmp -xz
sudo mv /tmp/go /usr/local
CGO_ENABLED=0 go install -a -installsuffix cgo std
)
}
install_debs() {
packages=( releases.hashicorp.com/vagrant/2.1.2/vagrant_2.1.2_x86_64.deb )
for package in "${packages[@]}"; do
owner=$(dirname "$package")
deb=$(basename "$package")
curl https://"${owner}"/"${deb}" -o /tmp/"${deb}"
dpkg -i /tmp/"${deb}"
done
}
install() {
apt update || true
apt -y upgrade
apt install -y \
alsa-utils \
apparmor \
bridge-utils \
code \
gcc \
google-chrome-stable \
htop \
make \
neovim \
tree \
tmux \
unzip \
virtualbox-5.2 \
zip \
zsh \
--no-install-recommends
apt autoremove
apt autoclean
apt clean
}
install_docker() {
curl https://get.docker.com -sSf | sh
}
install_vim() {
# create subshell
(
cd "$HOME"
# install .vim files
sudo rm -rf "${HOME}/.vim"
git clone --recursive https://github.com/bugbuilder/.vim.git "${HOME}/.vim"
(
cd "${HOME}/.vim"
make install
)
# install things needed for deoplete for vim
sudo apt update || true
sudo apt install -y \
python3-pip \
python3-setuptools \
--no-install-recommends
pip3 install -U \
setuptools \
wheel \
neovim
)
}
install_docker_toolkit() {
binaries=( machine/releases/download/v0.15.0/docker-machine-Linux-x86_64 compose/releases/download/1.22.0/docker-compose-Linux-x86_64 )
for binary in "${binaries[@]}"; do
version=$(dirname "$binary")
bin=$(basename "$binary")
curl -L https://github.com/docker/"${version}"/"${bin}" > /tmp/"${bin}"
chmod +x /tmp/"${bin}"
cp /tmp/"${bin}" /usr/local/bin/"${bin/-Linux-x86_64/}"
done
}
reminder() {
local C_GREEN='\033[0;32m'
echo -e "${C_GREEN}"
echo -e "Don't forget:"
echo -e " nvidia - run the installer nvidia/${NVIDIA_RUN}"
echo -e "${C_RESET}"
}
git_settings() {
cp .gitconfig /home/"${TARGET_USER}"
cp .gitignore_global /home/"${TARGET_USER}"
}
main() {
check_is_sudo
setup_sudo
sources
firmware
install
install_docker
install_docker_toolkit
install_debs
prepare_nvidia
install_golang
git_settings
reminder
}
main "$@"