Commit dbabc9cc authored by HgO's avatar HgO

Merge branch 'unstable' into 'stable'

Release changes for install party on 16/02/2020

Closes #21, #19, #23, #20, #26, and #24

See merge request !29
parents 9e85fea0 ae5c7ca7
......@@ -51,11 +51,23 @@ It can take about two hours from downloading and running the script until the Ne
## Downloading the script
The easiest way to get the script is by cloning the whole project and navigate to it.
There are several ways to get the script:
- Download the [standalone script](https://gitlab.domainepublic.net/Neutrinet/neutrinet_cube_install/blob/stable/neutrinet_cube_install.sh) (English only):
```shell
curl https://git.domainepublic.net/Neutrinet/neutrinet_cube_install/raw/stable/neutrinet_cube_install.sh -o neutrinet_cube_install.sh
```
- Clone the whole project and navigate to it:
```shell
git clone https://git.domainepublic.net/Neutrinet/neutrinet_cube_install
git clone https://gitlab.domainepublic.net/Neutrinet/neutrinet_cube_install.git
cd neutrinet_cube_install
```
- Download a zip file with the button on the [project page](https://git.domainepublic.net/Neutrinet/neutrinet_cube_install) (below the clone button), or run:
```shell
curl https://git.domainepublic.net/Neutrinet/neutrinet_cube_install/-/archive/stable/neutrinet_cube_install-stable.zip -o neutrinet_cube_install.zip
unzip neutrinet_cube_install.zip
cd neutrinet_cube_install-stable
```
## Running the script
......
#!/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"
This diff is collapsed.
This diff is collapsed.
......@@ -27,16 +27,19 @@
declare -A LOG_LEVELS=([DEBUG]=0 [INFO]=1 [WARN]=2 [ERROR]=3)
LOG_LEVEL=${LOG_LEVELS[INFO]}
CURRENT_SCRIPT_LOCATION="$(realpath $(dirname $0))"
export TEXTDOMAIN="neutrinet"
export TEXTDOMAINDIR="$(dirname $0)/locale"
export TEXTDOMAINDIR="$CURRENT_SCRIPT_LOCATION/locale"
CURRENT_SCRIPT_DIR="$(dirname $0)"
YNH_IMG_LOCATION="https://build.yunohost.org"
DEBIAN_CODENAME="stretch"
INTERNETCUBE_PREFIX="internetcube"
YUNOHOST_PREFIX="yunohost"
CUBE_RESOURCES_LOCATION="cube_resources"
CUBE_RESOURCES_DIR="cube_resources"
CUBE_RESOURCES_LOCATION="${CURRENT_SCRIPT_LOCATION}/$CUBE_RESOURCES_DIR"
GPG_HOME_DIR=".gnupg"
GPG_YUNOHOST_KEY="0x360AAF3259A3E6FF"
......@@ -53,18 +56,22 @@ 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"
HYPERCUBE_LOCATION="${CURRENT_SCRIPT_LOCATION}/${HYPERCUBE_FILE}"
CUSTOM_SCRIPT_PATH="${CURRENT_SCRIPT_DIR}/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
# See https://github.com/YunoHost/yunohost/blob/stretch-unstable/data/actionsmap/yunohost.yml#L82
LOGIN_PATTERN='^[a-z0-9_]+$'
# See https://github.com/YunoHost/yunohost/blob/master/data/actionsmap/yunohost.yml#L112
# See https://github.com/YunoHost/yunohost/blob/stretch-unstable/data/actionsmap/yunohost.yml#L90
NAME_PATTERN='^([^\W\d_]{2,30}[ ,.'\''-]{0,3})+$'
# See https://github.com/YunoHost/yunohost/blob/debian/2.4.0.4/data/actionsmap/yunohost.yml#L138
PASSWORD_PATTERN='^.{3,}$'
# See https://github.com/YunoHost/yunohost/blob/stretch-unstable/src/yunohost/utils/password.py
PASSWORD_PATTERN='^.{8,}$'
PASSWORD_PATTERN_DESCRIPTION=$"Password must have 8 symbols or more."
WIFI_SSID_PATTERN='^[\w\d\-_\.,!\? ]{1,32}$'
# See https://github.com/YunoHost/issues/issues/1319
WIFI_PASSWORD_PATTERN='^[^\{\}]{8,63}$'
......@@ -313,6 +320,8 @@ function check_gpg() {
then
warn $"Couldn't import Yunohost GPG key ($GPG_YUNOHOST_KEY) from $GPG_KEYSERVER"
prompt_continue_install
return
fi
if ! gpg -q --no-tty --batch --trust-model always --no-options \
......@@ -343,14 +352,16 @@ function check_sudo() {
}
function download_install_sd_script() {
pushd $CUBE_RESOURCES_LOCATION > /dev/null
info $"Downloading $INSTALL_SD_SCRIPT_NAME script..."
cd $CUBE_RESOURCES_LOCATION
curl --show-error --fail --silent --output "$INSTALL_SD_SCRIPT_NAME" "$INSTALL_SD_SCRIPT_LOCATION/$INSTALL_SD_SCRIPT_NAME"
check_integrity "$INSTALL_SD_SCRIPT_SHA256SUM" "$INSTALL_SD_SCRIPT_NAME"
chmod u+x "$INSTALL_SD_SCRIPT_NAME"
cd ..
popd > /dev/null
}
#=================================================
......@@ -405,9 +416,27 @@ 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")
local value=$(jq -r ".$key" "$HYPERCUBE_LOCATION")
if [[ $key =~ pass(word|phrase) ]]
then
......@@ -490,7 +519,7 @@ function show_hypercube_settings() {
function create_hypercube_file() {
debug $"Checking if $HYPERCUBE_FILE already exists..."
if [[ -f $HYPERCUBE_FILE ]]
if [[ -f $HYPERCUBE_LOCATION ]]
then
info $"Found $HYPERCUBE_FILE!"
show_hypercube_settings | column -t -s ':'
......@@ -554,12 +583,12 @@ function create_hypercube_file() {
prompt_pwd user_pwd $"Please provide your user password" \
$"Use a strong password! See https://ssd.eff.org/en/module/creating-strong-passwords for advice" \
"$PASSWORD_PATTERN" \
$"Password must have 3 symbols or more."
"$PASSWORD_PATTERN_DESCRIPTION"
prompt_pwd admin_pwd $"Please provide the admin password" \
$"Use a strong password! See https://ssd.eff.org/en/module/creating-strong-passwords for advice\nThis will let you access the admin console of your internet cube." \
"$PASSWORD_PATTERN" \
$"Password must have 3 symbols or more."
"$PASSWORD_PATTERN_DESCRIPTION"
info $"You will now need to enter your Neutrinet VPN certificates and credentials"
info $"If you want to reuse certificates from a previous install, you can find everything on that cube as user.crt, user.key, ca-server.crt and credentials in /etc/openvpn/keys"
......@@ -572,7 +601,7 @@ function create_hypercube_file() {
prompt_pwd vpn_pwd $"VPN password" \
$"Password you choose when ordering your VPN.\nIf you have lost your password, please contact a Neutrinet admin." \
"$PASSWORD_PATTERN" \
$"Password must have 3 symbols or more."
"$PASSWORD_PATTERN_DESCRIPTION"
location_has_error=true
while $location_has_error
......@@ -580,7 +609,7 @@ function create_hypercube_file() {
if confirm $"Would you like to import the VPN certificates from a directory?" "y"
then
read -e -r -p $"Enter your VPN certificates' location: " VPN_CERTIFICATES_LOCATION
if import_vpn_certificates $VPN_CERTIFICATES_LOCATION
if import_vpn_certificates "$VPN_CERTIFICATES_LOCATION"
then
location_has_error=false
fi
......@@ -680,38 +709,11 @@ EOF
do
json_args+=(--arg $json_arg "${!json_arg}")
done
jq "${json_args[@]}" "$hypercube_template" > "$HYPERCUBE_FILE"
jq "${json_args[@]}" "$hypercube_template" > "$HYPERCUBE_LOCATION"
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
......@@ -728,13 +730,13 @@ function get_image() {
fi
done
mkdir -p "$CUBE_RESOURCES_LOCATION"
cd "$CUBE_RESOURCES_LOCATION"
download_image
cd ..
}
function download_image() {
mkdir -p "$CUBE_RESOURCES_LOCATION"
pushd "$CUBE_RESOURCES_LOCATION" > /dev/null
debug $"Finding latest Yunohost $board image..."
ynh_image_zip="$(curl --show-error --fail --silent $YNH_IMG_LOCATION \
......@@ -771,7 +773,7 @@ function download_image() {
check_integrity "$ynh_image_sum" "$ynh_image_zip"
check_gpg "$ynh_image_sig" "$ynh_image_zip"
debug $"Unzipping $ynh_image_zip..."
info $"Unzipping $ynh_image_zip..."
unzip -p "$ynh_image_zip" > "$ynh_image"
rm "$ynh_image_zip"
fi
......@@ -784,13 +786,21 @@ function download_image() {
fi
debug $"Building internetcube image..."
chmod u+x $CUBE_BUILD_SCRIPT_DIR
check_sudo
sudo bash $CUBE_BUILD_SCRIPT_NAME "$ynh_image"
rm -rf $CUBE_BUILD_SCRIPT_DIR
sudo chmod u+x $CUBE_BUILD_SCRIPT_NAME
if ! sudo "./$CUBE_BUILD_SCRIPT_NAME" "$ynh_image"; then
# when the script fails, ensure that there isn't any corrupted built image left behind
rm -f "$image"
return 1
fi
rm -rf "$CUBE_BUILD_SCRIPT_DIR" "tmp"
fi
info $"We've got our internetcube image!"
popd > /dev/null
}
function flash_sd_card() {
......@@ -800,9 +810,14 @@ function flash_sd_card() {
download_install_sd_script
fi
local install_sd_options=(-y "$HYPERCUBE_FILE" -f $CUBE_RESOURCES_LOCATION/$image)
if $EXECUTE_CUSTOM_SCRIPT
local install_sd_options=(-y "$HYPERCUBE_LOCATION" -f "$CUBE_RESOURCES_LOCATION/$image")
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
......@@ -811,7 +826,21 @@ function flash_sd_card() {
install_sd_options+=(-d)
fi
"./$CUBE_RESOURCES_LOCATION/$INSTALL_SD_SCRIPT_NAME" "${install_sd_options[@]}"
"$CUBE_RESOURCES_LOCATION/$INSTALL_SD_SCRIPT_NAME" "${install_sd_options[@]}"
}
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() {
......@@ -849,7 +878,7 @@ function search_cube() {
keep_searching=true
while $keep_searching
do
"./$CUBE_RESOURCES_LOCATION/$INSTALL_SD_SCRIPT_NAME" -l || true
"$CUBE_RESOURCES_LOCATION/$INSTALL_SD_SCRIPT_NAME" -l || true
info $"If we found it you should be able to follow the progress at the HyperCube Debug url"
if ! confirm $"Do you want to continue searching?" "y"
......@@ -864,7 +893,7 @@ function search_cube() {
function cleanup_hypercube_file() {
local default_answer=$1
if [[ ! -e $HYPERCUBE_FILE ]]
if [[ ! -e $HYPERCUBE_LOCATION ]]
then
return
fi
......@@ -877,7 +906,7 @@ function cleanup_hypercube_file() {
if confirm $"Do you want to remove the $HYPERCUBE_FILE file?" $default_answer
then
info $"Removing $HYPERCUBE_FILE..."
rm -f "$HYPERCUBE_FILE"
rm -f "$HYPERCUBE_LOCATION"
fi
}
......@@ -890,10 +919,10 @@ function cleanup_cube_resources() {
fi
echo
info $"We stored some resources (Yunohost images, scripts, etc.) in the $CUBE_RESOURCES_LOCATION folder"
info $"We stored some resources (Yunohost images, scripts, etc.) in the $CUBE_RESOURCES_DIR 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
if confirm $"Do you want to remove the $CUBE_RESOURCES_DIR folder?" $default_answer
then
info $"Removing cube resources..."
rm -rf "$CUBE_RESOURCES_LOCATION"
......@@ -912,6 +941,11 @@ function cleanup_resources_on_abort() {
# In case we want to exit the trap function with CTRL+C
trap - ERR INT
# Clear terminal state in order to display user inputs
# This is needed when user input was previously hidden (e.g. prompt for password, etc.)
# See https://unix.stackexchange.com/questions/499471/reset-terminal-after-interrupting-read-r-s
stty sane
echo
error $"Installation aborted"
......@@ -944,17 +978,17 @@ 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() {
info $"Setting up the $CUBE_RESOURCES_LOCATION folder..."
mkdir -p "$CUBE_RESOURCES_LOCATION"
cd $CUBE_RESOURCES_LOCATION
info $"Setting up the $CUBE_RESOURCES_DIR folder..."
for board in lime lime2
do
......@@ -962,7 +996,6 @@ function prepare() {
download_image
done
cd ..
download_install_sd_script
}
......@@ -970,25 +1003,39 @@ 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
#=================================================
set -E
# Cleanup if any of the following command fails or if we do Ctrl+C
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