Files
ZFSBootMenu-Root-Install/install.sh

212 lines
3.8 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
baseDir="$(dirname "${0}" | sed "s|^\.|${PWD}|")"
printf \
'\033[?47l\012'
cat << EOF
#######################################
## ##
## $(cat "${baseDir}/title") Script ##
## ##
## Jean <jean@easthighnerd.net> ##
## ##
#######################################
###############
## ##
## Install ##
## ##
###############
EOF
source \
/etc/os-release
source \
"${baseDir}/system.conf"
if [[ ! "${disk}" == **/dev/disk/by-id/** ]]; then
if [[ "${disk}" == **/dev/nvme** ]]; then
part2='p2'
else
part2='2'
fi
else
part2='-part2'
fi
if [[ ! -f "/etc/mtab" ]]; then
"${baseDir}/mtab.sh"
fi
if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then
apt \
update
fi
if [[ "${ID}" == 'fedora' ]]; then
if [[ "${encryption}" == 'yes' ]]; then
cat << EOF | tee /etc/dracut.conf.d/zol.conf &> /dev/null
nofsck="yes"
add_dracutmodules+=" zfs "
omit_dracutmodules+=" btrfs "
install_items+=" /etc/zfs/keys/${hostname,,}.key "
EOF
else
cat <<EOF >/etc/dracut.conf.d/zol.conf
nofsck="yes"
add_dracutmodules+=" zfs "
omit_dracutmodules+=" btrfs "
EOF
fi
if [[ "${VERSION_ID}" -lt '41' ]]; then
dnf \
config-manager \
--disable \
updates
else
dnf \
config-manager \
setopt \
updates.enabled=0
fi
dnf \
install \
-y \
https://dl.fedoraproject.org/pub/fedora/linux/releases/${VERSION_ID}/Everything/x86_64/os/Packages/k/kernel-devel-$(uname -r).rpm
dnf \
--releasever=${VERSION_ID} \
install \
-y \
https://zfsonlinux.org/fedora/zfs-release-${ZOL_FEDORA_VER}$(rpm --eval "%{dist}").noarch.rpm
dnf \
install \
-y \
zfs \
zfs-dracut
if [[ "${VERSION_ID}" -lt '41' ]]; then
dnf \
config-manager \
--enable \
updates
else
dnf \
config-manager \
setopt \
updates.enabled=1
fi
fi
if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then
"${baseDir}/debian.sh" --dpkg-reconfigure
fi
# if [[ "${ID}" == 'debian' ]]; then
# printf \
# 'REMAKE_INITRD=yes\n' | \
# tee /etc/dkms/zfs.conf &> /dev/null
# fi
if [[ ! "${*}" = *--no-part* ]]; then
"${baseDir}/partition.sh" --efi
fi
if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then
"${baseDir}/debian.sh" --purge-os-prober
fi
if [[ "${ID}" == 'elementary' ]]; then
"${baseDir}/elementary.sh" --purge
"${baseDir}/elementary.sh" --apps
fi
printf \
'\033[?47h\033[2J\033[H'
cat << EOF
Enter a password for the root account:
EOF
passwd
printf \
'\033[?47l'
if [[ "${enableSwap}" == "yes" ]]; then
printf \
"swap\t${disk}${part2}\t/dev/random\tswap,cipher=aes-xts-plain64,size=512\n" | \
tee /etc/crypttab &> /dev/null
printf \
'dev/mapper/swap\tnone\tswap\tsw\t0\t0\n' | \
tee --append /etc/fstab &> /dev/null
fi
if [[ "${ID}" == 'debian' ]]; then
"${baseDir}/debian.sh" --network-manager
fi
if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then
printf \
"UMASK=0077\n" | \
tee /etc/initramfs-tools/conf.d/umask.conf &> /dev/null
update-initramfs \
-c \
-k all
elif [[ "${ID}" == 'fedora' ]]; then
dracut \
--force \
--regenerate-all
fi
zfs \
set \
org.zfsbootmenu:commandline='quiet splash rhgb noresume' \
${hostname,,}/ROOT/${ID}
if [[ ! "${*}" = *--no-part* ]]; then
if [[ ! -z "$(zfs list | grep 'keystore')" ]]; then
zfs \
set \
org.zfsbootmenu:keysource=${hostname,,}/keystore \
${hostname,,}
fi
fi
if [[ ! "${*}" = *--no-part* ]]; then
"${baseDir}/efi.sh"
fi
if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then
systemctl \
enable \
zfs.target
systemctl \
enable \
zfs-import-cache
systemctl \
enable \
zfs-mount
systemctl \
enable \
zfs-import.target
fi
zfs \
snapshot \
${hostname,,}/ROOT/${ID}@install
"${baseDir}/post-inst.sh"