scripts: remove issu & add luks-mount & ya pkg upgrade

This commit is contained in:
2026-01-10 08:57:14 +01:00
parent 490ce1f819
commit cff586109c
9 changed files with 122 additions and 58 deletions
@@ -63,7 +63,7 @@ SCRIPTS = {
def hex2rgb(hex_color: str) -> tuple[int, int, int]: def hex2rgb(hex_color: str) -> tuple[int, int, int]:
"""#rrggbb to (r, g, b)""" """#rrggbb to (r, g, b)"""
return tuple(int(hex_color[i : i + 2], 16) for i in (0, 2, 4)) # type: ignore return tuple(int(hex_color[i: i + 2], 16) for i in (0, 2, 4)) # type: ignore
def clamp(x, minimum, maximum) -> float: def clamp(x, minimum, maximum) -> float:
-27
View File
@@ -1,27 +0,0 @@
#!/bin/sh
# Description:
# Detect if the current user is a root or sudo user. Exits with code 0 if true, 1 otherwise.
# This script is required by some other scripts such as `smb-mount` and `wsl-mount`.
if [ "$(id -u)" -eq 0 ]; then
exit 0
fi
if [ -n "$SUDO_USER" ]; then
exit 0
fi
if [ "$LOGNAME" != "$USER" ]; then
exit 0
fi
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 0
fi
fi
exit 1
+99
View File
@@ -0,0 +1,99 @@
#!/usr/bin/env bash
# Description:
# Mount a LUKS encrypted partition and open a shell in the mounted directory.
# - If multiple LUKS devices are found, use fzf to select one (if available).
# - Uses environment variables to customize behavior:
# - LUKS_PARTITION: Path to the LUKS partition (overrides auto-detection).
# - LUKS_MAPPER_NAME: Name for the LUKS mapper (default: luks_mount_<timestamp>).
# - LUKS_MOUNT_POINT: Mount point for the decrypted volume (default: /mnt/luks).
# - Cleans up on exit (unmounts and closes the LUKS volume).
# Requirements:
# - cryptsetup
# - sudo privileges
# - fzf (optional, for selecting among multiple LUKS devices)
set -euo pipefail
[ "$(id -u)" -eq 0 ] && {
echo "[ERROR] Do not run this script in sudo mode." >&2
exit 1
}
find_luks_device() {
# Set $devices array to all LUKS devices
# lsblk command explained - n: no headings, p: full path, o: output format, l: list format
mapfile -t devices < <(lsblk -nplo NAME,FSTYPE | awk '$2 == "crypto_LUKS" {print $1}')
if [ ${#devices[@]} -eq 0 ]; then
echo "[ERROR] No LUKS devices found." >&2
return 1
elif [ ${#devices[@]} -eq 1 ]; then
echo "${devices[0]}"
else
# Multiple devices found
# Select one using fzf if available
if command -v fzf >/dev/null; then
printf "%s\n" "${devices[@]}" | fzf --prompt="Select LUKS device: "
else
echo "[ERROR] Multiple LUKS devices found. Please set LUKS_PARTITION env var." >&2
printf "%s\n" "${devices[@]}" >&2
return 1
fi
fi
}
LUKS_PARTITION="${LUKS_PARTITION:-$(find_luks_device)}"
[ -z "$LUKS_PARTITION" ] && exit 1
# Default to a unique name based on timestamp
LUKS_MAPPER_NAME="${LUKS_MAPPER_NAME:-luks_mount_$(date +%s)}"
# Fixed default mount point though
LUKS_MOUNT_POINT="${LUKS_MOUNT_POINT:-/mnt/luks}"
echo "[INFO] Partition: $LUKS_PARTITION" >&2
echo "[INFO] Mapper: $LUKS_MAPPER_NAME" >&2
echo "[INFO] Mount: $LUKS_MOUNT_POINT" >&2
mount_point_created=0
if [ ! -d "$LUKS_MOUNT_POINT" ]; then
sudo mkdir -p "$LUKS_MOUNT_POINT"
mount_point_created=1
fi
if ! sudo cryptsetup open "$LUKS_PARTITION" "$LUKS_MAPPER_NAME"; then
echo "[ERROR] Failed to open device." >&2
exit 1
fi
cleanup() {
echo "[INFO] Cleaning up..." >&2
# Make sure we are not in the mount point when unmounting
cd "$HOME" || true
if mountpoint -q "$LUKS_MOUNT_POINT"; then
sudo umount "$LUKS_MOUNT_POINT" || echo "[WARNING] Failed to unmount." >&2
fi
if [ -e "/dev/mapper/$LUKS_MAPPER_NAME" ]; then
sudo cryptsetup close "$LUKS_MAPPER_NAME" || echo "[WARNING] Failed to close LUKS mapper." >&2
fi
if [ $mount_point_created -eq 1 ] && [ -d "$LUKS_MOUNT_POINT" ]; then
sudo rmdir "$LUKS_MOUNT_POINT" || echo "[WARNING] Failed to remove mount point." >&2
fi
echo "[INFO] Done." >&2
}
trap cleanup EXIT INT TERM
sudo mount "/dev/mapper/$LUKS_MAPPER_NAME" "$LUKS_MOUNT_POINT"
sudo chown "$(whoami):$(whoami)" "$LUKS_MOUNT_POINT"
echo "[INFO] Successfully mounted at $LUKS_MOUNT_POINT." >&2
echo "[INFO] Exit this shell to unmount and close the LUKS volume..." >&2
cd "$LUKS_MOUNT_POINT"
USER_SHELL="${SHELL:-/bin/bash}"
if [[ "$USER_SHELL" == *"/bash" ]]; then
"$USER_SHELL" --rcfile <(cat ~/.bashrc 2>/dev/null; printf '%s\n' 'PS1="\[\e[1;31m\][LUKS]\[\e[0m\][\u@\h \W]\$ "') -i
else
"$USER_SHELL"
fi
+2 -6
View File
@@ -5,14 +5,10 @@
# #
# Requirements: # Requirements:
# - cifs-utils # - cifs-utils
# - ./issu
# - sudo privileges # - sudo privileges
[ "$(id -u)" -eq 0 ] && {
path=$(dirname "$(realpath "$0")") echo "Do not run this script in sudo mode." >&2
"$path"/issu && {
echo "Do not run this script in sudo mode."
exit 1 exit 1
} }
+1 -4
View File
@@ -5,12 +5,9 @@
# #
# Requirements: # Requirements:
# - cifs-utils # - cifs-utils
# - ./issu
# - sudo privileges # - sudo privileges
path=$(dirname "$(realpath "$0")") [ "$(id -u)" -eq 0 ] && {
"$path"/issu && {
echo "Do not run this script in sudo mode." echo "Do not run this script in sudo mode."
exit 1 exit 1
} }
+1 -3
View File
@@ -13,9 +13,7 @@
# This can be done using `qemu-img check -r all <VHDX_PATH>` # This can be done using `qemu-img check -r all <VHDX_PATH>`
path=$(dirname "$(realpath "$0")") [ "$(id -u)" -eq 0 ] && {
"$path"/issu && {
echo "Do not run this script in sudo mode." echo "Do not run this script in sudo mode."
exit 1 exit 1
} }
+5 -5
View File
@@ -1,11 +1,11 @@
[[plugin.deps]] [[plugin.deps]]
use = "yazi-rs/plugins:git" use = "yazi-rs/plugins:git"
rev = "398796d" rev = "68f7d48"
hash = "73788c7dc5827ef4677c502c3ea8fa19" hash = "36a484acf6a0a0219c543ccb4cee218f"
[[plugin.deps]] [[plugin.deps]]
use = "yazi-rs/plugins:smart-enter" use = "yazi-rs/plugins:smart-enter"
rev = "398796d" rev = "68f7d48"
hash = "56fdabc96fc1f4d53c96eb884b02a5be" hash = "56fdabc96fc1f4d53c96eb884b02a5be"
[[plugin.deps]] [[plugin.deps]]
@@ -15,8 +15,8 @@ hash = "699fe07e0d2d1b4af8dafb84168eeb04"
[[plugin.deps]] [[plugin.deps]]
use = "KKV9/compress" use = "KKV9/compress"
rev = "c264639" rev = "e2ae983"
hash = "e17c11b605d989568a1d1741ca17c584" hash = "36b570e2164f6ad2317cfb839e42ef4"
[[plugin.deps]] [[plugin.deps]]
use = "llanosrocas/yaziline" use = "llanosrocas/yaziline"
@@ -243,7 +243,7 @@ return {
is_level = true is_level = true
end end
end end
elseif arg:match("^%w[%w\\.]*$") then elseif arg:match("^[%w%.]+$") then
-- Handle default extension (e.g., 7z, zip) -- Handle default extension (e.g., 7z, zip)
if archive_commands["%." .. arg .. "$"] then if archive_commands["%." .. arg .. "$"] then
default_extension = arg default_extension = arg
@@ -265,7 +265,7 @@ return {
ya.input( ya.input(
{ {
title = "Create archive:", title = "Create archive:",
position = {"top-center", y = 3, w = 40} pos = {"top-center", y = 3, w = 40}
} }
) )
if event ~= 1 then if event ~= 1 then
@@ -362,7 +362,7 @@ return {
{ {
title = "Enter password:", title = "Enter password:",
obscure = true, obscure = true,
position = {"top-center", y = 3, w = 40} pos = {"top-center", y = 3, w = 40}
} }
) )
if event ~= 1 then if event ~= 1 then
@@ -388,7 +388,7 @@ return {
ya.input( ya.input(
{ {
title = string.format("Enter compression level (%s - %s)", archive_level_min, archive_level_max), title = string.format("Enter compression level (%s - %s)", archive_level_min, archive_level_max),
position = {"top-center", y = 3, w = 40} pos = {"top-center", y = 3, w = 40}
} }
) )
if event ~= 1 then if event ~= 1 then
@@ -476,7 +476,7 @@ return {
-- Move the final file from the temporary directory to the output directory -- Move the final file from the temporary directory to the output directory
local final_output_url, temp_url_processed = combine_url(output_dir, original_name), combine_url(temp_dir, original_name) local final_output_url, temp_url_processed = combine_url(output_dir, original_name), combine_url(temp_dir, original_name)
final_output_url, _ = tostring(fs.unique_name(Url(final_output_url))) final_output_url, _ = tostring(fs.unique_name(Url(final_output_url)))
local move_status, move_err = os.rename(temp_url_processed, final_output_url) local move_status, move_err = fs.rename(Url(temp_url_processed), Url(final_output_url))
if not move_status then if not move_status then
-- Notify the user if the move operation fails and clean up the temporary directory -- Notify the user if the move operation fails and clean up the temporary directory
notify_error(string.format("Failed to move %s to %s, error: %s", temp_url_processed, final_output_url, move_err), "error") notify_error(string.format("Failed to move %s to %s, error: %s", temp_url_processed, final_output_url, move_err), "error")
@@ -494,3 +494,4 @@ return {
end end
end end
} }
@@ -170,12 +170,12 @@ local function setup(st, opts)
[CODES.updated] = t.updated and ui.Style(t.updated) or ui.Style():fg("yellow"), [CODES.updated] = t.updated and ui.Style(t.updated) or ui.Style():fg("yellow"),
} }
local signs = { local signs = {
[CODES.ignored] = t.ignored_sign or "", [CODES.ignored] = t.ignored_sign or " ",
[CODES.untracked] = t.untracked_sign or "?", [CODES.untracked] = t.untracked_sign or "? ",
[CODES.modified] = t.modified_sign or "", [CODES.modified] = t.modified_sign or " ",
[CODES.added] = t.added_sign or "", [CODES.added] = t.added_sign or " ",
[CODES.deleted] = t.deleted_sign or "", [CODES.deleted] = t.deleted_sign or " ",
[CODES.updated] = t.updated_sign or "", [CODES.updated] = t.updated_sign or " ",
} }
Linemode:children_add(function(self) Linemode:children_add(function(self)