通过脚本将包从一个系统安装到另一个系统时出现问题

通过脚本将包从一个系统安装到另一个系统时出现问题

系统->Ubuntu 14.04

虚拟机中的系统 -> Ubuntu DEV 14.04

我正在使用以下脚本:

备份包

#!/bin/bash

dir=source_files

# if directory doesn't exist then make it
if [ ! -d "$dir" ]; then
    mkdir $dir
    echo "Created directory $dir"
fi

# Back up files to created directory
dpkg --get-selections > ./$dir/Package.list
sudo cp -R /etc/apt/sources.list* ./$dir
sudo apt-key exportall > ./$dir/Repo.keys

exit

恢复包

#!/bin/sh

path=./source_files

apt-cache dumpavail > ~/temp_avail
sudo dpkg --merge-avail ~/temp_avail
rm ~/temp_avail


sudo apt-key add $path/Repo.keys
sudo cp -R $path/sources.list* /etc/apt/
sudo apt-get update
sudo apt-get install dselect
sudo dpkg --set-selections < $path/Package.list
sudo apt-get dselect-upgrade -y

exit

这是包裹清单的链接(很长)

我编辑了上述包文件,以便它只能运行到ack-grep,这只是为了测试目的。

在运行脚本之前它ack-grep不起作用,我希望在运行恢复包后能够使用它,但仍然不能。

这是编辑后的列表:

account-plugin-aim                  install
account-plugin-facebook             install
account-plugin-flickr               install
account-plugin-google               install
account-plugin-jabber               install
account-plugin-salut                install
account-plugin-twitter              install
account-plugin-windows-live         install
account-plugin-yahoo                install
accountsservice                     install
ack-grep                            install

编辑

我尝试运行packageRestore.sh脚本时看到的一些错误;

W: GPG error: http://download.virtualbox.org trusty InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 54422A4B98AB5139
W: Failed to fetch cdrom://Ubuntu 14.04 LTS _Trusty Tahr_ - Release amd64 (20140417)/dists/trusty/main/binary-amd64/Packages  Please use apt-cdrom to make this CD-ROM recognized by APT. apt-get update cannot be used to add new CD-ROMs

W: Failed to fetch cdrom://Ubuntu 14.04 LTS _Trusty Tahr_ - Release amd64 (20140417)/dists/trusty/restricted/binary-amd64/Packages  Please use apt-cdrom to make this CD-ROM recognized by APT. apt-get update cannot be used to add new CD-ROMs

W: Failed to fetch cdrom://Ubuntu 14.04 LTS _Trusty Tahr_ - Release amd64 (20140417)/dists/trusty/main/binary-i386/Packages  Please use apt-cdrom to make this CD-ROM recognized by APT. apt-get update cannot be used to add new CD-ROMs

W: Failed to fetch cdrom://Ubuntu 14.04 LTS _Trusty Tahr_ - Release amd64 (20140417)/dists/trusty/restricted/binary-i386/Packages  Please use apt-cdrom to make this CD-ROM recognized by APT. apt-get update cannot be used to add new CD-ROMs

W: Failed to fetch http://ppa.launchpad.net/jon-severinsson/ffmpeg/ubuntu/dists/trusty/main/binary-amd64/Packages  404  Not Found

W: Failed to fetch http://ppa.launchpad.net/jon-severinsson/ffmpeg/ubuntu/dists/trusty/main/binary-i386/Packages  404  Not Found

E: Some index files failed to download. They have been ignored, or old ones used instead.

输出apt-key list

vco@osc:~/package-test$ apt-key list
/etc/apt/trusted.gpg
--------------------
pub   1024D/437D05B5 2004-09-12
uid                  Ubuntu Archive Automatic Signing Key <[email protected]>
sub   2048g/79164387 2004-09-12

pub   1024D/FBB75451 2004-12-30
uid                  Ubuntu CD Image Automatic Signing Key <[email protected]>

pub   4096R/C0B21F32 2012-05-11
uid                  Ubuntu Archive Automatic Signing Key (2012) <[email protected]>

pub   4096R/EFE21092 2012-05-11
uid                  Ubuntu CD Image Automatic Signing Key (2012) <[email protected]>

pub   1024D/3E5C1192 2010-09-20
uid                  Ubuntu Extras Archive Automatic Signing Key <[email protected]>

pub   1024D/7FAC5991 2007-03-08
uid                  Google, Inc. Linux Package Signing Key <[email protected]>
sub   2048g/C07CB649 2007-03-08

pub   1024R/1BD3A65C 2009-01-19
uid                  Launchpad PPA for Terminator

pub   1024R/CFCA9579 2009-06-02
uid                  Launchpad Jon Severinsson's PPA

pub   1024R/BF7B8DAF 2013-06-30
uid                  Launchpad PPA for Michael Blennerhassett

pub   1024R/EEA14886 2010-05-04
uid                  Launchpad VLC

手动安装软件包是可行的,将 package.list 编辑为以下格式然后作为 shell 脚本运行也是可行的,但这样做的问题是有些软件包需要卸载而不是安装(例如 thunderbird 和 banshee)

#! /bin/bash                                                                                                                                                                    

apt-get install account-plugin-aim -y
apt-get install account-plugin-facebook -y
apt-get install account-plugin-flickr -y
apt-get install account-plugin-google -y
apt-get install account-plugin-jabber -y
apt-get install account-plugin-salut -y
apt-get install account-plugin-twitter -y
apt-get install account-plugin-windows-live -y
apt-get install account-plugin-yahoo -y
apt-get install accountsservice -y
apt-get install ack-grep -y
apt-get install acl -y
apt-get install acpi-support -y
apt-get install acpid -y
apt-get install activity-log-manager -y
apt-get install activity-log-manager-control-center -y
apt-get install adduser -y
apt-get install adium-theme-ubuntu -y

编辑2

我已经为此编写了一个脚本,但我仍然不确定为什么上述方法不起作用

#!/usr/bin/env python3
# encoding: utf-8

import os
import sys
import subprocess

'''Takes in a list of installed packages and converts them into a shell script

Script creates two files 

    (1) installed_packages.sh 
    (2) deinstall_packages.sh

These are formatted into shell scripts (though still need "chmod +x ./") that
can be used to install the same packages on another system

'''

# Write information of all packages to this file
package_list_file = 'Package.List'

# Create file containing installed packages
subprocess.call('dpkg --get-selections > ./{}'.format(package_list_file), shell=True)

# so all lines are apt-get lines
aptget = 'apt-get install'
apt_remove = 'apt-get purge'

# shebang!
shebang = "#! /bin/bash\n\n"

# alter the lines to be apt-get lines
with open(package_list_file,'r') as f:
    with open('./install_packages.sh','w+') as install_file:
        with open('./deinstall_packages.sh','w+') as deinstall_file:
            install_file.write(shebang)
            deinstall_file.write(shebang)
            for line in f.readlines():
                package, action = line.split()
                if action == 'deinstall':
                    deinstall_file.write("{} {} -y\n".format(apt_remove,package))
                elif action == 'install':
                    install_file.write("{} {} -y\n".format(aptget,package))
                else:
                    print("line didn't match the pattern....")

exit()

答案1

问题 1

您复制了包含对 CD 的引用的 sources.list。尝试在 VM 中安装软件包时,(虚拟)驱动器中没有 CD,因此Failed to fetch cdrom://

问题 2

W: Failed to fetch http://ppa.launchpad.net/jon-severinsson/ffmpeg/ubuntu/dists/trusty/main/binary-amd64/Packages 404 Not Found 再次,原始 sources.lst 中存在导致错误的内容:PPA 不再存在,因此出现 404。

如果您使用了set -e恢复脚本,那么整个脚本会因以下错误过早终止apt-get update...

相关内容