Skip to content

Commit 60d3905

Browse files
authored
Merge pull request #74 from selfhoster1312/main
Give time for Internet connection to be setup, and ensure curl is installed
2 parents 76b4126 + ec9029d commit 60d3905

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

bookworm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# You should have received a copy of the GNU Affero General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18+
# RUN INSTALL SCRIPT WITH -a FOR NON-INTERACTIVE MODE.
19+
1820
set -u
1921

2022
# Globals
@@ -26,6 +28,18 @@ export DEBIAN_FRONTEND=noninteractive
2628
# Main functions #
2729
###############################################################################
2830

31+
function check_connection() {
32+
TIMEOUT=$1
33+
34+
while [ $TIMEOUT -gt 0 ]; do
35+
ping -c 1 -W 2 yunohost.org 2>&1 >/dev/null && return 0
36+
sleep 1
37+
TIMEOUT=$((TIMEOUT-1))
38+
done
39+
40+
return 1
41+
}
42+
2943
function usage() {
3044
cat << EOF
3145
Usage :
@@ -252,6 +266,16 @@ function check_assertions()
252266
# Assert we're root
253267
[[ "$(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; }
254268

269+
# Assert Internet is reachable
270+
if ! check_connection 30; then
271+
die "You need internet to use this script! yunohost.org did not respond to ping after more than 30s."
272+
fi
273+
274+
# Assert curl is setup
275+
if ! command -v curl 2>&1 >/dev/null; then
276+
apt_get_wrapper --yes install curl
277+
fi
278+
255279
# Check PATH var
256280
[[ "$PATH" == *"/sbin"* ]] || { error "Your environment PATH variable must contains /sbin directory. Maybe try running 'PATH=/sbin:\$PATH' to fix this."; return 1; }
257281

bullseye

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# You should have received a copy of the GNU Affero General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18+
# RUN INSTALL SCRIPT WITH -a FOR NON-INTERACTIVE MODE.
19+
1820
set -u
1921

2022
# Globals
@@ -37,6 +39,18 @@ compactbutton=white,black
3739
# Main functions #
3840
###############################################################################
3941

42+
function check_connection() {
43+
TIMEOUT=$1
44+
45+
while [ $TIMEOUT -gt 0 ]; do
46+
ping -c 1 -W 2 yunohost.org 2>&1 >/dev/null && return 0
47+
sleep 1
48+
TIMEOUT=$((TIMEOUT-1))
49+
done
50+
51+
return 1
52+
}
53+
4054
function usage() {
4155
echo "
4256
Usage :
@@ -237,6 +251,16 @@ function check_assertions()
237251
# Assert we're root
238252
[[ "$(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."
239253

254+
# Assert Internet is reachable
255+
if ! check_connection 30; then
256+
die "You need internet to use this script! yunohost.org did not respond to ping after more than 30s."
257+
fi
258+
259+
# Assert curl is setup
260+
if ! command -v curl 2>&1 >/dev/null; then
261+
apt_get_wrapper --yes install curl
262+
fi
263+
240264
# Check PATH var
241265
[[ "$PATH" == *"/sbin"* ]] || die "Your environment PATH variable must contains /sbin directory. Maybe try running 'PATH=/sbin:\$PATH' to fix this."
242266

0 commit comments

Comments
 (0)