282 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			282 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/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
 | 
						|
	if [[ -z "$(cat /etc/group | grep 'lpadmin')" ]]; then
 | 
						|
		groupadd --gid 108 lpadmin
 | 
						|
	fi
 | 
						|
 | 
						|
	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 --append /etc/apt/sources.list.d/${VERSION_CODENAME}.sources &> /dev/null
 | 
						|
 | 
						|
# ${VERSION_CODENAME^} Backports
 | 
						|
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
 | 
						|
 | 
						|
Package:		linux-*
 | 
						|
Pin:			release	n=${VERSION_CODENAME}-backports
 | 
						|
Pin-Priority:	-1
 | 
						|
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\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
 | 
						|
	ln -s /sbin/shutdown /usr/bin/shutdown
 | 
						|
fi
 | 
						|
 | 
						|
if [[ ! -f '/usr/bin/reboot' ]]; then
 | 
						|
	ln -s /sbin/reboot /usr/bin/reboot
 | 
						|
fi
 | 
						|
 | 
						|
zfs \
 | 
						|
	snapshot \
 | 
						|
	${HOSTNAME,,}/ROOT/${ID}@post-install
 | 
						|
 | 
						|
printf \
 | 
						|
	'\033[?47h\033[2J\033[H'
 | 
						|
 | 
						|
cat << EOF
 | 
						|
 | 
						|
Script has finished running
 | 
						|
 | 
						|
Please exit the chroot
 | 
						|
 | 
						|
Press any key to return to the main menu
 | 
						|
EOF
 | 
						|
 | 
						|
read -srn 1
 |