4

I'm trying to download all packages and needed dependencies on a server with working internet connection and transfer them on server without internet connection and then install them via apt-get.

I have two solutions to download packages:

  1. apt-get --print-uris --yes install pkgspec | grep ^\' | cut -d\' -f2 > downloads.list
    

Is useless because it works only for packages and dependencies that are not downloaded and installed already on a server with working internet connection.

  1. aptitude download '?reverse-depends(package)'
    

It downloads all packages and dependencies also if you don't need them.

Anyone knows a better solution to download a package and dependencies needed to be installed on a fresh install of Ubuntu server 16.04?

I want to create a script that goes trough a list of packages and downloads all packages and dependencies automatically.

Then I need a solution to use this packages on a offline computer with apt-get. Idea is to create a local apt repository that allows you to use your local packages via apt-get.

So I use this command to create Packages.gz that contains info about all packages that were download in first step.

dpkg-scanpackages . /dev/null | gzip > Packages.gz

Then I add a new source to /etc/apt/sources.list.d/ and run apt-get update.

deb [trusted=yes] file:///tmp/dpkgs /

Now I have a problem that I can for example install apache (still some errors). But if I want to install php I got the following error.

root@ubuntu:~# apt-get install php
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 php : Depends: php7.0 but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Anyone has a working solution for this problem? Thanks.

1

Lan Morrison has made an isorespin.sh script that will make an image from commands you give and with an added command can have all the updates to that time on the image and install any apt install you want on the install image it makes. I used it and it works real good.

For more details, see: Customizing Ubuntu ISOs: Documentation and examples of how to use isorespin.sh.

| improve this answer | |
0

I have never tried this, so YMMV.

Check out this and apt-offline.

They claim to do exactly what you want.

| improve this answer | |
0

My recommendation is to do ssh tunnels, I supose you are loging to server with an SSH connection from a machine who has internet connection, hence you can try to use reverse tunnels to have access at least to your desired repos... Please follow these steps:

  1. Log in to your server with the following command:

    ssh -R 127.0.0.1:9800:yourrepo.address:80 youruser@ServerWithoutInternetConnectionAddress
    
  2. Once logged in your server add the following line to /etc/hosts:

    127.0.0.1 yourrepo.adress
    
  3. In your repository configuration file in /etc/apt/sources.list or in /etc/apt/sources.list.d/repofile.list modify your repository address by adding used port (I've used 9800, although it can be any port higher than 1023):

    deb [arch=amd64] http://yourrepo.address:9800/ubuntu-mirror/ xenial main
    deb [arch=amd64] http://yourrepo.address:9800/ubuntu-mirror/ xenial-updates main
    deb [arch=amd64] http://yourrepo.address:9800/ubuntu-java/ xenial main
    deb [arch=amd64] http://yourrepo.address:9800/ubuntu-production/ xenial multiverse
    

Now apt-get update and apt-get install should be working. Please consider that you can have as many tunnels as repositories, you only need to change your source port.

E.g. consider that you have official ubuntu repository in /etc/apt/sources.list and other in /etc/apt/sources.list.d/repofile.listI can use port to 9801 for us.archive.ubuntu.com and port 9800 for /etc/apt/sources.list.d/repofile.list as following:

/etc/apt/sources.list

deb http://us.archive.ubuntu.com:9801/ubuntu/ xenial main restricted universe multiverse
deb-src http://us.archive.ubuntu.com:9801/ubuntu/ xenial main restricted multiverse
deb http://us.archive.ubuntu.com:9801/ubuntu/ xenial-security main restricted universe multiverse
deb http://us.archive.ubuntu.com:9801/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://us.archive.ubuntu.com:9801/ubuntu/ xenial-security main restricted multiverse
deb-src http://us.archive.ubuntu.com:9801/ubuntu/ xenial-updates main restricted multiverse

/etc/apt/sources.list

deb [arch=amd64] http://yourrepo.address:9800/ubuntu-mirror/ xenial main
deb [arch=amd64] http://yourrepo.address:9800/ubuntu-mirror/ xenial-updates main
deb [arch=amd64] http://yourrepo.address:9800/ubuntu-java/ xenial main
deb [arch=amd64] http://yourrepo.address:9800/ubuntu-production/ xenial multiverse

By adding this to /etc/hosts

127.0.0.1     yourrepo.adress      us.archive.ubuntu.com

And log in from a machine with internet connection as following:

ssh -R 127.0.0.1:9800:yourrepo.address:80 -R 127.0.0.1:9801:us.archive.ubuntu.com:80 youruser@ServerWithoutInternetConnectionAddress

PS: Consider that if your repository needs a key you will need to extract the key (from a machine that has the key apt-key export KEY_ID >> key.asc) and add it using the following command:

apt-key add key.asc
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.