60 lines
1.4 KiB
Bash
Executable File
60 lines
1.4 KiB
Bash
Executable File
#!/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' ]] || [[ "${ID}" == 'elementary' ]]; 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
|