add reinstall and bootloader
This commit is contained in:
parent
1d901448ca
commit
e992772134
216
elf_os.sh
216
elf_os.sh
@ -4,6 +4,16 @@ SCRIPT_DIR="$(cd "$(dirname "$BASH_SOURCE[0]")" && pwd)"
|
|||||||
|
|
||||||
. "$1"
|
. "$1"
|
||||||
|
|
||||||
|
ROOT_PARTITION_MAP=""
|
||||||
|
ROOT_PARTITION_MAP_NAME=""
|
||||||
|
if [[ $ENCRYPT_DISK = "true" ]]
|
||||||
|
then
|
||||||
|
ROOT_PARTITION_MAP="/dev/mapper/cryptelfroot"
|
||||||
|
ROOT_PARTITION_MAP_NAME="cryptelfroot"
|
||||||
|
else
|
||||||
|
ROOT_PARTITION_MAP="${ROOT_PARTITION}"
|
||||||
|
fi
|
||||||
|
|
||||||
function run(){
|
function run(){
|
||||||
echo "[ ] $1"
|
echo "[ ] $1"
|
||||||
echo "# $1" >>install.log
|
echo "# $1" >>install.log
|
||||||
@ -32,64 +42,31 @@ function run-chroot(){
|
|||||||
echo >>install.log
|
echo >>install.log
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "" >install.log
|
function preperations() {
|
||||||
|
|
||||||
if [[ $ENCRYPT_DISK = "true" ]]
|
|
||||||
then
|
|
||||||
|
|
||||||
echo -n "disk encryption password: "
|
|
||||||
read -s PASS
|
|
||||||
echo
|
echo
|
||||||
echo -n "retype password: "
|
echo === preperations
|
||||||
read -s PASSRE
|
|
||||||
echo
|
|
||||||
if [ "$PASS" != "$PASSRE" ]; then
|
|
||||||
echo "password do not match"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -n "password for $USERNAME: "
|
|
||||||
read -s PASS_USER
|
|
||||||
echo
|
|
||||||
echo -n "retype password: "
|
|
||||||
read -s PASSRE_USER
|
|
||||||
echo
|
|
||||||
|
|
||||||
if [ "$PASS_USER" != "$PASSRE_USER" ]; then
|
|
||||||
echo "password do not match"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
echo
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo === setup localisation
|
|
||||||
echo
|
echo
|
||||||
|
|
||||||
run "install git" "pacman -Sy --noconfirm git"
|
run "install git" "pacman -Sy --noconfirm git"
|
||||||
run "enable ntp" "timedatectl set-ntp true"
|
run "enable ntp" "timedatectl set-ntp true"
|
||||||
run "set timezone" "timedatectl set-timezone Europe/Amsterdam"
|
run "set timezone" "timedatectl set-timezone Europe/Amsterdam"
|
||||||
|
}
|
||||||
|
|
||||||
|
function format_disk() {
|
||||||
echo
|
echo
|
||||||
echo === setup partitions
|
echo === format disk
|
||||||
echo
|
echo
|
||||||
|
|
||||||
run "applly partion table" "sfdisk $DISK <$SFDISK_FILE"
|
run "applly partion table" "sfdisk $DISK <$SFDISK_FILE"
|
||||||
run "format boot partition" "mkfs.fat -F 32 ${UEFI_PARTITION}"
|
run "format boot partition" "mkfs.fat -F 32 ${UEFI_PARTITION}"
|
||||||
run "format swap partition" "mkswap ${SWAP_PARTITION}"
|
run "format swap partition" "mkswap ${SWAP_PARTITION}"
|
||||||
ROOT_PARTITION_MAP=""
|
if [[ $ENCRYPT_DISK = "true" ]]; then
|
||||||
if [[ $ENCRYPT_DISK = "true" ]]
|
|
||||||
then
|
|
||||||
ROOT_PARTITION_MAP="/dev/mapper/cryptelfroot"
|
|
||||||
ROOT_PARTITION_MAP_NAME="cryptelfroot"
|
|
||||||
echo -n "$PASS" >keyfile.luks
|
echo -n "$PASS" >keyfile.luks
|
||||||
run "encrypt root partition" "cryptsetup luksFormat --batch-mode --key-file keyfile.luks ${ROOT_PARTITION}" "rm keyfile.luks"
|
run "encrypt root partition" "cryptsetup luksFormat --batch-mode --key-file keyfile.luks ${ROOT_PARTITION}" "rm keyfile.luks"
|
||||||
run "map root partitaion" "cryptsetup open --batch-mode --key-file keyfile.luks ${ROOT_PARTITION} ${ROOT_PARTITION_MAP_NAME}" "rm keyfile.luks"
|
run "map root partitaion" "cryptsetup open --batch-mode --key-file keyfile.luks ${ROOT_PARTITION} ${ROOT_PARTITION_MAP_NAME}" "rm keyfile.luks"
|
||||||
rm keyfile.luks
|
rm keyfile.luks
|
||||||
run "format root partition" "mkfs.btrfs ${ROOT_PARTITION_MAP}"
|
run "format root partition" "mkfs.btrfs ${ROOT_PARTITION_MAP}"
|
||||||
else
|
else
|
||||||
ROOT_PARTITION_MAP="${ROOT_PARTITION}"
|
|
||||||
run "format root partition" "mkfs.btrfs ${ROOT_PARTITION}"
|
run "format root partition" "mkfs.btrfs ${ROOT_PARTITION}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -99,12 +76,38 @@ run "create root btrfs subvolume" "btrfs subvolume create /mnt/@elfRoot_b"
|
|||||||
run "create home btrfs subvolume" "btrfs subvolume create /mnt/@home"
|
run "create home btrfs subvolume" "btrfs subvolume create /mnt/@home"
|
||||||
run "create home btrfs subvolume" "btrfs subvolume create /mnt/@var"
|
run "create home btrfs subvolume" "btrfs subvolume create /mnt/@var"
|
||||||
run "unmount btrfs" "umount /mnt"
|
run "unmount btrfs" "umount /mnt"
|
||||||
run "mount root subvolume" "mount -o subvol=@elfRoot_a ${ROOT_PARTITION_MAP} /mnt"
|
if [[ $ENCRYPT_DISK = "true" ]]; then
|
||||||
|
run "unmap root partitaion" "cryptsetup close ${ROOT_PARTITION_MAP_NAME}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function mount_disk() {
|
||||||
|
subvol="@elfRoot_$1"
|
||||||
|
echo
|
||||||
|
echo === mount disk with subvol $1
|
||||||
|
echo
|
||||||
|
|
||||||
|
if [[ $ENCRYPT_DISK = "true" ]]; then
|
||||||
|
run "map root partitaion" "cryptsetup open --batch-mode --key-file keyfile.luks ${ROOT_PARTITION} ${ROOT_PARTITION_MAP_NAME}"
|
||||||
|
fi
|
||||||
|
run "mount root subvolume" "mount -o subvol=$subvol ${ROOT_PARTITION_MAP} /mnt"
|
||||||
run "mount home subvolume" "mount --mkdir -o subvol=@home ${ROOT_PARTITION_MAP} /mnt/home"
|
run "mount home subvolume" "mount --mkdir -o subvol=@home ${ROOT_PARTITION_MAP} /mnt/home"
|
||||||
run "mount home subvolume" "mount --mkdir -o subvol=@var ${ROOT_PARTITION_MAP} /mnt/var"
|
run "mount home subvolume" "mount --mkdir -o subvol=@var ${ROOT_PARTITION_MAP} /mnt/var"
|
||||||
run "mount boot partition" "mount --mkdir ${UEFI_PARTITION} /mnt/boot"
|
run "mount boot partition" "mount --mkdir ${UEFI_PARTITION} /mnt/boot"
|
||||||
run "enable swap" "swapon ${SWAP_PARTITION}"
|
run "enable swap" "swapon ${SWAP_PARTITION}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function umount_disk() {
|
||||||
|
echo
|
||||||
|
echo === mount disk
|
||||||
|
echo
|
||||||
|
|
||||||
|
run "mount root subvolume" "umount -R /mnt"
|
||||||
|
run "unmap root partitaion" "cryptsetup close ${ROOT_PARTITION_MAP_NAME}"
|
||||||
|
run "enable swap" "swapoff ${SWAP_PARTITION}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_base() {
|
||||||
echo
|
echo
|
||||||
echo === install arch
|
echo === install arch
|
||||||
echo
|
echo
|
||||||
@ -113,7 +116,9 @@ run "install base of arch" "pacstrap /mnt base linux linux-firmware"
|
|||||||
run "intall utitlities" "pacstrap /mnt btrfs-progs man vim sudo"
|
run "intall utitlities" "pacstrap /mnt btrfs-progs man vim sudo"
|
||||||
run "intall networkmanager" "pacstrap /mnt networkmanager"
|
run "intall networkmanager" "pacstrap /mnt networkmanager"
|
||||||
run "generate fstab" "genfstab -U /mnt >>/mnt/etc/fstab"
|
run "generate fstab" "genfstab -U /mnt >>/mnt/etc/fstab"
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_locals() {
|
||||||
echo
|
echo
|
||||||
echo === set locals
|
echo === set locals
|
||||||
echo
|
echo
|
||||||
@ -130,7 +135,9 @@ run-chroot "create hosts file" "cat >/etc/hosts <<EOF
|
|||||||
127.0.1.1 $HOSTNAME
|
127.0.1.1 $HOSTNAME
|
||||||
EOF
|
EOF
|
||||||
"
|
"
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_bootloader() {
|
||||||
echo
|
echo
|
||||||
echo === install bootloader
|
echo === install bootloader
|
||||||
echo
|
echo
|
||||||
@ -146,14 +153,12 @@ BOAT_LOADER_OPTIONS_A="cryptdevice=UUID=${DISKUUID}:${ROOT_PARTITION_MAP_NAME}:a
|
|||||||
fi
|
fi
|
||||||
BOAT_LOADER_OPTIONS_A="${BOAT_LOADER_OPTIONS_A}root=${ROOT_PARTITION_MAP} "
|
BOAT_LOADER_OPTIONS_A="${BOAT_LOADER_OPTIONS_A}root=${ROOT_PARTITION_MAP} "
|
||||||
BOAT_LOADER_OPTIONS_A="${BOAT_LOADER_OPTIONS_A}rootflags=subvol=@elfRoot_a "
|
BOAT_LOADER_OPTIONS_A="${BOAT_LOADER_OPTIONS_A}rootflags=subvol=@elfRoot_a "
|
||||||
BOAT_LOADER_OPTIONS_B="${BOAT_LOADER_OPTIONS_A}rootflags=subvol=@elfRoot_b "
|
|
||||||
if [[ $ENCRYPT_DISK = "true" ]]
|
if [[ $ENCRYPT_DISK = "true" ]]
|
||||||
then
|
then
|
||||||
BOAT_LOADER_OPTIONS_A="${BOAT_LOADER_OPTIONS_A}rd.luks.options=discard "
|
BOAT_LOADER_OPTIONS_A="${BOAT_LOADER_OPTIONS_A}rd.luks.options=discard "
|
||||||
BOAT_LOADER_OPTIONS_B="${BOAT_LOADER_OPTIONS_B}rd.luks.options=discard "
|
|
||||||
fi
|
fi
|
||||||
BOAT_LOADER_OPTIONS_A="${BOAT_LOADER_OPTIONS_A}rw"
|
BOAT_LOADER_OPTIONS_A="${BOAT_LOADER_OPTIONS_A}rw"
|
||||||
BOAT_LOADER_OPTIONS_B="${BOAT_LOADER_OPTIONS_B}rw"
|
BOAT_LOADER_OPTIONS_B="$(echo ${BOAT_LOADER_OPTIONS_A} | sed -e 's/@elfRoot_a/@elfRoot_b/g')"
|
||||||
run-chroot "install systemd-boot" "bootctl install"
|
run-chroot "install systemd-boot" "bootctl install"
|
||||||
run-chroot "create boot config A" "cat >/boot/loader/entries/elfA.conf <<EOF
|
run-chroot "create boot config A" "cat >/boot/loader/entries/elfA.conf <<EOF
|
||||||
title E.L.F. OS (A)
|
title E.L.F. OS (A)
|
||||||
@ -176,7 +181,9 @@ console-mode max
|
|||||||
editor no
|
editor no
|
||||||
EOF
|
EOF
|
||||||
"
|
"
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_user() {
|
||||||
echo
|
echo
|
||||||
echo === setup user
|
echo === setup user
|
||||||
echo
|
echo
|
||||||
@ -188,13 +195,17 @@ arch-chroot /mnt bash -c "echo \"${USERNAME}:${PASS_USER}\" | chpasswd" # don't
|
|||||||
run-chroot "add user to sudoers" "echo \"%admin ALL=(ALL:ALL) ALL\" >>/etc/sudoers"
|
run-chroot "add user to sudoers" "echo \"%admin ALL=(ALL:ALL) ALL\" >>/etc/sudoers"
|
||||||
run "clone keys repo" "git clone https://gitea.finnvanreenen.nl/LailaTheElf/keys.git /mnt/opt/keys"
|
run "clone keys repo" "git clone https://gitea.finnvanreenen.nl/LailaTheElf/keys.git /mnt/opt/keys"
|
||||||
run-chroot "create authoized keys" "cd /opt/keys/ssh && cat ${USER_SSH_KEYS} > /home/${USERNAME}/.ssh/authorized_keys"
|
run-chroot "create authoized keys" "cd /opt/keys/ssh && cat ${USER_SSH_KEYS} > /home/${USERNAME}/.ssh/authorized_keys"
|
||||||
|
}
|
||||||
|
|
||||||
|
function miscellaneous() {
|
||||||
echo
|
echo
|
||||||
echo === miscellaneous
|
echo === miscellaneous
|
||||||
echo
|
echo
|
||||||
|
|
||||||
run "set udev rules" "cp $SCRIPT_DIR/configs/udev/*.rules /mnt/etc/udev.d/rules/"
|
run "set udev rules" "cp $SCRIPT_DIR/configs/udev/*.rules /mnt/etc/udev.d/rules/"
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepair_firt_boot() {
|
||||||
echo
|
echo
|
||||||
echo === prepair first boot
|
echo === prepair first boot
|
||||||
echo
|
echo
|
||||||
@ -226,11 +237,124 @@ EOF
|
|||||||
run-chroot "enable first boot service" "systemctl enable first_boot.service"
|
run-chroot "enable first boot service" "systemctl enable first_boot.service"
|
||||||
run "make elfOS log dir" "mkdir /mnt/var/log/elfOS && chmod 700 /mnt/var/log/elfOS"
|
run "make elfOS log dir" "mkdir /mnt/var/log/elfOS && chmod 700 /mnt/var/log/elfOS"
|
||||||
run "copy install log to disk" "cp $SCRIPT_DIR/install.log /mnt/var/log/elfOS/install.log && chmod 700 /mnt/var/log/elfOS/install.log"
|
run "copy install log to disk" "cp $SCRIPT_DIR/install.log /mnt/var/log/elfOS/install.log && chmod 700 /mnt/var/log/elfOS/install.log"
|
||||||
|
}
|
||||||
|
|
||||||
|
function copy_a_to_b() {
|
||||||
|
if [[ $ENCRYPT_DISK = "true" ]]; then
|
||||||
|
run "map root partitaion" "cryptsetup open --batch-mode --key-file keyfile.luks ${ROOT_PARTITION} ${ROOT_PARTITION_MAP_NAME}"
|
||||||
|
fi
|
||||||
|
run "mount disk" "mount ${ROOT_PARTITION_MAP} /mnt"
|
||||||
|
run "copy a to b" "cp -R /mnt/@elfRoot_a /mnt/@elfRoot_b"
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "" >install.log
|
||||||
|
|
||||||
|
case $2 in
|
||||||
|
install)
|
||||||
|
if [[ $ENCRYPT_DISK = "true" ]]
|
||||||
|
then
|
||||||
|
echo -n "disk encryption password: "
|
||||||
|
read -s PASS
|
||||||
echo
|
echo
|
||||||
echo === umount and reboot
|
echo -n "retype password: "
|
||||||
|
read -s PASSRE
|
||||||
|
echo
|
||||||
|
if [ "$PASS" != "$PASSRE" ]; then
|
||||||
|
echo "password do not match"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -n "password for $USERNAME: "
|
||||||
|
read -s PASS_USER
|
||||||
|
echo
|
||||||
|
echo -n "retype password: "
|
||||||
|
read -s PASSRE_USER
|
||||||
|
echo
|
||||||
|
|
||||||
|
if [ "$PASS_USER" != "$PASSRE_USER" ]; then
|
||||||
|
echo "password do not match"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -n "are you sure you want to format ${DISK} (y/N): "
|
||||||
|
read -s confirm
|
||||||
|
echo
|
||||||
|
if [ "$confirm" != "y" ]; then
|
||||||
|
echo "exit"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
preperations
|
||||||
|
format_disk
|
||||||
|
mount_disk a
|
||||||
|
install_base
|
||||||
|
set_locals
|
||||||
|
install_bootloader
|
||||||
|
create_user
|
||||||
|
miscellaneous
|
||||||
|
prepair_firt_boot
|
||||||
|
umount_disk
|
||||||
|
copy_a_to_b
|
||||||
|
;;
|
||||||
|
reinstall_*)
|
||||||
|
if [[ $ENCRYPT_DISK = "true" ]]; then
|
||||||
|
echo -n "disk encryption password: "
|
||||||
|
read -s PASS
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -n "password for $USERNAME: "
|
||||||
|
read -s PASS_USER
|
||||||
|
echo
|
||||||
|
echo -n "retype password: "
|
||||||
|
read -s PASSRE_USER
|
||||||
|
echo
|
||||||
|
if [ "$PASS_USER" != "$PASSRE_USER" ]; then
|
||||||
|
echo "password do not match"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
|
||||||
|
preperations
|
||||||
|
if [[ "$2" = "reinstall_a"]]; then
|
||||||
|
mount_disk a
|
||||||
|
else
|
||||||
|
mount_disk b
|
||||||
|
fi
|
||||||
|
install_base
|
||||||
|
set_locals
|
||||||
|
install_bootloader
|
||||||
|
create_user
|
||||||
|
miscellaneous
|
||||||
|
prepair_firt_boot
|
||||||
|
umount_disk
|
||||||
|
;;
|
||||||
|
bootloader)
|
||||||
|
if [[ $ENCRYPT_DISK = "true" ]]; then
|
||||||
|
echo -n "disk encryption password: "
|
||||||
|
read -s PASS
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
preperations
|
||||||
|
mount_disk a
|
||||||
|
install_bootloader
|
||||||
|
umount_disk
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "$0 <config_file> <action>"
|
||||||
|
echo
|
||||||
|
echo "action:"
|
||||||
|
echo " install: install the full os"
|
||||||
|
echo " reinstall_a: re install os on system A"
|
||||||
|
echo " reinstall_b: re install os on system B"
|
||||||
|
echo " bootloader: re setup the bootloader"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo === reboot
|
||||||
echo
|
echo
|
||||||
|
|
||||||
run "umount drives" "umount -R /mnt"
|
|
||||||
run "close cryptelfroot" "cryptsetup close cryptelfroot"
|
|
||||||
run "reboot" "shutdown -r now"
|
run "reboot" "shutdown -r now"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user