Improve stability
This commit is contained in:
parent
22bc88823a
commit
a9f3d168a9
28
lib-core.sh
28
lib-core.sh
@ -666,19 +666,27 @@ full_sudo() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_http_response() {
|
get_utc_epoch_time() {
|
||||||
if exec 3<> "/dev/tcp/${1}/80"; then
|
local time=""
|
||||||
echo -e "GET / HTTP/1.1\nHost: ${1}\n\n" >&3
|
local epoch=""
|
||||||
|
|
||||||
(
|
if exec 3<> "/dev/tcp/iana.org/80"; then
|
||||||
IFS=""
|
echo -e "GET / HTTP/1.1\nHost: iana.org\n\n" >&3
|
||||||
|
|
||||||
while read -r -t 1 line 0<&3; do
|
while read -r -t 2 line 0<&3; do
|
||||||
echo "${line//$"\r"}"
|
if [[ "${line}" =~ "Date:" ]]; then
|
||||||
done
|
time="${line#*':'}"; exec 3<&-; break
|
||||||
)
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
exec 3<&-; return 0
|
exec 3<&-
|
||||||
|
|
||||||
|
if [[ "${time}" ]]; then
|
||||||
|
epoch="$(date -d "${time}" "+%s")"
|
||||||
|
echo "$((epoch + 2))"
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
exec 3<&-; return 1
|
exec 3<&-; return 1
|
||||||
fi
|
fi
|
||||||
|
@ -40,6 +40,10 @@ WHITESUR_SOURCE+=("lib-install.sh")
|
|||||||
# Some apt version doesn't update the repo list before it install some app.
|
# Some apt version doesn't update the repo list before it install some app.
|
||||||
# It may cause "unable to fetch..." when you're trying to install them
|
# It may cause "unable to fetch..." when you're trying to install them
|
||||||
|
|
||||||
|
#--------------------PACMAN--------------------#
|
||||||
|
# 'Syu' (with a single y) may causes "could not open ... decompression failed"
|
||||||
|
# and "target not found <package>". We got to force 'pacman' to update the repos
|
||||||
|
|
||||||
#--------------------OTHERS--------------------#
|
#--------------------OTHERS--------------------#
|
||||||
# Sometimes, some Ubuntu distro doesn't enable automatic time. This can cause
|
# Sometimes, some Ubuntu distro doesn't enable automatic time. This can cause
|
||||||
# 'Release file for ... is not valid yet'. This may also happen on other distros
|
# 'Release file for ... is not valid yet'. This may also happen on other distros
|
||||||
@ -55,23 +59,24 @@ installation_sorry() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
prepare_deps() {
|
prepare_deps() {
|
||||||
local head=""
|
|
||||||
local remote_time=""
|
local remote_time=""
|
||||||
local local_time=""
|
local local_time=""
|
||||||
|
|
||||||
prompt -i "DEPS: Checking your internet connection..."
|
prompt -i "DEPS: Checking your internet connection..."
|
||||||
|
|
||||||
if ! head="$(get_http_response 'time.cloudflare.com')"; then
|
local_time="$(date -u "+%s")"
|
||||||
|
|
||||||
|
if ! remote_time="$(get_utc_epoch_time)"; then
|
||||||
prompt -e "DEPS ERROR: You have an internet connection issue\n"; exit 1
|
prompt -e "DEPS ERROR: You have an internet connection issue\n"; exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
remote_time="$(echo "${head}" | awk -F ': ' '/Date/{print $2}' | date -f - "+%s")"
|
# 5 minutes is the maximum reasonable time delay, so we choose '4' here just
|
||||||
local_time="$(date -u "+%s")"
|
# in case
|
||||||
|
if (( local_time < remote_time-(4*60) )); then
|
||||||
if (( remote_time-(5*60) > local_time )); then
|
|
||||||
prompt -w "DEPS: Your system clock is wrong"
|
prompt -w "DEPS: Your system clock is wrong"
|
||||||
prompt -i "DEPS: Updating your system clock..."
|
prompt -i "DEPS: Updating your system clock..."
|
||||||
sudo date -s "@${remote_time}"; sudo hwclock --systohc
|
# Add "+ 25" here to accomodate potential time delay by sudo prompt
|
||||||
|
sudo date -s "@$((remote_time + 25))"; sudo hwclock --systohc
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,8 +170,6 @@ install_theme_deps() {
|
|||||||
sudo yum install -y sassc glib2-devel libxml2
|
sudo yum install -y sassc glib2-devel libxml2
|
||||||
elif has_command pacman; then
|
elif has_command pacman; then
|
||||||
# Rolling release
|
# Rolling release
|
||||||
# 'Syu' (with a single y) may causes "could not open ... decompression failed"
|
|
||||||
# and "target not found <package>". We got to force 'pacman' to update the repos
|
|
||||||
sudo pacman -Syyu --noconfirm --needed sassc glib2 libxml2
|
sudo pacman -Syyu --noconfirm --needed sassc glib2 libxml2
|
||||||
elif has_command xbps-install; then
|
elif has_command xbps-install; then
|
||||||
# Rolling release
|
# Rolling release
|
||||||
@ -197,7 +200,7 @@ install_beggy_deps() {
|
|||||||
sudo yum install -y ImageMagick
|
sudo yum install -y ImageMagick
|
||||||
elif has_command pacman; then
|
elif has_command pacman; then
|
||||||
# Rolling release
|
# Rolling release
|
||||||
sudo pacman -Syu --noconfirm --needed imagemagick
|
sudo pacman -Syyu --noconfirm --needed imagemagick
|
||||||
elif has_command xbps-install; then
|
elif has_command xbps-install; then
|
||||||
# Rolling release
|
# Rolling release
|
||||||
prepare_xbps && sudo xbps-install -Sy ImageMagick
|
prepare_xbps && sudo xbps-install -Sy ImageMagick
|
||||||
@ -225,7 +228,7 @@ install_dialog_deps() {
|
|||||||
sudo yum install -y dialog
|
sudo yum install -y dialog
|
||||||
elif has_command pacman; then
|
elif has_command pacman; then
|
||||||
# Rolling release
|
# Rolling release
|
||||||
sudo pacman -Syu --noconfirm --needed dialog
|
sudo pacman -Syyu --noconfirm --needed dialog
|
||||||
elif has_command xbps-install; then
|
elif has_command xbps-install; then
|
||||||
# Rolling release
|
# Rolling release
|
||||||
prepare_xbps && sudo xbps-install -Sy dialog
|
prepare_xbps && sudo xbps-install -Sy dialog
|
||||||
|
Loading…
x
Reference in New Issue
Block a user