From 15a56f4ed8932a8a4c178eb1432474d3a85d9414 Mon Sep 17 00:00:00 2001 From: guruswarupa Date: Thu, 19 Sep 2024 09:41:56 +0530 Subject: [PATCH 01/10] added auto mount script --- tabs/system-setup/9-auto-mount.sh | 89 +++++++++++++++++++++++++++++++ tabs/system-setup/tab_data.toml | 6 ++- 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tabs/system-setup/9-auto-mount.sh diff --git a/tabs/system-setup/9-auto-mount.sh b/tabs/system-setup/9-auto-mount.sh new file mode 100644 index 000000000..f6e29606e --- /dev/null +++ b/tabs/system-setup/9-auto-mount.sh @@ -0,0 +1,89 @@ +#!/bin/sh -e + +. ../common-script.sh + +# Function to display available drives and allow the user to select one +select_drive() { + clear + printf "%b\n" "Available drives and partitions:" + lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT,LABEL,UUID | grep -v 'loop' # list all non-loop devices + printf "\n" + printf "%b\n" "Enter the drive/partition name (e.g., sda1, sdb1): " + read -r drive_name + # Check if the input is valid + if lsblk | grep -q "${drive_name}"; then + partition="/dev/${drive_name}" + else + printf "%b\n" "Invalid drive/partition name!" + exit 1 + fi +} + +# Function to get UUID and FSTYPE of the selected drive +get_uuid_fstype() { + UUID=$(blkid -s UUID -o value "${partition}") + FSTYPE=$(lsblk -no FSTYPE "${partition}") + NAME=$(lsblk -no NAME "${partition}") + + if [ -z "$UUID" ]; then + printf "%b\n" "Failed to retrieve the UUID. Exiting." + exit 1 + fi + + if [ -z "$FSTYPE" ]; then + printf "%b\n" "Failed to retrieve the filesystem type. Exiting." + exit 1 + fi +} + +# Function to create a mount point +create_mount_point() { + printf "%b\n" "Enter the mount point path (e.g., /mnt/hdd): " + read -r mount_point + if [ ! -d "$mount_point" ]; then + printf "%b\n" "Mount point doesn't exist. Creating it..." + $ESCALATION_TOOL mkdir -p "$mount_point" + else + printf "%b\n" "Mount point already exists." + fi +} + +# Function to update /etc/fstab with a comment on the first line and the actual entry on the second line +update_fstab() { + printf "%b\n" "Adding entry to /etc/fstab..." + $ESCALATION_TOOL cp /etc/fstab /etc/fstab.bak # Backup fstab + + # Prepare the comment and the fstab entry + comment="# Mount for /dev/$NAME" + fstab_entry="UUID=$UUID $mount_point $FSTYPE defaults 0 2" + + # Append the comment and the entry to /etc/fstab + printf "%b\n" "$comment" | $ESCALATION_TOOL tee -a /etc/fstab > /dev/null + printf "%b\n" "$fstab_entry" | $ESCALATION_TOOL tee -a /etc/fstab > /dev/null + printf "%b\n" "" | $ESCALATION_TOOL tee -a /etc/fstab > /dev/null + + printf "%b\n" "Entry added to /etc/fstab:" + printf "%b\n" "$comment" + printf "%b\n" "$fstab_entry" +} + + +# Function to mount the drive +mount_drive() { + printf "%b\n" "Mounting the drive..." + $ESCALATION_TOOL mount -a + if mount | grep "$mount_point" > /dev/null; then + printf "%b\n" "Drive mounted successfully at $mount_point." + else + printf "%b\n" "${RED}Failed to mount the drive.${RC}" + exit 1 + fi +} + +checkEnv +checkEscalationTool +select_drive +get_uuid_fstype +create_mount_point +update_fstab +mount_drive diff --git a/tabs/system-setup/tab_data.toml b/tabs/system-setup/tab_data.toml index 4eabb4d5e..c32edbfa5 100644 --- a/tabs/system-setup/tab_data.toml +++ b/tabs/system-setup/tab_data.toml @@ -89,4 +89,8 @@ script = "5-samba-ssh-setup.sh" [[data]] name = "Docker Setup" -script = "6-docker-setup.sh" \ No newline at end of file +script = "6-docker-setup.sh" + +[[data]] +name = "Auto Mount Drive" +script = "9-auto-mount.sh" \ No newline at end of file From 5624720fc70015937f2dcf2408b1e09c3a370458 Mon Sep 17 00:00:00 2001 From: Guru Swarupa <112751363+guruswarupa@users.noreply.github.com> Date: Thu, 19 Sep 2024 19:17:01 +0530 Subject: [PATCH 02/10] Update tabs/system-setup/9-auto-mount.sh Co-authored-by: Nyx <144965845+nnyyxxxx@users.noreply.github.com> --- tabs/system-setup/9-auto-mount.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabs/system-setup/9-auto-mount.sh b/tabs/system-setup/9-auto-mount.sh index f6e29606e..b5d49a63b 100644 --- a/tabs/system-setup/9-auto-mount.sh +++ b/tabs/system-setup/9-auto-mount.sh @@ -51,7 +51,7 @@ create_mount_point() { # Function to update /etc/fstab with a comment on the first line and the actual entry on the second line update_fstab() { printf "%b\n" "Adding entry to /etc/fstab..." - $ESCALATION_TOOL cp /etc/fstab /etc/fstab.bak # Backup fstab + $ESCALATION_TOOL cp /etc/fstab /etc/fstab.bak # Backup fstab # Prepare the comment and the fstab entry comment="# Mount for /dev/$NAME" From 3fb7f626e969574342b83d0b34ce13a952eeb61d Mon Sep 17 00:00:00 2001 From: Guru Swarupa <112751363+guruswarupa@users.noreply.github.com> Date: Thu, 19 Sep 2024 19:17:11 +0530 Subject: [PATCH 03/10] Update tabs/system-setup/9-auto-mount.sh Co-authored-by: Nyx <144965845+nnyyxxxx@users.noreply.github.com> --- tabs/system-setup/9-auto-mount.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabs/system-setup/9-auto-mount.sh b/tabs/system-setup/9-auto-mount.sh index b5d49a63b..80ff89339 100644 --- a/tabs/system-setup/9-auto-mount.sh +++ b/tabs/system-setup/9-auto-mount.sh @@ -60,7 +60,7 @@ update_fstab() { # Append the comment and the entry to /etc/fstab printf "%b\n" "$comment" | $ESCALATION_TOOL tee -a /etc/fstab > /dev/null printf "%b\n" "$fstab_entry" | $ESCALATION_TOOL tee -a /etc/fstab > /dev/null - printf "%b\n" "" | $ESCALATION_TOOL tee -a /etc/fstab > /dev/null + printf "%b\n" "" | "$ESCALATION_TOOL" tee -a /etc/fstab > /dev/null printf "%b\n" "Entry added to /etc/fstab:" printf "%b\n" "$comment" From 4260401be4145ee9aab6b03986a964d5296f61a3 Mon Sep 17 00:00:00 2001 From: Guru Swarupa <112751363+guruswarupa@users.noreply.github.com> Date: Thu, 19 Sep 2024 19:17:34 +0530 Subject: [PATCH 04/10] Update tabs/system-setup/9-auto-mount.sh Co-authored-by: Nyx <144965845+nnyyxxxx@users.noreply.github.com> --- tabs/system-setup/9-auto-mount.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabs/system-setup/9-auto-mount.sh b/tabs/system-setup/9-auto-mount.sh index 80ff89339..8222d0f40 100644 --- a/tabs/system-setup/9-auto-mount.sh +++ b/tabs/system-setup/9-auto-mount.sh @@ -73,7 +73,7 @@ mount_drive() { printf "%b\n" "Mounting the drive..." $ESCALATION_TOOL mount -a if mount | grep "$mount_point" > /dev/null; then - printf "%b\n" "Drive mounted successfully at $mount_point." + printf "%b\n" "${GREEN}Drive mounted successfully at $mount_point${RC}." else printf "%b\n" "${RED}Failed to mount the drive.${RC}" exit 1 From ab582b5230d0f108c9ae6e2bde06e4977b73dc92 Mon Sep 17 00:00:00 2001 From: Guru Swarupa <112751363+guruswarupa@users.noreply.github.com> Date: Thu, 19 Sep 2024 19:19:28 +0530 Subject: [PATCH 05/10] Update tabs/system-setup/9-auto-mount.sh Co-authored-by: Nyx <144965845+nnyyxxxx@users.noreply.github.com> --- tabs/system-setup/9-auto-mount.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabs/system-setup/9-auto-mount.sh b/tabs/system-setup/9-auto-mount.sh index 8222d0f40..05c1624bc 100644 --- a/tabs/system-setup/9-auto-mount.sh +++ b/tabs/system-setup/9-auto-mount.sh @@ -50,7 +50,7 @@ create_mount_point() { # Function to update /etc/fstab with a comment on the first line and the actual entry on the second line update_fstab() { - printf "%b\n" "Adding entry to /etc/fstab..." + printf "%b\n" "${YELLOW}Adding entry to /etc/fstab...${RC}" $ESCALATION_TOOL cp /etc/fstab /etc/fstab.bak # Backup fstab # Prepare the comment and the fstab entry From d8e088d909dc579483ad3bb9d5180a2ceacea0b9 Mon Sep 17 00:00:00 2001 From: Guru Swarupa <112751363+guruswarupa@users.noreply.github.com> Date: Thu, 19 Sep 2024 19:19:34 +0530 Subject: [PATCH 06/10] Update tabs/system-setup/9-auto-mount.sh Co-authored-by: Nyx <144965845+nnyyxxxx@users.noreply.github.com> --- tabs/system-setup/9-auto-mount.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabs/system-setup/9-auto-mount.sh b/tabs/system-setup/9-auto-mount.sh index 05c1624bc..a942334bd 100644 --- a/tabs/system-setup/9-auto-mount.sh +++ b/tabs/system-setup/9-auto-mount.sh @@ -26,7 +26,7 @@ get_uuid_fstype() { NAME=$(lsblk -no NAME "${partition}") if [ -z "$UUID" ]; then - printf "%b\n" "Failed to retrieve the UUID. Exiting." + printf "%b\n" "${RED}Failed to retrieve the UUID. Exiting.${RC}" exit 1 fi From 9911639b46535136704b352c590b64e3f98d5834 Mon Sep 17 00:00:00 2001 From: Guru Swarupa <112751363+guruswarupa@users.noreply.github.com> Date: Thu, 19 Sep 2024 19:19:39 +0530 Subject: [PATCH 07/10] Update tabs/system-setup/9-auto-mount.sh Co-authored-by: Nyx <144965845+nnyyxxxx@users.noreply.github.com> --- tabs/system-setup/9-auto-mount.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabs/system-setup/9-auto-mount.sh b/tabs/system-setup/9-auto-mount.sh index a942334bd..4d0852738 100644 --- a/tabs/system-setup/9-auto-mount.sh +++ b/tabs/system-setup/9-auto-mount.sh @@ -31,7 +31,7 @@ get_uuid_fstype() { fi if [ -z "$FSTYPE" ]; then - printf "%b\n" "Failed to retrieve the filesystem type. Exiting." + printf "%b\n" "${RED}Failed to retrieve the filesystem type. Exiting.${RC}" exit 1 fi } From c0f153c75d1f1f404395f69ef0a2f12c46005b8d Mon Sep 17 00:00:00 2001 From: Guru Swarupa <112751363+guruswarupa@users.noreply.github.com> Date: Thu, 19 Sep 2024 19:19:46 +0530 Subject: [PATCH 08/10] Update tabs/system-setup/9-auto-mount.sh Co-authored-by: Nyx <144965845+nnyyxxxx@users.noreply.github.com> --- tabs/system-setup/9-auto-mount.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabs/system-setup/9-auto-mount.sh b/tabs/system-setup/9-auto-mount.sh index 4d0852738..2048a3683 100644 --- a/tabs/system-setup/9-auto-mount.sh +++ b/tabs/system-setup/9-auto-mount.sh @@ -14,7 +14,7 @@ select_drive() { if lsblk | grep -q "${drive_name}"; then partition="/dev/${drive_name}" else - printf "%b\n" "Invalid drive/partition name!" + printf "%b\n" "${RED}Invalid drive/partition name!${RC}" exit 1 fi } From b8d9466e4ebc00f94b41c0743d343a59ef1d6daf Mon Sep 17 00:00:00 2001 From: Guru Swarupa <112751363+guruswarupa@users.noreply.github.com> Date: Thu, 19 Sep 2024 19:19:52 +0530 Subject: [PATCH 09/10] Update tabs/system-setup/9-auto-mount.sh Co-authored-by: Nyx <144965845+nnyyxxxx@users.noreply.github.com> --- tabs/system-setup/9-auto-mount.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabs/system-setup/9-auto-mount.sh b/tabs/system-setup/9-auto-mount.sh index 2048a3683..ee05bdea9 100644 --- a/tabs/system-setup/9-auto-mount.sh +++ b/tabs/system-setup/9-auto-mount.sh @@ -44,7 +44,7 @@ create_mount_point() { printf "%b\n" "Mount point doesn't exist. Creating it..." $ESCALATION_TOOL mkdir -p "$mount_point" else - printf "%b\n" "Mount point already exists." + printf "%b\n" "${RED}Mount point already exists.${RC}" fi } From 4e0381a16a58a1b3f034d8d5c3655a3cd098d649 Mon Sep 17 00:00:00 2001 From: Guru Swarupa <112751363+guruswarupa@users.noreply.github.com> Date: Thu, 19 Sep 2024 19:19:56 +0530 Subject: [PATCH 10/10] Update tabs/system-setup/9-auto-mount.sh Co-authored-by: Nyx <144965845+nnyyxxxx@users.noreply.github.com> --- tabs/system-setup/9-auto-mount.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabs/system-setup/9-auto-mount.sh b/tabs/system-setup/9-auto-mount.sh index ee05bdea9..fd81df516 100644 --- a/tabs/system-setup/9-auto-mount.sh +++ b/tabs/system-setup/9-auto-mount.sh @@ -41,7 +41,7 @@ create_mount_point() { printf "%b\n" "Enter the mount point path (e.g., /mnt/hdd): " read -r mount_point if [ ! -d "$mount_point" ]; then - printf "%b\n" "Mount point doesn't exist. Creating it..." + printf "%b\n" "${YELLOW}Mount point doesn't exist. Creating it..${RC}." $ESCALATION_TOOL mkdir -p "$mount_point" else printf "%b\n" "${RED}Mount point already exists.${RC}"