-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit-config.sh
executable file
·319 lines (267 loc) · 8.98 KB
/
init-config.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
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
#!/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 "Skipping 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=(ALL:ALL) 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 "Skipping 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
gesture swipe left 4 xdotool key ctrl+w
gesture swipe right 4 xdotool key ctrl+t
# 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
gesture swipe left 4 ydotool key 29:1 17:1 17:0 29:0
gesture swipe right 4 ydotool key 29:1 20:1 20: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_install_ohmyzsh() {
echo "Do you want to install oh my zsh? (y/n)"
read -r answer
if [ "$answer" == "${answer#[Yy]}" ]; then
print_color yellow "Skipping oh my zsh installation"
return
fi
${PKG_UPDATE}
${PKG_INSTALL} zsh
${PKG_INSTALL} curl
echo "After oh-my-zsh installation, exit to continue the setup"
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 "Skipping 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 "Skipping 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}"
git config --global credential.usehttppath true
git config --global pull.ff only
git config --global pull.rebase false
git config --global init.defaultBranch master
touch /home/$USERNAME/.gitignore_global
git config --global core.excludesfile /home/$USERNAME/.gitignore_global
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 user.signingKey "${keyid}"
git config --global commit.gpgSign true
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 "Skipping 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 "Skipping 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 "Skipping 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
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_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"