-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsetup
More file actions
executable file
·324 lines (286 loc) · 9.66 KB
/
Copy pathsetup
File metadata and controls
executable file
·324 lines (286 loc) · 9.66 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/usr/bin/env sh
# init
# Author: Lucas Larson
#
# Description: bootstrap a new machine
# Assumptions: installation target is one of Arch Linux or Alpine Linux
# Alpine Linux
# wget -O- https://lucaslarson.net/setup | sh
# Arch Linux
# curl https://lucaslarson.net/setup | sh
if command -v -- apk >/dev/null 2>&1; then
alias install='command apk add --verbose'
elif command -v -- pacman >/dev/null 2>&1; then
alias install='command pacman --sync --verbose --noconfirm'
elif command -v -- apt-get >/dev/null 2>&1; then
alias install='command apt-get install --show-progress --assume-yes'
fi
printf -- '\n\n .\137\137 .\137\137 \137\137\n' >&2
printf -- ' \174\137\137\174 \137\137\137\137 \174\137\137\174\057 \174\137\n' >&2
printf -- ' \174 \174\057 \134\174 \134 \137\137\134\n' >&2
printf -- ' \174 \174 \174 \134 \174\174 \174\n' >&2
printf -- ' \174\137\137\174\137\137\137\174' >&2
printf -- ' \057\137\137\174\174\137\137\174\n' >&2
printf -- ' \134\057\n\n' >&2
printf -- ' Linux setup\n' >&2
sleep 1
printf -- ' a Lucas Larson production\n\n' >&2
sleep 1
# save `date` for backup files
now="$(date -- '+%Y%m%d%H%M%S')"
# unset `$PS4`
# if this quaternary prompt string is already unset, then
# set it to the POSIX default: `+ `
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
ps4_temporary="${PS4:-+ }"
unset PS4 >/dev/null 2>&1 || PS4=''
set -o xtrace
# pacman
# https://askubuntu.com/a/459425
command -v -- pacman >/dev/null 2>&1 && {
install --refresh --refresh ||
# https://wiki.archlinux.org/?oldid=667441#Installing_packages
install --refresh --sysupgrade 2>/dev/null
}
# apk
command -v -- apk >/dev/null 2>&1 || {
# trust apk only if it matches a known checksum
{ set +o xtrace; } 2>/dev/null
printf -- 'verifying apk tools integrity...\n' >&2
set -o xtrace
# https://web.archive.org/web/20201127045648id_/github.com/ish-app/ish/wiki/Installing-apk-on-the-App-Store-Version#wiki-body
wget --output-document=- -- 'https://dl-cdn.alpinelinux.org/alpine/v3.16/main/'"$(uname -m)"'/apk-tools-static-2.12.9-r3.apk' |
tar --extract --gzip --strip-components=1 --verbose -- sbin/apk.static &&
./apk.static add apk-tools &&
rm -- ./apk.static
# configure only main and community repositories at first
{ test -d '/etc' || mkdir -- '/etc'; } &&
{ test -d '/etc/apk' || mkdir -- '/etc/apk'; } && {
printf -- 'https://dl-cdn.alpinelinux.org/alpine/latest-stable/main\n'
printf -- 'https://dl-cdn.alpinelinux.org/alpine/latest-stable/community\n'
} >'/etc/apk/repositories'
# update
{ set +o xtrace; } 2>/dev/null
printf -- 'updating Alpine Linux repositories...\n' >&2
set -o xtrace
apk update --progress --verbose
apk upgrade --progress --verbose
}
# https://wiki.alpinelinux.org/w/index.php?oldid=17773&title=How_to_get_regular_stuff_working#Man_pages
# man-pages adds `man0`, `man2`, man4`, `man6` to `/usr/share/man/`
{ test -d '/usr/share/man/man0' &&
test -d '/usr/share/man/man2' &&
test -d '/usr/share/man/man4' &&
test -d '/usr/share/man/man6'; } || {
{ set +o xtrace; } 2>/dev/null
printf -- 'installing man pages...\n' >&2
set -o xtrace
install man-pages
}
command -v -- mandoc >/dev/null 2>&1 || {
{ set +o xtrace; } 2>/dev/null
printf -- 'installing mandoc for man pages...\n' >&2
set -o xtrace
install mandoc
}
command -v -- less >/dev/null 2>&1 || {
{ set +o xtrace; } 2>/dev/null
printf -- 'installing less to read man pages...\n' >&2
set -o xtrace
install less
}
# https://wiki.alpinelinux.org/w/index.php?oldid=17773&title=How_to_get_regular_stuff_working#Shell_.40_commandline
# https://web.archive.org/web/20210218201739id_/web.archive.org/screenshot/docs.google.com/document/d/10-8wjANQGbG43XZ0wN57M1RYOLUwu9RZATNe9vJQYKw/mobilebasic
# https://wiki.alpinelinux.org/w/index.php?oldid=18038&title=Alpine_newbie_apk_packages#coreutils_libc_and_utmps_in_alpine
install coreutils
{ command -v -- coreutils >/dev/null 2>&1 &&
find -- . --version 2>/dev/null | grep -e 'findutils' >/dev/null 2>&1; } || {
{ set +o xtrace; } 2>/dev/null
printf -- 'installing Linux utilities...\n' >&2
set -o xtrace
}
install util-linux pciutils usbutils coreutils binutils findutils grep wget curl openssl sudo sed attr dialog readline
# add additional Alpine Linux repositories if applicable
command -v -- apk >/dev/null 2>&1 &&
test -s '/etc/apk/repositories' && {
{
printf -- 'https://dl-cdn.alpinelinux.org/alpine/edge/main\n'
printf -- 'https://dl-cdn.alpinelinux.org/alpine/edge/community\n'
printf -- 'https://dl-cdn.alpinelinux.org/alpine/edge/testing\n'
} >>'/etc/apk/repositories' &&
apk update
}
# ssh
# https://wiki.alpinelinux.org/w/index.php?oldid=13842&title=Setting_up_a_ssh-server#OpenSSH
test -d '/etc/ssh' || {
{ set +o xtrace; } 2>/dev/null
printf -- 'installing OpenSSH...\n' >&2
set -o xtrace
install openssh
}
# gpg
# https://wiki.alpinelinux.org/w/index.php?oldid=17295&title=Setting_up_a_laptop#Creating_GPG_keys
command -v -- gpg2 >/dev/null 2>&1 || {
{ set +o xtrace; } 2>/dev/null
printf -- 'installing GPG...\n' >&2
set -o xtrace
install gnupg
}
# git
command -v -- git >/dev/null 2>&1 || {
{ set +o xtrace; } 2>/dev/null
printf -- 'installing Git...\n' >&2
set -o xtrace
install git
}
# git user
git config --global --get -- user.name >/dev/null 2>&1 || {
git config --global -- user.name 'Lucas Larson'
}
# git default branch
git config --global --get -- init.defaultBranch >/dev/null 2>&1 || {
git config --global -- init.defaultBranch 'main'
}
# time zone
{ set +o xtrace; } 2>/dev/null
printf -- 'updating time zone information...\n' >&2
set -o xtrace
install --no-cache tzdata ||
install tzdata
# python
{ set +o xtrace; } 2>/dev/null
printf -- 'checking Python installation...\n' >&2
set -o xtrace
command -v -- python >/dev/null 2>&1 || {
{ set +o xtrace; } 2>/dev/null
printf -- 'installing Python...\n' >&2
set -o xtrace
install python3
}
# zsh
command -v -- zsh >/dev/null 2>&1 || {
{ set +o xtrace; } 2>/dev/null
printf -- 'installing Zsh...\n' >&2
set -o xtrace
install zsh
{ set +o xtrace; } 2>/dev/null
}
# chsh
# part of shadow on Alpine Linux
command -v -- chsh >/dev/null 2>&1 || {
install shadow
}
# update, repair everything again before close
command -v -- apk >/dev/null 2>&1 && {
{ set +o xtrace; } 2>/dev/null
printf -- 'updating...\n' >&2
set -o xtrace
apk update --progress --verbose --verbose
{ set +o xtrace; } 2>/dev/null
printf -- 'upgrading...\n' >&2
set -o xtrace
apk upgrade --progress --verbose
{ set +o xtrace; } 2>/dev/null
printf -- 'repairing and resolving dependencies...\n' >&2
set -o xtrace
apk fix --depends --progress --verbose --verbose
{ set +o xtrace; } 2>/dev/null
printf -- 'verifying installations...\n' >&2
set -o xtrace
apk verify --progress --verbose --verbose && {
{ set +o xtrace; } 2>/dev/null
printf -- 'verified\n' >&2
set -o xtrace
}
}
# cleanup
{ set +o xtrace; } 2>/dev/null
printf -- 'cleaning up temporary installation files and performing housekeeping...\n' >&2
set -o xtrace
# message of the day
test -w '/etc/motd' &&
test -s '/etc/motd' &&
cp -- '/etc/motd' '/etc/motd-'"${now-}" &&
touch '/etc/motd'
# delete thumbnail cache files
find -- . \
'(' \
-name '.DS_Store' -o \
-name 'Desktop.ini' -o \
-name 'Thumbs.db' -o \
-name 'desktop.ini' -o \
-name 'thumbs.db' \
')' \
-delete 2>/dev/null
# delete empty files
# except those within `.git/` directories
# and those with specific names
find -- . \
-size 0 \
! -path "${DOTFILES:-${HOME%/}/Library/CloudStorage/Dropbox/dotfiles}"'/Library/*' \
! -path "${HOME%/}"'/Library/*' \
! -path '*/.git/*' \
! -path '*/Test*' \
! -path '*/test*' \
! -path '*/.well-known/*' \
! -name "$(printf -- 'Icon\015\012')" \
! -name '*LOCK' \
! -name '*empty*' \
! -name '*hushlogin' \
! -name '*ignore' \
! -name '*journal' \
! -name '*lock' \
! -name '*lockfile' \
! -name '.dirstamp' \
! -name '.gitkeep' \
! -name '.gitmodules' \
! -name '.keep' \
! -name '.sudo_as_admin_successful' \
! -name '.watchmanconfig' \
! -name '__init__.py' \
! -name 'favicon.*' \
-delete 2>/dev/null
# delete empty directories recursively
# but skip Git-specific and `/.well-known/` directories
find -- . \
-type d \
-links 2 \
-path '*/.git' -prune -o \
-path '*/.well-known' -prune -o \
-delete 2>/dev/null
# if the shell can be changed and
# if zsh is available, then replace bash, ash, and sh with zsh in `/etc/passwd`
test -w '/etc/passwd' &&
command -v -- zsh >/dev/null 2>&1 &&
grep -E -e '/bin/b?a?sh' '/etc/passwd' >/dev/null 2>&1 &&
cp -- '/etc/passwd' '/etc/passwd-'"${now-}" &&
sed -e 's|/bin/b\{0,1\}a\{0,1\}sh$|'"$(command -v -- zsh)"'|' '/etc/passwd-'"${now-}" >'/etc/passwd'
# install dotfiles
{ set +o xtrace; } 2>/dev/null
printf -- 'ensuring there is local access to dotfiles...\n'
set -o xtrace
git -C "${DOTFILES:-${HOME%/}/Maestral/dotfiles}" rev-parse --is-inside-work-tree >/dev/null 2>&1 || {
{ test -d "${DOTFILES:-${HOME%/}/Maestral}" || mkdir -- "${DOTFILES:-${HOME%/}/Maestral}"; } &&
{ test -d "${DOTFILES:-${HOME%/}/Maestral/dotfiles}" || mkdir -- "${DOTFILES:-${HOME%/}/Maestral/dotfiles}"; } &&
git -c core.ignoreCase=false clone \
--branch dev \
--progress \
--recursive \
--template='' \
-- \
https://github.com/LucasLarson/dotfiles \
"${DOTFILES:-${HOME%/}/Maestral/dotfiles}"
}
# done
{ set +o xtrace; } 2>/dev/null
printf -- 'installation complete\n' >&2
sleep 1
printf -- 'exiting to apply updates...\n' >&2
# restore `$PS4`
PS4="${ps4_temporary:-+ }"
unset ps4_temporary >/dev/null 2>&1 || ps4_temporary=''
{
printf -- '\n'
printf -- 'done!\n'
} >&2
exit