-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·206 lines (162 loc) · 6.11 KB
/
install.sh
File metadata and controls
executable file
·206 lines (162 loc) · 6.11 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
#!/usr/bin/env bash
#--------------------#
# Initialisation #
#--------------------#
CURRENT_USERNAME='frostphoenix'
RESET=$(tput sgr0)
WHITE=$(tput setaf 7)
BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
BRIGHT=$(tput bold)
UNDERLINE=$(tput smul)
OK="[${GREEN}OK${RESET}]\t"
INFO="[${BLUE}INFO${RESET}]\t"
WARN="[${MAGENTA}WARN${RESET}]\t"
ERROR="[${RED}ERROR${RESET}]\t"
set -e
#------------------------------#
# Check if running as root #
#------------------------------#
if [[ $EUID -eq 0 ]]; then
echo -e "${ERROR}This script should ${RED}NOT${RESET} be executed as root!"
echo -e "${INFO}Exiting..."
exit 1
fi
#------------------------------------#
# Check if whiptail is installed #
#------------------------------------#
if ! command -v whiptail &> /dev/null; then
echo -e "${INFO}whiptail not found, downloading required packages"
nix-shell -p newt --run "$(realpath "$0")"
exit $?
fi
#---------------------#
# Greating banner #
#---------------------#
clear
echo -E "$CYAN
_____ _ ____ _ _
| ___| __ ___ ___| |_| _ \| |__ ___ ___ _ __ (_)_ __
| |_ | '__/ _ \/ __| __| |_) | '_ \ / _ \ / _ \ '_ \| \ \/ /
| _|| | | (_) \__ \ |_| __/| | | | (_) | __/ | | | |> <
|_| |_| \___/|___/\__|_| |_| |_|\___/ \___|_| |_|_/_/\_\
_ _ _ ___ ___ _ _ _
| \ | (_)_ __/ _ \ ___ |_ _|_ __ ___| |_ __ _| | | ___ _ __
| \| | \ \/ / | | / __| | || '_ \/ __| __/ _' | | |/ _ \ '__|
| |\ | |> <| |_| \__ \ | || | | \__ \ || (_| | | | __/ |
|_| \_|_/_/\_\\\\___/|___/ |___|_| |_|___/\__\__,_|_|_|\___|_|
${BLUE} ─── https://github.com/Frost-Phoenix/nixos-config ─── ${RESET}
"
#------------------#
# Get username #
#------------------#
while true; do
username=$(whiptail --inputbox "Enter your username:" 9 40 --title "Username" 3>&1 1>&2 2>&3)
if [ $? != 0 ]; then
exit 1
fi
if ! [[ $username =~ ^[a-z][a-z0-9_-]{0,31}$ ]]; then
whiptail --msgbox "Invalid username: '$username'" 8 40 --title Error 3>&1 1>&2 2>&3
continue
fi
if (whiptail --yesno "Use '$username' as username?" 8 40 --title "Confirm Username"); then
break
fi
done
#-----------------#
# Choose host #
#-----------------#
while true; do
HOST=$(whiptail --radiolist "Choose a host:" 11 48 3 \
"desktop" "Desktop configuration" ON \
"laptop" "Laptop configuration" OFF \
"vm" "Virtual machine configuration" OFF \
--title "Host" 3>&1 1>&2 2>&3)
if [ $? != 0 ]; then
exit 1
fi
if (whiptail --yesno "Use the '$HOST' host?" 8 40 --title "Confirm Host"); then
break
fi
done
#------------------------#
# pkgs configuration #
#------------------------#
whiptail --msgbox "This config includes Aseprite, a pixel art editing software. It requires being built from source, which can take a very long time depending on your hardware. You will have the option to disable it, with the intent of speeding up the installation." 12 60 --title "Aseprite Information"
if (whiptail --yesno "Disable Aseprite (faster install)?" --defaultno 8 40 --title "Aseprite"); then
DISABLE_ASEPRITE="Yes"
else
DISABLE_ASEPRITE="No"
fi
#---------------------------#
# Recap of user choices #
#---------------------------#
SUMMARY="\
Username: $username
Host: $HOST
Disable Aseprite: $DISABLE_ASEPRITE
"
whiptail --msgbox "$SUMMARY" 11 40 --title "Installation Summary"
#-----------------------#
# Last Confirmation #
#-----------------------#
if ! (whiptail --yesno "You are about to build the system for host '$HOST'. Proceed?" 9 40 --title "Final Confirmation"); then
exit 0
fi
#---------------------#
# Change username #
#---------------------#
echo -e "${INFO}Changing username to ${GREEN}$username${RESET}"
find ./hosts ./modules flake.nix -type f -exec sed -i -e "s/${CURRENT_USERNAME}/${username}/g" {} +
#------------------------------#
# Apply pkgs configuration #
#------------------------------#
if [[ $DISABLE_ASEPRITE = "Yes" ]]; then
echo -e "${INFO}Disabling Aseprite"
sed -i '3s/ / # /' modules/home/aseprite/aseprite.nix
fi
#----------------------#
# Clear git config #
#----------------------#
echo -e "${INFO}Clearing git config"
sed -i 's/"Frost-Phoenix"/""/g' modules/home/git.nix
sed -i 's/"67cyril6767@gmail.com"/""/g' modules/home/git.nix
#------------------------------#
# Prepare the environement #
#------------------------------#
## Create common dirrectories
echo -e "${INFO}Preparing the environment"
for dir in ~/Music ~/Documents ~/Pictures/wallpapers/others; do
echo -e "${INFO}Creating folder: ${MAGENTA}${dir}${RESET}"
mkdir -p "$dir"
done
## Copy wallpapers
echo -e "${INFO}Copying wallpapers..."
if cp -r wallpapers/otherWallpaper/gruvbox/* ~/Pictures/wallpapers/others/ &&
cp -r wallpapers/otherWallpaper/nixos/* ~/Pictures/wallpapers/others/ &&
ln -sf $PWD/wallpapers/wallpaper.png ~/Pictures/wallpapers/wallpaper; then
echo -e "${OK}Wallpapers copied successfully."
else
echo -e "${WARN}Some wallpapers could not be copied!"
whiptail --msgbox "Some wallpapers failed to copy." 8 40 --title "Warning"
fi
## Get the hardware configuration
if [ ! -f /etc/nixos/hardware-configuration.nix ]; then
echo -e "${ERROR} ${MAGENTA}/etc/nixos/hardware-configuration.nix${RESET} not found! Aborting."
whiptail --msgbox "/etc/nixos/hardware-configuration.nix not found! Aborting." 9 40 --title "Error"
exit 1
fi
echo -e "${INFO}Copying ${MAGENTA}/etc/nixos/hardware-configuration.nix${RESET} to ${MAGENTA}./hosts/${HOST}/${RESET}"
cp /etc/nixos/hardware-configuration.nix hosts/${HOST}/hardware-configuration.nix
#------------------#
# Installation #
#------------------#
echo -e "${INFO}Starting system build... this may take a while."
sudo nixos-rebuild switch --flake .#${HOST}
echo -e "${INFO}System build finished successfully"
echo -e "${INFO}You can now reboot to apply the config"