Added files to git repo
This commit is contained in:
263
post-inst.sh
Executable file
263
post-inst.sh
Executable file
@ -0,0 +1,263 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
|
||||
BASEDIR="$(dirname "${0}" | sed "s|^\.|${PWD}|")"
|
||||
|
||||
|
||||
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
|
||||
|
||||
if [[ "${ID}" == 'fedora' ]]; then
|
||||
printf \
|
||||
'\033[?47h\033[2J\033[H'
|
||||
|
||||
cat << EOF
|
||||
|
||||
Enter a password for the new user account:
|
||||
EOF
|
||||
passwd \
|
||||
${USERNAME}
|
||||
|
||||
printf \
|
||||
'\033[?47l'
|
||||
|
||||
usermod \
|
||||
-a \
|
||||
-G \
|
||||
audio,cdrom,dip,floppy,wheel,video,dialout \
|
||||
${USERNAME}
|
||||
else
|
||||
usermod \
|
||||
-a \
|
||||
-G \
|
||||
audio,cdrom,dip,floppy,netdev,plugdev,sudo,video,dialout,lpadmin \
|
||||
${USERNAME}
|
||||
fi
|
||||
|
||||
if [[ "${ID}" == 'elementary' ]]; then
|
||||
cat << EOF > /etc/apt/sources.list.d/backports.list
|
||||
deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_VERSION_CODENAME}-backports main restricted universe multiverse
|
||||
deb-src http://archive.ubuntu.com/ubuntu/ ${UBUNTU_VERSION_CODENAME}-backports main restricted universe multiverse
|
||||
EOF
|
||||
|
||||
cat << EOF > /etc/apt/preferences.d/backports.pref
|
||||
Package: *
|
||||
Pin: release n=${UBUNTU_VERSION_CODENAME}*
|
||||
Pin-Priority: 990
|
||||
|
||||
Package: linux* /wayland/
|
||||
Pin: release n=${UBUNTU_VERSION_CODENAME}-backports
|
||||
Pin-Priority: -1
|
||||
EOF
|
||||
elif [[ "${ID}" == 'debian' ]]; then
|
||||
cat << EOF | tee /etc/apt/sources.list.d/backports.sources &> /dev/null
|
||||
Enabled: yes
|
||||
Types: deb deb-src
|
||||
URIs: http://deb.debian.org/debian/
|
||||
Suites: ${VERSION_CODENAME}-backports
|
||||
Components: main non-free-firmware contrib
|
||||
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
|
||||
EOF
|
||||
|
||||
cat << EOF | tee /etc/apt/preferences.d/backports.pref &> /dev/null
|
||||
Package: *
|
||||
Pin: release n=${VERSION_CODENAME}*
|
||||
Pin-Priority: 990
|
||||
EOF
|
||||
|
||||
if [[ "${VERSION_CODENAME}" == 'bookworm' ]]; then
|
||||
cat << EOF | tee --append /etc/apt/preferences.d/backports.pref &> /dev/null
|
||||
|
||||
Package: /wayland/
|
||||
Pin: release n=${VERSION_CODENAME}-backports
|
||||
Pin-Priority: -1
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${ID}" == 'debian' ]] || [[ "${ID}" == 'elementary' ]]; then
|
||||
apt \
|
||||
dist-upgrade \
|
||||
--yes
|
||||
fi
|
||||
|
||||
if [[ "${ID}" == 'elementary' ]]; then
|
||||
apt \
|
||||
install \
|
||||
--yes \
|
||||
--autoremove \
|
||||
elementary-desktop
|
||||
elif [[ "${ID}" = 'debian' ]]; then
|
||||
if [[ ! -f /usr/bin/tasksel ]]; then
|
||||
apt \
|
||||
install \
|
||||
--yes \
|
||||
tasksel
|
||||
fi
|
||||
|
||||
tasksel \
|
||||
--new-install
|
||||
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
|
||||
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 /usr/bin/home-fix.sh\n' | \
|
||||
tee /var/spool/cron/root &> /dev/null
|
||||
elif [[ "${ID}" == 'debian' ]]; then
|
||||
printf \
|
||||
'@reboot /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
|
||||
|
||||
zfs \
|
||||
snapshot \
|
||||
${HOSTNAME,,}/ROOT/${ID}@post-install
|
||||
|
||||
printf \
|
||||
'\033[?47h\033[2J\033[H'
|
||||
|
||||
cat << EOF
|
||||
|
||||
Script has finished running
|
||||
|
||||
Please reboot your computer
|
||||
|
||||
Press any key to return to the main menu
|
||||
EOF
|
||||
|
||||
read -srn 1
|
Reference in New Issue
Block a user