Merge pull request #74 from selfhoster1312/main

Give time for Internet connection to be setup, and ensure curl is installed
This commit is contained in:
Alexandre Aubin 2024-05-06 16:03:15 +02:00 committed by GitHub
commit 60d3905678
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 48 additions and 0 deletions

View file

@ -15,6 +15,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# 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; }

View file

@ -15,6 +15,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# 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."