Commit bbd8f426 authored by HgO's avatar HgO

Include neutrinet specifics in general script

* Remove the custom neutrinet script thing
* Make sure the script creates it in the cube_resources folder and uses that one
parent 0e740178
This diff is collapsed.
This diff is collapsed.
......@@ -53,11 +53,13 @@ INSTALL_SD_SCRIPT_REVISION="53768298394ddbe0016b2b8dfacff20aff7fb9ac"
INSTALL_SD_SCRIPT_LOCATION="https://raw.githubusercontent.com/labriqueinternet/labriqueinter.net/${INSTALL_SD_SCRIPT_REVISION}"
INSTALL_SD_SCRIPT_SHA256SUM="1853276b132d1916e3224ce8496e3ce7d09e5c0d1d961422b923d5198f59f323"
INSTALL_SD_SCRIPT_NAME="install-sd.sh"
INSTALL_SD_CUSTOM_SCRIPT_ENABLED=true
HYPERCUBE_FILE="install.hypercube"
CUSTOM_SCRIPT_PATH="${CUBE_RESOURCES_LOCATION}/custom_neutrinet_specifics.sh"
EXECUTE_CUSTOM_SCRIPT=true
CUSTOM_SCRIPT_NAME="custom_neutrinet_specifics.sh"
CUSTOM_SCRIPT_PATH="${CUBE_RESOURCES_LOCATION}/$CUSTOM_SCRIPT_NAME"
USER_CUSTOM_SCRIPT_ENABLED=false
# See https://github.com/YunoHost/yunohost/blob/master/data/actionsmap/yunohost.yml#L104
LOGIN_PATTERN='^[a-z0-9_]+$'
......@@ -407,6 +409,24 @@ function check_dependencies() {
info $"Dependencies OK"
}
function check_custom_script() {
if $USER_CUSTOM_SCRIPT_ENABLED
then
info $"Checking location of your custom script ($CUSTOM_SCRIPT_PATH)..."
if [[ -f $CUSTOM_SCRIPT_PATH ]]
then
info $"Your custom script will be added when flashing the sd card"
else
warn $"Either the custom script's location is wrong, or it is not a regular file"
warn $"No custom script will be added during this install"
INSTALL_SD_CUSTOM_SCRIPT_ENABLED=false
fi
else
debug $"Neutrinet's specifics script will be added when flashing the sd card"
fi
}
function get_hypercube_setting() {
local key="$1"
local value=$(jq -r ".$key" "$HYPERCUBE_FILE")
......@@ -687,33 +707,6 @@ EOF
info $"$HYPERCUBE_FILE created!"
}
function add_custom_script() {
if confirm $"Do you want to add Neutrinet's specifics to the installation?" "y"
then
info $"Neutrinet's specifics script will be added when flashing the sd card"
else
location_has_error=true
while $location_has_error
do
if confirm $"Would you like to add your own custom script?" "n"
then
read -e -r -p $"Enter your custom script's location: " CUSTOM_SCRIPT_PATH
if [[ ! -f "$CUSTOM_SCRIPT_PATH" ]]
then
error $"Either the location is wrong or it is not a regular file"
else
info $"Your custom script will be added when flashing the sd card"
location_has_error=false
fi
else
info $"No custom script will be added then"
EXECUTE_CUSTOM_SCRIPT=false
location_has_error=false
fi
done
fi
}
function get_image() {
echo -n $"What hardware are you installing on?" "[lime/lime2]: "
board_has_error=true
......@@ -805,8 +798,13 @@ function flash_sd_card() {
create_custom_script
local install_sd_options=(-y "$HYPERCUBE_FILE" -f $CUBE_RESOURCES_LOCATION/$image)
if $EXECUTE_CUSTOM_SCRIPT
if $INSTALL_SD_CUSTOM_SCRIPT_ENABLED
then
if ! $USER_CUSTOM_SCRIPT_ENABLED
then
create_custom_script
fi
install_sd_options+=(-c "$CUSTOM_SCRIPT_PATH")
fi
......@@ -832,6 +830,20 @@ yunohost app install neutrinet --force --debug --args "domain=${main_domain}&pat
EOF
}
function create_custom_script() {
cat << "EOF" > $CUSTOM_SCRIPT_PATH
#!/bin/bash
# Adding neutrinet specifics
main_domain=$(yunohost tools maindomain --output=plain)
yunohost app fetchlist -n neutrinet -u https://neutrinet.be/apps.json --debug
yunohost app fetchlist --debug
yunohost app install neutrinet --force --debug --args "domain=${main_domain}&path=/neutrinet"
EOF
}
function prepare_cube() {
info $"Alright! Time to prepare the cube!"
info $"Make sure the Cube is not connected to a power source (e.g: the power cable should be unplugged)"
......@@ -962,11 +974,13 @@ function show_help() {
format_indent 4 "$(format_title $"Neutrinet Cube installer")"
echo
format_bold $"OPTIONS"
format_indent 2 "$(format_bold "-p")" >&2
format_indent 4 $"Download and prepare all scripts and board images needed for installing a cube" >&2
format_indent 4 "$(format_dim $"Next time this script is run from the same folder as it is run now, these scripts and images will be used")" >&2
format_indent 2 "$(format_bold "-h")" >&2
format_indent 4 $"Show this help" >&2
format_indent 2 "$(format_bold "-p")"
format_indent 4 $"Download and prepare all scripts and board images needed for installing a cube"
format_indent 4 "$(format_dim $"Next time this script is run from the same folder as it is run now, these scripts and images will be used")"
format_indent 2 "$(format_bold "-c <custom script path>")"
format_indent 4 $"Install the custom script from <custom script path> instead of Neutrinet's specifics"
format_indent 2 "$(format_bold "-h")"
format_indent 4 $"Show this help"
}
function prepare() {
......@@ -988,14 +1002,26 @@ function prepare() {
# GET OPTIONS
#=================================================
while getopts "vhp" opt; do
while getopts "vhpc:" opt; do
case $opt in
v) LOG_LEVEL=${LOG_LEVELS[DEBUG]};;
p) prepare; exit 0;;
h) show_help; exit 0;;
\?) show_help; exit 0;;
v)
LOG_LEVEL=${LOG_LEVELS[DEBUG]}
;;
p)
prepare
exit 0
;;
c)
CUSTOM_SCRIPT_PATH=$OPTARG
USER_CUSTOM_SCRIPT_ENABLED=true
;;
h | \?)
show_help
exit 0
;;
esac
done
#=================================================
# SCRIPT
#=================================================
......@@ -1005,8 +1031,8 @@ trap "cleanup_resources_on_abort" ERR INT
show_welcome
check_dependencies
check_custom_script
create_hypercube_file
add_custom_script
get_image
flash_sd_card
prepare_cube
......
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