离网环境apt 递归下载脚本

离网环境ubuntu安装依赖包是件很麻烦的事情,往往出现安装A需要依赖B,依赖B需要依赖C等等,下面脚本是递归下载用,用法是./XX.sh packname

#!/bin/bash

logfile=/root/log
ret=""
function getDepends()
{
   echo "fileName is" $1>>$logfile
   # use tr to del < >
   ret=`apt-cache depends $1|grep Depends |cut -d: -f2 |tr -d "<>"`
   echo $ret|tee  -a $logfile
}
# 需要获取其所依赖包的包
libs="gnome-shell"                  # 或者用$1,从命令行输入库名字

# download libs dependen. deep in 3
i=0
while [ $i -lt 5 ] ;
do
    let i++
    echo $i
    # download libs
    newlist=" "
    for j in $libs
    do
        added="$(getDepends $j)"
        newlist="$newlist $added"
        sudo apt download $added  -d -y
    done

    libs=$newlist
done

你可能感兴趣的:(离网环境apt 递归下载脚本)