From 78b9d3e16093971a690ce6d951646d0edb494185 Mon Sep 17 00:00:00 2001 From: Ciriaco Garcia de Celis Date: Fri, 26 Apr 2019 01:31:58 +0200 Subject: [PATCH 1/2] support uptime from Android 9+ --- neofetch | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index 55e53238..9b40412d 100755 --- a/neofetch +++ b/neofetch @@ -1211,8 +1211,14 @@ get_uptime() { # Get uptime in seconds. case "$os" in "Linux" | "Windows" | "MINIX") - seconds="$(< /proc/uptime)" - seconds="${seconds/.*}" + if [ -f /proc/uptime ]; then + seconds="$(< /proc/uptime)" + seconds="${seconds/.*}" + else # Android >= 9 denies /proc/uptime access + boot=$(date -d"$(uptime -s)" +%s) \ + && now="$(date +%s)" \ + && seconds="$((now - boot))" + fi ;; "Mac OS X" | "iPhone OS" | "BSD" | "FreeMiNT") From c86413c18ada1655ec4131f493254ee71e06530c Mon Sep 17 00:00:00 2001 From: Ciriaco Garcia de Celis Date: Wed, 1 May 2019 12:04:44 +0200 Subject: [PATCH 2/2] uptime for Android 9+ (refactorized) --- neofetch | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/neofetch b/neofetch index 9b40412d..496af946 100755 --- a/neofetch +++ b/neofetch @@ -1211,13 +1211,13 @@ get_uptime() { # Get uptime in seconds. case "$os" in "Linux" | "Windows" | "MINIX") - if [ -f /proc/uptime ]; then + if [[ -r /proc/uptime ]]; then seconds="$(< /proc/uptime)" seconds="${seconds/.*}" - else # Android >= 9 denies /proc/uptime access - boot=$(date -d"$(uptime -s)" +%s) \ - && now="$(date +%s)" \ - && seconds="$((now - boot))" + else + boot="$(date -d"$(uptime -s)" +%s)" + now="$(date +%s)" + seconds="$((now - boot))" fi ;;