-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathubuntu
More file actions
executable file
·265 lines (234 loc) · 5.25 KB
/
ubuntu
File metadata and controls
executable file
·265 lines (234 loc) · 5.25 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
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
260
261
262
263
264
265
#!/usr/bin/env bash
set -e
set -o pipefail
export DEBIAN_FRONTEND=noninteractive
usage() {
echo "
usage: ubuntu.sh <command> [<args>]
base install base required packages
dotfiles gets dotfiles
asdf install asdf version manager
pipx install pipx - for running python apps in virtual environments
fzf install fzf - fuzzy file finder
zsh-default switch default shell to zsh"
}
# Choose a user account to use for this installation
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='command -v user account should be used? '
select opt in "${options[@]}"; do
readonly TARGET_USER=$opt
break
done
fi
}
check_is_sudo() {
if [ "$EUID" -ne 0 ]; then
echo "Please run as root."
exit
fi
}
app_exists() {
local app="$1"
if (! type "$app" >/dev/null 2>&1); then
# App doesn't exist
return 1
else
# App exists
return 0
fi
}
install_if_missing() {
local app="$1"
if app_exists "$app"; then
echo "$app already installed"
else
echo "$app not installed; installing now!"
install_"$app"
fi
}
setup_sources() {
if [ ! $DISTRIB_CODENAME = 'focal' ]; then
# Older versions of ubuntu need the rcm repository added
add-apt-repository --yes \
ppa:martin-frost/thoughtbot-rcm
fi
}
install_fzf() {
if ! [[ -d "$HOME/.fzf" ]]; then
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
# Install fzf using the fzf install script with the following arguments:
# - key-bindings - enable key bindings (ctrl-t, ctrl-r, alt-c)
# - completion - Enable fuzzy completion
# - no-update-rc - don't update the shell configuration files (it's already updated in this
# dotfiles configuration
# - no-bash - since these dotfiles expect zsh
# - no-fish - since these dotfiles expect zsh
~/.fzf/install --key-bindings --completion --no-update-rc --no-bash --no-fish
else
echo "fzf already instealled; skipping"
fi
}
base_min() {
apt update || true
apt -y upgrade
apt install -y \
apt-transport-https \
autoconf \
automake \
bison \
bc \
build-essential \
bzip2 \
ca-certificates \
caca-utils \
calibre \
coreutils \
curl \
dirmngr \
djvulibre-bin \
dnsutils \
ffmpegthumbnailer \
file \
findutils \
fontforge \
gcc \
git \
gnupg \
gnupg2 \
gpg \
grep \
gzip \
highlight \
hostname \
imagemagick-6.q16 \
indent \
iptables \
jq \
less \
libc6-dev \
libevent-dev \
libffi-dev \
libimage-exiftool-perl \
libncurses5-dev \
libreadline-dev \
libssl-dev \
libtool \
libyaml-dev \
libxslt-dev \
locales \
lsof \
make \
mount \
net-tools \
odt2txt \
p7zip-full \
pkg-config \
poppler-utils \
python-chardet \
python3-pip \
python3-venv \
ranger \
rcm \
silversearcher-ag \
ssh \
strace \
sudo \
tar \
transmission-cli \
tree \
tzdata \
unixodbc-dev \
unzip \
w3m \
xclip \
xz-utils \
zip \
zsh \
--no-install-recommends
apt autoremove -y
apt autoclean
apt clean
# Upgrade setuptools
# Setuptools is a tool to download, build, install, upgrade, and uninstall Python packages
sudo -H -u "$TARGET_USER" pip3 install --user --upgrade setuptools
}
base() {
base_min
}
install_asdf() {
git clone https://github.com/asdf-vm/asdf.git ~/.asdf
(
cd ~/.asdf
git checkout "$(git describe --abbrev=0 --tags)"
)
}
install_pipx() {
python3 -m pip install --user pipx
python3 -m pipx ensurepath
}
set_default_shell() {
chsh -s $(which zsh)
echo 'Log out and log back in for the shell change to take effect.'
}
get_dotfiles() {
# create subshell
(
cd "$HOME"
if [[ ! -d "${HOME}/.dotfiles" ]]; then
# install dotfiles from repo
# use https in case an ssh key hasn't been setup yet
echo "Cloning dotfiles into \$HOME/.dotfiles"
git clone https://github.com/ncronquist/dotfiles.git "${HOME}/.dotfiles"
fi
cd "${HOME}/.dotfiles"
# switch the remote to ssh andk we'll assume an ssh key will be
# setup before trying to push any changes
git remote set-url origin git@github.com:ncronquist/dotfiles.git
echo -e 'Dotfiles are now available at $HOME/.dotfiles.'
echo -e 'Move to that directory and run "./install/ubuntu" to install the required dependencies.'
echo -e '\n\n cd $HOME/.dotfiles\n ./install/ubuntu\n'
)
}
main() {
local command="$1"
case $command in
"" | "-h" | "--help")
usage
;;
"base")
. /etc/lsb-release
check_is_sudo
get_user
setup_sources
base
;;
"dotfiles")
get_dotfiles
;;
"asdf")
install_asdf
;;
"pipx")
install_pipx
;;
"fzf")
install_fzf
;;
"zsh-default")
set_default_shell
;;
*)
usage
;;
esac
}
main "$@"