-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·166 lines (135 loc) · 5.04 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
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
#!/bin/sh
# Installation script
# Usage: install.sh <username>
[ "$#" -ne 1 ] && { printf 'Usage: install.sh <username>\n'; exit 1; }
[ "$(whoami)" = 'root' ] || { printf 'Root permission is needed!\n'; exit 1; }
cd "${0%/*}" || exit 1
username="$1"
# Configure user
id -u "$username" >/dev/null 2>&1 || { useradd -m "$username" || exit 1; }
# Configure user password
[ "$(passwd -S "$username" | cut -d ' ' -f 2)" != 'P' ] && \
{ printf 'User Password\n'; passwd -q "$username" || exit 1; }
# Configure root password
[ "$(passwd -S | cut -d ' ' -f 2)" != 'P' ] && \
{ printf 'Root Password\n'; passwd -q || exit 1; }
step=1
while [ "$step" -gt 0 ]; do clear
# Check internet connection
while ! ping -c 1 archlinux.org >/dev/null 2>&1; do
printf 'No internet connection!\n'
sleep 3
done
case "$step" in
1) # Configure Pacman
sed -E -e 's/^#?(ParallelDownloads[[:space:]]*=).+$/\1 5/' \
-e 's/^#?(Color)$/\1/' -i /etc/pacman.conf
;;
2) # Install 'reflector' package
pacman -S --needed reflector || \
{ printf "Failed to install 'reflector' package!\n"; exit 1; }
;;
3) # Get the latest pacman mirrorlist
printf 'Update pacman mirrorlist? [y/N]: '; read -r ans
[ -n "${ans}" ] && { [ -z "${ans#y}" ] || [ -z "${ans#Y}" ]; } && \
{ ./bin/update-mirrorlist.sh || exit 1; }
;;
4) # Update system
pacman -Rns --noconfirm mkinitcpio 2>/dev/null
pacman -Syu || { printf 'Failed to update system!\n'; exit 1; }
;;
5) # Install packages
sed -E -n 's/^[[:space:]]*\*[[:space:]]*([[:alnum:]_-]*)[[:space:]]*$/\1/p' \
./packages.txt | pacman -S --needed - || \
{ printf 'Failed to install packages!\n'; exit 1; }
;;
6) # Install the CPU microcode
./install-cpu-microcode.sh || \
{ printf 'Failed to install CPU microcode!\n'; exit 1; }
;;
7) # Install AUR helper
if ! command -v paru >/dev/null 2>&1; then
su --pty --login "$username" -c "
git clone https://aur.archlinux.org/paru-bin.git '$(pwd)/paru-bin'
( cd '$(pwd)/paru-bin' && makepkg -si )
rm -rf ./paru-bin
"
command -v paru >/dev/null 2>&1 || \
{ printf 'Failed to install AUR helper!\n'; exit 1; }
else
printf 'AUR helper is already installed, skipping ...\n'
fi
;;
8) # Install AUR packages
su --pty --login "$username" -c "
sed -E -n 's/^[[:space:]]*@[[:space:]]*([[:alnum:]_-]*)[[:space:]]*$/\1/p' \
'$(pwd)/packages.txt' | paru -S --needed -
" || { printf 'Failed to install AUR packages!\n'; exit 1; }
;;
9) # Install dotfiles
printf 'Install dotfiles? [Y/n]: '; read -r ans
{ [ "$ans" = 'Y' ] || [ "$ans" = 'y' ] || [ -z "$ans" ]; } && \
{ su --login "$username" -c "$(pwd)/dotfiles-install.sh" || exit 1; }
;;
10) # Build and install nix packages
usermod -a -G nix-users "$username" || exit 1
usermod -s /bin/zsh "$username" || exit 1 # Set user shell
export NIXPKGS_ALLOW_UNFREE=1 # Allow non-free nix packages
su --pty --login "$username" -c 'nix run --impure "${XDG_CONFIG_HOME}/nix/pkgs#profile.switch"' || \
{ printf 'Failed to install nix packages!\n'; exit 1; }
;;
*) step=-1 ;;
esac
printf "Press [Enter] to continue (enter 'q' to quit): "
read -r input; [ "$input" = 'q' ] && exit 1
step=$((step + 1))
done; clear
# Configure user groups
useradd -a -G wheel,audio,video,uucp,disk "$username" || exit 1
# Rootless containers
touch /etc/subuid /etc/subgid
usermod --add-subuids 100000-165535 --add-subgids 100000-165535 "$username" || exit 1
# Copy files to their respective directories
cp -R ./etc/ / || exit 1
cp -R ./bin/ /usr/local/ || exit 1
# Set timezone
./set-timezone.sh || exit 1
# Generate the locales
locale-gen || exit 1
# Enable networking
systemctl enable systemd-resolved.service
systemctl enable systemd-networkd.service
systemctl disable systemd-networkd-wait-online.service
systemctl enable iwd.service
# Enable firewall
systemctl enable nftables.service
# Enable apparmor service
systemctl enable apparmor.service
# Enable bluetooth service
systemctl enable bluetooth.service
# Enable power services
systemctl enable tlp.service
# Enable SSH
systemctl enable sshd.service
# Enable music player daemon (MPD)
su --login "$username" -c 'mkdir -p ~/.local/share/mpd/playlists'
systemctl --user --machine="${username}"'@.host' enable mpd.service
systemctl --user --machine="${username}"'@.host' enable mpd-mpris.service # MPRIS protocol
# Enable Syncthing
systemctl --user --machine="${username}"'@.host' enable syncthing.service
# Enable Emanote
systemctl --user --machine="${username}"'@.host' enable emanote.service
# Enable audio
systemctl --user --machine="${username}"'@.host' enable pipewire.service
systemctl --user --machine="${username}"'@.host' enable wireplumber.service
# Enable automount
systemctl enable autofs.service
# Enable nix
systemctl enable nix-daemon.service
# Enable IPFS
systemctl --user --machine="${username}"'@.host' enable ipfs.service
# Enable GNS3 server
systemctl enable gns3-server@"${username}".service
systemctl enable libvirtd.service
# Enroll secure boot keys and create UEFI executables
./enroll-secureboot-keys.sh