diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-01-24 20:35:27 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-01-24 20:35:27 +0900 |
| commit | c80a54e42b52ce297f0f2f71af23c562832025c7 (patch) | |
| tree | dcce8bb977a770f473325d48f6f70b21d9818a40 /ar/.local/bin/partlabel | |
init
Diffstat (limited to 'ar/.local/bin/partlabel')
| -rwxr-xr-x | ar/.local/bin/partlabel | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/ar/.local/bin/partlabel b/ar/.local/bin/partlabel new file mode 100755 index 0000000..fb62fcd --- /dev/null +++ b/ar/.local/bin/partlabel @@ -0,0 +1,85 @@ +#!/bin/sh + +command_exists() { command -v "$1" >/dev/null 2>&1; } +get_fs_type() { sudo blkid -o value -s TYPE "$1" 2>/dev/null; } +label_ext() { sudo e2label "$1" "$2"; } +label_fat() { sudo fatlabel "$1" "$2"; } +label_ntfs() { sudo ntfslabel --force --quiet "$1" "$2"; } +label_btrfs() { sudo btrfs filesystem label "$1" "$2"; } +label_luks() { sudo cryptsetup config "$1" --label "$2"; } +label_parted() { sudo parted "$1" name "$2" "$3"; } +print_label() { sudo lsblk -o NAME,LABEL; } + +echo "Partition Labeling Script" +for cmd in blkid e2label fatlabel ntfslabel btrfs parted lsblk cryptsetup; do + if ! command_exists "$cmd"; then + echo "Error: $cmd is not installed or not in PATH." + echo "Installing necessary package for $cmd..." + case $cmd in + blkid | lsblk) + sudo pacman -S --noconfirm util-linux + ;; + e2label) + sudo pacman -S --noconfirm e2fsprogs + ;; + fatlabel) + sudo pacman -S --noconfirm dosfstools + ;; + ntfslabel) + sudo pacman -S --noconfirm ntfs-3g + ;; + btrfs) + sudo pacman -S --noconfirm btrfs-progs + ;; + parted) + sudo pacman -S --noconfirm parted + ;; + cryptsetup) + sudo pacman -S --noconfirm cryptsetup + ;; + *) + echo "Unknown command: $cmd" + exit 1 + ;; + esac + fi +done + +print_label +echo -n "\nEnter the partition (e.g., /dev/sda1): " +read partition + +fs_type=$(get_fs_type "$partition") + +if [ -z "$fs_type" ]; then + echo "Unable to determine file system type for $partition. Please ensure the partition exists and has a valid file system." + echo "Debugging information:" + echo "blkid output for $partition:" + sudo blkid "$partition" + echo "Raw blkid output:" + sudo blkid + exit 1 +fi + +echo "Detected file system type: $fs_type" +echo -n "Enter the label: " +read label + +case "$fs_type" in +ext2 | ext3 | ext4) label_ext "$partition" "$label" ;; +vfat) label_fat "$partition" "$label" ;; +ntfs) label_ntfs "$partition" "$label" ;; +btrfs) label_btrfs "$partition" "$label" ;; +crypto_LUKS) + echo "Labeling LUKS partition using cryptsetup." + label_luks "$partition" "$label" + ;; +*) + echo "File system type $fs_type is not directly supported by this script. Attempting to label with parted." + label_parted "$partition" "$label" + ;; +esac + +echo "Partition labeled successfully. Verifying..." +print_label +echo "Done." |
