pika-installer-gtk4/data/scripts/automatic-partition-install.sh

131 lines
6.1 KiB
Bash
Raw Normal View History

2024-01-22 18:14:41 +01:00
#! /bin/bash
2024-02-18 20:36:24 +01:00
export LANG=en_US.UTF8
2024-01-22 20:09:13 +01:00
set -e
2024-02-19 18:44:10 +01:00
S_DISK="$(cat "/tmp/pika-installer-gtk4-target-auto.txt")"
S_LOCALE="$(cat "/tmp/pika-installer-gtk4-lang.txt")"
S_KEYBOARD="$(cat "/tmp/pika-installer-gtk4-keyboard.txt")"
S_TIMEZONE="$(cat "/tmp/pika-installer-gtk4-timezone.txt")"
2024-01-22 18:14:41 +01:00
p3_size=$(echo "scale=2 ; $(cat /tmp/pika-installer-p3-size.txt) / 1024 / 1024" | bc | cut -f1 -d".")
2024-01-23 15:19:10 +01:00
touch "/tmp/pika-installer-gtk4-status-parting.txt"
2024-01-22 18:14:41 +01:00
2024-01-22 18:57:18 +01:00
if [[ ! -f "/tmp/pika-installer-gtk4-target-automatic-luks.txt" ]]
2024-01-22 18:14:41 +01:00
then
2024-02-19 18:44:10 +01:00
for part in $(sudo /usr/lib/pika/pika-installer-gtk4/scripts/partition-utility.sh get_partitions | grep ${S_DISK}); do
PARTITION="/dev/$part"
sudo swapoff $PARTITION || true
done
2024-02-19 18:44:10 +01:00
wipefs -af /dev/${S_DISK}
2024-01-22 18:57:18 +01:00
# Partition the drives
2024-02-19 18:44:10 +01:00
parted -s -a optimal /dev/${S_DISK} mklabel gpt \
2024-01-22 18:57:18 +01:00
mkpart "linux-efi" 1MiB 513Mib \
mkpart "linux-boot" 513Mib 1537Mib \
2024-01-30 15:40:27 +01:00
mkpart "linux-root" 1537Mib "$p3_size"Mib \
mkpart "linux-home" "$p3_size"Mib 100% \
2024-01-22 18:14:41 +01:00
print
2024-01-22 18:57:18 +01:00
# add p to partition if it's nvme
2024-02-19 18:44:10 +01:00
if echo ${S_DISK} | grep -i "nvme"
2024-01-22 18:14:41 +01:00
then
2024-01-23 15:19:10 +01:00
#
2024-01-23 16:32:24 +01:00
sleep 10
2024-01-22 18:57:18 +01:00
# Add filesystems
2024-02-19 18:44:10 +01:00
yes | mkfs -t vfat -F 32 /dev/${S_DISK}p1
yes | mkfs -t ext4 /dev/${S_DISK}p2
yes | mkfs.btrfs -f /dev/${S_DISK}p3
yes | mkfs.btrfs -f /dev/${S_DISK}p4
2024-01-23 15:19:10 +01:00
sleep 2
2024-01-22 18:57:18 +01:00
# Begin Mounting
2024-01-22 18:14:41 +01:00
mkdir -p /media/pika-install-mount
2024-02-19 18:44:10 +01:00
mount /dev/${S_DISK}p3 /media/pika-install-mount/
2024-01-22 18:14:41 +01:00
mkdir -p /media/pika-install-mount/home
2024-02-19 18:44:10 +01:00
mount /dev/${S_DISK}p4 /media/pika-install-mount/home
2024-01-22 18:14:41 +01:00
mkdir -p /media/pika-install-mount/boot
2024-02-19 18:44:10 +01:00
mount /dev/${S_DISK}p2 /media/pika-install-mount/boot
2024-01-22 18:14:41 +01:00
mkdir -p /media/pika-install-mount/boot/efi
2024-02-19 18:44:10 +01:00
mount /dev/${S_DISK}p1 /media/pika-install-mount/boot/efi
pikainstall -r /media/pika-install-mount/ -l ${S_LOCALE} -k ${S_KEYBOARD} -t ${S_TIMEZONE} && touch /tmp/pika-installer-gtk4-successful.txt || touch /tmp/pika-installer-gtk4-fail.txt && exit 1
2024-01-22 18:14:41 +01:00
else
2024-01-23 16:32:24 +01:00
sleep 10
2024-01-22 18:57:18 +01:00
# Add filesystems
2024-02-19 18:44:10 +01:00
yes | mkfs -t vfat -F 32 /dev/${S_DISK}1
yes | mkfs -t ext4 /dev/${S_DISK}2
yes | mkfs.btrfs -f /dev/${S_DISK}3
yes | mkfs.btrfs -f /dev/${S_DISK}4
2024-01-23 15:19:10 +01:00
sleep 2
2024-01-22 18:57:18 +01:00
# Begin Mounting
2024-01-22 18:14:41 +01:00
mkdir -p /media/pika-install-mount
2024-02-19 18:44:10 +01:00
mount /dev/${S_DISK}3 /media/pika-install-mount/
2024-01-22 18:14:41 +01:00
mkdir -p /media/pika-install-mount/home
2024-02-19 18:44:10 +01:00
mount /dev/${S_DISK}4 /media/pika-install-mount/home
2024-01-22 18:14:41 +01:00
mkdir -p /media/pika-install-mount/boot
2024-02-19 18:44:10 +01:00
mount /dev/${S_DISK}2 /media/pika-install-mount/boot
2024-01-22 18:14:41 +01:00
mkdir -p /media/pika-install-mount/boot/efi
2024-02-19 18:44:10 +01:00
mount /dev/${S_DISK}1 /media/pika-install-mount/boot/efi
pikainstall -r /media/pika-install-mount/ -l ${S_LOCALE} -k ${S_KEYBOARD} -t ${S_TIMEZONE} && touch /tmp/pika-installer-gtk4-successful.txt || touch /tmp/pika-installer-gtk4-fail.txt && exit 1
2024-01-22 18:14:41 +01:00
fi
else
2024-02-19 18:44:10 +01:00
S_LUKS_KEY="$(cat "/tmp/pika-installer-gtk4-target-automatic-luks.txt")"
for part in $(sudo /usr/lib/pika/pika-installer-gtk4/scripts/partition-utility.sh get_partitions | grep ${S_DISK}); do
PARTITION="/dev/$part"
sudo swapoff $PARTITION || true
done
2024-02-19 18:44:10 +01:00
wipefs -af /dev/${S_DISK}
2024-01-22 20:32:48 +01:00
# Partition the drives
2024-02-19 18:44:10 +01:00
parted -s -a optimal /dev/${S_DISK} mklabel gpt \
2024-01-22 20:32:48 +01:00
mkpart "linux-efi" 1MiB 513Mib \
mkpart "linux-boot" 513Mib 1537Mib \
2024-01-30 15:40:27 +01:00
mkpart "linux-root" 1537Mib "$p3_size"Mib \
mkpart "linux-home" "$p3_size"Mib 100% \
2024-01-22 20:32:48 +01:00
print
# add p to partition if it's nvme
2024-02-19 18:44:10 +01:00
if echo ${S_DISK} | grep -i "nvme"
2024-01-22 20:32:48 +01:00
then
2024-01-23 16:32:24 +01:00
sleep 10
2024-01-22 20:32:48 +01:00
# Add filesystems
2024-02-19 18:44:10 +01:00
yes | mkfs -t vfat -F 32 /dev/${S_DISK}p1
yes | mkfs -t ext4 /dev/${S_DISK}p2
printf ${S_LUKS_KEY} | cryptsetup -q -v --type luks2 luksFormat /dev/${S_DISK}p3
printf ${S_LUKS_KEY} | cryptsetup -q -v --type luks2 luksFormat /dev/${S_DISK}p4
printf ${S_LUKS_KEY} | cryptsetup -q -v luksOpen /dev/${S_DISK}p3 crypt_root
printf ${S_LUKS_KEY} | cryptsetup -q -v luksOpen /dev/${S_DISK}p4 crypt_home
2024-01-22 20:32:48 +01:00
yes | mkfs.btrfs -f /dev/mapper/crypt_root
yes | mkfs.btrfs -f /dev/mapper/crypt_home
2024-01-23 15:19:10 +01:00
sleep 2
2024-01-22 20:32:48 +01:00
# Begin Mounting
mkdir -p /media/pika-install-mount
mount /dev/mapper/crypt_root /media/pika-install-mount/
mkdir -p /media/pika-install-mount/home
mount /dev/mapper/crypt_home /media/pika-install-mount/home
mkdir -p /media/pika-install-mount/boot
2024-02-19 18:44:10 +01:00
mount /dev/${S_DISK}p2 /media/pika-install-mount/boot
2024-01-22 20:32:48 +01:00
mkdir -p /media/pika-install-mount/boot/efi
2024-02-19 18:44:10 +01:00
mount /dev/${S_DISK}p1 /media/pika-install-mount/boot/efi
pikainstall -r /media/pika-install-mount/ -c ${S_LUKS_KEY} -l ${S_LOCALE} -k ${S_KEYBOARD} -t ${S_TIMEZONE} && touch /tmp/pika-installer-gtk4-successful.txt || touch /tmp/pika-installer-gtk4-fail.txt && exit 1
2024-01-22 20:32:48 +01:00
else
2024-01-23 16:32:24 +01:00
sleep 10
2024-01-22 20:32:48 +01:00
# Add filesystems
2024-02-19 18:44:10 +01:00
yes | mkfs -t vfat -F 32 /dev/${S_DISK}1
yes | mkfs -t ext4 /dev/${S_DISK}2
printf ${S_LUKS_KEY} | cryptsetup -q -v --type luks2 luksFormat /dev/${S_DISK}3
printf ${S_LUKS_KEY} | cryptsetup -q -v --type luks2 luksFormat /dev/${S_DISK}4
printf ${S_LUKS_KEY} | cryptsetup -q -v luksOpen /dev/${S_DISK}3 crypt_root
printf ${S_LUKS_KEY} | cryptsetup -q -v luksOpen /dev/${S_DISK}4 crypt_home
2024-01-22 20:32:48 +01:00
yes | mkfs.btrfs -f /dev/mapper/crypt_root
yes | mkfs.btrfs -f /dev/mapper/crypt_home
2024-01-23 15:19:10 +01:00
sleep 2
2024-01-22 20:32:48 +01:00
# Begin Mounting
mkdir -p /media/pika-install-mount
mount /dev/mapper/crypt_root /media/pika-install-mount/
mkdir -p /media/pika-install-mount/home
mount /dev/mapper/crypt_home /media/pika-install-mount/home
mkdir -p /media/pika-install-mount/boot
2024-02-19 18:44:10 +01:00
mount /dev/${S_DISK}2 /media/pika-install-mount/boot
2024-01-22 20:32:48 +01:00
mkdir -p /media/pika-install-mount/boot/efi
2024-02-19 18:44:10 +01:00
mount /dev/${S_DISK}1 /media/pika-install-mount/boot/efi
pikainstall -r /media/pika-install-mount/ -c ${S_LUKS_KEY} -l ${S_LOCALE} -k ${S_KEYBOARD} -t ${S_TIMEZONE} && touch /tmp/pika-installer-gtk4-successful.txt || touch /tmp/pika-installer-gtk4-fail.txt && exit 1
2024-01-22 20:32:48 +01:00
fi
2024-01-22 18:14:41 +01:00
fi