Skip to content

Commit

Permalink
Add includes to main script
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanways committed Dec 14, 2023
1 parent ba294c5 commit c81fb27
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 61 deletions.
10 changes: 9 additions & 1 deletion includes/create_box.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #

# Creates chroot

#echo "Hello World"

create_box() {

export dir=/var/pandoras/
dir=/var/pandoras

read -r -p "Type your new chroot name: " chroot
read -r -p "Type your new chroot size (in GB): " size
Expand All @@ -50,3 +53,8 @@ create_box() {
umount $dir/environment
}

# Call the parse_skill_ if the script is run directly (not sourced)
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
(create_box)
fi

5 changes: 5 additions & 0 deletions includes/duplicate_box.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ duplicate_box() {
cp $dir/images/"$old".img $dir/images/"$new".img
}

# Call the parse_skill_ if the script is run directly (not sourced)
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
(duplicate_box)
fi

5 changes: 5 additions & 0 deletions includes/enter_box.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ enter-box() {
chroot $dir/environment /bin/su -
}

# Call the parse_skill_ if the script is run directly (not sourced)
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
(enter-box)
fi

5 changes: 5 additions & 0 deletions includes/list_boxes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ list_boxes() {
"
}

# Call the parse_skill_ if the script is run directly (not sourced)
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
(list_boxes)
fi

5 changes: 5 additions & 0 deletions includes/start_box.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ start_box() {
chroot $dir/environment /bin/su -c 'sh /boot/boot.sh'
}

# Call the parse_skill_ if the script is run directly (not sourced)
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
(start_box)
fi

5 changes: 5 additions & 0 deletions includes/stop_box.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ stop_box() {
umount $dir/environment
}

# Call the parse_skill_ if the script is run directly (not sourced)
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
(stop_box)
fi

117 changes: 57 additions & 60 deletions pandoras.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
# Run the application using sudo and with parameters, for example:
# shell> sudo pandoras start-box

# TODO:
# Export dir if required
#export dir=/var/chroot/

# Prints license
display_license() {

Expand Down Expand Up @@ -70,16 +66,16 @@ display_help() {
cat <<EOT
Pandoras (v0.0.1)
Options Usage: pandoras [option]
Options Usage: (sudo) pandoras [option]
Boxes Options:
start-box Starts chroot
stop-box Stops chroot
create-box Creates chroot
delete-box Deletes chroot
duplicate-box Duplicates chroot
enter-box Enters the chroot
list-boxes Lists all the chroots
-start-box Starts chroot
-stop-box Stops chroot
-create-box Creates chroot
-delete-box Deletes chroot
-duplicate-box Duplicates chroot
-enter-box Enters the chroot
-list-boxes Lists all the chroots
Other Options:
-g, --license Print the GPL license notification
Expand All @@ -91,59 +87,60 @@ EOT

# Prints version
display_version() {
echo "Commbase (v0.0.1)";
}

# Routes options
route_option() {

# Path to functions
export dir=/var/pandoras/includes

case "$1" in

'start-box')
start_box.sh
;;
'stop-box')
stop_box.sh
;;
'create-box')
create_box.sh
;;
'delete-box')
delete_box.sh
;;
'duplicate-box')
duplicate_box.sh
;;
'enter-box')
enter_box.sh
;;
'list-boxes')
list_boxes.sh
;;
'-g' | '--license')
display_license | more
exit 99
;;
'-h' | '--help')
display_help | less
exit 99
;;
'-V' | '-v' | '--version')
display_version
exit 99
;;
esac

echo "Commbase (v0.0.1)";
}

# Options
main() {
route_option "$1";
case $1 in
'-start-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; }
;;
'-stop-box')
cd /var/pandoras/includes || { echo "Error: Unable to change directory."; exit 1; }
bash stop_box.sh stop_box || { echo "Error: stop_box.sh failed."; exit 1; }
;;
'-create-box')
cd /var/pandoras/includes || { echo "Error: Unable to change directory."; exit 1; }
bash create_box.sh create_box || { echo "Error: create_box.sh failed."; exit 1; }
;;
'-delete-box')
cd /var/pandoras/includes || { echo "Error: Unable to change directory."; exit 1; }
bash delete_box.sh delete_box || { echo "Error: delete_box.sh failed."; exit 1; }
;;
'-duplicate-box')
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; }
;;
'-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; }
;;
'-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; }
;;
'-g' | '--license')
display_license | more
exit 99
;;
'-h' | '--help')
display_help | less
exit 99
;;
'-V' | '-v' | '--version')
display_version
exit 99
;;
esac
}

main "$1";
# Set the script to exit on any error
set -e

# Call the main function with the provided arguments
main "$@"

exit 99

0 comments on commit c81fb27

Please sign in to comment.