forked from Cambria-Linux/cambria
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
313 lines (254 loc) · 8.24 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
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#!/bin/bash
# Exit on error
set -e
#===================================================
# Cambria Linux install script
#===================================================
# Create system_install script to allow the usage of 'gum spin'.
cat << EOMF > system_install.sh
#!/usr/bin/env bash
# Mount root partition
mkfs.ext4 -F \$ROOT_PART &>/dev/null
mkdir -p /mnt/gentoo
mount \$ROOT_PART /mnt/gentoo
# Copy stage archive
cp \$FILE /mnt/gentoo
# Extract stage archive
cd /mnt/gentoo
tar xpf \$FILE --xattrs-include='*.*' --numeric-owner
# Mount UEFI partition
mkfs.vfat \$UEFI_PART &>/dev/null
mkdir -p /mnt/gentoo/boot/efi
mount \$UEFI_PART /mnt/gentoo/boot/efi
mkswap \$SWAP_PART
echo "UUID=\$(blkid -o value -s UUID "\$UEFI_PART") /boot/efi vfat defaults 0 2" >>/mnt/gentoo/etc/fstab
echo "UUID=\$(blkid -o value -s UUID "\$ROOT_PART") / \$(lsblk -nrp -o FSTYPE \$ROOT_PART) defaults 1 1" >>/mnt/gentoo/etc/fstab
echo "UUID=\$(blkid -o value -s UUID "\$SWAP_PART") swap swap pri=1 0 0" >>/mnt/gentoo/etc/fstab
# Keymap configuration
echo "KEYMAP=\$KEYMAP" >/mnt/gentoo/etc/vconsole.conf
# Execute installation stuff
mount --types proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/dev
mount --bind /run /mnt/gentoo/run
mount --make-slave /mnt/gentoo/run
cat <<EOF | chroot /mnt/gentoo
grub-install --efi-directory=/boot/efi
grub-mkconfig -o /boot/grub/grub.cfg
systemd-machine-id-setup
useradd -m -G users,wheel,audio,video,input -s /bin/bash \$USERNAME
echo -e "\${USER_PASSWORD}\n\${USER_PASSWORD}" | passwd -q \$USERNAME
echo -e "\${ROOT_PASSWORD}\n\${ROOT_PASSWORD}" | passwd -q
systemctl preset-all --preset-mode=enable-only
EOF
rm /mnt/gentoo/\$(basename \$FILE)
EOMF
chmod +x system_install.sh
exit_() {
echo $1
exit
}
#mount_iso() {
# mkdir -p /mnt/iso
# if [ -b /dev/mapper/ventoy ]; then
# mount /dev/mapper/ventoy /mnt/iso
# elif [ -b /dev/disk/by-label/ISOIMAGE* ]; then
# mount /dev/disk/by-label/ISOIMAGE* /mnt/iso
# fi
#}
installation_mode_selection() {
case $(gum choose "Automatic" "Manual") in
"Automatic") automatic_install;;
"Manual") manual_install;;
esac
}
manual_install() {
stage_selection
clear
disk_selection
cfdisk $DISK
clear
root_part_selection
clear
uefi_part_selection
clear
swap_part_selection
clear
user_account
clear
root_password
clear
config_keymap
clear
}
automatic_install() {
stage_selection
clear
disk_selection
clear
automatic_partitioning
clear
user_account
clear
root_password
clear
config_keymap
clear
}
automatic_partitioning() {
[[ "$DISK" == *"nvme"* ]] && DISK_P="${DISK}p" || DISK_P="$DISK"
echo "Enter SWAP size in Gib:"
echo ""
SWAP_SIZE=$(gum input --placeholder="If not sure set to (CPU_threads*2) - ram_size + 1 only if the result is positive, else set to 1")
gum confirm "All content from $DISK will be loose, continue?" || exit_ "Exiting..."
SFDISK_CONFIG="label: gpt
"
SFDISK_CONFIG+="device: $DISK
"
SFDISK_CONFIG+="${DISK_P}1: size=256M,type=uefi
"
SFDISK_CONFIG+="${DISK_P}2: size=${SWAP_SIZE}G,type=swap
"
SFDISK_CONFIG+="${DISK_P}3: type=linux
"
echo "$SFDISK_CONFIG" | sfdisk --force --no-reread $DISK
UEFI_PART="${DISK_P}1"
SWAP_PART="${DISK_P}2"
ROOT_PART="${DISK_P}3"
}
showkeymap() {
if [ -d /usr/share/kbd/keymaps ]; then
find /usr/share/kbd/keymaps/ -type f -iname "*.map.gz" -printf "%f\n" | sed 's|.map.gz||g' | sed '/include\//d' | sort
else
find /usr/share/keymaps/ -type f -iname "*.map.gz" -printf "%f\n" | sed 's|.map.gz||g' | sed '/include\//d' | sort
fi
}
root_password() {
echo "Root account configuration:"
echo ""
ROOT_PASSWORD=$(gum input --password --placeholder="Enter root password")
}
user_account() {
echo "User account creation: "
echo ""
USERNAME=$(gum input --placeholder="Enter username")
USER_PASSWORD=$(gum input --password --placeholder "Enter $USERNAME's password")
}
stage_selection() {
echo "STAGE SELECTION:"
echo ""
ARCHIVES=/mnt/cdrom/*.tar.xz
if [ "${#ARCHIVES[@]}" == "1" ]; then
FILE=${ARCHIVES[0]}
else
FILE=$(gum choose --header="Select the wanted stage:" ${ARCHIVES[@]})
fi
}
disk_selection() {
echo "Disk selection:"
echo ""
disks=$(lsblk -o NAME,SIZE,MODEL -d -p | grep -v "loop0" | grep -v "sr0" | grep -v "zram0" | tail -n +2)
DISK=$(echo "$disks" | gum choose --header="Select the disk to install Cambria into:" | cut -d ' ' -f 1)
}
root_part_selection() {
parts=$(ls $DISK* | grep "$DISK.*" | tail -n +2)
echo "Root partition selection:"
echo ""
ROOT_PART=$(gum choose --header="Select the root partition: (/)" $parts)
}
uefi_part_selection() {
not_parsed_parts=$(ls $DISK* | grep "$DISK.*" | tail -n +2)
parts=""
for part in $not_parsed_parts; do
[ "$part" != "$ROOT_PART" ] && parts+="$part "
done
echo "UEFI partition selection:"
echo ""
UEFI_PART=$(gum choose --header="Select the efi partiton: (/boot/efi)" $parts)
}
swap_part_selection() {
not_parsed_parts=$(ls $DISK* | grep "$DISK.*" | tail -n +2)
parts=""
for part in $not_parsed_parts; do
[ "$part" != "$ROOT_PART" ] && [ "$part" != "$UEFI_PART" ] && parts+="$part "
done
echo "SWAP partition selection:"
echo ""
SWAP_PART=$(gum choose --header="Select the swap partition:" $parts)
}
config_keymap() {
unset KEYMAP keymappart
echo "Keymap selection:"
echo ""
keymappart=$(showkeymap | gum filter --placeholder="Enter and find your keymap...")
}
echo "========================================================================"
echo " WELCOME ON CAMBRIA LINUX ! "
echo "========================================================================"
echo ""
echo "This script is here to help you install our distro easily. "
echo "Let us guide you step-by-step and you'll have a fully working Gentoo ! "
echo ""
echo "Let's start !"
echo ""
gum confirm "Ready?" || exit_ "See you next time!"
echo ""
installation_mode_selection
gum confirm "Install Cambria on $ROOT_PART from $DISK ? DATA MAY BE LOST!" || exit_ "Installation aborted, exiting."
gum spin -s pulse --show-output --title="Please wait while the script is doing the install for you :D" /usr/bin/env ROOT_PART=$ROOT_PART UEFI_PART=$UEFI_PART KEYMAP=$KEYMAP USERNAME=$USERNAME USER_PASSWORD=$USER_PASSWORD ROOT_PASSWORD=$ROOT_PASSWORD FILE=$FILE SWAP_PART=$SWAP_PART bash ./system_install.sh
clear
# Locale configuration
LOCALE=$(grep "UTF-8" /mnt/gentoo/usr/share/i18n/SUPPORTED | awk '{print $1}' | sed 's/^#//;s/\.UTF-8//' | gum filter --limit 1 --header "Choose your locale:")
echo "$LOCALE.UTF-8 UTF-8" >> /mnt/gentoo/etc/locale.gen
cat <<EOF | chroot /mnt/gentoo
locale-gen
eselect locale set $LOCALE.UTF-8
EOF
# Keymap configuration
xkb_symbols=$(find /mnt/gentoo/usr/share/X11/xkb/symbols -maxdepth 1 -type f)
X11_KEYMAP=$(for file in ${xkb_symbols[@]}; do [ "$(cat $file | grep '// Keyboard layouts')" != "" ] && echo $(basename $file) ; done | sort | gum filter --header "Choose a X11 keymap:")
mkdir -p /mnt/gentoo/etc/X11/xorg.conf.d
cat <<EOF > /mnt/gentoo/etc/X11/xorg.conf.d/00-keyboard.conf
Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
Option "XkbLayout" "$X11_KEYMAP"
EndSection
EOF
# Timezone configuration
unset TIMEZONE location country listloc listc countrypart
for l in /mnt/gentoo/usr/share/zoneinfo/*; do
[ -d $l ] || continue
l=${l##*/}
case $l in
Etc|posix|right) continue;;
esac
listloc="$listloc $l"
done
location=$(echo $listloc | tr ' ' '\n' | gum filter --header "Choose a location:")
for c in /mnt/gentoo/usr/share/zoneinfo/$location/*; do
c=${c##*/}
listc="$listc $c"
done
country=$(echo $listc | tr ' ' '\n' | gum filter --header "Choose a city:")
rm -f /mnt/gentoo/etc/localtime
ln -s /usr/share/zoneinfo/$location/$country /mnt/gentoo/etc/localtime
cp /usr/bin/cambria-center /mnt/gentoo/usr/bin/
mkdir -p /mnt/gentoo/etc/xdg/autostart
cp /etc/xdg/autostart/cambria-center.desktop /mnt/gentoo/etc/xdg/autostart/
# VM Max Map Count
cat <<EOF > /mnt/gentoo/etc/sysctl.conf
vm.max_map_count=1048576
EOF
cat <<EOF | chroot /mnt/gentoo
su $USERNAME -c "cd /home/$USERNAME && LANG=$LOCALE.UTF-8 xdg-user-dirs-update"
EOF
clear
echo "Installation has finished !"
echo "Press R to reboot..."
read REBOOT
if [ "$REBOOT" == "R" ] || [ "$REBOOT" == "r" ]; then
reboot
fi