-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
auto-install.sh
executable file
·272 lines (220 loc) · 7.88 KB
/
auto-install.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
#!/usr/bin/env bash
set -e
# Set some colors for output messages
OK="$(tput setaf 2)[OK]$(tput sgr0)"
ERROR="$(tput setaf 1)[ERROR]$(tput sgr0)"
NOTE="$(tput setaf 3)[NOTE]$(tput sgr0)"
WARN="$(tput setaf 5)[WARN]$(tput sgr0)"
CAT="$(tput setaf 6)[ACTION]$(tput sgr0)"
ORANGE=$(tput setaf 166)
YELLOW=$(tput setaf 3)
RESET=$(tput sgr0)
if [ -n "$(grep -i nixos < /etc/os-release)" ]; then
echo "Verified this is NixOS."
echo "-----"
else
echo "$ERROR This is not NixOS or the distribution information is not available."
exit 1
fi
if command -v git &> /dev/null; then
echo "$OK Git is installed, continuing with installation."
echo "-----"
else
echo "$ERROR Git is not installed. Please install Git and try again."
echo "Example: nix-shell -p git"
exit 1
fi
echo "$NOTE Ensure In Home Directory"
cd || exit
echo "-----"
backupname=$(date "+%Y-%m-%d-%H-%M-%S")
if [ -d "NixOS-Hyprland" ]; then
echo "$NOTE NixOS-Hyprland exists, backing up to NixOS-Hyprland-backups folder."
if [ -d "NixOS-Hyprland-backups" ]; then
echo "Moving current version of NixOS-Hyprland to backups folder."
sudo mv "$HOME"/NixOS-Hyprland NixOS-Hyprland-backups/"$backupname"
sleep 1
else
echo "$NOTE Creating the backups folder & moving NixOS-Hyprland to it."
mkdir -p NixOS-Hyprland-backups
sudo mv "$HOME"/NixOS-Hyprland NixOS-Hyprland-backups/"$backupname"
sleep 1
fi
else
echo "$OK Thank you for choosing KooL's NixOS-Hyprland"
echo "$OK I hope you find your time here enjoyable!"
fi
echo "-----"
echo "$NOTE Cloning & Entering NixOS-Hyprland Repository"
git clone --depth 1 https://github.com/JaKooLit/NixOS-Hyprland.git ~/NixOS-Hyprland
cd ~/NixOS-Hyprland || exit
printf "\n%.0s" {1..2}
# Checking if running on a VM and enable in default config.nix
if hostnamectl | grep -q 'Chassis: vm'; then
echo "${NOTE} Your system is running on a VM. Enabling guest services.."
echo "${WARN} A Kind reminder to enable 3D acceleration.."
sed -i '/vm\.guest-services\.enable = false;/s/vm\.guest-services\.enable = false;/ vm.guest-services.enable = true;/' hosts/default/config.nix
fi
printf "\n%.0s" {1..1}
# Checking if system has nvidia gpu and enable in default config.nix
if command -v lspci > /dev/null 2>&1; then
# lspci is available, proceed with checking for Nvidia GPU
if lspci -k | grep -A 2 -E "(VGA|3D)" | grep -iq nvidia; then
echo "${NOTE} Nvidia GPU detected. Setting up for nvidia..."
sed -i '/drivers\.nvidia\.enable = false;/s/drivers\.nvidia\.enable = false;/ drivers.nvidia.enable = true;/' hosts/default/config.nix
fi
fi
echo "-----"
printf "\n%.0s" {1..1}
echo "$NOTE Default options are in brackets []"
echo "$NOTE Just press enter to select the default"
sleep 1
echo "-----"
read -rp "$CAT Enter Your New Hostname: [ default ] " hostName
if [ -z "$hostName" ]; then
hostName="default"
fi
echo "-----"
# Create directory for the new hostname, unless the default is selected
if [ "$hostName" != "default" ]; then
mkdir -p hosts/"$hostName"
cp hosts/default/*.nix hosts/"$hostName"
else
echo "Default hostname selected, no extra hosts directory created."
fi
echo "-----"
read -rp "$CAT Enter your keyboard layout: [ us ] " keyboardLayout
if [ -z "$keyboardLayout" ]; then
keyboardLayout="us"
fi
sed -i 's/keyboardLayout\s*=\s*"\([^"]*\)"/keyboardLayout = "'"$keyboardLayout"'"/' ./hosts/$hostName/variables.nix
echo "-----"
installusername=$(echo $USER)
sed -i 's/username\s*=\s*"\([^"]*\)"/username = "'"$installusername"'"/' ./flake.nix
echo "$NOTE Generating The Hardware Configuration"
attempts=0
max_attempts=3
hardware_file="./hosts/$hostName/hardware.nix"
while [ $attempts -lt $max_attempts ]; do
sudo nixos-generate-config --show-hardware-config > "$hardware_file" 2>/dev/null
if [ -f "$hardware_file" ]; then
echo "${OK} Hardware configuration successfully generated."
break
else
echo "${WARN} Failed to generate hardware configuration. Attempt $(($attempts + 1)) of $max_attempts."
attempts=$(($attempts + 1))
# Exit if this was the last attempt
if [ $attempts -eq $max_attempts ]; then
echo "${ERROR} Unable to generate hardware configuration after $max_attempts attempts."
exit 1
fi
fi
done
echo "-----"
echo "$NOTE Setting Required Nix Settings Then Going To Install"
git config --global user.name "installer"
git config --global user.email "[email protected]"
git add .
sed -i 's/host\s*=\s*"\([^"]*\)"/host = "'"$hostName"'"/' ./flake.nix
printf "\n%.0s" {1..2}
echo "$NOTE Rebuilding NixOS..... so pls be patient.."
echo "-----"
echo "$CAT In the meantime, go grab a coffee or stretch or something..."
echo "-----"
echo "$ERROR YES!!! YOU read it right.. you staring too much at your monitor ha ha... joke :)......"
printf "\n%.0s" {1..2}
# Set the Nix configuration for experimental features
NIX_CONFIG="experimental-features = nix-command flakes"
#sudo nix flake update
sudo nixos-rebuild switch --flake ~/NixOS-Hyprland/#"${hostName}"
echo "-----"
printf "\n%.0s" {1..2}
# for initial zsh
# Check if ~/.zshrc and exists, create a backup, and copy the new configuration
if [ -f "$HOME/.zshrc" ]; then
cp -b "$HOME/.zshrc" "$HOME/.zshrc-backup" || true
fi
# Copying the preconfigured zsh themes and profile
cp -r 'assets/.zshrc' ~/
# GTK Themes and Icons installation
printf "Installing GTK-Themes and Icons..\n"
if [ -d "GTK-themes-icons" ]; then
echo "$NOTE GTK themes and Icons folder exist..deleting..."
rm -rf "GTK-themes-icons"
fi
echo "$NOTE Cloning GTK themes and Icons repository..."
if git clone --depth 1 https://github.com/JaKooLit/GTK-themes-icons.git ; then
cd GTK-themes-icons
chmod +x auto-extract.sh
./auto-extract.sh
cd ..
echo "$OK Extracted GTK Themes & Icons to ~/.icons & ~/.themes folders"
else
echo "$ERROR Download failed for GTK themes and Icons.."
fi
echo "$OK Extracted Bibata-Modern-Ice.tar.xz to ~/.icons folder."
echo "-----"
printf "\n%.0s" {1..2}
# Check for existing configs and copy if does not exist
for DIR1 in gtk-3.0 Thunar xfce4; do
DIRPATH=~/.config/$DIR1
if [ -d "$DIRPATH" ]; then
echo -e "${NOTE} Config for $DIR1 found, no need to copy."
else
echo -e "${NOTE} Config for $DIR1 not found, copying from assets."
cp -r assets/$DIR1 ~/.config/ && echo "Copy $DIR1 completed!" || echo "Error: Failed to copy $DIR1 config files."
fi
done
echo "-----"
printf "\n%.0s" {1..3}
# Clean up
# GTK Themes and Icons
if [ -d "GTK-themes-icons" ]; then
echo "$NOTE GTK themes and Icons folder exist..deleting..."
rm -rf "GTK-themes-icons"
fi
echo "-----"
printf "\n%.0s" {1..3}
# Cloning Hyprland-Dots repo to home folder
# KooL's Dots installation
printf "$NOTE Downloading Hyprland dots from main to HOME folder..\n"
if [ -d ~/Hyprland-Dots ]; then
cd ~/Hyprland-Dots
git stash
git pull
git stash apply
chmod +x copy.sh
./copy.sh
else
if git clone --depth 1 https://github.com/JaKooLit/Hyprland-Dots ~/Hyprland-Dots; then
cd ~/Hyprland-Dots || exit 1
chmod +x copy.sh
./copy.sh
else
echo -e "$ERROR Can't download Hyprland-Dots"
fi
fi
#return to NixOS-Hyprland directory
cd ~/NixOS-Hyprland
# copy fastfetch config for NixOS
cp -r assets/fastfetch ~/.config/ || true
printf "\n%.0s" {1..2}
if command -v Hyprland &> /dev/null; then
printf "\n${OK} Yey! Installation Completed.${RESET}\n"
sleep 2
printf "\n${NOTE} You can start Hyprland by typing Hyprland (note the capital H!).${RESET}\n"
printf "\n${NOTE} It is highly recommended to reboot your system.${RESET}\n\n"
# Prompt user to reboot
read -rp "${CAT} Would you like to reboot now? (y/n): ${RESET}" HYP
if [[ "$HYP" =~ ^[Yy]$ ]]; then
# If user confirms, reboot the system
systemctl reboot
else
# Print a message if the user does not want to reboot
echo "Reboot skipped."
fi
else
# Print error message if Hyprland is not installed
printf "\n${WARN} Hyprland failed to install. Please check Install-Logs...${RESET}\n\n"
exit 1
fi