# Set up a local APT repository

John Simpson `<jms1@jms1.net>` 2019-08-13

# Background

There is no way to install software "permanently" under Tails. Instead, Tails keeps a list of packages which will be installed on the running system, every time it boots. It comes with a post-install handler which, after a new package is installed, asks the user whether or not that package should be installed every time Tails boots.

However, this handler is only triggered when a package is installed using `apt` or something which uses `apt` (i.e. "`apt install`", "`apt-get install`", Synaptic, etc.) In particular, if you install a package using "`dpkg`", the handler will not be triggered, and Tails will not remember to install that package when it boots.

In order to install a package using `apt`, we need to set up a local APT repo, from which the `apt` utilities can install packages. This repo obviously needs to be in the persistent volume.

We're going to create a `/live/persistence/TailsData_unlocked/local-repo` directory, which will be the APT repo. This is where you will store any `.deb` files you want to install, which don't come from the default Tails repos.

# Pre-requisites

* Persistent volume is mounted, with "Additional Software" enabled
* Administration password is set

# Procedure

Create the directory, and make it owned by the `amnesia` user.

```
$ sudo mkdir -m 0755 /live/persistence/TailsData_unlocked/local-repo
$ sudo chown amnesia:amnesia /live/persistence/TailsData_unlocked/local-repo
```

Within that directory, create a script which builds the index files which allow the `apt` programs to use the directory as a repo.

```
$ cd /live/persistence/TailsData_unlocked/local-repo
$ nano go
```

```
#!/bin/bash
apt-ftparchive packages . > Packages
apt-ftparchive release  . > Release
chmod -R go=u-w .
```

```
$ chmod 0755 go
$ ./go
```

### Make Tails *use* the new APT repository

The next step is to create a persistent `sources.list.d` directory, and then configure the persistence program to symlink the directory's contents into the `/etc/apt/sources.list.d/` directory when Tails boots.


Create the persistent directory and the source list file, pointing to the `/live/persistence/TailsData_unlocked/local-repo/` directory we created above.

```
$ cd /live/persistence/TailsData_unlocked/
$ sudo mkdir -m 0755 sources.list.d
$ sudo chown amnesia:amnesia sources.list.d
$ cd sources.list.d
$ nano local.list
```

```
deb [trusted=yes] file:/live/persistence/TailsData_unlocked/local-repo ./
```

```
$ chmod -R go=u-w .
```

Next, we need to make the Persistence software automatically symlink the sources files in this directory into `/etc/apt/sources.list.d/` when Tails boots.

> **WARNING:** Be VERY careful when editing the `persistence.conf` file. If you make a typo and don't fix it before rebooting, you can destroy the persistence functionality.
> 
> If this happens, the only way to fix it is to remove and re-create the persistent volume.

```
$ cd /live/persistence/TailsData_unlocked
$ sudo cp -a persistence.conf persistnce.conf.bak
$ sudo nano persistence.conf
```

Add this line to the end of the file:

```
/etc/apt/sources.list.d         source=sources.list.d,link
```

At this point we could reboot, but it's quicker to just create the same symlink(s) that the persistence software will create when Tails reboots.

```
$ cd /etc/apt/sources.list.d
$ sudo ln -s /live/persistence/TailsData_unlocked/sources.list.d/* .
```

The new source should now be visible to the `apt` programs. Update the `apt` software's caches with the contents of the new repo. (Note that if the machine is online, this will also update its cached information about the normal Tails and Debian repos as well.)

```
$ sudo apt update
```

# Using the local repo

Copy the `.deb` files to the `/live/persistence/TailsData_unlocked/local-repo/` directory.

After adding, updating, or removing packages, run the `./go` script in that directory to rebuild the indexes, then run "`sudo apt update`" to update the system's cached copies of the index files.

After this, normal `apt` utilities should work as expected.

Also, when you install packages using "`apt install`", Tails will ask if you want that package to *always* be installed whenever you boot Tails with that Persistent Volume enabled.
