Files
ZFSBootMenu-Root-Install/post-inst.sh

157 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
baseDir="$(realpath "$(dirname "${0}")")"
source \
/etc/os-release
source \
"${baseDir}/system.conf"
printf \
'\033[?47l\012'
cat << EOF
#######################################
## ##
## $(cat "${baseDir}/title") Script ##
## ##
## Jean <jean@easthighnerd.net> ##
## ##
#######################################
####################
## ##
## Post ##
## Installation ##
## ##
####################
EOF
source \
/etc/os-release
source \
"${baseDir}/system.conf"
# if [[ ! "${*}" = *--no-part* ]]; then
zfs create\
${hostname,,}/home/${username}
zfs create\
${hostname,,}/home/${username}/.config
zfs create\
-o canmount=off\
${hostname,,}/home/${username}/.var
zfs create\
${hostname,,}/home/${username}/.var/app
zfs create\
-o canmount=off\
${hostname,,}/home/${username}/.local
zfs create\
-o canmount=off\
${hostname,,}/home/${username}/.local/share
zfs create\
${hostname,,}/home/${username}/.local/share/flatpak
printf \
'Adding user account...\n'
adduser ${username}
# else
# adduser --no-create-home ${username}
# fi
"${baseDir}/adduser.sh"
if [[ "${ID}" == 'elementary' ]]; then
"${baseDir}/namarupa.sh"
elif [[ "${ID}" == 'debian' ]]; then
"${baseDir}/debian.sh" --contrib
fi
if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then
apt \
--update \
dist-upgrade \
--yes
fi
if [[ "${ID}" = 'debian' ]]; then
"${baseDir}/debian.sh" --tasksel
fi
if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then
for file in /etc/logrotate.d/* ; do
if grep -Eq "(^|[^#y])compress" "$file" ; then
sed -i -r "s/(^|[^#y])(compress)/\1#\2/" "$file"
fi
done
cat << EOF | tee /usr/bin/zfs-system-snapshot-apt &> /dev/null
#!/bin/bash
set -euo pipefail
TIMESTAMP="\$(date +%Y_%m_%d-%H_%M_%S)"
if [[ -z "\$(zfs list -t snapshot | grep 'apt-\${TIMESTAMP}')" ]]; then
zfs snapshot \$(zfs mount | grep 'ROOT' | sed 's| .*||')@apt-\${TIMESTAMP} && printf "\n- Snapshot taken\n\n"
fi
EOF
chmod \
+x \
/usr/bin/zfs-system-snapshot-apt
printf \
'DPkg::Pre-Install-Pkgs {"/usr/bin/zfs-system-snapshot-apt";};\n' | \
tee /etc/apt/apt.conf.d/90-zfs_system-snapshot &> /dev/null
printf \
'DPkg::Post-Invoke {"apt moo";};\n' | \
tee /etc/apt/apt.conf.d/99-apt_moo &> /dev/null
fi
# if [[ ! "${*}" = *--no-part* ]]; then
"${baseDir}/home-fix-setup.sh"
# fi
if [[ ! -f '/usr/bin/shutdown' ]]; then
ln -s /sbin/shutdown /usr/bin/shutdown
fi
if [[ ! -f '/usr/bin/reboot' ]]; then
ln -s /sbin/reboot /usr/bin/reboot
fi
zfs \
snapshot \
${hostname,,}/ROOT/${ID}@post-install
printf \
'\033[?47h\033[2J\033[H'
cat << EOF
Script has finished running
Please exit the chroot
Press any key to return to the main menu
EOF
read -srn 1