From 633c5e8c7fb72fafb019b53bd4501bef6a8da75f Mon Sep 17 00:00:00 2001
From: Esteban Herrera <stv.herrera@gmail.com>
Date: Mon, 8 Jan 2024 22:38:33 -0600
Subject: [PATCH] Remove mount and start options with interactive dialogs.

---
 README.md             |  2 +-
 env/.env              |  2 +-
 includes/start_box.sh | 36 ++++++-------------------
 includes/stop_box.sh  | 25 ++++-------------
 pandoras.sh           | 62 ++++++++++++++++++++++++-------------------
 5 files changed, 49 insertions(+), 78 deletions(-)

diff --git a/README.md b/README.md
index bf883c5..41f8eba 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ Universal Chroot environment that can be deployed to most Linux distributions to
 - Delete a box
 - Duplicate a box
 - Enter a box
-- List boxes
+- List boxes and filesystems
 - Mount a partition or directory
 - Upsize a box
 
diff --git a/env/.env b/env/.env
index cf5e502..98ff1af 100644
--- a/env/.env
+++ b/env/.env
@@ -1 +1 @@
-RUNNING_IMAGE_NAME=""
+RUNNING_IMG_NAME=""
diff --git a/includes/start_box.sh b/includes/start_box.sh
index a28ff9e..bc98cc2 100644
--- a/includes/start_box.sh
+++ b/includes/start_box.sh
@@ -38,34 +38,13 @@ start_box() {
 
   export dir=/var/pandoras
 
-  sudo bash ./list_boxes.sh
-  read -r -p "Type your image name: " image
-
-  # Ask if a custom partition or directory should be added
-  read -r -p "Do you want to add a custom partition or directory? (y/n): " add_custom_part
+  # Check if a box name is provided as a command-line parameter
+  if [ -n "$1" ]; then
+    image="$1"
+  fi
 
   mount $dir/images/"$image".img $dir/environment
 
-  if [ "$add_custom_part" == "y" ]; then
-    # Ask for the device path or directory path
-    read -r -p "Type the device or directory path (e.g., /dev/sdXn or /path/to/directory): " custom_part
-
-    # Create the temporary custom mount points file
-    echo "$custom_part $dir/environment/$custom_part" > "$dir/images/tmp_mounts.mnt"
-
-    # Check if it's a directory or a device
-    if [ -b "$custom_part" ]; then
-      # It's a block device (partition)
-      mount "$custom_part" $dir/environment/mnt
-    elif [ -d "$custom_part" ]; then
-      # It's a directory
-      mount -o bind "$custom_part" $dir/environment/mnt
-    else
-      echo "Invalid path or type. Exiting."
-      return
-    fi
-  fi
-
   # Check if the mount file exists
   if [ ! -f "$dir/images/$image.filesystems.mnt" ]; then
     echo "File not found: $dir/images/$image.filesystems.mnt"
@@ -82,11 +61,12 @@ start_box() {
   done < "$dir/images/$image.filesystems.mnt"
 
   # Update the running image name
-  sed -i "s/^RUNNING_IMAGE_NAME=.*/RUNNING_IMAGE_NAME=\"$image\"/" $ENV_FILE
+  sed -i "s/^RUNNING_IMG_NAME=.*/RUNNING_IMG_NAME=\"$image\"/" $ENV_FILE
 
   chroot $dir/environment /bin/su -c 'sh /boot/boot.sh'
 }
 
-if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
-  (start_box)
+# Check if a command-line argument is provided and call start_box with the argument
+if [ -n "$1" ]; then
+  (start_box "$1")
 fi
diff --git a/includes/stop_box.sh b/includes/stop_box.sh
index 993d838..5cf1f87 100644
--- a/includes/stop_box.sh
+++ b/includes/stop_box.sh
@@ -48,28 +48,11 @@ stop_box() {
   sed '1 d' $dir/process/6 > $dir/process/7
   sh $dir/process/6
 
-  # Unmount custom mounts
-
-  # Check if the mount file exists
-  if [ ! -f "$dir/images/tmp_mounts.mnt" ]; then
-    echo "File not found: $dir/images/tmp_mounts.mnt"
-  else
-    # Unmount the mount file content
-    while IFS= read -r line; do
-      # Use cut to extract the first field
-      target_point=$(echo "$line" | cut -d' ' -f2)
-
-      umount "$target_point"
-    done < "$dir/images/tmp_mounts.mnt"
-
-    rm $dir/images/tmp_mounts.mnt
-  fi
-
   # Unmount filesystems
 
   # Check if the mount file exists
-  if [ ! -f "$dir/images/$RUNNING_IMAGE_NAME.filesystems.mnt" ]; then
-    echo "File not found: $dir/images/$RUNNING_IMAGE_NAME.filesystems.mnt"
+  if [ ! -f "$dir/images/$RUNNING_IMG_NAME.filesystems.mnt" ]; then
+    echo "File not found: $dir/images/$RUNNING_IMG_NAME.filesystems.mnt"
     exit 1
   else
     # Unmount the mount file content
@@ -78,7 +61,7 @@ stop_box() {
       target_point=$(echo "$line" | cut -d' ' -f2)
 
       umount "$target_point"
-    done < "$dir/images/$RUNNING_IMAGE_NAME.filesystems.mnt"
+    done < "$dir/images/$RUNNING_IMG_NAME.filesystems.mnt"
 
     umount $dir/environment
   fi
@@ -86,4 +69,6 @@ stop_box() {
 
 if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
   (stop_box)
+  sleep 3s
+  (stop_box)
 fi
diff --git a/pandoras.sh b/pandoras.sh
index 1351d05..44d4d0b 100755
--- a/pandoras.sh
+++ b/pandoras.sh
@@ -64,40 +64,58 @@ EOT
 display_help() {
 
 cat <<EOT
-Pandoras (v0.1.1)
+Pandoras (v0.1.3)
 
-Options Usage: (sudo) pandoras [option]
+Options Usage: (sudo) pandoras [options]
 
 Boxes Options:
-  	-s, --start-box		Starts chroot
-  	-t, --stop-box		Stops chroot
-  	-c, --create-box	Creates chroot
-  	-r, --delete-box	Deletes chroot
-  	-d, --duplicate-box	Duplicates chroot
-  	-e, --enter-box		Enters the chroot
-  	-l, --list-boxes	Lists chroots
-  	-f, --list-filesystems	Lists chroots filesystems
-  	-u, --upsize-box	Upsizes chroot
+    -l, --list-boxes                  Lists chroots
+    -f, --list-filesystems            Lists chroots filesystems
+    -s, --start-box <box_name>        Starts chroot no dialogs
+    -e, --enter-box                   Enters the chroot
+    -t, --stop-box                    Stops chroot
+    -c, --create-box                  Creates chroot
+    -r, --delete-box                  Deletes chroot
+    -d, --duplicate-box               Duplicates chroot
+    -u, --upsize-box                  Upsizes chroot
 
 More Options:
-	-g, --license		Print the GPL license notification
-	-h, --help		Print this Help
-	-V, -v, --version	Print software version and exit
+    -g, --license                     Print the GPL license notification
+    -h, --help                        Print this Help
+    -V, -v, --version                 Print software version and exit
 
 EOT
 }
 
 # Prints version
 display_version() {
-  echo "Commbase (v0.0.1)";
+  echo "Pandoras (v0.1.2)";
 }
 
 # Options
 main() {
   case $1 in
+    '-l' | '--list-boxes')
+      cd /var/pandoras/includes || { echo "Error: Unable to change directory."; exit 1; }
+      bash list_boxes.sh list_boxes || { echo "Error: list_boxes.sh failed."; exit 1; }
+      ;;
+    '-f' | '--list-filesystems')
+      cd /var/pandoras/includes || { echo "Error: Unable to change directory."; exit 1; }
+      bash list_filesystems.sh list_boxes || { echo "Error: list_filesystems.sh failed."; exit 1; }
+      ;;
     '-s' | '--start-box')
+      # Check if a box name is provided
+      if [ -z "$2" ]; then
+        echo "Error: Box name is required for start-box."
+        exit 1
+      fi
+      cd /var/pandoras/includes || { echo "Error: Unable to change directory."; exit 1; }
+      # Pass the box name as a parameter to start_box.sh
+      bash start_box.sh "$2" || { echo "Error: start_box.sh failed."; exit 1; }
+      ;;
+    '-e' | '--enter-box')
       cd /var/pandoras/includes || { echo "Error: Unable to change directory."; exit 1; }
-      bash start_box.sh start_box || { echo "Error: start_box.sh failed."; exit 1; }
+      bash enter_box.sh enter_box || { echo "Error: enter_box.sh failed."; exit 1; }
       ;;
     '-t' | '--stop-box')
       cd /var/pandoras/includes || { echo "Error: Unable to change directory."; exit 1; }
@@ -115,18 +133,6 @@ main() {
       cd /var/pandoras/includes || { echo "Error: Unable to change directory."; exit 1; }
       bash duplicate_box.sh duplicate_box || { echo "Error: duplicate_box.sh failed."; exit 1; }
       ;;
-    '-e' | '--enter-box')
-      cd /var/pandoras/includes || { echo "Error: Unable to change directory."; exit 1; }
-      bash enter_box.sh enter_box || { echo "Error: enter_box.sh failed."; exit 1; }
-      ;;
-    '-l' | '--list-boxes')
-      cd /var/pandoras/includes || { echo "Error: Unable to change directory."; exit 1; }
-      bash list_boxes.sh list_boxes || { echo "Error: list_boxes.sh failed."; exit 1; }
-      ;;
-    '-f' | '--list-filesystems')
-      cd /var/pandoras/includes || { echo "Error: Unable to change directory."; exit 1; }
-      bash list_filesystems.sh list_boxes || { echo "Error: list_filesystems.sh failed."; exit 1; }
-      ;;
     '-u' | '--upsize-box')
       cd /var/pandoras/includes || { echo "Error: Unable to change directory."; exit 1; }
       bash upsize_box.sh upsize_box || { echo "Error: upsize_box.sh failed."; exit 1; }