-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_system
executable file
·299 lines (242 loc) · 9.37 KB
/
setup_system
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
#!/usr/bin/env bash
# shellcheck disable=SC2064
set -euxo pipefail
if [[ "$OSTYPE" =~ ^darwin ]];
then
REPO_DIR=/opt/repos
else
REPO_DIR=/repos
fi
export REPO_DIR
readlinkf() { perl -MCwd -e 'print Cwd::abs_path shift' "$1";}
if [[ $(id -u) -ne 0 ]] ; then echo "Please run as root" ; exit 1 ; fi
PROJECT_DIR=${1-$(readlinkf /p)}
SECRETS_REPO=${2-}
SHARED_REPO=$REPO_DIR/linux-shared
if [[ "$OSTYPE" =~ ^darwin ]];
then
dscl . create /Groups/linux-shared
dscl . create /Groups/linux-shared PrimaryGroupID 999
# Allow sudo auth via TouchID
sed -i 's/pam_smartcard.so/pam_smartcard.so\nauth sufficient pam_tid.so/' /etc/pam.d/sudo
grep -v -E "($REPO_DIR|$PROJECT_DIR)" /etc/synthetic.conf >/etc/synthetic_new.conf || true
# shellcheck disable=SC2129
echo -e "repos\t$REPO_DIR" >>/etc/synthetic_new.conf
echo -e "r\t$SHARED_REPO" >>/etc/synthetic_new.conf
echo -e "p\t$PROJECT_DIR" >>/etc/synthetic_new.conf
if diff /etc/synthetic.conf /etc/synthetic_new.conf
then
rm /etc/synthetic_new.conf
else
chmod 644 /etc/synthetic_new.conf
mv /etc/synthetic_new.conf /etc/synthetic.conf
echo "Please reboot so synthetic.conf takes effect and rerun the install with the same arguments"
exit 0
fi
else
groupadd linux-shared || true
rm /r || true
ln -s "$SHARED_REPO" /r
rm /p || true
ln -s "$PROJECT_DIR" /p
fi
old_umask=$(umask)
umask 007
mkdir -p "$REPO_DIR"
chgrp linux-shared "$REPO_DIR"
chmod gu+rwx "$REPO_DIR"
if [ ! -d "$SHARED_REPO" ]
then
git clone "git@github.com:${GITHUB_USER-mrichtarsky}/linux-shared.git" "$SHARED_REPO"
else
cd "$SHARED_REPO"
git pull
fi
source /r/lib/bash/tools.sh
source /r/setup/settings.sh
if [ "$SECRETS_REPO" != "" ] && [ ! -d "$REPO_DIR/secrets" ]
then
git clone "$SECRETS_REPO" "$REPO_DIR/secrets"
fi
umask "$old_umask"
pushdt /r
git config --local core.sharedrepository true
git submodule init
git submodule update
/r/setup/fix_perms "$REPO_DIR"
mkdir -p "$PROJECT_DIR"
chmod 755 "$PROJECT_DIR"
rm -rf "$TOOLS_PATH"
mkdir -p "$TOOLS_PATH" # /p/tools, from settings.sh
chgrp linux-shared "$TOOLS_PATH"
chmod u=rwx,g=rxs "$TOOLS_PATH"
/r/build/git
function _download_install() {
CMD="$1"
X86_64="$2"
AARCH64="$3"
tmpdir=$(mktemp -d)
trap "rm -rf $tmpdir" RETURN
cd "$tmpdir"
case $(uname -m) in
x86_64) url="$X86_64" ;;
aarch64) url="$AARCH64" ;;
esac
wget -O ar.tar.gz "$url"
tar xf ar.tar.gz
mv "$CMD" /usr/local/bin
}
if [[ ! "$OSTYPE" =~ ^darwin ]];
then
PACKAGES=(
dos2unix expect gcc htop make mc nano ncdu python3 python3-pip ripgrep rlwrap
sysstat tmux tree xsel zsh yank)
DISTRO=$(awk '/^ID=/' /etc/*-release | awk -F'=' '{ print tolower($2) }')
echo "Distribution: $DISTRO"
if [ "$DISTRO" == '"sles"' ];
then
zypper ar -f http://download.opensuse.org/distribution/leap/15.1/repo/oss/ opensuse || true
zypper --non-interactive remove python3-pylint python3-wrapt || true # Installed by pip
zypper --gpg-auto-import-keys --non-interactive install "${PACKAGES[@]}" \
libcurl-devel libopenssl-devel moreutils moreutils-parallel progress \
python3-devel ShellCheck
_download_install duf \
https://github.com/muesli/duf/releases/download/v0.8.1/duf_0.8.1_linux_x86_64.tar.gz \
https://github.com/muesli/duf/releases/download/v0.8.1/duf_0.8.1_linux_arm64.tar.gz
elif [ "$DISTRO" == '"rhel"' ];
then
yum install --assumeyes "${PACKAGES[@]}" libcurl-devel ShellCheck
_download_install duf \
https://github.com/muesli/duf/releases/download/v0.8.1/duf_0.8.1_linux_x86_64.tar.gz \
https://github.com/muesli/duf/releases/download/v0.8.1/duf_0.8.1_linux_arm64.tar.gz
else
apt install --yes "${PACKAGES[@]}" duf fswatch libcurl4-openssl-dev libssl-dev \
mailutils moreutils parallel progress python3-dev python-is-python3 \
shellcheck ugrep
apt remove --yes apport apport-symptoms python3-apport watchman
fi
# VSCode watches
add_if_not_present /etc/sysctl.conf fs.inotify.max_user_watches=524288
add_if_not_present /etc/sysctl.conf fs.inotify.max_user_instances=10000
add_if_not_present /etc/sysctl.conf fs.inotify.max_queued_events=200000
add_if_not_present /etc/sysctl.conf fs.file-max=5000000
sysctl -p
add_if_not_present /etc/pam.d/login 'session required pam_limits.so'
# libtree
tmp_libtree=$(mktemp -d)
trap "rm -rf $tmp_libtree" EXIT
cd "$tmp_libtree"
git clone https://github.com/haampie/libtree.git
cd libtree
make
make install
# gron
_download_install gron \
https://github.com/tomnomnom/gron/releases/download/v0.7.1/gron-linux-amd64-0.7.1.tgz \
https://github.com/tomnomnom/gron/releases/download/v0.7.1/gron-linux-arm64-0.7.1.tgz
# btop
tmp_btop=$(mktemp -d)
trap "rm -rf $tmp_btop" EXIT
cd "$tmp_btop"
case $(uname -m) in
x86_64) url=https://github.com/aristocratos/btop/releases/download/v1.2.13/btop-x86_64-linux-musl.tbz ;;
aarch64) url=https://github.com/aristocratos/btop/releases/download/v1.2.13/btop-aarch64-linux-musl.tbz ;;
esac
wget -O btop.tbz "$url"
tar xf btop.tbz
cd btop
./install.sh /usr/local
# viddy / watch
_download_install viddy \
https://github.com/sachaos/viddy/releases/download/v0.3.6/viddy_0.3.6_Linux_x86_64.tar.gz \
https://github.com/sachaos/viddy/releases/download/v0.3.6/viddy_0.3.6_Linux_arm64.tar.gz
# lazydocker
_download_install lazydocker \
https://github.com/jesseduffield/lazydocker/releases/download/v0.20.0/lazydocker_0.20.0_Linux_x86_64.tar.gz \
https://github.com/jesseduffield/lazydocker/releases/download/v0.20.0/lazydocker_0.20.0_Linux_arm64.tar.gz
# bottom
_download_install btm \
https://github.com/ClementTsang/bottom/releases/download/0.8.0/bottom_x86_64-unknown-linux-gnu.tar.gz \
https://github.com/ClementTsang/bottom/releases/download/0.8.0/bottom_aarch64-unknown-linux-gnu.tar.gz
# broot
tmp_broot=$(mktemp -d)
trap "rm -rf $tmp_broot" RETURN
cd "$tmp_broot"
wget https://dystroy.org/broot/download/x86_64-linux/broot
chmod a+x broot
mv broot /usr/local/bin
cd /r
fi
rm -f /usr/local/sbin/ll
ln -s /r/setup/_impl/files/ll /usr/local/sbin/ll
mkdir -p "$TOOLS_PATH/bin"
mkdir -p "$TOOLS_PATH/share"
curl https://cht.sh/:cht.sh >"$TOOLS_PATH/bin/cht.sh"
curl https://cheat.sh/:bash_completion >"$TOOLS_PATH/share/cht_sh.bash_completion"
chmod ug+x "$TOOLS_PATH/bin/cht.sh"
export RUSTUP_HOME="${TOOLS_PATH}/rust"
export CARGO_HOME="${RUSTUP_HOME}/.cargo"
curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain=stable
source "${RUSTUP_HOME}/.cargo/env"
cargo install bat choose du-dust fd-find git-delta httm hyperfine lsd zoxide
# For some reason, cargo does not respect the setgid bit
chgrp -R linux-shared "${CARGO_HOME}/bin"
# python
PIP_INSTALL="python3 -m pip install --upgrade"
if [ -v DISTRO ] && [ "$DISTRO" == "ubuntu" ];
then
PIP_INSTALL+=" --break-system-packages"
fi
$PIP_INSTALL setuptools
$PIP_INSTALL cachier httpx keyring keyrings.cryptfile libcst pre-commit prodict \
proselint pylint pypyp pytest-timeout pytest-timestamper rich telegram-send tqdm \
trash-cli
$PIP_INSTALL symbex || true
install_path=$(dirname "$(which trash)")
for suffix in "" "-empty" "-list" "-put" "-restore" "-rm"; do
chgrp linux-shared "${install_path}/trash${suffix}"
chmod o= "${install_path}/trash${suffix}"
done
# shellcheck disable=SC2043
for file in pre-commit; do
chgrp linux-shared "${install_path}/${file}"
chmod o= "${install_path}/${file}"
done
sitecust_dir=$(python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')
chgrp -R linux-shared "$sitecust_dir"
chmod -R g+s "$sitecust_dir"
rm -f "$sitecust_dir/sitecustomize.py"
ln -s /r/setup/_impl/files/sitecustomize.py "$sitecust_dir"
# Do not spool mail locally for any user. First, make sure
# root email is sent to external email. Then, we use a script
# to check that no mail is stuck in local spool.
# User aliases will be added for each user in install_for_user.
# Might need to be added manually for users like www-data in /etc/aliases.
replace_or_add /etc/aliases root "root: $(cat $REPO_DIR/secrets/notify_email)"
newaliases
add_cronjob cronjobs/find_unread_mail "0 * * * * /r/cronjobs/find_unread_mail"
add_cronjob cronjobs/clean_disk_caches "00 05 * * * /r/s/cronic_no_stderr_check /r/cronjobs/clean_disk_caches"
add_cronjob cronjobs/pull "10 05 * * * /r/s/cronic_no_stderr_check /r/cronjobs/pull /r"
add_cronjob cronjobs/is_repo_clean "08 05 * * * /r/s/cronic_no_stderr_check /r/cronjobs/is_repo_clean /r"
# Correct permissions for trash-cli
# On Darwin there is only one file system and we use the default location.
# / is read_only so cannot be used
if [[ ! "$OSTYPE" =~ ^darwin ]]; then
mkdir -p /.Trash
chmod a+rwxt /.Trash
fi
if [[ ! "$OSTYPE" =~ ^darwin ]]; then
pushdt /etc
cp /r/configs/git/.gitignore_ubuntu_etc .gitignore
if [ ! -d .git ]; then
git init
git add .
git config user.name root
git config user.email root@localhost
git commit -m 'Initial commit'
fi
fi
rm -r "${RUSTUP_HOME}/.cargo/registry/"
chmod -R g=u "$TOOLS_PATH"
cp /r/setup/SYSTEM_VERSION /r/setup/state/
echo "OK"