-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfinish_install.sh
More file actions
176 lines (148 loc) · 5.99 KB
/
finish_install.sh
File metadata and controls
176 lines (148 loc) · 5.99 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
#!/bin/bash
#
# finish_install.sh - part of the MiniArch project
# Copyright (C) 2024-2025, JustScott, development@justscott.me
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
source /activate_installation_variables.sh
source /shared_lib
STDOUT_LOG_PATH="/dev/null"
STDERR_LOG_PATH="/miniarcherrors.log"
INSTALLATION_VARIABLES_FILE=/activate_installation_variables.sh
#---------------- System Configuration ----------------
{
{
echo "$system_name" > /etc/hostname
echo -e '127.0.0.1 localhost\n::1 localhost\n127.0.1.1 '"$system_name" >> /etc/hosts
} >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Set system name: '$system_name'"
[[ $? -ne 0 ]] && exit 1
}
#---------------- User Configuration ----------------
{
{
useradd -G wheel,audio,video,storage -m "$username"
if [[ -n "$user_password" ]]
then
echo "$username":"$user_password" | chpasswd
else
passwd -d "$username"
fi
chmod u+w /etc/sudoers
echo '%wheel ALL=(ALL:ALL) ALL' >> /etc/sudoers
chmod u-w /etc/sudoers
} >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Set up user: '$username'"
[[ $? -ne 0 ]] && exit 1
}
#---------------- System Settings & Packages ----------------
{
{
# Set the keyboard orientation
echo $user_locale >> /etc/locale.gen
export LANG="$(echo $user_locale | awk '{print $1}')"
echo "LANG=$LANG" > /etc/locale.conf
locale-gen
} >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Configure locale: '$user_locale'"
[[ $? -ne 0 ]] && exit 1
if [[ -n "$user_timezone" ]]
then
ln -sf /usr/share/zoneinfo/$user_timezone /etc/localtime >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Set timezone: '$user_timezone'"
[[ $? -ne 0 ]] && exit 1
fi
}
#---------------- Swap File Configuration ----------------
{
case $filesystem in
'ext4')
{
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
echo '/swapfile none swap 0 0' >> /etc/fstab
} >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Create & configure swapfile for the '$filesystem' filesystem"
[[ $? -ne 0 ]] && exit 1
;;
'btrfs')
{
btrfs subvolume create /swap
btrfs filesystem mkswapfile --size 2g --uuid clear /swap/swapfile
swapon /swap/swapfile
echo '/swap/swapfile none swap defaults 0 0' >> /etc/fstab
} >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Create & configure swapfile for the '$filesystem' filesystem"
[[ $? -ne 0 ]] && exit 1
;;
esac
}
#---------------- Grub Configuration ----------------
{
{
if [[ "$encrypt_system" == true ]]; then
root_partition_UUID="$( \
blkid "$root_partition" \
| awk -F'UUID="' '{print $2}' \
| awk -F'"' '{print $1}')"
if [[ -z "$root_partition_UUID" ]]
then
printf "\e[31m%s\e[0m" "Failed to get root partition UUID. This shouldn't happen. Stopping"
exit 1
fi
# Encryption configuration
echo "GRUB_CMDLINE_LINUX='cryptdevice=UUID=${root_partition_UUID}:cryptdisk'" >> /etc/default/grub
echo -e 'MODULES=()\nBINARIES=()\nFiles=()\nHOOKS=(base udev microcode autodetect modconf block encrypt filesystems keyboard fsck)' > /etc/mkinitcpio.conf
fi
echo -e '\nGRUB_DISABLE_OS_PROBER=false\nGRUB_SAVEDEFAULT=true\nGRUB_DEFAULT=saved' >> /etc/default/grub
} >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Configure Grub (with encryption if chosen)"
[[ $? -ne 0 ]] && exit 1
}
#---------------- Cleanup & Prepare ----------------
{
# Temporary fix to mkinitcpio error ('file not found: /etc/vconsole.conf')
if ! [[ -f "/etc/vconsole.conf" ]]
then
touch /etc/vconsole.conf &>/dev/null
fi
mkinitcpio --allpresets >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Generate initial ramdisk environment"
[[ $? -ne 0 ]] && exit 1
if [[ $uefi_enabled == true ]]
then
grub-install --efi-directory=/boot $removable_flag \
>>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "EFI Grub Install"
[[ $? -ne 0 ]] && exit 1
else
grub-install $boot_partition \
>>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Non-EFI Grub Install"
[[ $? -ne 0 ]] && exit 1
fi
grub-mkconfig -o /boot/grub/grub.cfg \
>>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Make grub config"
[[ $? -ne 0 ]] && exit 1
{
systemctl enable NetworkManager
rm /finish_install.sh
shred -zu $INSTALLATION_VARIABLES_FILE "$STDERR_LOG_PATH"
} >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Enable systemd services & delete temporary MiniArch files"
[[ $? -ne 0 ]] && exit 1
}
exit 0