5.14 离线安装软件

当没有网络连接的电脑上需要安装某个软件时,可以使用下面的脚本下载该软件以及依赖包,在脱机电脑上执行:
sudo dpkg -i *.deb
如果上述安装命令最后报错,则需要执行:sudo apt install -f
如果提示缺少软件包(依赖),则拷贝依赖包名(例如XXX),在有网络的电脑上执行apt download XXX下载,再拷贝到脱机电脑上双击安装即可。
批量下载脚本如下:

#! /bin/bash        
pkg="$*"            
function getDepends()       
{       
    ret=`apt-cache depends $1 |grep -i 依赖 |sed 's/(.*)//' |cut -d: -f2`   
    if [[ -z $ret ]]; then              
        echo "$1 No depends"            
        echo -n     
    else        
#       echo $ret           
#       apt-cache depends $1 |grep -i 依赖          
#       echo ''         
    for i in $ret           
    do      
        if [[ `echo $pkg |grep -e "$i "` ]]; then       
#           echo "$i already in set"        
          echo -n       
        elif [[ $i =~ '<' ]]; then      
            echo "Drop $i"      
        elif [[ "$i" != "libc6" &&      
            "$i" != "libcairo2" &&      
            !("$i" =~ "glib") &&        
            !("$i" =~ "gtk") &&             
            !("$i" =~ "font")       
        ]]; then            
#      echo "Download $i ing"       
    pkg="$pkg $i"           
    getDepends $i       
    fi      
   done     
  fi        
}       

for j in $@     
do      
    getDepends $j       
done        

apt download $pkg -d -y
Copyright © DOSU community 2020 all right reserved,powered by Gitbook该文章修订时间: 2020-09-12 12:06:10

results matching ""

    No results matching ""