From 4d7215fce66bde69009b67e6ad8e3fcccce32cc3 Mon Sep 17 00:00:00 2001 From: Andrey Zimin Date: Mon, 26 Feb 2024 13:41:18 +0300 Subject: [PATCH] initial commit --- PKGBUILD | 26 ++++ chrooted_post_install.sh | 314 +++++++++++++++++++++++++++++++++++++++ main_fix_autologin.sh | 19 +++ makepkg.sh | 59 ++++++++ post_install.sh | 63 ++++++++ 5 files changed, 481 insertions(+) create mode 100755 PKGBUILD create mode 100755 chrooted_post_install.sh create mode 100755 main_fix_autologin.sh create mode 100755 makepkg.sh create mode 100755 post_install.sh diff --git a/PKGBUILD b/PKGBUILD new file mode 100755 index 0000000..1704cb2 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,26 @@ +pkgname=tarch-install-scripts +pkgver=1.0 +pkgrel=1 +pkgdesc="Tarch OS install Scripts" +url="https://gitcast.ru/tarch_os/tarch-bin" +arch=("any") +license=("GPL3") + +source=( + "chrooted_post_install.sh" + "post_install.sh" + "main_fix_autologin.sh" +) + +sha512sums=( + "SKIP" + "SKIP" + "SKIP" +) + +package() { + local bin=${pkgdir}/usr/bin + install -Dm755 chrooted_post_install.sh ${bin}/chrooted_post_install.sh + install -Dm755 post_install.sh ${bin}/post_install.sh + install -Dm755 main_fix_autologin.sh ${bin}/main_fix_autologin.sh +} diff --git a/chrooted_post_install.sh b/chrooted_post_install.sh new file mode 100755 index 0000000..1f334c6 --- /dev/null +++ b/chrooted_post_install.sh @@ -0,0 +1,314 @@ +#!/bin/bash + +# Get new user's username # +new_user=`cat /etc/passwd | grep "/home" | cut -d: -f1 | head -1` + +# Check if package installed (0) or not (1) # +_is_pkg_installed() { + local pkgname="$1" + pacman -Q "$pkgname" >& /dev/null +} + +# Remove a package # +_remove_a_pkg() { + local pkgname="$1" + pacman -Rsn --noconfirm "$pkgname" +} + +# Remove package(s) if installed # +_remove_pkgs_if_installed() { + local pkgname + + for pkgname in "$@"; do + _is_pkg_installed "$pkgname" && _remove_a_pkg "$pkgname" + done +} + +# Enable/Disable services/targets # +_manage_systemd_services() { + local _enable_services=( + "NetworkManager.service" + "bluetooth.service" + "cups.service" + "avahi-daemon.service" + "systemd-timesyncd.service" + "sddm-plymouth.service" + ) + + local _snapd_services=( + "apparmor.service" + "snapd.apparmor.service" + "snapd.socket" + ) + + local srvt + local snapsrv + + # Enable hypervisors services if installed on it # + [[ `lspci | grep -i virtualbox` ]] && echo "+---------------------->>" && echo "[*] Enabling vbox service..." && systemctl enable -f vboxservice.service + [[ `lspci -k | grep -i qemu` ]] && echo "+---------------------->>" && echo "[*] Enabling qemu service..." && systemctl enable -f qemu-guest-agent.service + + # Manage services on target system # + for srv in "${_enable_services[@]}"; do + echo "+---------------------->>" + echo "[*] Enabling $srv for target system..." + systemctl enable -f ${srv} + done + + # Manage snapd services on target system + #if [[ -x `which snap` ]]; then + # for snapsrv in "${_snapd_services[@]}"; do + # echo "+---------------------->>" + # echo "[*] Enabling $snapsrv for target system..." + # systemctl enable -f ${snapsrv} + # done + #fi + + # Manage targets on target system # + systemctl disable -f multi-user.target +} + +# Remove virtualbox pkgs if not running in vbox # +_remove_vbox_pkgs() { + local vbox_pkg="virtualbox-guest-utils" + local vsrvfile="/etc/systemd/system/multi-user.target.wants/vboxservice.service" + + lspci | grep -i "virtualbox" >/dev/null + + if [[ "$?" != 0 ]]; then + echo "+---------------------->>" + echo "[*] Removing $vbox_pkg from target system..." + test -n "`pacman -Q $vbox_pkg 2>/dev/null`" && pacman -Rnsdd ${vbox_pkg} --noconfirm + + if [[ -L "$vsrvfile" ]]; then + rm -f "$vsrvfile" + fi + fi +} + +# Remove vmware pkgs if not running in vmware # +_remove_vmware_pkgs() { + local vmware_pkgs=("open-vm-tools" "xf86-input-vmmouse" "xf86-video-vmware") + local _vw_pkg + + lspci | grep -i "VMware" >/dev/null + + if [[ "$?" != 0 ]]; then + for _vw_pkg in "${vmware_pkgs[@]}"; do + echo "+---------------------->>" + echo "[*] Removing ${_vw_pkg} from target system..." + test -n "`pacman -Q ${_vw_pkg} 2>/dev/null`" && pacman -Rnsdd ${_vw_pkg} --noconfirm + done + fi +} + +# Remove qemu guest pkg if not running in Qemu # +_remove_qemu_pkgs() { + local qemu_pkg="qemu-guest-agent" + local qsrvfile="/etc/systemd/system/multi-user.target.wants/qemu-guest-agent.service" + + lspci -k | grep -i "qemu" >/dev/null + + if [[ "$?" != 0 ]]; then + echo "+---------------------->>" + echo "[*] Removing $qemu_pkg from target system..." + test -n "`pacman -Q $qemu_pkg 2>/dev/null`" && pacman -Rnsdd ${qemu_pkg} --noconfirm + + if [[ -L "$qsrvfile" ]]; then + rm -f "$qsrvfile" + fi + fi +} + +# Remove Un-wanted Drivers # +_remove_unwanted_graphics_drivers() { + local gpu_file="/var/log/gpu-card-info.bash" + local amd_card='' + local amd_driver='' + local intel_card='' + local intel_driver='' + + if [[ -r "$gpu_file" ]]; then + echo "+---------------------->>" + echo "[*] Getting drivers info from $gpu_file file..." + source ${gpu_file} + else + echo "+---------------------->>" + echo "[!] Warning: file $gpu_file does not exist!" + fi + + # Remove AMD drivers # + if [[ -n "`lspci -k | grep 'Advanced Micro Devices'`" ]]; then + amd_card=yes + elif [[ -n "`lspci -k | grep 'AMD/ATI'`" ]]; then + amd_card=yes + elif [[ -n "`lspci -k | grep 'Radeon'`" ]]; then + amd_card=yes + fi + + echo "+---------------------->>" + echo "[*] AMD Card : $amd_card" + + if [[ "$amd_card" == 'no' ]]; then + echo "[*] Removing AMD drivers from target system..." + _remove_pkgs_if_installed xf86-video-amdgpu xf86-video-ati + fi + + # Remove intel drivers # + echo "+---------------------->>" + echo "[*] Intel Card : $intel_card" + + if [[ "$intel_card" == 'no' ]]; then + echo "[*] Removing Intel drivers from target system..." + _remove_pkgs_if_installed xf86-video-intel + fi +} + +# Remove un-wanted ucode package # +_remove_unwanted_ucode() { + cpu="`grep -w "^vendor_id" /proc/cpuinfo | head -n 1 | awk '{print $3}'`" + + case "$cpu" in + GenuineIntel) echo "+---------------------->>" && echo "[*] Removing amd-ucode from target system..." + _remove_pkgs_if_installed amd-ucode + ;; + *) echo "+---------------------->>" && echo "[*] Removing intel-ucode from target system..." + _remove_pkgs_if_installed intel-ucode + ;; + esac +} + +# Remove unnecessary packages # +_remove_unwanted_packages() { + local _packages_to_remove=( + "tarch-install-scripts" + "tarch-calamares" + "calamares" + "archinstall" + "arch-install-scripts" + "ckbcomp" + "boost" + "mkinitcpio-archiso" + "darkhttpd" + "irssi" + "lftp" + "kitty-terminfo" + "lynx" + "mc" + "ddrescue" + "testdisk" + "syslinux" + ) + + local rpkg + + echo "+---------------------->>" + echo "[*] Removing unnecessary packages..." + + for rpkg in "${_packages_to_remove[@]}"; do + pacman -Q ${rpkg} &>/dev/null + if [[ "$?" == 0 ]]; then + pacman -Rnsc ${rpkg} --noconfirm + fi + done +} + +# Delete Unnecessary Files # + +# Clean live ISO stuff from target system # +_clean_target_system() { + local _files_to_remove=( + /etc/sudoers.d/02_g_wheel + /etc/systemd/system/{etc-pacman.d-gnupg.mount,getty@tty1.service.d} + /etc/systemd/system/getty@tty1.service.d/autologin.conf + /etc/initcpio + /etc/mkinitcpio-archiso.conf + /etc/polkit-1/rules.d/49-nopasswd-calamares.rules + /etc/{group-,gshadow-,passwd-,shadow-} + /etc/udev/rules.d/81-dhcpcd.rules + /etc/skel/{.xinitrc,.xsession,.xprofile} + /home/"$new_user"/{.xinitrc,.xsession,.xprofile,.wget-hsts,.screenrc,.ICEauthority} + /root/{.automated_script.sh,.zlogin} + /root/{.xinitrc,.xsession,.xprofile} + /usr/local/bin/{Installation_guide} + /usr/share/applications/xfce4-about.desktop + /usr/share/calamares + /{gpg.conf,gpg-agent.conf,pubring.gpg,secring.gpg} + /var/lib/NetworkManager/NetworkManager.state + ) + + local dfile + + echo "+---------------------->>" + echo "[*] Deleting live ISO files..." + + for dfile in "${_files_to_remove[@]}"; do + rm -rf ${dfile} + done + + find /usr/lib/initcpio -name archiso* -type f -exec rm '{}' \; +} + +# Perform Misc Operations # + +_perform_various_stuff() { + # Copy grub theme to boot directory # + echo "+---------------------->>" + echo "[*] Copying grub theme to boot directory..." + mkdir -p /boot/grub/themes + cp -rf /usr/share/grub/themes/tarch /boot/grub/themes + + # disabling autologin for lightdm (if exist) # + lightdm_config='/etc/lightdm/lightdm.conf' + + if [[ -e "$lightdm_config" ]]; then + echo "+---------------------->>" + echo "[*] Disabling autologin for lightdm..." + sed -i -e 's|autologin-user=.*|#autologin-user=username|g' "$lightdm_config" + sed -i -e 's|autologin-session=.*|#autologin-session=openbox|g' "$lightdm_config" + fi + + # disabling autologin for lxdm (if exist) # + lxdm_config='/etc/lxdm/lxdm.conf' + + if [[ -e "$lxdm_config" ]]; then + echo "+---------------------->>" + echo "[*] Disabling autologin for lxdm..." + sed -i -e 's/autologin=.*/#autologin=username/g' "$lxdm_config" + fi + + # disabling autologin for sddm (if exist) # + sddm_config='/etc/sddm.conf.d/kde_settings.conf' + + if [[ -e "$sddm_config" ]]; then + echo "+---------------------->>" + echo "[*] Disabling autologin for sddm..." + sed -i -e 's/User=liveuser/#User=username/g' "$sddm_config" + fi + + # Perform various operations # + echo "+---------------------->>" + echo "[*] Running operations as new user : ${new_user}..." + + [[ -x `which exodia-hooks-runner` ]] && exodia-hooks-runner + + runuser -l ${new_user} -c 'xdg-user-dirs-update' + runuser -l ${new_user} -c 'xdg-user-dirs-gtk-update' + + # Journal stuff # + sed -i 's/volatile/auto/g' /etc/systemd/journald.conf 2>>/tmp/.errlog + sed -i 's/.*pam_wheel\.so/#&/' /etc/pam.d/su +} + +## ------------------------------------------------------------------------------------------------ ## + +# Execute Script # +_manage_systemd_services +_remove_vbox_pkgs +_remove_vmware_pkgs +_remove_qemu_pkgs +_remove_unwanted_graphics_drivers +_remove_unwanted_ucode +_remove_unwanted_packages +_clean_target_system +_perform_various_stuff diff --git a/main_fix_autologin.sh b/main_fix_autologin.sh new file mode 100755 index 0000000..11e7715 --- /dev/null +++ b/main_fix_autologin.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +## Fix Calamares Autologin ## + +## ----------------------- ## + +# Dirs # +DM_FILE='/etc/sddm.conf' + +enable_autologin() { + _session_name="$1" + + if [[ `cat $DM_FILE | grep 'Autologin'` ]]; then + sed -i -e "s/Session=.*/Session=$_session_name/g" "$DM_FILE" + fi +} + +# Execute In Target # +enable_autologin 'bspwm' diff --git a/makepkg.sh b/makepkg.sh new file mode 100755 index 0000000..4c0b4e4 --- /dev/null +++ b/makepkg.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +source "$HOME/bin/scripts/system/style" + +BUILDING_DIR="build" + +# Script Termination # +exit_on_signal_SIGINT () { + { printf "\n\n%s\n" "Script interrupted." 2>&1; echo; } + exit 0 +} + +exit_on_signal_SIGTERM () { + { printf "\n\n%s\n" "Script terminated." 2>&1; echo; } + exit 0 +} + +# Этот скрипт устанавливает ловушку (trap) для сигнала SIGINT и SIGTERM. +# Когда скрипт получает сигнал SIGINT (например, когда пользователь нажимает Ctrl+C), он будет вызывать функцию +trap exit_on_signal_SIGINT SIGINT +trap exit_on_signal_SIGTERM SIGTERM + +CLEANINH_BUILDING_DIR (){ + cd .. + rm -rf ${BUILDING_DIR} + sleep 0.5 +} + +BUILD_PKG () { + echo -e "\n ${BOLD}${GREEN}[+] создаем дирректорию сборки... ${RESET_COLOR}" + mkdir -p ${BUILDING_DIR} + sleep 0.5 + + echo -e "\n ${CYAN} ==> копируем файлы в дирректорию сборки... ${RESET_COLOR}" + cp -r `ls | grep -v '^build$'` ${BUILDING_DIR} + sleep 0.5 + + echo -e "\n ${CYAN} ==> копируем файлы в дирректорию сборки... ${RESET_COLOR}" + cd ${BUILDING_DIR} + sleep 0.5 + + # Building # + echo -e "\n ${CYAN}[+] собираем пакет... ${RESET_COLOR}" + makepkg -s -f + sleep 0.5 + + if ls *.pkg.tar.zst 1> /dev/null 2>&1; then + echo -e "\n ${CYAN}[+] переносим пакеты и очищаем дирректорию... ${RESET_COLOR}" + mv ./*.pkg.tar.zst ../../tarch-bin/x86_64/ + sleep 0.5 + CLEANINH_BUILDING_DIR + echo -e "\n ${BOLD}${GREEN}[✔] завершено... ${RESET_COLOR}" + else + echo -e "\n ${BOLD}${RED}[✘] сборка не удалась... ${RESET_COLOR}" + fi + echo -e "\n" +} + +BUILD_PKG diff --git a/post_install.sh b/post_install.sh new file mode 100755 index 0000000..6faa446 --- /dev/null +++ b/post_install.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# Get mount points of target system according to installer being used (calamares) # +if [[ `pidof calamares` ]]; then + chroot_path="/tmp/`lsblk | grep 'calamares-root' | awk '{ print $NF }' | sed -e 's/\/tmp\///' -e 's/\/.*$//' | tail -n1`" +else + chroot_path="/mnt" +fi + +if [[ "$chroot_path" == "/tmp/" ]]; then + echo "+---------------------->>" + echo "[!] Fatal error: `basename $0`: chroot_path is empty!" +fi + +# Use chroot not arch-chroot # +arch_chroot() { + chroot "$chroot_path" /bin/bash -c ${1} +} + +# Detect drivers in use in live session # +gpu_file="$chroot_path"/var/log/gpu-card-info.bash + +_detect_vga_drivers() { + local card=no + local driver=no + + if [[ -n "`lspci -k | grep -P 'VGA|3D|Display' | grep -w "${2}"`" ]]; then + card=yes + if [[ -n "`lsmod | grep -w ${3}`" ]]; then + driver=yes + fi + + if [[ -n "`lspci -k | grep -wA2 "${2}" | grep 'Kernel driver in use: ${3}'`" ]]; then + driver=yes + fi + fi + + echo "${1}_card=$card" >> ${gpu_file} + echo "${1}_driver=$driver" >> ${gpu_file} +} + +echo "+---------------------->>" +echo "[*] Detecting GPU card & drivers used in live session..." + +# Detect AMD # +_detect_vga_drivers "amd" "AMD" "amdgpu" + +# Detect Intel # +_detect_vga_drivers "intel" "Intel Corporation" "i915" + +# For logs # +echo "+---------------------->>" +echo "[*] Content of $gpu_file :" +cat ${gpu_file} + +## ----------------------------------------------------------------------------------------------- ## + +# Run the final script inside calamares chroot (target system) # +if [[ `pidof calamares` ]]; then + echo "+---------------------->>" + echo "[*] Running chroot post installation script in target system..." + arch_chroot "/usr/bin/chrooted_post_install.sh" +fi