Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
- }
- function Pause() {
- if [[ -z $1 ]]; then
- read -n1 -r -p "continue..."
- else
- read -n1 -r -p "$1"
- fi
- }
- export IFS=$'\n'
- # Store all reverse dependencies in an indexed array and output them to STDOUT & a log file
- # for easy checking later
- LIST=( $( apt-rdepends $1 | grep -v "^ " ) )
- echo ${LIST[*]}
- echo ${LIST[*]} > getdepends.log.results
- Pause "... Packages that will be downloaded (Continue or CTRL+C) ..."
- # Try to download the dependencies
- RESULTS=( $( apt-get download ${LIST[*]} |& cut -d' ' -f 8 ) )
- # If RESULTS contains any items that means we have packages that are
- # problematic that need to be removed from LIST. (note: `|&` is shortform for `2>&1 |`)
- LISTLEN=${#LIST[@]} #Array elements aren't removed so the size is constant
- 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" ) )
- echo ${LIST[*]} > getdepends.list #Log of downloaded packages
- echo ${FULLRESULTS[*]} >> getdepends.fullresults #Verbose log of skipped packages
- echo ${RESULTS[*]} >> getdepends.results #Just the name of skipped packages
- done
- apt-get download ${LIST[*]}
Add Comment
Please, Sign In to add comment