Debian

Debian 腳本下載已安裝軟體包的原始碼失敗

  • February 10, 2018

I used the next script from askububtu to automate the download of all installed packages in a fresh debian 9.3 LXDE installation.

From here:

#!/bin/bash
dpkg --get-selections | while read line
do
       package=`echo $line | awk '{print $1}'`
       mkdir $package
       cd $package
       apt-get -q source $package
       cd ..
done

My problem is that I get some errors and it downloads a similar but not the wanted package:

sh: 1: dpkg-source: not found W: Download is performed unsandboxed as root as file ’libreoffice_5.2.7-1.dsc’ couldn’t be accessed by user ‘_apt’. - pkgAcquire::Run (13: Permission denied) E: Unpack command ‘dpkg-source –no-check -x libreoffice_5.2.7-1.dsc’ failed. Reading package lists… Picking ’libreoffice’ as source package instead of ’libreoffice-calc’

You can imagine that it downloads 300MB or so every 3-4 minutes (libreoffice) for many times (for almost every dependency of libreoffice)…

Does anyone has a better suggestion than that script to automate the source download of the packages used on my system?

There’s a fundamental problem with the script you’re using: it’s based on binary packages, not source packages. That’s why you’re downloading the LibreOffice source multiple times: there are many binary packages built from the same source package…

Another problem is that you don’t have dpkg-source installed, so the source packages can’t be extracted.

I would use something like this instead:

#!/bin/bash
dpkg-query -f '${Source}\n' -W | cut -d\  -f1 | sort -u | while read package
do
   mkdir $package
   pushd $package
   apt-get -q source $package
   popd
done

If you don’t want to extract the source, add -d to the apt-get line, that will avoid the dpkg-source errors.

引用自:https://unix.stackexchange.com/questions/423274