Split off creating and setting up 'home-fix.sh'
This commit is contained in:
59
home-fix-setup.sh
Normal file
59
home-fix-setup.sh
Normal 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
|
||||||
53
post-inst.sh
53
post-inst.sh
@@ -203,56 +203,9 @@ EOF
|
|||||||
tee /etc/apt/apt.conf.d/99-apt_moo &> /dev/null
|
tee /etc/apt/apt.conf.d/99-apt_moo &> /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! "${*}" = *--no-part* ]]; then
|
# if [[ ! "${*}" = *--no-part* ]]; then
|
||||||
cat << EOF | tee /usr/bin/home-fix.sh &> /dev/null
|
"${baseDir}/home-fix-setup.sh"
|
||||||
#!/bin/bash
|
# fi
|
||||||
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 [[ ! -f '/usr/bin/shutdown' ]]; then
|
if [[ ! -f '/usr/bin/shutdown' ]]; then
|
||||||
ln -s /sbin/shutdown /usr/bin/shutdown
|
ln -s /sbin/shutdown /usr/bin/shutdown
|
||||||
|
|||||||
Reference in New Issue
Block a user