Moved automatic ZFS snapshot triggered by apt into seperate script. Moved 'logrotate' and 'initramfs' functions into 'debian.sh'

This commit is contained in:
2025-12-31 23:32:29 -05:00
parent 3e7a7a5788
commit 2b1a2f29ee
4 changed files with 60 additions and 57 deletions

28
apt-snapshot.sh Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/bash
set -euo pipefail
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

View File

@@ -178,4 +178,31 @@ elif [[ "${1}" == '--tasksel' ]]; then
tasksel \ tasksel \
--new-install --new-install
elif [[ "${1}" == '--initramfs' ]]; then
printf \
"UMASK=0077\n" | \
tee /etc/initramfs-tools/conf.d/umask.conf &> /dev/null
update-initramfs \
-c \
-k all
elif [[ "${1}" == '--logrotate' ]]; 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
elif [[ "${1}" == '--systemctl-enable' ]]; then
systemctl \
enable \
zfs.target
systemctl \
enable \
zfs-import-cache
systemctl \
enable \
zfs-mount
systemctl \
enable \
zfs-import.target
fi fi

View File

@@ -110,15 +110,7 @@ if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then
"${baseDir}/debian.sh" --dpkg-reconfigure "${baseDir}/debian.sh" --dpkg-reconfigure
fi fi
# if [[ "${ID}" == 'debian' ]]; then "${baseDir}/partition.sh" --efi
# 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 if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then
"${baseDir}/debian.sh" --purge-os-prober "${baseDir}/debian.sh" --purge-os-prober
@@ -160,13 +152,7 @@ if [[ "${ID}" == 'debian' ]]; then
fi fi
if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then
printf \ "${baseDir}/debian.sh" --initramfs
"UMASK=0077\n" | \
tee /etc/initramfs-tools/conf.d/umask.conf &> /dev/null
update-initramfs \
-c \
-k all
elif [[ "${ID}" == 'fedora' ]]; then elif [[ "${ID}" == 'fedora' ]]; then
dracut \ dracut \
--force \ --force \
@@ -192,18 +178,7 @@ if [[ ! "${*}" = *--no-part* ]]; then
fi fi
if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then
systemctl \ "${baseDir}/debian.sh" --systemctl-enable
enable \
zfs.target
systemctl \
enable \
zfs-import-cache
systemctl \
enable \
zfs-mount
systemctl \
enable \
zfs-import.target
fi fi
zfs \ zfs \

View File

@@ -93,36 +93,9 @@ if [[ "${ID}" = 'debian' ]]; then
fi fi
if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then
for file in /etc/logrotate.d/* ; do "${baseDir}/debian.sh" --logrotate
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 "${baseDir}/apt-snapshot.sh"
#!/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 fi
# if [[ ! "${*}" = *--no-part* ]]; then # if [[ ! "${*}" = *--no-part* ]]; then