-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fetch-repo-package-list timer and service
Signed-off-by: Richard Oliver <[email protected]>
- Loading branch information
1 parent
84d1e21
commit a94c61b
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# fetch-repo-package-list | ||
|
||
## Usage | ||
### Oneshot | ||
To fetch the latest Raspberry Pi OS package list: | ||
``` | ||
systemctl start fetch-repo-package-list@$(systemd-escape https://archive.raspberrypi.org/debian).service | ||
``` | ||
|
||
The service makes use of systemd's CacheDirectory, and RuntimeDirectory during | ||
execution. The updated package list is outputted to the RuntimeDirectory, | ||
which would typically as follows for the above example: | ||
``` | ||
/var/run/fetch-repo-package-list@https\:--archive.raspberrypi.org-debian.service/Packages | ||
``` | ||
|
||
### Regularly via timer | ||
To fetch package lists every day at a random, but consistent, time between midnight and 6a.m. (local time): | ||
``` | ||
systemctl enable --now fetch-repo-package-list@$(systemd-escape https://archive.raspberrypi.org/debian).timer | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
REPOSITORY="$1" | ||
REPOSITORY="${REPOSITORY:-https://archive.raspberrypi.org/debian}" | ||
RELEASE="${RELEASE:-bookworm}" | ||
ARCH="${ARCH:-arm64}" | ||
|
||
# Should be set by systemd | ||
SERVICE_NAME="fetch-repo-package-list@https:--archive.raspberrypi.org-debian.service" | ||
CACHE_DIRECTORY="${CACHE_DIRECTORY:=/var/cache/${SERVICE_NAME}}" | ||
RUNTUME_DIRECTORY="${RUNTIME_DIRECTORY:=/run/${SERVICE_NAME}}" | ||
|
||
PGZ="Packages.gz" | ||
PACKAGES_GZ_FILE="${CACHE_DIRECTORY}/${PGZ}" | ||
PACKAGES_GZ_ETAG_FILE="${CACHE_DIRECTORY}/${PGZ}.etag" | ||
PACKAGES_GZ_URL="${REPOSITORY}/dists/${RELEASE}/main/binary-${ARCH}/${PGZ}" | ||
|
||
>&2 echo "Downloading latest package information for ${RELEASE}:${ARCH} from ${REPOSITORY}" | ||
curl \ | ||
--etag-compare ${PACKAGES_GZ_ETAG_FILE} \ | ||
--etag-save ${PACKAGES_GZ_ETAG_FILE} \ | ||
${PACKAGES_GZ_URL} \ | ||
-o ${PACKAGES_GZ_FILE} \ | ||
2> /dev/null | ||
|
||
PACKAGES_GZ_ETAG="$(< ${PACKAGES_GZ_ETAG_FILE})" | ||
PACKAGES_GZ_ETAG="${PACKAGES_GZ_ETAG%\"}" | ||
PACKAGES_GZ_ETAG="${PACKAGES_GZ_ETAG#\"}" | ||
|
||
# Extract the downloaded file, use the etag as a suffix to create a unique file | ||
PACKAGES_FILE="${CACHE_DIRECTORY}/Packages_${PACKAGES_GZ_ETAG}" | ||
if [ ! -f ${PACKAGES_FILE} ] | ||
then | ||
gunzip --to-stdout ${PACKAGES_GZ_FILE} > ${PACKAGES_FILE} | ||
fi | ||
|
||
>&2 echo "Copying Packages to runtime directory" | ||
cp --update "${PACKAGES_FILE}" "${RUNTIME_DIRECTORY}/Packages" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[Unit] | ||
Description=Downloads latest packages from repo | ||
Wants=fetch-repo-package-list@%i.timer | ||
|
||
[Service] | ||
Type=oneshot | ||
EnvironmentFile=/etc/rpi-sb-provisioner/config | ||
ExecStart=/usr/local/bin/fetch-repo-package-list "%I" | ||
#ConfigurationDirectory=rpi-sb-provisioner | ||
CacheDirectory=%n | ||
RuntimeDirectory=%n | ||
RuntimeDirectoryPreserve=true | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[Unit] | ||
Description=Regularly run the package downloader | ||
|
||
[Timer] | ||
OnCalendar=daily | ||
RandomizedDelaySec=6hours | ||
FixedRandomDelay=true | ||
Persistent=true | ||
|
||
[Install] | ||
WantedBy=timers.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,9 @@ depends: | |
- rpi-eeprom | ||
- rpiboot | ||
- coreutils | ||
- curl | ||
- bash | ||
- gzip | ||
|
||
# Recommended packages. (overridable) | ||
# This will expand any env var you set in the field, e.g. ${RECOMMENDS_BLA} | ||
|
@@ -207,6 +210,15 @@ contents: | |
- src: key-writer/keywriter.sh | ||
dst: /usr/local/bin/keywriter.sh | ||
|
||
- src: fetch-repo-package-list/fetch-repo-package-list.timer | ||
dst: /usr/local/lib/systemd/system/[email protected] | ||
|
||
- src: fetch-repo-package-list/fetch-repo-package-list.service | ||
dst: /usr/local/lib/systemd/system/[email protected] | ||
|
||
- src: fetch-repo-package-list/fetch-repo-package-list | ||
dst: /usr/local/bin/fetch-repo-package-list | ||
|
||
# This will add all files in some/directory or in subdirectories at the | ||
# same level under the directory /etc. This means the tree structure in | ||
# some/directory will not be replicated. | ||
|