commit ef050df059426c1d1e6b52bbe7d6c31902e26473 Author: Andrey Zimin Date: Mon Feb 26 13:57:04 2024 +0300 initial commit diff --git a/PKGBUILD b/PKGBUILD new file mode 100755 index 0000000..2d57c8d --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,54 @@ +pkgname="tarch-hooks" +pkgver=1.0 +pkgrel=1 +pkgdesc="Pacman hooks for Tarch OS to fix various system files" +url="https://gitcast.ru/tarch_os/tarch-bin" +arch=("any") +license=("GPL3") + +source=( + "tarch-hook-grub.hook" + "tarch-hook-nm.hook" + "tarch-hooks.hook" + "tarch-hooks-misc" + "tarch-hooks-runner" + "tarch-hook-thunar.hook" + "tarch-hook-zsh.hook" + "tarch-lsb-release.hook" + "tarch-os-release.hook" + "tarch-reboot-required" + "tarch-reboot-required.hook" +) + +sha512sums=( + "SKIP" + "SKIP" + "SKIP" + "SKIP" + "SKIP" + "SKIP" + "SKIP" + "SKIP" + "SKIP" + "SKIP" + "SKIP" +) + +package() { + + local hooks=${pkgdir}/usr/share/libalpm/hooks + local bin=${pkgdir}/usr/bin + + install -Dm644 tarch-hooks.hook "${hooks}"/tarch-hooks.hook + install -Dm644 tarch-lsb-release.hook "${hooks}"/tarch-lsb-release.hook + install -Dm644 tarch-os-release.hook "${hooks}"/tarch-os-release.hook + install -Dm644 tarch-reboot-required.hook "${hooks}"/tarch-reboot-required.hook + install -Dm644 tarch-hook-nm.hook "${hooks}"/tarch-hook-nm.hook + install -Dm644 tarch-hook-thunar.hook "${hooks}"/tarch-hook-thunar.hook + install -Dm644 tarch-hook-zsh.hook "${hooks}"/tarch-hook-zsh.hook + install -Dm644 tarch-hook-grub.hook "${hooks}"/tarch-hook-grub.hook + + install -Dm755 tarch-hooks-runner "${bin}"/tarch-hooks-runner + install -Dm755 tarch-reboot-required "${bin}"/tarch-reboot-required + install -Dm755 tarch-hooks-misc "${bin}"/tarch-hooks-misc +} 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/tarch-hook-grub.hook b/tarch-hook-grub.hook new file mode 100755 index 0000000..79bf5f5 --- /dev/null +++ b/tarch-hook-grub.hook @@ -0,0 +1,12 @@ +[Trigger] +Operation = Install +Operation = Upgrade +Type = Package +Target = grub* +Target = grub-* +Target = grub2-* + +[Action] +Description = Fixing naming for grub entries... +When = PostTransaction +Exec = /usr/bin/tarch-hooks-misc fix-grub diff --git a/tarch-hook-nm.hook b/tarch-hook-nm.hook new file mode 100755 index 0000000..5203771 --- /dev/null +++ b/tarch-hook-nm.hook @@ -0,0 +1,10 @@ +[Trigger] +Operation = Install +Operation = Upgrade +Type = Package +Target = networkmanager-dmenu-git + +[Action] +Description = Creating network manager script for bspwm... +When = PostTransaction +Exec = /usr/bin/tarch-hooks-misc fix-nmd diff --git a/tarch-hook-thunar.hook b/tarch-hook-thunar.hook new file mode 100755 index 0000000..c7737ef --- /dev/null +++ b/tarch-hook-thunar.hook @@ -0,0 +1,10 @@ +[Trigger] +Operation = Install +Operation = Upgrade +Type = Package +Target = thunar + +[Action] +Description = Fixing thunar wallpaper module for bspwm... +When = PostTransaction +Exec = /usr/bin/tarch-hooks-misc fix-thunar diff --git a/tarch-hook-zsh.hook b/tarch-hook-zsh.hook new file mode 100755 index 0000000..1e89d01 --- /dev/null +++ b/tarch-hook-zsh.hook @@ -0,0 +1,11 @@ +[Trigger] +Operation = Install +Operation = Upgrade +Operation = Remove +Type = Path +Target = usr/bin/* +[Action] +Description = Updating executables in /usr/bin... +Depends = zsh +When = PostTransaction +Exec = /usr/bin/install -Dm644 /dev/null /var/cache/zsh/pacman diff --git a/tarch-hooks-misc b/tarch-hooks-misc new file mode 100755 index 0000000..5f8be23 --- /dev/null +++ b/tarch-hooks-misc @@ -0,0 +1,37 @@ +#!/bin/bash + +fix_thunar() { + # Remove thunar wallpaper plugin # + twplug="/usr/lib/thunarx-3/thunar-wallpaper-plugin.so" + + if [[ -e "$twplug" ]]; then + rm -rf "$twplug" + fi +} + +fix_nmd() { + # Create nmd script for bspwm session # + cp -rf /usr/bin/networkmanager_dmenu /usr/local/bin/nmd && sed -i -e 's/config.ini/nmd.ini/g' /usr/local/bin/nmd +} + +fix_grub() { + sed -i -e 's/GRUB_DISTRIBUTOR=.*/GRUB_DISTRIBUTOR="Tarch OS"/g' /etc/default/grub + cat /etc/grub.d/10_linux | grep 'OS="${GRUB_DISTRIBUTOR} Linux"' &>/dev/null + + if [[ "$?" == 0 ]]; then + sed -i -e 's/OS="${GRUB_DISTRIBUTOR} Linux"/OS="${GRUB_DISTRIBUTOR}"/g' /etc/grub.d/10_linux + fi +} + +main() { + local hookname="$1" + + case "$hookname" in + fix-thunar) fix_thunar ;; + fix-nmd) fix_nmd ;; + fix-grub) fix_grub ;; + "") echo "Nothing to do!";; + esac +} + +main "$@" diff --git a/tarch-hooks-runner b/tarch-hooks-runner new file mode 100755 index 0000000..0481f39 --- /dev/null +++ b/tarch-hooks-runner @@ -0,0 +1,51 @@ +#!/bin/bash + +fix_lsb_release() { + local file=/etc/lsb-release + + if [[ -z "`grep "^DISTRIB_RELEASE=" $file`" ]]; then + # add missing DISTRIB_RELEASE= # + echo "DISTRIB_RELEASE=rolling" >> "$file" + fi + + sed -i "$file" \ + -e 's|^DISTRIB_ID=.*$|DISTRIB_ID=tarch|' \ + -e 's|^DISTRIB_RELEASE=.*$|DISTRIB_RELEASE=rolling|' \ + -e 's|^DISTRIB_DESCRIPTION=.*$|DISTRIB_DESCRIPTION=\"Tarch OS\"|' +} + +fix_os_release() { + local file=/usr/lib/os-release + + sed -i "$file" \ + -e 's|^NAME=.*$|NAME=\"Tarch OS\"|' \ + -e 's|^PRETTY_NAME=.*$|PRETTY_NAME=\"Tarch OS\"|' \ + -e 's|^ID=.*$|ID=tarch|' \ + -e 's|^ID_LIKE=.*$|ID_LIKE=arch|' \ + -e 's|^BUILD_ID=.*$|BUILD_ID=rolling|' \ + -e 's|^HOME_URL=.*$|HOME_URL=\"https://tarchos.ru\"|' \ + -e 's|^DOCUMENTATION_URL=.*$|DOCUMENTATION_URL=\"https://tarchos.ru\"|' \ + -e 's|^SUPPORT_URL=.*$|SUPPORT_URL=\"https://tarchos.ru"|' \ + -e 's|^BUG_REPORT_URL=.*$|BUG_REPORT_URL=\"https://tarchos.ru"|' \ + -e 's|^LOGO=.*$|LOGO=tarch|' + + if [ -z "$(grep "^ID_LIKE=" $file)" ] && [ -n "$(grep "^ID=" $file)" ]; then + # add missing ID_LIKE= # + sed -i $file -e '/^ID=/a \ID_LIKE=arch' + fi + + # fix issue file # + sed -i 's|Arch Linux|Tarch OS|g' /etc/issue /usr/share/factory/etc/issue +} + +main() { + local hookname="$1" + + case "$hookname" in + os-release) fix_os_release ;; + lsb-release) fix_lsb_release ;; + "") fix_os_release fix_lsb_release ;; + esac +} + +main "$@" diff --git a/tarch-hooks.hook b/tarch-hooks.hook new file mode 100755 index 0000000..7ff0ba8 --- /dev/null +++ b/tarch-hooks.hook @@ -0,0 +1,10 @@ +[Trigger] +Operation = Install +Operation = Upgrade +Type = Package +Target = tarch-hooks + +[Action] +Description = Updating Tarch OS System Configurations... +When = PostTransaction +Exec = /usr/bin/tarch-hooks-runner diff --git a/tarch-lsb-release.hook b/tarch-lsb-release.hook new file mode 100755 index 0000000..9109164 --- /dev/null +++ b/tarch-lsb-release.hook @@ -0,0 +1,10 @@ +[Trigger] +Operation = Install +Operation = Upgrade +Type = Package +Target = lsb-release + +[Action] +Description = Updating Tarch OS LSB Configurations... +When = PostTransaction +Exec = /usr/bin/tarch-hooks-runner lsb-release diff --git a/tarch-os-release.hook b/tarch-os-release.hook new file mode 100755 index 0000000..5a66aa3 --- /dev/null +++ b/tarch-os-release.hook @@ -0,0 +1,10 @@ +[Trigger] +Operation = Install +Operation = Upgrade +Type = Package +Target = filesystem + +[Action] +Description = Updating Tarch OS OS-Specific Configurations... +When = PostTransaction +Exec = /usr/bin/tarch-hooks-runner os-release diff --git a/tarch-reboot-required b/tarch-reboot-required new file mode 100755 index 0000000..984bdef --- /dev/null +++ b/tarch-reboot-required @@ -0,0 +1,86 @@ +#!/bin/bash + +# Avoid unnecessary reboots: don't notify if an updated package is +# - not currently running (e.g. alternative kernel) +# - not in use (e.g. alternative driver) + +## Colors ---------------------------- + +# Reset +Color_Off='\033[0m' # Text Reset + +# Regular Colors +Black='\033[0;30m' Red='\033[0;31m' Green='\033[0;32m' Yellow='\033[0;33m' +Blue='\033[0;34m' Purple='\033[0;35m' Cyan='\033[0;36m' White='\033[0;37m' + +# Bold +BBlack='\033[1;30m' BRed='\033[1;31m' BGreen='\033[1;32m' BYellow='\033[1;33m' +BBlue='\033[1;34m' BPurple='\033[1;35m' BCyan='\033[1;36m' BWhite='\033[1;37m' + +## ----------------------------------- + +_notify_reboot_required() { + local xx + + for xx in "$DESKTOP_SESSION" "$XDG_CURRENT_DESKTOP"; do + if [[ -n "$xx" ]]; then + break + fi + done + + if [[ -n "$xx" ]]; then + local user userid cmd + for user in $(/usr/bin/users); do + userid=$(/usr/bin/id -u $user) + cmd=(DISPLAY=:0 DBUS_SESSION_ADDRESS=unix:path=/run/user/$userid/bus /usr/bin/notify-send) + cmd+=(--icon=system-reboot --urgency=critical) + cmd+=("\"Core system package upgraded, You need to reboot the machine.\"") + /usr/bin/su $user -c "${cmd[*]}" + done + else + # at TTY + echo -e ${BRed}"\n[*] Core system package upgraded, You need to reboot the machine.\n"${Color_Off} >&2 + fi + +} + +RunningKernel() { + cat /proc/cmdline | sed 's|.*/vmlinuz-\(linux[a-z0-9-]*\) .*|\1|' +} + +main() { + # targets from the hook (stdin) # + local targets=$(tee /dev/null) + local target + local notify=no + local runningKernel="$(RunningKernel)" + + for target in $targets; do + case "$target" in + linux | linux-lts | linux-zen | linux-hardened | linux-lts?? | linux-lts???) + # Note: only official and older LTS kernels are checked. + if [[ "$target" = "$runningKernel" ]] ; then + notify=yes + break + fi + ;; + btrfs-progs) + if [[ -n "$(/usr/bin/df -hT | awk '{print $2}' | grep -w btrfs)" ]] ; then + notify=yes + break + fi + ;; + *) + notify=yes + break + ;; + esac + done + + if [[ "$notify" = "yes" ]]; then + _notify_reboot_required + unset -f _notify_reboot_required + fi +} + +main "$@" diff --git a/tarch-reboot-required.hook b/tarch-reboot-required.hook new file mode 100755 index 0000000..45200b1 --- /dev/null +++ b/tarch-reboot-required.hook @@ -0,0 +1,32 @@ +[Trigger] +Operation = Upgrade +Type = Package +Target = amd-ucode +Target = intel-ucode +Target = btrfs-progs +Target = cryptsetup +Target = linux +Target = linux-hardened +Target = linux-lts +Target = linux-zen +Target = linux-firmware +Target = nvidia +Target = nvidia-dkms +Target = nvidia-*xx-dkms +Target = nvidia-*xx +Target = nvidia-*lts-dkms +Target = nvidia*-lts +Target = mesa +Target = systemd* +Target = wayland +Target = egl-wayland +Target = xf86-video-* +Target = xorg-server* +Target = xorg-fonts* + +[Action] +Description = Checking if user should be informed about rebooting... +When = PostTransaction +Depends = libnotify +NeedsTargets +Exec = /usr/bin/tarch-reboot-required