Commit 94f6555f authored by HgO's avatar HgO

Merge branch '13-cleanup-cube-resources' into 'unstable'

Resolve "Optionally clean up the cube_resources and install.hypercube"

See merge request Neutrinet/neutrinet_cube_install!15
parents 9299998f da32bf28
......@@ -213,15 +213,17 @@ function confirm() {
local message="$1"
local default="$2"
message="$message [y/n]"
if [[ -n $default ]]
then
message="$message ($default)"
fi
message="$message: "
answer_has_error=true
while $answer_has_error
do
echo -n "$message [y/n]"
if [[ -n $default ]]
then
echo -n " ($default)"
fi
echo -n ": "
echo -n "$message"
read -r answer
......@@ -842,6 +844,63 @@ function search_cube() {
fi
}
function cleanup_hypercube_file() {
local default_answer=$1
if [[ ! -e $HYPERCUBE_FILE ]]
then
return
fi
echo
info "During this install, we created the $HYPERCUBE_FILE file with the personal details you entered earlier"
info "If you leave this file, you can reuse this information for another install"
warn "This file contains the passwords you provided! For safety reasons, you shouldn't keep it longer than needed!!!"
if confirm "Do you want to remove the $HYPERCUBE_FILE file?" $default_answer
then
info "Removing $HYPERCUBE_FILE..."
fi
}
function cleanup_cube_resources() {
local default_answer=$1
if [[ ! -e $CUBE_RESOURCES_LOCATION ]]
then
return
fi
echo
info "We stored some resources (Yunohost images, scripts, etc.) in the $CUBE_RESOURCES_LOCATION folder"
info "These resources could be reused for another cube install, so you wouldn't need to download everything again"
if confirm "Do you want to remove the $CUBE_RESOURCES_LOCATION folder?" $default_answer
then
info "Removing cube resources..."
rm -rf "$CUBE_RESOURCES_LOCATION"
fi
}
function cleanup_resources_on_success() {
# No need to enter the trap function if we are already in the cleanup step
trap "exit 1" INT
cleanup_hypercube_file "y"
cleanup_cube_resources "y"
}
function cleanup_resources_on_abort() {
# In case we want to exit the trap function with CTRL+C
trap "exit 1" INT
echo
error "Installation aborted"
cleanup_hypercube_file "n"
cleanup_cube_resources "n"
}
function show_goodbye() {
echo
echo "Alright, that's all we could do for now. We hope you'll be happy with your cube!"
......@@ -903,6 +962,8 @@ done
# Exit if any of the following command fails
set -e
trap "cleanup_resources_on_abort" EXIT
show_welcome
check_dependencies
create_hypercube_file
......@@ -911,4 +972,5 @@ get_image
flash_sd_card
prepare_cube
search_cube
cleanup_resources_on_success
show_goodbye
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment