Skip to content

Commit 8ec1c71

Browse files
committed
2 parents 73fd8ab + a083c23 commit 8ec1c71

File tree

7 files changed

+388
-0
lines changed

7 files changed

+388
-0
lines changed

podman-install/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Podman Install
2+
3+
## Features
4+
5+
* Automatically install podman from https://unifi.boostchicken.io
6+
* Persists through firmware updates
7+
8+
## Requirements
9+
10+
1. You have successfully set up the on boot script described
11+
[here](https://github.com/unifi-utilities/unifios-utilities/tree/main/on-boot-script)
12+
2. [Optional] [`25-add-cron-jobs.sh`](https://github.com/unifi-utilities/unifios-utilities/blob/main/on-boot-script/examples/udm-files/on_boot.d/25-add-cron-jobs.sh)
13+
14+
## Installation
15+
16+
1. Copy `on_boot.d/00-podman.sh` to `/data/on_boot.d`
17+
2. Copy the contents of `conf` to `/data/podman/conf`
18+
19+
## Customization
20+
21+
Optional: automatic updates
22+
23+
* Copy `cronjobs/update-podman` to `/data/cronjobs`
24+
* Re-run `/data/on_boot.d/25-add-cron-jobs.sh`
25+
26+
The script can be run manually. Normally, it will refuse to overwrite an existing podman install. If you've installed podman manually, or if you are using UDM 1.x firmware (which includes podman), then the script will do nothing.
27+
28+
If you run `/data/on_boot.d/00-podman.sh --force`, then podman will be reinstalled, even if it aready exists.
29+
30+
Normally, the script will reuse previously-downloaded zip files. This should cause the previously-installed version to be reinstalled automatically after a firmware upgrade.
31+
32+
If you run `/data/on_boot.d/00-podman.sh --download-only`, then the latest zip file will be downloaded from [https://unifi.boostchicken.io/](https://unifi.boostchicken.io/), but not installed.
33+
34+
You can combine the two args to forcefully upgrade to the latest version:
35+
36+
```bash
37+
/data/on_boot.d/00-podman.sh --download-only && /data/on_boot.d/00-podman.sh --force
38+
```
39+
40+
### Why not `podman-update`?
41+
42+
https://github.com/unifi-utilities/unifios-utilities/issues/288#issuecomment-992404375
43+

podman-install/conf/libpod.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
max_log_size = 104857600

podman-install/conf/policy.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"default": [
3+
{ "type": "insecureAcceptAnything" }
4+
],
5+
"transports": {
6+
"docker-daemon": {
7+
"": [{"type":"insecureAcceptAnything"}]
8+
}
9+
}
10+
}
11+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
unqualified-search-registries = ['docker.io']

podman-install/conf/storage.conf

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
# This file is is the configuration file for all tools
2+
# that use the containers/storage library. The storage.conf file
3+
# overrides all other storage.conf files. Container engines using the
4+
# container/storage library do not inherit fields from other storage.conf
5+
# files.
6+
#
7+
# Note: The storage.conf file overrides other storage.conf files based on this precedence:
8+
# /usr/containers/storage.conf
9+
# /etc/containers/storage.conf
10+
# $HOME/.config/containers/storage.conf
11+
# $XDG_CONFIG_HOME/containers/storage.conf (If XDG_CONFIG_HOME is set)
12+
# See man 5 containers-storage.conf for more information
13+
# The "container storage" table contains all of the server options.
14+
[storage]
15+
16+
# Default Storage Driver, Must be set for proper operation.
17+
driver = "vfs"
18+
19+
# Temporary storage location
20+
runroot = "/run/containers/storage"
21+
22+
# Primary Read/Write location of container storage
23+
# When changing the graphroot location on an SELINUX system, you must
24+
# ensure the labeling matches the default locations labels with the
25+
# following commands:
26+
# semanage fcontext -a -e /var/lib/containers/storage /NEWSTORAGEPATH
27+
# restorecon -R -v /NEWSTORAGEPATH
28+
graphroot = "/var/lib/containers/storage"
29+
30+
31+
# Storage path for rootless users
32+
#
33+
# rootless_storage_path = "$HOME/.local/share/containers/storage"
34+
35+
[storage.options]
36+
# Storage options to be passed to underlying storage drivers
37+
38+
# AdditionalImageStores is used to pass paths to additional Read/Only image stores
39+
# Must be comma separated list.
40+
additionalimagestores = [
41+
]
42+
43+
# Remap-UIDs/GIDs is the mapping from UIDs/GIDs as they should appear inside of
44+
# a container, to the UIDs/GIDs as they should appear outside of the container,
45+
# and the length of the range of UIDs/GIDs. Additional mapped sets can be
46+
# listed and will be heeded by libraries, but there are limits to the number of
47+
# mappings which the kernel will allow when you later attempt to run a
48+
# container.
49+
#
50+
# remap-uids = 0:1668442479:65536
51+
# remap-gids = 0:1668442479:65536
52+
53+
# Remap-User/Group is a user name which can be used to look up one or more UID/GID
54+
# ranges in the /etc/subuid or /etc/subgid file. Mappings are set up starting
55+
# with an in-container ID of 0 and then a host-level ID taken from the lowest
56+
# range that matches the specified name, and using the length of that range.
57+
# Additional ranges are then assigned, using the ranges which specify the
58+
# lowest host-level IDs first, to the lowest not-yet-mapped in-container ID,
59+
# until all of the entries have been used for maps.
60+
#
61+
# remap-user = "containers"
62+
# remap-group = "containers"
63+
64+
# Root-auto-userns-user is a user name which can be used to look up one or more UID/GID
65+
# ranges in the /etc/subuid and /etc/subgid file. These ranges will be partitioned
66+
# to containers configured to create automatically a user namespace. Containers
67+
# configured to automatically create a user namespace can still overlap with containers
68+
# having an explicit mapping set.
69+
# This setting is ignored when running as rootless.
70+
# root-auto-userns-user = "storage"
71+
#
72+
# Auto-userns-min-size is the minimum size for a user namespace created automatically.
73+
# auto-userns-min-size=1024
74+
#
75+
# Auto-userns-max-size is the minimum size for a user namespace created automatically.
76+
# auto-userns-max-size=65536
77+
78+
[storage.options.overlay]
79+
# ignore_chown_errors can be set to allow a non privileged user running with
80+
# a single UID within a user namespace to run containers. The user can pull
81+
# and use any image even those with multiple uids. Note multiple UIDs will be
82+
# squashed down to the default uid in the container. These images will have no
83+
# separation between the users in the container. Only supported for the overlay
84+
# and vfs drivers.
85+
#ignore_chown_errors = "false"
86+
87+
# Inodes is used to set a maximum inodes of the container image.
88+
# inodes = ""
89+
90+
# Path to an helper program to use for mounting the file system instead of mounting it
91+
# directly.
92+
#mount_program = "/usr/bin/fuse-overlayfs"
93+
94+
# mountopt specifies comma separated list of extra mount options
95+
mountopt = "nodev"
96+
97+
# Set to skip a PRIVATE bind mount on the storage home directory.
98+
# skip_mount_home = "false"
99+
100+
# Size is used to set a maximum size of the container image.
101+
# size = ""
102+
103+
# ForceMask specifies the permissions mask that is used for new files and
104+
# directories.
105+
#
106+
# The values "shared" and "private" are accepted.
107+
# Octal permission masks are also accepted.
108+
#
109+
# "": No value specified.
110+
# All files/directories, get set with the permissions identified within the
111+
# image.
112+
# "private": it is equivalent to 0700.
113+
# All files/directories get set with 0700 permissions. The owner has rwx
114+
# access to the files. No other users on the system can access the files.
115+
# This setting could be used with networked based homedirs.
116+
# "shared": it is equivalent to 0755.
117+
# The owner has rwx access to the files and everyone else can read, access
118+
# and execute them. This setting is useful for sharing containers storage
119+
# with other users. For instance have a storage owned by root but shared
120+
# to rootless users as an additional store.
121+
# NOTE: All files within the image are made readable and executable by any
122+
# user on the system. Even /etc/shadow within your image is now readable by
123+
# any user.
124+
#
125+
# OCTAL: Users can experiment with other OCTAL Permissions.
126+
#
127+
# Note: The force_mask Flag is an experimental feature, it could change in the
128+
# future. When "force_mask" is set the original permission mask is stored in
129+
# the "user.containers.override_stat" xattr and the "mount_program" option must
130+
# be specified. Mount programs like "/usr/bin/fuse-overlayfs" present the
131+
# extended attribute permissions to processes within containers rather then the
132+
# "force_mask" permissions.
133+
#
134+
# force_mask = ""
135+
136+
[storage.options.thinpool]
137+
# Storage Options for thinpool
138+
139+
# autoextend_percent determines the amount by which pool needs to be
140+
# grown. This is specified in terms of % of pool size. So a value of 20 means
141+
# that when threshold is hit, pool will be grown by 20% of existing
142+
# pool size.
143+
# autoextend_percent = "20"
144+
145+
# autoextend_threshold determines the pool extension threshold in terms
146+
# of percentage of pool size. For example, if threshold is 60, that means when
147+
# pool is 60% full, threshold has been hit.
148+
# autoextend_threshold = "80"
149+
150+
# basesize specifies the size to use when creating the base device, which
151+
# limits the size of images and containers.
152+
# basesize = "10G"
153+
154+
# blocksize specifies a custom blocksize to use for the thin pool.
155+
# blocksize="64k"
156+
157+
# directlvm_device specifies a custom block storage device to use for the
158+
# thin pool. Required if you setup devicemapper.
159+
# directlvm_device = ""
160+
161+
# directlvm_device_force wipes device even if device already has a filesystem.
162+
# directlvm_device_force = "True"
163+
164+
# fs specifies the filesystem type to use for the base device.
165+
# fs="xfs"
166+
167+
# log_level sets the log level of devicemapper.
168+
# 0: LogLevelSuppress 0 (Default)
169+
# 2: LogLevelFatal
170+
# 3: LogLevelErr
171+
# 4: LogLevelWarn
172+
# 5: LogLevelNotice
173+
# 6: LogLevelInfo
174+
# 7: LogLevelDebug
175+
# log_level = "7"
176+
177+
# min_free_space specifies the min free space percent in a thin pool require for
178+
# new device creation to succeed. Valid values are from 0% - 99%.
179+
# Value 0% disables
180+
# min_free_space = "10%"
181+
182+
# mkfsarg specifies extra mkfs arguments to be used when creating the base
183+
# device.
184+
# mkfsarg = ""
185+
186+
# metadata_size is used to set the `pvcreate --metadatasize` options when
187+
# creating thin devices. Default is 128k
188+
# metadata_size = ""
189+
190+
# Size is used to set a maximum size of the container image.
191+
# size = ""
192+
193+
# use_deferred_removal marks devicemapper block device for deferred removal.
194+
# If the thinpool is in use when the driver attempts to remove it, the driver
195+
# tells the kernel to remove it as soon as possible. Note this does not free
196+
# up the disk space, use deferred deletion to fully remove the thinpool.
197+
# use_deferred_removal = "True"
198+
199+
# use_deferred_deletion marks thinpool device for deferred deletion.
200+
# If the device is busy when the driver attempts to delete it, the driver
201+
# will attempt to delete device every 30 seconds until successful.
202+
# If the program using the driver exits, the driver will continue attempting
203+
# to cleanup the next time the driver is used. Deferred deletion permanently
204+
# deletes the device and all data stored in device will be lost.
205+
# use_deferred_deletion = "True"
206+
207+
# xfs_nospace_max_retries specifies the maximum number of retries XFS should
208+
# attempt to complete IO when ENOSPC (no space) error is returned by
209+
# underlying storage device.
210+
# xfs_nospace_max_retries = "0"
211+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# update and reinstall podman each day
2+
#00 00 * * * root sh -c '/data/on_boot.d/00-podman.sh --download-only && /data/on_boot.d/00-podman.sh --force'
3+
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/sh
2+
3+
if which unifi-os >/dev/null 2>&1; then
4+
echo 'Cowardly refusing to install on UDM 1.x'
5+
exit 1
6+
fi
7+
8+
udm_model() {
9+
case "$(ubnt-device-info model || true)" in
10+
"UniFi Dream Machine SE")
11+
echo "udmse"
12+
;;
13+
"UniFi Dream Machine Pro")
14+
echo "udmpro"
15+
;;
16+
"UniFi Dream Machine")
17+
echo "udm"
18+
;;
19+
"UniFi Dream Router")
20+
echo "udr"
21+
;;
22+
*)
23+
echo "unknown"
24+
;;
25+
esac
26+
}
27+
28+
29+
DESIRED_ZIPFILE='udmse-podman-install.zip'
30+
case "$(udm_model)" in
31+
udmse|udmpro)
32+
DESIRED_ZIPFILE="$(udm_model)-podman-install.zip"
33+
;;
34+
*)
35+
# shrug
36+
# udmse-podman-install.zip seems to work fine on UDM 2.4.x
37+
true
38+
;;
39+
esac
40+
41+
42+
# Get DataDir location
43+
DATA_DIR="/mnt/data"
44+
case "$(ubnt-device-info firmware || true)" in
45+
1*)
46+
DATA_DIR="/mnt/data"
47+
;;
48+
2*)
49+
DATA_DIR="/data"
50+
;;
51+
3*)
52+
DATA_DIR="/data"
53+
;;
54+
*)
55+
echo "ERROR: No persistent storage found." 1>&2
56+
exit 1
57+
;;
58+
esac
59+
60+
61+
CACHE_DIR="${DATA_DIR}/podman/cache"
62+
INSTALL_ROOT="${DATA_DIR}/podman/install"
63+
CONF_DIR="${DATA_DIR}/podman/conf"
64+
65+
mkdir -p "${CACHE_DIR}" "${INSTALL_ROOT}" "${CONF_DIR}"
66+
67+
URL="https://unifi.boostchicken.io/${DESIRED_ZIPFILE}"
68+
69+
if [ "$1" = '--download-only' ]; then
70+
echo "downloading ${URL}" \
71+
&& curl -Lsfo "${CACHE_DIR}/${DESIRED_ZIPFILE}" "${URL}" \
72+
&& echo "downloaded ${URL}"
73+
exit $?
74+
fi
75+
76+
if podman version >/dev/null 2>&1; then
77+
if [ "$1" = '--force' ]; then
78+
echo 'overwriting existing podman install (--force)'
79+
else
80+
echo 'podman is already installed; skipping'
81+
exit 0
82+
fi
83+
fi
84+
85+
if [ -f "${CACHE_DIR}/${DESIRED_ZIPFILE}" ]; then
86+
echo "(using cache at ${CACHE_DIR}/${DESIRED_ZIPFILE})"
87+
elif echo "downloading ${URL}" \
88+
&& curl -Lsfo "${CACHE_DIR}/${DESIRED_ZIPFILE}" "${URL}"; then
89+
echo "downloaded ${URL}"
90+
else
91+
echo 'download failed'
92+
exit 1
93+
fi
94+
95+
unzip -o "${CACHE_DIR}/${DESIRED_ZIPFILE}" -d "${CACHE_DIR}" >/dev/null
96+
unzip -o "${CACHE_DIR}/podman-install.zip" -d "${INSTALL_ROOT}" >/dev/null
97+
rm -f "${CACHE_DIR}/podman-install.zip"
98+
99+
for SOURCE in $(find "${INSTALL_ROOT}" -not -type d); do
100+
TARGET="$(expr "${SOURCE}" : "${INSTALL_ROOT}\(.*\)")"
101+
mkdir -p "$(dirname "${TARGET}")"
102+
ln -sf "${SOURCE}" "${TARGET}"
103+
done
104+
105+
# fix missing config files
106+
for CONFIG in $(cd "${CONF_DIR}" && echo *); do
107+
[ -e "${CONF_DIR}/${CONFIG}" ] || continue
108+
ln -sf "${CONF_DIR}/${CONFIG}" "/etc/containers/${CONFIG}"
109+
done
110+
111+
if podman version >/dev/null 2>&1; then
112+
echo "podman $(podman version -f '{{.Client.Version}}') was installed successfully"
113+
exit 0
114+
fi
115+
116+
echo 'Something went wrong'
117+
exit 1
118+

0 commit comments

Comments
 (0)