Repository navigation
Expand file tree
/
Copy pathinit-config.sh
More file actions
executable file
·378 lines (318 loc) · 11.5 KB
/
Copy pathinit-config.sh
File metadata and controls
executable file
·378 lines (318 loc) · 11.5 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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#!/bin/bash
function init_config() {
if [ "$USERNAME" == "root" ]; then
print_color red "WARNING: Run the script as your user, not root!"
exit 1
fi
echo "Do you want to configure the system? (y/n)"
read -r answer
if [[ "$answer" == "${answer#[Yy]}" ]]; then
print_color yellow "Exiting configuration script"
exit 1
fi
# Detecting distribution
if ! command -v apt >/dev/null 2>&1; then
print_color red "Detected non Debian system, exiting the script"
exit 1
fi
# Checking if Xorg is in use.
# If this is run from ssh it will return tty, ignore it
if [ "$XDG_SESSION_TYPE" == "xorg" ]; then
print_color yellow "WARNING: you running Xorg, consider switching to Wayland"
fi
echo "Detected architecture: $(dpkg --print-architecture)"
# Check if secure boot is enabled
if ! command -v mokutil >/dev/null 2>&1; then
print_color yellow "Could not check if secure boot is enabled or not"
else
if mokutil --sb-state | grep -q "SecureBoot enabled"; then
echo "Secure Boot is enabled, as expected!"
else
print_color red "WARNING: Secure Boot is disabled"
fi
fi
# Check if hard drive is encrypted
if lsblk -nf | grep -qi "luk"; then
echo "Hard drive is encrypted, as expected!"
else
print_color red "WARNING: Hard drive seems to not be encrypted"
fi
}
function init_sudo() {
echo "Do you want to configure sudo? (y/n)"
read -r answer
if [[ "$answer" == "${answer#[Yy]}" ]]; then
print_color yellow "Skipped sudo configuration"
return
fi
su -c "/sbin/usermod -a -G sudo ${USERNAME}"
# Right now NOPASSWD is on ALL which is not ideal (but still quite convenient).
# Change it to something like this to include only some commands:
# NOPASSWD:/usr/bin/apt update, /usr/bin/apt upgrade
su -c "echo \"${USERNAME} ALL=(root) NOPASSWD: ALL\" | tee /etc/sudoers.d/${USERNAME}"
echo "sudo configuration completed!"
# TODO: Add check that /etc/sudoers.d/${USERNAME} exists and is correct
print_color green "Open a new shell, relaunch the script and skip sudo configuration"
exit 0
}
function init_touchpad_gestures() {
echo "Do you want to configure touchpad gestures? (y/n)"
read -r answer
if [[ "$answer" == "${answer#[Yy]}" ]]; then
print_color yellow "Skipped touchpad gestures configuration"
return
fi
${PKG_UPDATE}
${PKG_INSTALL} make
# Building libinput-gestures from github
mkdir -p ~/dev >/dev/null 2>&1
git clone https://github.com/bulletmark/libinput-gestures.git ~/dev/libinput-gestures
sudo make -C ~/dev/libinput-gestures install
# or "sudo ./libinput-gestures-setup install"
${PKG_INSTALL} wmctrl
${PKG_INSTALL} libinput-tools
mkdir -p ~/.config >/dev/null 2>&1
echo "Pick either xdotool or ydotool:"
echo "Use (x)dotool on x11 and (y)dotool on Wayland (x/y)"
read -r answer
if [[ "$answer" == "${answer#[Xx]}" ]]; then
echo "Configuring touchpad gestures to use xdotool"
${PKG_INSTALL} xdotool
echo -e '# Swipe threshold (0-100)
swipe_threshold 0\n
# Gestures:
gesture swipe left 3 xdotool key ctrl+shift+Tab
gesture swipe right 3 xdotool key ctrl+Tab
# 4-finger: switch desktop, swipe direction = target desktop
# KWin'"'"'s built-in 4-finger swipe is blocked by InputActions
gesture swipe left 4 xdotool key ctrl+Left
gesture swipe right 4 xdotool key ctrl+Right
# These have no effect due to Kwin KDE6 already using these gestures (ARGH!)
# gesture swipe up 3 xdotool key ctrl+alt+Up
# gesture swipe down 3 xdotool key ctrl+alt+Down' \
> ~/.config/libinput-gestures.conf
else
echo "Configuring touchpad gestures to use ydotool"
# Installing yodotool
${PKG_INSTALL} scdoc
git clone https://github.com/ReimuNotMoe/ydotool.git ~/dev/ydotool
mkdir ~/dev/ydotool/build
cmake -B ~/dev/ydotool/build -S ~/dev/ydotool
make -C ~/dev/ydotool/build
sudo make -C ~/dev/ydotool/build install
# Creating the ydotool service for the ydotoold daemon
sudo touch /etc/systemd/system/ydotool.service
echo -e '[Unit]
Description=ydotool daemon
Documentation=https://github.com/ReimuNotMoe/ydotool\n
[Service]
Type=simple
ExecStart=/usr/local/bin/ydotoold --socket-path=/run/user/1000/.ydotool_socket --socket-perm 0666
Restart=always\n
[Install]
WantedBy=multi-user.target' \
| sudo tee /etc/systemd/system/ydotool.service
# Running the ydotool service
sudo systemctl daemon-reload
sudo systemctl enable ydotool
sudo systemctl start ydotool
# Checking that the service is running as expected
sudo systemctl status ydotool
echo -e '# Swipe threshold (0-100)
swipe_threshold 0\n
# Gestures:
gesture swipe left 3 ydotool key 29:1 42:1 15:1 15:0 29:0 42:0
gesture swipe right 3 ydotool key 29:1 15:1 15:0 29:0
# 4-finger: switch desktop (Ctrl+Left/Right), swipe direction = target desktop
# KWin'"'"'s built-in 4-finger swipe is blocked by InputActions
gesture swipe left 4 ydotool key 29:1 105:1 105:0 29:0
gesture swipe right 4 ydotool key 29:1 106:1 106:0 29:0
# These have no effect due to Kwin KDE6 already using these gestures (ARGH!)
# gesture swipe up 3 ydotool key ctrl+alt+Up
# gesture swipe down 3 ydotool key ctrl+alt+Down' \
> ~/.config/libinput-gestures.conf
fi
sudo usermod -a -G input "${USERNAME}"
libinput-gestures-setup stop desktop autostart start
# DEBUG IF NOT WORKING
# check output of these commands:
# libinput-gestures -l
# libinput-gestures-setup status
# this can be needed (run it in the repo folder):
# sudo libinput-gestures-setup install
}
function init_kwin_gestures() {
echo "Do you want to disable KWin's 3-finger horizontal swipe with InputActions? (y/n)"
read -r answer
if [[ "$answer" == "${answer#[Yy]}" ]]; then
print_color yellow "Skipped InputActions installation"
return
fi
# KWin (Plasma 6) hardcodes 3- and 4-finger horizontal swipes to switch
# virtual desktops. The InputActions KWin plugin blocks the 3-finger one,
# so libinput-gestures can use 3-finger left/right for tab switching.
# It also blocks the 4-finger one: libinput-gestures switches desktops
# with swipe direction = target desktop (mac-style, inverted from KWin).
${PKG_UPDATE}
${PKG_INSTALL} curl git cmake g++ extra-cmake-modules qt6-declarative-dev \
qt6-tools-dev kwin-dev libkf6configwidgets-dev gettext libkf6kcmutils-dev \
libyaml-cpp-dev libxkbcommon-dev pkg-config libevdev-dev libdrm-dev \
libcli11-dev liblayershellqtinterface-dev
# Building InputActions (installs to /usr via "sudo make install")
mkdir -p ~/dev >/dev/null 2>&1
curl -fsSL -o ~/dev/inputactions-installer.sh \
https://raw.githubusercontent.com/InputActions/installer/refs/heads/main/install.sh
chmod +x ~/dev/inputactions-installer.sh
~/dev/inputactions-installer.sh --ctl --kwin --latest-stable
mkdir -p ~/.config/inputactions >/dev/null 2>&1
echo -e 'touchpad:
gestures:
# Block KWin'"'"'s built-in 3-finger horizontal desktop switch;
# libinput-gestures uses 3-finger left/right for tabs.
- type: swipe
fingers: 3
direction: left_right
# Block KWin'"'"'s built-in 4-finger horizontal desktop switch;
# libinput-gestures switches desktops with swipe direction = target
# desktop (mac-style), inverted from KWin'"'"'s default.
- type: swipe
fingers: 4
direction: left_right' \
> ~/.config/inputactions/config.yaml
# Enabling the plugin now and at login
kwriteconfig6 --file kwinrc --group Plugins --key kwin_gesturesEnabled true
qdbus6 org.kde.KWin /Effects org.kde.kwin.Effects.loadEffect kwin_gestures
# NOTES
# After a Plasma update, rerun the installer and restart KWin:
# ~/dev/inputactions-installer.sh --ctl --kwin --latest-stable
# If KWin crashes repeatedly, remove "kwin_gesturesEnabled=true" from ~/.config/kwinrc
# If a bad config makes input unusable, hold backspace+space+enter for 2s
# Check config with: inputactions config issues
}
function init_install_ohmyzsh() {
echo "Do you want to install oh my zsh? (y/n)"
read -r answer
if [[ "$answer" == "${answer#[Yy]}" ]]; then
print_color yellow "Skipped oh my zsh installation"
return
fi
print_color green "After oh-my-zsh installation, exit to continue the setup!"
sleep 1
${PKG_UPDATE}
${PKG_INSTALL} zsh
${PKG_INSTALL} curl
set -e
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
set +e
}
function init_configure_zsh() {
echo "Do you want to configure zsh? (y/n)"
read -r answer
if [[ "$answer" == "${answer#[Yy]}" ]]; then
print_color yellow "Skipped zsh configuration"
return
fi
cat ~/.bash_history >> ~/.zsh_history
# Add .zshrc_custom link to .zshrc file
CONFIG_DIR=$SCRIPT_PATH
CONFIG_DIR=${CONFIG_DIR%/}
echo "CONFIG_DIR: $CONFIG_DIR"
echo -e "
export CONFIG_DIR=${CONFIG_DIR}
# Custom .zshrc file:
if [ -f ~/.zshrc_custom ]; then
. ~/.zshrc_custom
fi" \
>> ~/.zshrc
# Commented out since it's added back in .zshrc_custom
sed -i 's/^source $ZSH\/oh-my-zsh.sh/#source $ZSH\/oh-my-zsh.sh/' ~/.zshrc
print_color white "Showing ~/.zshrc file after changes:"
cat ~/.zshrc
}
function init_git() {
echo "Do you want to perform git configuration? (y/n)"
read -r answer
if [[ "$answer" == "${answer#[Yy]}" ]]; then
print_color yellow "Skipped git configuration"
return
fi
${PKG_UPDATE}
${PKG_INSTALL} git
${PKG_INSTALL} git-lfs
echo "Insert git user.name:"
read -r name
git config --global user.name "${name}"
echo "Insert git user.email:"
read -r email
git config --global user.email "${email}"
# Shared with update-config.sh, see git-config.sh
apply_git_config
echo "Do you want to setup git signing? (y/n)"
read -r answer
if [[ "$answer" == "${answer#[Nn]}" ]]; then
echo "Insert gpg key ID:"
read -r keyid
git config --global commit.gpgSign true
git config --global user.signingKey "${keyid}"
else
git config --global commit.gpgSign false
fi
# Configuring git lfs
git lfs install
print_color white "Review your git configuration"
git config --global --list --show-origin
}
function init_grub() {
echo "Do you want to perform grub configuration? (y/n)"
read -r answer
if [[ "$answer" == "${answer#[Yy]}" ]]; then
print_color yellow "Skipped grub configuration"
return
fi
echo -e "\n# User defined resolution for grub\nGRUB_GFXMODE=640x480\n" \
| sudo tee -a /etc/default/grub
sudo update-grub
}
function install_packages() {
echo "Do you want to install the packages? (y/n)"
read -r answer
if [[ "$answer" == "${answer#[Yy]}" ]]; then
print_color yellow "Skipped packages installation"
return
fi
$SCRIPT_PATH/install-deps.sh init
}
function init_config_files() {
echo "Do you want to sync the config files? (y/n)"
read -r answer
if [[ "$answer" == "${answer#[Yy]}" ]]; then
print_color yellow "Skipped config files sync"
return
fi
# The init argument will make the script skip the deps check
$SCRIPT_PATH/update-config.sh init
}
SCRIPT_PATH=$(dirname "${BASH_SOURCE[0]}")
if [[ "${SCRIPT_PATH:0:1}" != "/" ]]; then
echo "This script needs to be called with the absolute path"
exit 1
fi
cd $SCRIPT_PATH
source print-color.sh
source git-config.sh
print_color green "New Linux installation setup"
USERNAME=$(whoami)
PKG_UPDATE="sudo apt-get update"
PKG_INSTALL="sudo apt-get install -y"
init_config
init_sudo
init_touchpad_gestures
init_kwin_gestures
init_install_ohmyzsh
init_configure_zsh
init_git
init_grub
install_packages
init_config_files
print_color green "First setup completed!"
print_color white "Close the terminal for all the changes to take place"