ubuntu 下载离线安装包及其依赖

使用以下脚本下载keepalived deb安装包及其3层依赖

#!/bin/bash

logfile=./
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="keepalived" # 或者用$1,从命令行输入库名字
apt-get download $libs

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

libs=$newlist

done

转载于:https://blog.51cto.com/a1liujin/2046699

你可能感兴趣的:(ubuntu 下载离线安装包及其依赖)