Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·222 lines (173 loc) · 5.94 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·222 lines (173 loc) · 5.94 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
#!/bin/bash
set -Eeuo pipefail
if [[ $EUID -ne 0 ]]; then
echo "Please run this script with sudo:"
echo " sudo $0"
exit 1
fi
trap 'echo "Error on line $LINENO while running: $BASH_COMMAND" | tee -a ./setup.log >&2' ERR
TARGET_USER="${SUDO_USER:-$USER}"
DISTRO="unknown"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LIB_DIR="/usr/local/lib/VMTUNE"
POLKIT_DIR="/usr/share/polkit-1"
BATTERY_FILE="/var/lib/libvirt/images/fakebattery.aml"
INSTALL_DIR="/usr/local/bin/"
detect_distro() {
local STRING=$(cat /etc/os-release)
shopt -s nocasematch
if [[ "$STRING" == *fedora* ]]; then
echo "Fedora detected"
DISTRO="Fedora"
else
echo "Supported distro not detected..."
echo "exiting"
DISTRO="Unknown"
shopt -u nocasematch
exit 1
fi
shopt -u nocasematch
}
update_system() {
echo "Starting system update..."
dnf update -y
echo "System update completed successfully."
}
setup_snapshots() {
echo "Setting up automatic snapshots..."
dnf install snapper python3-dnf-plugin-snapper -y
# Root Snapper config
if [ ! -f /etc/snapper/configs/root ]; then
echo "Creating Snapper config for / ..."
snapper -c root create-config /
else
echo "Snapper root config already exists."
fi
# Home Snapper config (only works on Btrfs)
if findmnt -n /home | grep -q "btrfs"; then
if [ ! -f /etc/snapper/configs/home ]; then
echo "Creating Snapper config for /home ..."
snapper -c home create-config /home
else
echo "Snapper home config already exists."
fi
else
echo "WARNING: /home is not on Btrfs. Skipping home Snapper config."
fi
# libvirt images Snapper config (ONLY when on Btrfs)
if findmnt -n /var/lib/libvirt/images | grep -q "btrfs"; then
if [ ! -f /etc/snapper/configs/libvirt-images ]; then
echo "Creating Snapper config for /var/lib/libvirt/images ..."
snapper -c libvirt-images create-config /var/lib/libvirt/images
else
echo "Snapper libvirt-images config already exists."
fi
else
echo "NOTICE: /var/lib/libvirt/images is not on Btrfs. Snapper will not be used for it."
fi
# Always attempt COW disable – safe on both Btrfs and XFS
if [ -d /var/lib/libvirt/images ]; then
echo "Disabling COW on /var/lib/libvirt/images ..."
if ! chattr +C /var/lib/libvirt/images; then
echo "INFO: Could not disable COW (expected if filesystem is XFS or ext4)"
fi
else
echo "WARNING: /var/lib/libvirt/images does not exist."
fi
systemctl enable --now snapper-timeline.timer
systemctl enable --now snapper-cleanup.timer
echo "Automatic snapshots setup completed successfully."
}
setup_virtualization_tools() {
echo "Starting installation of virtualization tools..."
dnf group install --with-optional "virtualization" -y
dnf install python3-pip -y
echo "Virtualization tools installed successfully."
systemctl enable --now libvirtd
echo "libvirtd service enabled successfully."
usermod -aG libvirt "$TARGET_USER"
echo "User $TARGET_USER added to libvirt group."
}
setup_looking_glass() {
if [ ! -f ./src/core/install_looking-glass.sh ]; then
echo "ERROR: install_looking-glass.sh not found."
exit 1
fi
echo "Running Looking Glass installer..."
./src/core/install_looking-glass.sh --action full-install
echo "Looking Glass installation completed."
}
setup_gaming_laptop() {
if [[ ! -f "$BATTERY_FILE" ]]; then
read -rp "Are you using an ASUS gaming laptop? (y for yes / n for no): " ASUS_LAPTOP
if [[ "$ASUS_LAPTOP" == "y" || "$ASUS_LAPTOP" == "1" ]]; then
echo "Special optimizations will be applied."
cp "$SCRIPT_DIR/assets/fakebattery.aml" "/var/lib/libvirt/images/"
else
echo "No ASUS laptop detected. Skipping ASUS-specific tweaks."
fi
fi
}
setup_VMTUNE() {
echo "Installing the VMTUNE tool now..."
echo "Creating polkit directories..."
mkdir -p "$POLKIT_DIR/actions"
mkdir -p "$POLKIT_DIR/rules.d"
echo "Installing polkit policy and rules..."
cp "$SCRIPT_DIR/assets/vmtune.policy" "$POLKIT_DIR/actions/"
cp "$SCRIPT_DIR/assets/50-vmtune.rules" "$POLKIT_DIR/rules.d/"
echo "Resetting $LIB_DIR..."
rm -rf "$LIB_DIR"
mkdir -p "$LIB_DIR"
echo "Copying project files to $LIB_DIR..."
cp -r "$SCRIPT_DIR/src" "$LIB_DIR/"
cp -r "$SCRIPT_DIR/assets" "$LIB_DIR/"
cp -r "$SCRIPT_DIR/hooks" "$LIB_DIR/"
cp "$SCRIPT_DIR/pyproject.toml" "$LIB_DIR/"
echo "Installing vmtune executables to $INSTALL_DIR..."
cp "$SCRIPT_DIR/bin/vmtune" "$INSTALL_DIR"
cp "$SCRIPT_DIR/bin/vmtune.sh" "$INSTALL_DIR"
cp "$SCRIPT_DIR/bin/vmtunegui" "$INSTALL_DIR"
echo "Installing Python api package for user $TARGET_USER..."
sudo -H -u "$TARGET_USER" pip install --user "$SCRIPT_DIR"
systemctl restart polkit
}
setup_desktop_environment() {
echo "Starting installation of desktop environment..."
dnf install sway \
waybar \
pavucontrol \
gtk-murrine-engine \
wofi \
network-manager-applet \
NetworkManager-tui \
nm-connection-editor \
firefox \
curl \
python \
blueman \
kernel-tools \
sddm -y
#sed -i '/^installonly_limit=/d' /etc/dnf/dnf.conf
#echo "installonly_limit=2" >> /etc/dnf/dnf.conf
systemctl enable sddm
systemctl enable NetworkManager
systemctl set-default graphical.target
if [ ! -d "/home/$TARGET_USER/.themes" ]; then
mkdir -p "/home/$TARGET_USER/.themes"
fi
cp -rf ../.themes/Gruvbox-B-MB-Dark "/home/$TARGET_USER/.themes/"
cp ../.gtkrc-2.0 "/home/$TARGET_USER/"
cp -rf ../.config "/home/$TARGET_USER/.config"
chown -R "$TARGET_USER:$TARGET_USER" "/home/$TARGET_USER/.themes"
chown -R "$TARGET_USER:$TARGET_USER" "/home/$TARGET_USER/.config"
chown "$TARGET_USER:$TARGET_USER" "/home/$TARGET_USER/.gtkrc-2.0"
echo "Desktop environment installed successfully."
}
update_system
setup_virtualization_tools
#setup_looking_glass
setup_gaming_laptop
setup_VMTUNE
echo "Setup completed successfully."
echo "Please reboot your system to apply all changes."