Skip to content

Commit

Permalink
Remove mount and start options with interactive dialogs.
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanways committed Jan 9, 2024
1 parent d402cad commit 633c5e8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 78 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion env/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
RUNNING_IMAGE_NAME=""
RUNNING_IMG_NAME=""
36 changes: 8 additions & 28 deletions includes/start_box.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
25 changes: 5 additions & 20 deletions includes/stop_box.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -78,12 +61,14 @@ 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
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
(stop_box)
sleep 3s
(stop_box)
fi
62 changes: 34 additions & 28 deletions pandoras.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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; }
Expand Down

0 comments on commit 633c5e8

Please sign in to comment.