0

System -> Ubuntu 14.04

System in VM -> Ubuntu DEV 14.04

I'm using the following scripts :

Back up packages

#!/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

Restore packages

#!/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

Here is a link to the package list(It's quite long)

I edited the above package file down so that it would only run up to ack-grep, this was just for testing purposes.

Before running the script ack-grep didn't work, I was expecting to be able to use it after running the restore packages, I still couldn't though.

This is the edited list :

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

Edit

Some errors that I see when I try and run the packageRestore.sh script;

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.

output of 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 <ftpmaster@ubuntu.com>
sub   2048g/79164387 2004-09-12

pub   1024D/FBB75451 2004-12-30
uid                  Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>

pub   4096R/C0B21F32 2012-05-11
uid                  Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com>

pub   4096R/EFE21092 2012-05-11
uid                  Ubuntu CD Image Automatic Signing Key (2012) <cdimage@ubuntu.com>

pub   1024D/3E5C1192 2010-09-20
uid                  Ubuntu Extras Archive Automatic Signing Key <ftpmaster@ubuntu.com>

pub   1024D/7FAC5991 2007-03-08
uid                  Google, Inc. Linux Package Signing Key <linux-packages-keymaster@google.com>
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

Installing the packages manually works, as does editing the package.list to the following format then running as a shell script, the problem with this is that some of the packages are to be deinstalled rather than installed (such as thunderbird and 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

edit 2

I've written a script for this, but I'm still not sure why the above doesn't work

#!/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()
baxx
  • 175

1 Answers1

0

Issue 1

You copy the sources.list which contains references to a CD. When trying to install the packages in your VM, there's no CD in the (virtual) drive, hence Failed to fetch cdrom://.

Issue 2

W: Failed to fetch http://ppa.launchpad.net/jon-severinsson/ffmpeg/ubuntu/dists/trusty/main/binary-amd64/Packages 404 Not Found Again, there's something in the original sources.lst that's causing the error: The PPA doesn't exist (anymore), hence the 404.

If you used set -e for the restore-script, then the whole script terminates prematurely on the error of apt-get update...

Jan
  • 12,291
  • 3
  • 32
  • 38
  • hmm, so this method just can't work in a VM then? – baxx Apr 23 '15 at 11:24
  • I'm not saying that, no. Issue #2 should also show on the original machine (else it's a network issue with the VM), and issue #1 should also show if you don't have the physical CD in the physical drive. – Jan Apr 23 '15 at 11:28