-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·105 lines (77 loc) · 2.91 KB
/
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
#!/bin/sh
# In order to suppress this warning, run the script with first parameter set to "y"
startup_warning () {
echo "WARNING: This script was created to setup Khenzii's working environment (NixOS configuration + some dotfiles)"
echo ""
echo "It will execute those steps in order to do so:"
echo "1. clone https://github.com/Khenziii/nixos-config [1]"
echo "2. create symlinks using GNU's stow in order to apply settings"
echo "3. run some commands to setup applied settings (for example rebuild the system, if NixOS config got applied)"
echo ""
echo "[1] Please make sure, that you're running this script in the directory from which you'd like to manage the config. You won't be able to move this folder later, without breaking all of the symlinks."
echo ""
read -p "Do you want to proceed? (Y/n): " response
# `^^` converts the string to uppercase
if [ "${response^^}" != "Y" ]; then
echo "Exiting.."
exit
fi
echo "Proceeding.."
}
# Exits, if the script doesn't have necessary permissions
check_if_executed_by_root() {
if ! [ "$EUID" = "0" ]; then
echo "This script needs to be executed with 'sudo', or by the root user. Exiting.."
exit
fi
}
# Exits, if $1 is not installed
check_if_installed () {
if ! which $1 > /dev/null 2>&1; then
echo "$1 is not installed. Please install it, and rerun the script."
exit
fi
}
# Exits, if not running an Unix based OS
check_if_running_unix() {
# This variable will be set to "Darwin" for MacOS and "Linux" for Linux distributions
os_name=$(uname -s)
if ! ([ "$os_name" = "Darwin" ] || [ "$os_name" = "Linux" ]); then
echo "You're not using an Unix-Like OS. Please stop using Windows (:pray:) and rerun this script, lol."
exit
fi
}
# Exits, if not running NixOS
check_if_running_nixos() {
if ! cat /etc/os-release | grep -q "NixOS"; then
echo "You're not running NixOS, exiting.."
exit
fi
}
agreement=$1
if [ "${agreement^^}" != "Y" ]; then
startup_warning
fi
check_if_running_unix
check_if_executed_by_root
check_if_installed "git"
check_if_installed "stow"
echo "Running 'git clone'.."
git clone https://github.com/Khenziii/nixos-config || { echo "Failed to run 'git clone', exiting.."; exit; }
cd nixos-config
echo "Creating dotfiles symlinks.."
stow --no-folding --adopt -t "/home/$SUDO_USER" dotfiles
echo "Creating placeholders.."
# Those files are written to by `nwg-displays`, and imported from hyprland.conf.
# During the installation phase, we create empty placeholders, so that mentioned
# imports don't throw any "File not found" errors.
touch ~/.config/hypr/monitors.conf
touch ~/.config/hypr/workspaces.conf
# Ensure, that `/etc/nixos/hardware-configuration.nix` is present.
echo "Generating NixOS config.."
check_if_running_nixos
sudo nixos-generate-config
echo "Installing NixOS config.."
sudo nixos-rebuild switch --flake ".#iusenixosbtw" --impure
home-manager switch --flake ".#khenzii"
echo "Successfully applied the whole config!"