Skip to content

Commit d746588

Browse files
committed
🎈 Epoche 2 / Golang Refactor
1 parent 1c0c9f4 commit d746588

File tree

10 files changed

+342
-1349
lines changed

10 files changed

+342
-1349
lines changed

PKGBUILD

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# Maintainer: Cookie Engineer <@cookiengineer>
22

33
pkgname=pacman-backup
4-
pkgver=r7.e8dd759
4+
pkgver=r16.7a7623c
55
pkgrel=1
6-
pkgdesc='Backup tool for off-the-grid updates via portable USB sticks or (mesh) LAN networks.'
6+
pkgdesc='Pacman Backup tool for off-the-grid updates via portable USB sticks or (mesh) LAN networks.'
77
arch=('i686' 'x86_64' 'armv6h' 'armv7h' 'aarch64')
8-
makedepends=('git')
9-
depends=('nodejs')
8+
makedepends=('git' 'go')
109
url='https://github.com/cookiengineer/pacman-backup'
1110
license=('GPL')
1211
provides=('pacman-backup')
@@ -20,8 +19,12 @@ pkgver() {
2019
printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
2120
}
2221

22+
build() {
23+
cd "${srcdir}/${_gitname}";
24+
bash build.sh;
25+
}
2326
package() {
24-
cd "${srcdir}/${_gitname}"
25-
install -Dm755 pacman-backup.js "$pkgdir/usr/bin/pacman-backup";
27+
cd "${srcdir}/${_gitname}";
28+
install -Dm755 "build/pacman-backup_linux_amd64" "$pkgdir/usr/bin/pacman-backup";
2629
}
2730

README.md

Lines changed: 32 additions & 249 deletions
Original file line numberDiff line numberDiff line change
@@ -1,299 +1,82 @@
11

22
# Pacman Backup
33

4-
Backup tool for off-the-grid updates via portable USB sticks or (mesh) LAN networks.
4+
Offline Pacman Cache management tool that allows off-the-grid updates via
5+
sneakernet (usb drives) or mesh Wi-Fi networks.
56

67

78
## Share Updates via USB Drive
89

9-
In the below example, make sure that `pacman-usbdrive` is writable.
10-
Replace the path with the correct one that points to your mounted USB drive.
10+
In the below example, make sure that `usb-drive` is writable. Replace the path with
11+
the correct one that points to your mounted USB drive.
1112

12-
**Step 1**:
13-
14-
On the machine with internet connection, insert and mount the USB drive.
15-
16-
Use `pacman-backup archive` to copy the package cache to the backup folder.
17-
Use `pacman-backup cleanup` to remain only the latest version of each package.
18-
19-
The `archive` action will also copy the necessary database files for `pacman -Sy`.
13+
**Step 1**: On the machine _with_ internet connection, insert and mount the USB drive.
2014

2115
```bash
2216
# Machine with internet connection
23-
24-
sudo pacman -Sy;
25-
sudo pacman -Suw;
26-
27-
pacman-backup archive /run/media/$USER/pacman-usbdrive;
28-
pacman-backup cleanup /run/media/$USER/pacman-usbdrive;
17+
pacman-backup download /run/media/$USER/usb-drive;
18+
pacman-backup cleanup /run/media/$USER/usb-drive;
2919
sync;
3020

31-
# Unmount the USB drive and walk to other machine
21+
# Unmount the USB drive and sneak/walk to other machine
3222
```
3323

34-
**Step 2**:
35-
36-
On the machine without internet connection, insert and mount the USB drive.
37-
38-
Copy the necessary database files to pacman's `sync` folder (which is `$DBPath/sync` of `pacman.conf`).
39-
40-
Use `pacman-backup upgrade` to update from the backupfolder.
41-
This will output the pacman command that you should verify manually before executing it.
24+
**Step 2**: On the machine _without_ internet connection, insert and mount the USB drive.
4225

4326
```bash
4427
# Machine without internet connection
45-
46-
sudo cp /run/media/$USER/pacman-usbdrive/sync/*.db /var/lib/pacman/sync/;
47-
pacman-backup upgrade /run/media/$USER/pacman-usbdrive;
48-
49-
# :: Use this to install upgrades from cache:
50-
# (...) pacman -U command (...)
28+
pacman-backup upgrade /run/media/$USER/usb-drive;
5129
```
5230

31+
## Share Updates via Wi-Fi Mesh Network
5332

54-
## Share Updates via LAN Connection
55-
56-
In the below example, the machine with internet connection has the IP `192.168.0.10`.
33+
In the below example, the machine _with_ internet connection has the IP `192.168.0.10`.
5734
Replace the IP with the correct one that matches your setup. If in doubt, use `ip` or `ifconfig`.
5835

5936

60-
**Step 1**:
61-
62-
On the machine with internet connection, connect the LAN cable (and internet connection).
63-
64-
Use `pacman-backup serve` to start a pacman server that can be used by other pacman clients.
37+
**Step 1**: On the machine with internet connection, download all updates and serve them as
38+
local pacman archive mirror.
6539

6640
```bash
6741
# Machine with internet connection
68-
69-
sudo pacman -Sy;
70-
sudo pacman -Suw;
71-
42+
sudo pacman-backup download;
7243
pacman-backup serve;
7344
```
7445

75-
**Step 2**:
76-
77-
On the machine without internet connection, connect the LAN cable and verify that the server
78-
(the machine with internet connection) is reachable via its IP. If in doubt, use `ping`.
79-
80-
Use `pacman-backup download 192.168.0.10` to download the packages to pacman's package cache.
81-
82-
Use `pacman-backup upgrade` to update from the local pacman cache.
83-
This will output the pacman command that you should verify manually before executing it.
46+
**Step 2**: On the machine _without_ direct internet connection, download updates from the
47+
local pacman archive mirror.
8448

8549
```bash
8650
# Machine without internet connection
87-
88-
sudo pacman-backup download 192.168.0.10;
89-
pacman-backup upgrade;
51+
sudo pacman-backup download http://192.168.0.10:15678/;
52+
sudo pacman-backup upgrade;
9053
```
9154

92-
## Share Updates via LAN Cache Proxy
93-
94-
`pacman-backup` can also emulate a local Cache Proxy for other pacman clients.
95-
If `pacman-backup serve` is running on the machine with internet connection, it
96-
can be used for `pacman` directly.
97-
98-
Note that if the packages don't exist, they will appear in the logs but aren't downloaded
99-
directly; and that partial upgrades are not officially supported by Arch Linux.
10055

101-
In the below example, the machine with internet connection has the IP `192.168.0.10`.
102-
Replace the IP with the correct one that matches your setup. If in doubt, use `ip` or `ifconfig`.
103-
104-
**Step 1**:
105-
106-
On the machine with internet connection, connect the LAN cable (and internet connection).
107-
108-
Use `pacman-backup serve` to start a pacman server that can be used by other pacman clients.
56+
## Manual Export and Import of Database Files and Package Cache
10957

58+
If you don't trust automated upgrades and want to use `pacman` directly, that's fine. You
59+
can do so by using `export` on the machine with internet connection and `import` on the
60+
machine without internet connection.
11061

11162
```bash
11263
# Machine with internet connection
64+
sudo pacman -Syuw;
65+
pacman-backup export /run/media/$USER/usb-drive;
66+
sync;
11367

114-
sudo pacman -Sy;
115-
sudo pacman -Suw;
116-
117-
pacman-backup serve;
118-
```
119-
120-
**Step 2**:
121-
122-
Modify the `/etc/pacman.d/mirrorlist` to have as a first entry the following line:
123-
124-
```conf
125-
# Machine without internet connection
126-
# Pacman Mirrorlist for local server
127-
128-
Server = http://192.168.0.10:15678
68+
# Unmount the USB drive and sneak/walk to other machine
12969
```
13070

131-
Use `pacman -Sy` and `pacman -Su` to update from the Cache Proxy.
132-
13371
```bash
13472
# Machine without internet connection
73+
sudo pacman-backup import /run/media/$USER/usb-drive;
74+
sync;
13575

136-
sudo pacman -Sy;
137-
sudo pacman -Su; # or use -Suw
138-
```
139-
140-
141-
## Advanced Usage
142-
143-
### Available CLI parameters
144-
145-
The `pacman-backup` script tries to identify parameters dynamically, which means that
146-
they do not have to be written in a specific order. However, to avoid confusion, the
147-
parameters are detected in different ways; and that is documented here:
148-
149-
- `ACTION` can be either of `archive`, `cleanup`, `download`, `serve`, or `upgrade`. Defaulted with `null` (and shows help).
150-
- `FOLDER` has to start with `/`. Defaulted with `null` (and uses `/var/cache/pacman/pkg` and `/var/lib/pacman/sync`).
151-
- `MIRROR` has to start with `https://` and contain the full `mirrorlist` syntaxed URL. Supported variables are `$arch` and `$repo`. Defaulted with `https://arch.eckner.net/os/$arch`.
152-
- `SERVER` has to be an `IPv4` separated by `.` or an `IPv6` separated by `:`. Defaulted with `null`.
153-
- `SERVER` can optionally be a `hostname`. If it is a `hostname`, make sure it's setup in the `/etc/hosts` file.
154-
155-
Full example (which won't make sense but is parsed correctly):
156-
157-
```bash
158-
# IMPORTANT: MIRROR string needs to be escaped, otherwise bash will try to replace it.
159-
160-
pacman-backup download /run/media/cookiengineer/my-usb-drive "https://my.own.mirror/archlinux/\$repo/os/\$arch" 192.168.0.123;
161-
162-
# :: pacmab-backup download
163-
# -> FOLDER: "/run/media/cookiengineer/my-usb-drive"
164-
# -> MIRROR: "https://my.own/mirror/archlinux/$repo/os/$arch"
165-
# -> SERVER: "192.168.0.123"
166-
# -> USER: "cookiengineer"
167-
```
168-
169-
### archive
170-
171-
`archive` allows to backup everything to a specified folder. It copies the files from
172-
`/var/cache/pacman/pkg` and `/var/lib/pacman/sync` into `$FOLDER/pkgs` and `$FOLDER/sync`.
173-
174-
```bash
175-
# copy local packages to /target/folder/pkgs
176-
# copy local database to /target/folder/sync
177-
178-
pacman-backup archive /target/folder;
179-
```
180-
181-
### cleanup
182-
183-
`cleanup` allows to cleanup the package cache in a way that only the latest version of
184-
each package is kept (for each architecture).
185-
186-
If no folder is specified, it will clean up `/var/cache/pacman/pkg`.
187-
If a folder is specified, it will clean up `$FOLDER/pkgs`.
188-
189-
```bash
190-
# cleanup /var/cache/pacman/pkg
191-
192-
sudo pacman-backup cleanup;
193-
```
194-
195-
```bash
196-
# cleanup /target/folder/pkgs
197-
198-
pacman-backup cleanup /target/folder;
199-
```
200-
201-
### download
202-
203-
`download` allows to download packages from a `pacman-backup serve` based server.
204-
205-
If no folder and a server is specified, it will run `pacman -Sy` in advance and download to `/var/cache/pacman/pkg`.
206-
If a folder and a server is specified, it will run `pacman -Sy` in advance and download to `$FOLDER/pkgs`.
207-
208-
If no folder and no server is specified, it will generate a URL list of packages
209-
that can be copy/pasted into a download manager of choice (e.g. uGet or jdownloader).
210-
211-
```bash
212-
# download packages to /var/cache/pacman/pkg
213-
# download database to /var/lib/pacman/sync
214-
215-
sudo pacman-backup download 1.3.3.7;
216-
```
217-
218-
```bash
219-
# download packages to /target/folder/pkgs
220-
# download database to /target/folder/sync
221-
222-
pacman-backup download 1.3.3.7 /target/folder;
223-
```
224-
225-
```bash
226-
# generate HTTP/S URL list for packages that need downloading
227-
228-
pacman-backup download;
229-
```
230-
231-
### serve
232-
233-
`serve` allows to start a `pacman` server that can be used as a local mirror.
234-
235-
If no folder is specified, it will serve from `/var/cache/pacman/pkg` and `/var/lib/pacman/sync`.
236-
If a folder is specified, it will serve from `$FOLDER/pkgs` and `$FOLDER/sync`.
237-
238-
```bash
239-
# serve packages from /var/cache/pacman/pkg
240-
# serve database from /var/lib/pacman/sync
241-
242-
pacman-backup serve;
243-
```
244-
245-
```bash
246-
# serve packages from /source/folder/pkgs
247-
# serve database from /source/folder/sync
248-
249-
pacman-backup serve /source/folder;
250-
```
251-
252-
### upgrade
253-
254-
`upgrade` allows to generate an executable `pacman` command that uses the specified
255-
cache folder as a package source by leveraging the `--cachedir` parameter.
256-
257-
If no folder is specified, it will upgrade from `/var/cache/pacman/pkg`.
258-
If a folder is specified, it will upgrade from `$FOLDER/pkgs`.
259-
260-
```bash
261-
# generate upgrade command via packages from /var/cache/pacman/pkg
262-
263-
pacman-backup upgrade;
264-
```
265-
266-
```bash
267-
# generate upgrade command via packages from /source/folder/pkgs
268-
269-
pacman-backup upgrade /source/folder;
76+
sudo pacman -Su;
27077
```
27178

272-
### upgrade (Partial Upgrades)
273-
274-
`upgrade` also prints out a command for missing packages that need downloading.
275-
276-
In the scenario that the local database says that more packages need to be downloaded
277-
to update everything, it will output an additional command that is prepared to let
278-
`pacman` download the packages to the specified folder.
27979

280-
This is helpful in the scenario that the "offline machine" has more packages installed
281-
than the "online machine" (so that more packages need to be downloaded to fully
282-
upgrade the "offline machine").
80+
# License
28381

284-
Then you can simply copy/paste the generated command to a text file and execute it
285-
next time you're online - in order to automatically download everything that's
286-
required for the "offline machine".
287-
288-
```bash
289-
# Example output for partial upgrade scenario
290-
# (executed on machine without internet connection)
291-
292-
pacman-backup upgrade 1.3.3.7;
293-
294-
# :: Use this to install upgrades from cache:
295-
# (...) pacman -U command (...)
296-
297-
# :: Use this to download upgrades into cache:
298-
# (...) pacman -Sw --cachedir command (...)
299-
```
82+
GPL3

TODO.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
# actions/Cleanup
3+
4+
- [ ] Implement a cleanup mechanism
5+
- [ ] Keep only the newest version of package files in the cache
6+
7+
- [ ] Maybe harfbuzz and icu need to be preserved in older versions?
8+

0 commit comments

Comments
 (0)