Skip to content

Commit 468addc

Browse files
feat: show remote download size
1 parent 3d3a510 commit 468addc

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

udroid/src/udroid.sh

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,13 @@ list() {
740740
export size=false
741741
export show_installed_only=false
742742
local show_pretty=false
743+
local show_remote_download_size=false
743744
local path=$DEFAULT_FS_INSTALL_DIR
744745

745746
while [ $# -gt 0 ]; do
746747
case $1 in
747748
--size) size=true; shift 1;;
749+
--download-size | -ds) show_remote_download_size=true; shift 1;;
748750
--list-installed) show_installed_only=true; shift 1;;
749751
--path) path=$2; LOG "list(): looking in $path"; shift 2;;
750752
--help) help_list; exit 0;;
@@ -822,9 +824,17 @@ list() {
822824
_size_line=""
823825
fi
824826

827+
if $show_remote_download_size; then
828+
_r_size_header=" down* size |"
829+
_r_size_line="--|"
830+
else
831+
_r_size_header=""
832+
_r_size_line=""
833+
fi
834+
825835
# header
826-
echo -e "| suites | supported | status |$_size_header" > $tempfile
827-
echo -e "|--------|-----------|--------|$_size_line" >> $tempfile
836+
echo -e "| suites | supported | status |$_size_header$_r_size_header" > $tempfile
837+
echo -e "|--------|-----------|--------|$_size_line"$_r_size_line >> $tempfile
828838

829839
for suite in $suites; do
830840
varients=$(cat $distro_data | jq -r ".$suite.varients[]")
@@ -842,6 +852,19 @@ list() {
842852
supported=false
843853
fi
844854

855+
if $supported; then
856+
if $show_remote_download_size; then
857+
link=$(cat $distro_data | jq -r ".$suite.$varient.${host_arch}url")
858+
remote_size=$( wget --spider -m -np $link 2>&1 | grep -i Content-Length | awk '{print $2}')
859+
860+
if [[ -z $remote_size ]]; then
861+
remote_size="?"
862+
else
863+
remote_size=$(numfmt --to=iec-i --suffix=B --padding=7 $remote_size) # <- By GitHub Copilot
864+
fi
865+
fi
866+
fi
867+
845868
# check if installed
846869
if [[ -d $path/$name ]]; then
847870
_installed="[installed]"
@@ -852,9 +875,9 @@ list() {
852875
# check size
853876
if [[ $size == true ]]; then
854877
if [[ -d $path/$name ]]; then
855-
_size="$(du -sh $path/$name 2> /dev/null | awk '{print $1}')"
878+
_size="$(du -sh $path/$name 2> /dev/null | awk '{print $1}') |"
856879
else
857-
_size=""
880+
_size="|"
858881
fi
859882
else
860883
_size=""
@@ -869,10 +892,10 @@ list() {
869892

870893
# print out
871894
if ! $show_installed_only; then
872-
echo -e "|$suite:$varient|$support_status|$_installed|$_size" >> $tempfile
895+
echo -e "|$suite:$varient|$support_status|$_installed|$_size$remote_size" >> $tempfile
873896
else
874897
if [[ -d $path/$name/bin ]]; then
875-
echo -e "|$suite:$varient|$support_status|$_installed|$_size" >> $tempfile
898+
echo -e "|$suite:$varient|$support_status|$_installed|$_size$remote_size" >> $tempfile
876899
fi
877900
fi
878901
done

0 commit comments

Comments
 (0)