From f2144078e9c84882a488c41821de6a5abe104bed Mon Sep 17 00:00:00 2001 From: Uyanide Date: Tue, 29 Jul 2025 02:07:07 +0200 Subject: [PATCH] better scripts --- .scripts/fetch-weather.sh | 2 +- .scripts/issu.sh | 8 +++-- {.utils => .scripts}/truecolor-test.sh | 0 .scripts/workspace-new.sh | 2 +- .utils/live-mount.sh | 29 +++++++++++++++++++ .utils/live_mount.sh | 18 ------------ .scripts/set_nv_env.sh => .utils/set_nv_env | 2 -- .../unset_nv_env.sh => .utils/unset_nv_env | 2 -- 8 files changed, 37 insertions(+), 26 deletions(-) rename {.utils => .scripts}/truecolor-test.sh (100%) create mode 100755 .utils/live-mount.sh delete mode 100755 .utils/live_mount.sh rename .scripts/set_nv_env.sh => .utils/set_nv_env (91%) mode change 100755 => 100644 rename .scripts/unset_nv_env.sh => .utils/unset_nv_env (94%) mode change 100755 => 100644 diff --git a/.scripts/fetch-weather.sh b/.scripts/fetch-weather.sh index 3c653f8..e4823cd 100755 --- a/.scripts/fetch-weather.sh +++ b/.scripts/fetch-weather.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/env bash ## Collect data cache_dir="$HOME/.cache/eww/weather" diff --git a/.scripts/issu.sh b/.scripts/issu.sh index 303e231..d1080a5 100755 --- a/.scripts/issu.sh +++ b/.scripts/issu.sh @@ -12,6 +12,10 @@ if [ "$LOGNAME" != "$USER" ]; then exit 1 fi -if [ "$(ps -o comm= -p $(ps -o ppid= -p $$) 2>/dev/null)" = "su" ]; then - exit 1 +ppid=$(ps -o ppid= -p $$ 2>/dev/null) +if [ -n "$ppid" ]; then + parent_comm=$(ps -o comm= -p "$ppid" 2>/dev/null) + if [ "$parent_comm" = "su" ]; then + exit 1 + fi fi diff --git a/.utils/truecolor-test.sh b/.scripts/truecolor-test.sh similarity index 100% rename from .utils/truecolor-test.sh rename to .scripts/truecolor-test.sh diff --git a/.scripts/workspace-new.sh b/.scripts/workspace-new.sh index 8577e05..f4d5032 100755 --- a/.scripts/workspace-new.sh +++ b/.scripts/workspace-new.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/env bash # get highest workspace ID max_id=$(hyprctl workspaces | grep '^workspace ID ' | awk '{print $3}' | sort -n | tail -1) diff --git a/.utils/live-mount.sh b/.utils/live-mount.sh new file mode 100755 index 0000000..7df1fbc --- /dev/null +++ b/.utils/live-mount.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +[ -z "$MOUNT_DIR" ] && MOUNT_DIR="/mnt" + +if ! umount "$MOUNT_DIR" -R; then + echo "Failed to unmount $MOUNT_DIR." + exit 1 +fi + +[ -z "$DEVICE" ] && DEVICE="/dev/sda" +[ -z "$START_PART" ] && START_PART="1" + +efi_part="${DEVICE}p${START_PART}" + +START_PART=$(expr $START_PART + 1) +boot_part="${DEVICE}p${START_PART}" + +START_PART=$(expr $START_PART + 1) +btrfs_part="${DEVICE}p${START_PART}" + +mount "$btrfs_part" -o subvol=@ "$MOUNT_DIR" +mount "$btrfs_part" -o subvol=@home "$MOUNT_DIR"/home +mount "$btrfs_part" -o subvol=@log"$MOUNT_DIR"/var/log +mount "$btrfs_part" -o subvol=@cache "$MOUNT_DIR"/var/cache +mount "$btrfs_part" -o subvol=@tmp "$MOUNT_DIR"/tmp +# mount "$btrfs_part" -o subvol=@swap "$MOUNT_DIR"/swap +mount "$boot_part" "$MOUNT_DIR"/boot +mount "$efi_part" "$MOUNT_DIR"/boot/efi +swapon "$MOUNT_DIR"/swap/swapfile \ No newline at end of file diff --git a/.utils/live_mount.sh b/.utils/live_mount.sh deleted file mode 100755 index c85f7a7..0000000 --- a/.utils/live_mount.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -device="/dev/nvme0n1" -efi_part="${device}p3" -boot_part="${device}p4" -btrfs_part="${device}p5" - -umount /mnt -R - -mount $btrfs_part -o subvol=@ /mnt -mount $btrfs_part -o subvol=@home /mnt/home -mount $btrfs_part -o subvol=@log /mnt/var/log -mount $btrfs_part -o subvol=@cache /mnt/var/cache -mount $btrfs_part -o subvol=@tmp /mnt/tmp -mount $btrfs_part -o subvol=@swap /mnt/swap -mount $boot_part /mnt/boot -mount $efi_part /mnt/boot/efi -swapon /mnt/swap/swapfile \ No newline at end of file diff --git a/.scripts/set_nv_env.sh b/.utils/set_nv_env old mode 100755 new mode 100644 similarity index 91% rename from .scripts/set_nv_env.sh rename to .utils/set_nv_env index 9771b85..c9f9dcb --- a/.scripts/set_nv_env.sh +++ b/.utils/set_nv_env @@ -1,5 +1,3 @@ -#!/bin/sh - export __NV_PRIME_RENDER_OFFLOAD=1 export __GLX_VENDOR_LIBRARY_NAME=nvidia export __VK_LAYER_NV_optimus=NVIDIA_only diff --git a/.scripts/unset_nv_env.sh b/.utils/unset_nv_env old mode 100755 new mode 100644 similarity index 94% rename from .scripts/unset_nv_env.sh rename to .utils/unset_nv_env index bf7342d..b637282 --- a/.scripts/unset_nv_env.sh +++ b/.utils/unset_nv_env @@ -1,5 +1,3 @@ -#!/bin/sh - # __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia __VK_LAYER_NV_optimus=NVIDIA_only unset __NV_PRIME_RENDER_OFFLOAD unset __GLX_VENDOR_LIBRARY_NAME