Refactoring repository...
Some checks are pending
Check Conventional Commit / check-commit-message (push) Waiting to run

This commit is contained in:
CELESTIFYX
2025-01-14 19:02:06 +02:00
parent 876fa0988e
commit 08abac9e7d
33171 changed files with 4677 additions and 761 deletions

View File

@@ -0,0 +1,38 @@
# Maintainer: Eshan Roy <eshan@snigdhaos.org>
# Maintainer: CELESTIFYX Team <celestifyx@celestifyx.com>
# Contributor: d3v1l0n <d3v1l0n@outlook.in>
pkgname="snigdhaos-libs"
pkgdesc="Libs for Snigdha OS"
pkgver=1.0.0
pkgrel=1
arch=("any")
license=("GPL-3.0-or-later")
depends=("libnotify"
"expect")
source=("launch-terminal"
"snigdhaos.shlib"
"check-snapshot-boot"
"install-package"
"org.snigdhaos.libs.pkexec.policy"
"pkexec-gui")
sha512sums=("2fec0c2f15a5ebddf6ece386c8e8f82cb5cd8c1bc733d36fb7acfbe02c7c64cfc50e8af0177b9ad0473b5fbf838f27b8eac76d761f312d0c1deba4edf22a9d5e"
"2f774655c434968e3026a80a7628cd4a65f3bf3f26c4aa23388e0fe333ed27891610b08608efc9185e029b70732dbeb35a9f813df15147b2d9b7d2fb7222f2c9"
"11a7b18824976bbb1a7990ed4bbe23c30b7604fa67c311765ecd284a657ca84c2589bb088f432b9969c377bb3e98f96a5ee55bdefaac9925c283635bc890364f"
"b7f63febaa7ff9bd5a3bd44e7b055c230bd742bcd6da8adde86fedd055115181811338e642dfc4cd2466df599a48d58d3527bcd01764203043485148e5f239e0"
"db1a46ea1415144cf7c0b4c8136c16507ac658d9d661ae2d15f0366cfed2c047522f040f9c21d5f9172d64c6a547c0bd0eb0bb41b0805827cb122cd4d8b5ab74"
"e43c1733654cd31b6f26cb41c063ad4b87aca2e3d92e29d4533c41c3369c3e602824fe70a2556b2d5707dd16e66e7586470e44281a79510b38dfa129c6323bdc")
package() {
install -Dm755 "launch-terminal" "${pkgdir}"/usr/lib/snigdhaos/launch-terminal
install -Dm755 "install-package" "${pkgdir}"/usr/lib/snigdhaos/install-package
install -Dm755 "check-snapshot-boot" "${pkgdir}"/usr/lib/snigdhaos/check-snapshot-boot
install -Dm755 "pkexec-gui" "${pkgdir}"/usr/lib/snigdhaos/pkexec-gui
install -Dm644 "snigdhaos.shlib" "${pkgdir}"/usr/lib/snigdhaos/snigdhaos.shlib
install -d "${pkgdir}/var/lib/snigdhaos/tmp"
install -Dm0644 "org.snigdhaos.libs.pkexec.policy" "${pkgdir}/usr/share/polkit-1/actions/org.snigdhaos.libs.pkexec.policy"
}

View File

@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Check if /proc/cmdline exists
if [[ -f "/proc/cmdline" ]]; then
# Check if booting from a Btrfs snapshot
if grep -qE 'subvol=@/.snapshots/[0-9]+/snapshot' /proc/cmdline; then
echo "Booting from a Btrfs snapshot.";
exit 0
else
echo "Not booting from a Btrfs snapshot.";
exit 1
fi
else
# Handle the case where /proc/cmdline is missing
echo "Error: /proc/cmdline not found.";
exit 2
fi

View File

@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -e
# Determine whether to use GUI authentication based on environment and variable
SNIGDHAOSLIB_GUI="${SNIGDHAOSLIB_GUI:-true}"
# If running in a non-graphical environment, disable GUI authentication
if [ -z "$DISPLAY" ]; then
SNIGDHAOSLIB_GUI=false
fi
# Check if we need to run with elevated privileges and handle accordingly
if [[ $EUID -ne 0 ]] && [ "$SNIGDHAOSLIB_GUI" == "true" ]; then
# Use pkexec to elevate with GUI if necessary
exec pkexec /usr/lib/snigdhaos/install-package "$@";
exit 1
fi
# Use sudo for elevation if we are not using pkexec
if [[ $EUID -ne 0 ]]; then
sudo pacman -S --noconfirm "$@"
else
# If we're already root, simply run pacman
pacman -S --noconfirm "$@"
fi

View File

@@ -0,0 +1,126 @@
#!/usr/bin/env bash
set -e
# Color definitions
RESET="\033[0m"
BOLD="\033[1m"
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
CYAN="\033[1;36m"
# Default shell
LAUNCH_TERMINAL_SHELL="bash"
function usage() {
# Use echo to output the help message with colors
echo -e "${BOLD}Usage:${RESET} ${0##*/} [cmd] [options]"
echo -e ""
echo -e "${BOLD}Options:${RESET}"
echo -e " -s [shell] Change the shell to [shell]."
echo -e " -h Display this help message."
echo -e ""
echo -e "${BOLD}Description:${RESET}"
echo -e " This script launches a specified command in an appropriate terminal emulator,"
echo -e " automatically detecting the best option based on the desktop environment."
echo -e ""
echo -e "${BOLD}Examples:${RESET}"
echo -e " ${CYAN}${0##*/} \"echo Hello World\" -s zsh${RESET}"
exit "${1:-0}"
}
# Parse command-line options
while getopts "s:h" arg; do
case "${arg}" in
s) LAUNCH_TERMINAL_SHELL="${OPTARG}" ;;
h | ?) usage 0 ;;
*)
echo -e "${RED}Invalid argument: '${arg}'${RESET}";
usage 1
;;
esac
done
shift "$((OPTIND - 1))"
# Validate input command
if [ "$#" -lt 1 ]; then
echo -e "${RED}Error:${RESET} A command is required to execute."
usage 1
fi
COMMAND="${1}"
# Detect terminal emulator
declare -A terminals=(["alacritty"]="alacritty -e bash -c"
["konsole"]="konsole -e bash -c"
["kgx"]="kgx -- bash -c"
["gnome-terminal"]="gnome-terminal -- bash -c"
["xfce4-terminal"]="xfce4-terminal --disable-server --command"
["qterminal"]="qterminal -e bash -c"
["lxterminal"]="lxterminal -e bash -c"
["mate-terminal"]="mate-terminal --disable-factory -e bash -c"
["xterm"]="xterm -e bash -c"
["foot"]="foot -T exec-terminal -e bash -c")
term_order=("alacritty"
"konsole"
"kgx"
"gnome-terminal"
"mate-terminal"
"xfce4-terminal"
"qterminal"
"lxterminal"
"xterm"
"foot")
# Desktop environment-specific terminal preference
case "${XDG_CURRENT_DESKTOP}" in
KDE) terminal="konsole" ;;
GNOME)
if command -v "kgx" &>/dev/null; then
terminal="kgx"
else
terminal="gnome-terminal"
fi
;;
XFCE) terminal="xfce4-terminal" ;;
LXQt) terminal="qterminal" ;;
MATE) terminal="mate-terminal" ;;
esac
# Fallback: Check for available terminals
if [ -z "${terminal}" ] || ! command -v "${terminal}" &>/dev/null; then
for i in "${term_order[@]}"; do
if command -v "${i}" &>/dev/null; then
terminal="${i}"
break
fi
done
fi
# Error handling if no terminal is found
if [ -z "${terminal}" ]; then
echo -e "${RED}Error:${RESET} No terminal emulator found!";
notify-send -t 1500 --app-name="Terminal Launcher" "No terminal emulator found!";
exit 1
fi
# Debug detected terminal
echo -e "${YELLOW}Detected terminal:${RESET} ${BOLD}${terminal}${RESET}"
# Launch the command in the terminal
echo -e "${CYAN}Launching command:${RESET} ${BOLD}${COMMAND}${RESET}"
eval "${terminals[${terminal}]} \"${COMMAND}\"" || {
echo -e "${RED}Failed to launch command!${RESET}";
exit 2
}
# Success message
echo -e "${GREEN}Command executed successfully in terminal!${RESET}"

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD polkit Policy Configuration 1.0//EN" "http://www.freedesktop.org/software/polkit/policyconfig-1.dtd">
<policyconfig>
<!-- Vendor Information -->
<vendor>Snigdha OS</vendor>
<vendor_url>https://snigdhaos.org</vendor_url>
<!-- Policy for Installing Packages -->
<action id="org.snigdhaos.package.install">
<description>Install software using the pacman package manager</description>
<message>Administrator authentication is required to install software using pacman.</message>
<icon_name>snigdhaos-pacman</icon_name>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/lib/snigdhaos/install-package</annotate>
<annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
</action>
<!-- Policy for Running Graphical Programs with Elevated Privileges -->
<action id="org.snigdhaos.graphical.run-as-root">
<description>Run graphical applications with administrative privileges</description>
<message>Administrator authentication is required to run this graphical application with elevated privileges.</message>
<icon_name>snigdhaos-root-gui</icon_name>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/lib/snigdhaos/pkexec-gui</annotate>
<annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
</action>
</policyconfig>

View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# Ensure pkexec is available
if ! command -v pkexec &>/dev/null; then
echo "Error: 'pkexec' is not installed. Please install PolicyKit to proceed.";
exit 1
fi
# Check if the script is being run as root
if [[ "${EUID}" -ne 0 ]]; then
# Attempt to elevate privileges and rerun the script with pkexec
exec pkexec /usr/lib/snigdhaos/pkexec-gui "$@";
exit 1
fi
# Export environment variables from the parent process
# ShellCheck Directive: Allow environment variables to be read and exported from /proc
# shellcheck disable=SC2163
while IFS= read -rd '' var; do
export "${var}"
done < <(grep --null-data -ae "^\($XDG_CURRENT_DESKTOP\|WAYLAND_DISPLAY\|XDG_RUNTIME_DIR\|XDG_SESSION_TYPE\|XCURSOR_SIZE\|LC_.*\|LANG\|LANGUAGE\|QT_WAYLAND_FORCE_DPI\|QT_QPA_PLATFORMTHEME\|QT_STYLE_OVERRIDE\)=" /proc/$PPID/environ)
# Adjust WAYLAND_DISPLAY if running on Wayland
if [[ -n "${WAYLAND_DISPLAY}" ]]; then
export WAYLAND_DISPLAY="${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}"
fi
# Set the root user's runtime directory
export XDG_RUNTIME_DIR="/run/user/0"
# Execute the provided command with root privileges
exec "$@"

View File

@@ -0,0 +1,30 @@
#!/usr/bin/env bash
function snigdhaoslib_add_update_notice() {
# Ensure the directory exists
if ! mkdir -p /var/lib/snigdhaos/tmp; then
echo "Error: Failed to create directory /var/lib/snigdhaos/tmp" >&2;
return 1
fi
# Get the current date
current_date="$(date +%F)"
# Ensure the input message is not empty
if [ -z "${1}" ]; then
echo "Error: No update message provided." >&2;
return 1
fi
# Replace multiple spaces with a single space
message="${1//[[:space:]]+/ }"
# Append the message to the file with the current date
if ! printf "%s %s\n" "${current_date}" "${message}" >> /var/lib/snigdhaos/tmp/update_notices; then
echo "Error: Failed to write to /var/lib/snigdhaos/tmp/update_notices" >&2;
return 1
fi
# Optionally, display a success message (for debugging/logging purposes)
echo "Update notice successfully added for ${current_date}."
}