Skip to content

Commit

Permalink
Merge pull request #32 from RandomCoderOrg/revamp-v2.5-list-remote-size
Browse files Browse the repository at this point in the history
Revamp v2.5 list remote size
  • Loading branch information
SaicharanKandukuri authored Feb 1, 2023
2 parents 3d3a510 + 50c59ee commit 4c51f38
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 120 deletions.
10 changes: 6 additions & 4 deletions udroid/src/help_udroid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ help_root() {
# help_list: show help for list
help_list() {
echo "udroid [ list| --list ] [options]"
echo "show a table of all available distros/suites"
echo "options:"
echo " -h, --help show this help message and exit"
echo " --size show size of each distro"
echo " --path <path> path to look for distros"
echo " --list-installed show only installed distros"
echo " -h, --help show this help message and exit"
echo " --size show size of each distro"
echo " --download-size | -ds show download size of each distro"
echo " --path <path> path to look for distros"
echo " --list-installed show only installed distros"
}

# help_upgrade: show help for upgrade
Expand Down
215 changes: 99 additions & 116 deletions udroid/src/udroid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -736,149 +736,132 @@ parser() {
## List
# list all the avalible suites varients and their status
list() {

TITLE "list()"
export size=false
export show_installed_only=false
local show_pretty=false
local show_remote_download_size=false
local path=$DEFAULT_FS_INSTALL_DIR

while [ $# -gt 0 ]; do
case $1 in
--size) size=true; shift 1;;
--download-size | -ds) show_remote_download_size=true; shift 1;;
--list-installed) show_installed_only=true; shift 1;;
--path) path=$2; LOG "list(): looking in $path"; shift 2;;
--help) help_list; exit 0;;
--pretty) show_pretty=true; shift 1;;
*) shift ;;
esac
done

fetch_distro_data "offline"

if ! $show_remote_download_size; then
fetch_distro_data "offline"
else
fetch_distro_data "online"
fi

suites=$(cat $distro_data | jq -r '.suites[]')
tempfile=$(mktemp udroid-list-table-XXXXXX)

if ! $show_pretty; then
# loop over suites
for suite in $suites; do
echo "$suite: "
varients=$(cat $distro_data | jq -r ".$suite.varients[]")

# loop over varients
for varient in $varients; do
# get name
name=$(cat $distro_data | jq -r ".$suite.$varient.Name")
supported_arch=$(cat $distro_data | jq -r ".$suite.$varient.arch")

host_arch=$(dpkg --print-architecture)
if [[ $host_arch =~ $supported_arch ]]; then
supported=true
else
supported=false
fi

# check if installed
if [[ -d $path/$name ]]; then
_installed="[installed]"
else
_installed=""
fi

# check size
if [[ $size == true ]]; then
if [[ -d $path/$name ]]; then
_size="[ SIZE: $(du -sh $path/$name | awk '{print $1}') ]"
else
_size=""
fi
else
_size=""
fi

# set support status
if [[ $supported == true ]]; then
support_status="\e[1;32m [supported]\e[0m"
else
support_status="\e[31m [unsupported]\e[0m"
fi

# print out
if ! $show_installed_only; then
echo -e "\t- $varient $support_status $_installed $_size"
else
if [[ -d $path/$name ]]; then
echo -e "\t- $varient $support_status $_installed $_size"
fi
fi
done
done
if $size; then
_size_header=" size |"
_size_line="--|"
else
tempfile=$(mktemp udroid-list-table-XXXXXX)

if $size; then
_size_header=" size |"
_size_line="--|"
else
_size_header=""
_size_line=""
fi

# header
echo -e "| suites | supported | status |$_size_header" > $tempfile
echo -e "|--------|-----------|--------|$_size_line" >> $tempfile

for suite in $suites; do
varients=$(cat $distro_data | jq -r ".$suite.varients[]")

# loop over varients
for varient in $varients; do
# get name
name=$(cat $distro_data | jq -r ".$suite.$varient.Name")
supported_arch=$(cat $distro_data | jq -r ".$suite.$varient.arch")

host_arch=$(dpkg --print-architecture)
if [[ $host_arch =~ $supported_arch ]]; then
supported=true
else
supported=false
fi

# check if installed
if [[ -d $path/$name ]]; then
_installed="[installed]"
_size_header=""
_size_line=""
fi

if $show_remote_download_size; then
_r_size_header=" down* size |"
_r_size_line="--|"
else
_r_size_header=""
_r_size_line=""
fi

echo -e "reading data ( This a may take a minute ) ..."

# header
echo -e "| suites | supported | status |$_size_header$_r_size_header" > $tempfile
echo -e "|--------|-----------|--------|$_size_line"$_r_size_line >> $tempfile

for suite in $suites; do
varients=$(cat $distro_data | jq -r ".$suite.varients[]")
# loop over varients
for varient in $varients; do
# get name
name=$(cat $distro_data | jq -r ".$suite.$varient.Name")
supported_arch=$(cat $distro_data | jq -r ".$suite.$varient.arch")
host_arch=$(dpkg --print-architecture)

if [[ $host_arch =~ $supported_arch ]]; then
supported=true
else
_installed=""
fi
supported=false
fi

# check size
if [[ $size == true ]]; then
if [[ -d $path/$name ]]; then
_size="$(du -sh $path/$name 2> /dev/null | awk '{print $1}')"
if $supported; then
if $show_remote_download_size; then
link=$(cat $distro_data | jq -r ".$suite.$varient.${host_arch}url")
remote_size=$( wget --spider -m -np $link 2>&1 | grep -i Length | awk '{print $2}')
if [[ -z $remote_size ]]; then
remote_size="?"
else
_size=""
remote_size=$(numfmt --to=iec-i --suffix=B --padding=7 $remote_size) # <- By GitHub Copilot
fi
else
_size=""
fi
fi

# set support status
if [[ $supported == true ]]; then
support_status="YES"
# check if installed
if [[ -d $path/$name ]]; then
_installed="[installed]"
else
_installed=""
fi

# check size
if [[ $size == true ]]; then
if [[ -d $path/$name ]]; then
_size="$(du -sh $path/$name 2> /dev/null | awk '{print $1}') |"
else
support_status="NO"
_size="|"
fi

# print out
if ! $show_installed_only; then
echo -e "|$suite:$varient|$support_status|$_installed|$_size" >> $tempfile
else
if [[ -d $path/$name/bin ]]; then
echo -e "|$suite:$varient|$support_status|$_installed|$_size" >> $tempfile
fi
else
_size=""
fi

# set support status
if [[ $supported == true ]]; then
support_status="YES"
else
support_status="NO"
fi

# print out
if ! $show_installed_only; then
echo -e "|$suite:$varient|$support_status|$_installed|$_size$remote_size" >> $tempfile
else
if [[ -d $path/$name/bin ]]; then
echo -e "|$suite:$varient|$support_status|$_installed|$_size$remote_size" >> $tempfile
fi
done
fi
done
g_format $tempfile
fi
done

# footer
{
echo ""
echo ""
echo "**SIZE**: space occupied by installed distro"
echo "**DOWN SIZE**: download size of suite"
echo ""
echo "To install a suite (ex: **jammy:raw**), run:"
echo "\`\`\`bash"
echo "udroid install jammy:raw"
echo "\`\`\`"
echo ""
} >> $tempfile

g_format $tempfile
}

remove() {
Expand Down

0 comments on commit 4c51f38

Please sign in to comment.