Split off creating and setting up 'home-fix.sh'

This commit is contained in:
2025-12-24 16:14:33 -05:00
parent f44f7464b9
commit 648d07f355
2 changed files with 62 additions and 50 deletions

59
home-fix-setup.sh Normal file
View File

@@ -0,0 +1,59 @@
#!/bin/bash
set -euo pipefail
baseDir="$(realpath "$(dirname "${0}")")"
source \
/etc/os-release
source \
"${baseDir}/system.conf"
cat << EOF | tee /usr/bin/home-fix.sh &> /dev/null
#!/bin/bash
set -euo pipefail
chown -R ${username}:${username} /home/${username}
sudo -u ${username} cp -a /etc/skel/. /home/${username}
if [[ ! -z "\$(find -P /home/${username}/ | grep '\.face')" ]]; then
find -P /home/${username}/ | grep '\.face' | xargs -d '\n' -I {} rm {}
fi
if [[ ! -z "\$(find -P /var/spool/cron | grep 'root')" ]]; then
rm \$(find -P /var/spool/cron | grep 'root')
fi
printf "\$(date +%Y-%m-%d\ %H:%M:%S) I did the thing\n" | tee /var/log/home-fix.log &> /dev/null
if [[ -f '/usr/bin/home-fix.sh' ]]; then
rm /usr/bin/home-fix.sh
fi
zfs snapshot ${hostname,,}/ROOT/${ID}@home-fix
zfs snapshot -r ${hostname,,}/home/${username}@home-fix
EOF
chmod \
+x \
/usr/bin/home-fix.sh
if [[ "${ID}" == 'fedora' ]]; then
printf \
"@reboot\tsudo -u ${username} '${baseDir}/finalize.sh'\n@reboot\t/usr/bin/home-fix.sh\n" | \
tee /var/spool/cron/root &> /dev/null
elif [[ "${ID}" == 'debian' ]]; then
printf \
"@reboot\tsudo -u ${username} '${baseDir}/finalize.sh'\n@reboot\t/usr/bin/home-fix.sh\n" | \
tee /var/spool/cron/crontabs/root &> /dev/null
chown \
:crontab \
/var/spool/cron/crontabs/root
chmod \
0600 \
/var/spool/cron/crontabs/root
fi

View File

@@ -203,56 +203,9 @@ EOF
tee /etc/apt/apt.conf.d/99-apt_moo &> /dev/null
fi
if [[ ! "${*}" = *--no-part* ]]; then
cat << EOF | tee /usr/bin/home-fix.sh &> /dev/null
#!/bin/bash
set -euo pipefail
chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}
sudo -u ${USERNAME} cp -a /etc/skel/. /home/${USERNAME}
if [[ ! -z "\$(find -P /home/${USERNAME}/ | grep '\.face')" ]]; then
find -P /home/${USERNAME}/ | grep '\.face' | xargs -d '\n' -I {} rm {}
fi
if [[ ! -z "\$(find -P /var/spool/cron | grep 'root')" ]]; then
rm \$(find -P /var/spool/cron | grep 'root')
fi
printf "\$(date +%Y-%m-%d\ %H:%M:%S) I did the thing\n" | tee /var/log/home-fix.log &> /dev/null
if [[ -f '/usr/bin/home-fix.sh' ]]; then
rm /usr/bin/home-fix.sh
fi
zfs snapshot ${HOSTNAME,,}/ROOT/${ID}@home-fix
zfs snapshot -r ${HOSTNAME,,}/home/${USERNAME}@home-fix
EOF
chmod \
+x \
/usr/bin/home-fix.sh
if [[ "${ID}" == 'fedora' ]]; then
printf \
"@reboot\tsudo -u ${USERNAME} '${BASEDIR}/finalize.sh'\n@reboot\t/usr/bin/home-fix.sh\n" | \
tee /var/spool/cron/root &> /dev/null
elif [[ "${ID}" == 'debian' ]]; then
printf \
"@reboot\tsudo -u ${USERNAME} '${BASEDIR}/finalize.sh'\n@reboot\t/usr/bin/home-fix.sh\n" | \
tee /var/spool/cron/crontabs/root &> /dev/null
chown \
:crontab \
/var/spool/cron/crontabs/root
chmod \
0600 \
/var/spool/cron/crontabs/root
fi
fi
# if [[ ! "${*}" = *--no-part* ]]; then
"${baseDir}/home-fix-setup.sh"
# fi
if [[ ! -f '/usr/bin/shutdown' ]]; then
ln -s /sbin/shutdown /usr/bin/shutdown