From ec9029daf3f7bb0d21f553f9de440cca5a611299 Mon Sep 17 00:00:00 2001 From: selfhoster1312 Date: Sat, 12 Aug 2023 12:19:01 +0200 Subject: [PATCH] Give time for Internet connection ; ensure curl is installed --- bookworm | 24 ++++++++++++++++++++++++ bullseye | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/bookworm b/bookworm index 86b8e1d..494aed4 100755 --- a/bookworm +++ b/bookworm @@ -15,6 +15,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +# RUN INSTALL SCRIPT WITH -a FOR NON-INTERACTIVE MODE. + set -u # Globals @@ -26,6 +28,18 @@ export DEBIAN_FRONTEND=noninteractive # Main functions # ############################################################################### +function check_connection() { + TIMEOUT=$1 + + while [ $TIMEOUT -gt 0 ]; do + ping -c 1 -W 2 yunohost.org 2>&1 >/dev/null && return 0 + sleep 1 + TIMEOUT=$((TIMEOUT-1)) + done + + return 1 +} + function usage() { cat << EOF Usage : @@ -252,6 +266,16 @@ function check_assertions() # Assert we're root [[ "$(id -u)" == "0" ]] || { error "This script must be run as root. On most setups, the command 'sudo -i' can be run first to become root."; return 1; } + # Assert Internet is reachable + if ! check_connection 30; then + die "You need internet to use this script! yunohost.org did not respond to ping after more than 30s." + fi + + # Assert curl is setup + if ! command -v curl 2>&1 >/dev/null; then + apt_get_wrapper --yes install curl + fi + # Check PATH var [[ "$PATH" == *"/sbin"* ]] || { error "Your environment PATH variable must contains /sbin directory. Maybe try running 'PATH=/sbin:\$PATH' to fix this."; return 1; } diff --git a/bullseye b/bullseye index 8e3112b..f6c2e23 100755 --- a/bullseye +++ b/bullseye @@ -15,6 +15,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +# RUN INSTALL SCRIPT WITH -a FOR NON-INTERACTIVE MODE. + set -u # Globals @@ -37,6 +39,18 @@ compactbutton=white,black # Main functions # ############################################################################### +function check_connection() { + TIMEOUT=$1 + + while [ $TIMEOUT -gt 0 ]; do + ping -c 1 -W 2 yunohost.org 2>&1 >/dev/null && return 0 + sleep 1 + TIMEOUT=$((TIMEOUT-1)) + done + + return 1 +} + function usage() { echo " Usage : @@ -237,6 +251,16 @@ function check_assertions() # Assert we're root [[ "$(id -u)" == "0" ]] || die "This script must be run as root. On most setups, the command 'sudo -i' can be run first to become root." + # Assert Internet is reachable + if ! check_connection 30; then + die "You need internet to use this script! yunohost.org did not respond to ping after more than 30s." + fi + + # Assert curl is setup + if ! command -v curl 2>&1 >/dev/null; then + apt_get_wrapper --yes install curl + fi + # Check PATH var [[ "$PATH" == *"/sbin"* ]] || die "Your environment PATH variable must contains /sbin directory. Maybe try running 'PATH=/sbin:\$PATH' to fix this."