Skip to content

Instantly share code, notes, and snippets.

@nutrino
Last active June 4, 2022 06:39
Show Gist options
  • Select an option

  • Save nutrino/a6f0fd62530c59ce27f1d52346bac590 to your computer and use it in GitHub Desktop.

Select an option

Save nutrino/a6f0fd62530c59ce27f1d52346bac590 to your computer and use it in GitHub Desktop.
Download Debian/Ubuntu packages from online and install them to offline
apt-get download $(apt-rdepends $1|grep -v "^ " |grep -v "^libc-dev$" | sed 's/debconf-2.0/debconf/g')
@nutrino
Copy link
Author

nutrino commented Dec 12, 2019

getdepends.sh

https://superuser.com/questions/1112525/ignore-apt-get-download-errors

#!/bin/bash
 export MAXPARAMETERS=255

 function array_contains_find_index() {
     local n=$#
     local i=0
     local value=${!n}

     for (( i=1; i < n; i++ )) {
         if [ "${!i}" == "${value}" ]; then
             echo "REMOVING $i: ${!i} = ${value}"
             return $i
         fi
     }
     return $MAXPARAMETERS
 }

 LIST=( $( apt-rdepends $1 | grep -v "^ " ) )
 echo ${LIST[*]}
 read -n1 -r -p "... Packages that will be downloaded (Continue or CTRL+C) ..."

 RESULTS=( $( apt-get download ${LIST[*]} |& cut -d' ' -f 8 ) )
 LISTLEN=${#LIST[@]}

 while [ ${#RESULTS[@]} -gt 0 ]; do
     for (( i=0; i < $LISTLEN; i++ )); do
         array_contains_find_index ${RESULTS[@]} ${LIST[$i]}
         ret=$?

         if (( $ret != $MAXPARAMETERS )); then
             unset LIST[$i]
         fi
     done

     FULLRESULTS=$( apt-get download ${LIST[*]} 2>&1  )
     RESULTS=( $( echo $FULLRESULTS |& cut -d' ' -f 11 | sed -r "s/'(.*?):(.*$)/\1/g" ) )
 done

 apt-get download ${LIST[*]}

@nutrino
Copy link
Author

nutrino commented Jun 4, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment