Alpine helpers
The reduced helper set Alpine install scripts get from lib/alpine.func, and how it differs from the Debian library.
Source: lib/alpine.func.
Alpine has no apt, dpkg or systemd, so most of the regular library cannot run
there. lib/alpine.func reimplements a small subset under the same names, using
apk. It is not part of lib/API.txt.
When it is loaded
| Script | Loaded by | Library |
|---|---|---|
install/alpine-*-install.sh | update_os in lxc/install.func, when the OS family is alpine | lib/alpine.func only |
ct/alpine-*.sh (update_script) | start | lib/tools.func with all its parts, as on Debian |
This split matters:
- In an install script only the functions on this page exist. There is no
setup_deb822_repo,curl_with_retry,curl_download,create_backup,setup_nodejsand so on. Install packages withapk add. - In
update_scriptthe full library is available, and the functions that share a name with this page are the regular ones documented under forge and system. That is whyct/alpine-wakapi.shcan callcreate_backupandrestore_backup. Helpers that need apt or systemd still do not work on Alpine;ensure_dependenciesandis_package_installeddo, they useapkthere.
If msg_info, msg_ok, msg_warn or msg_error are not defined when the file
is loaded, it defines plain echo versions of them.
A CI workflow in core
(alpine-parity.yml)
warns on a pull request that changes a function in the regular library which
lib/alpine.func also defines, without touching lib/alpine.func.
Releases from GitHub
fetch_and_deploy_gh_release
Download a GitHub release and put it in place, then write ~/.<app>.
fetch_and_deploy_gh_release <app> <owner/repo> [mode] [version] [target] [asset_pattern]| Argument / variable | Default | Meaning |
|---|---|---|
app | required | Stamp name (lower case, spaces removed), default target, file name in singlefile mode |
repo | required | GitHub repository |
mode | tarball | tarball (alias source), binary, prebuild or singlefile |
version | latest | latest or an exact tag |
target | /opt/<app> | Target directory, created if missing |
asset_pattern | empty | Glob for the asset. Required for prebuild and singlefile; binary defaults to *.apk |
CLEAN_INSTALL, CLEAN_INSTALL_KEEP | off | Empty the target first, keeping the listed paths. tarball and prebuild only |
USE_ORIGINAL_FILENAME | false | true keeps the asset's file name in singlefile mode |
GITHUB_TOKEN | unset | Sent to the GitHub API |
| Mode | Behaviour on Alpine |
|---|---|
tarball | Source archive extracted, content of its top-level directory copied into target |
binary | An .apk asset, installed with apk add --allow-untrusted. Any other file type is an error |
prebuild | .zip, .tar.gz, .tgz, .tar.xz, .tar.zst or .tar.bz2 extracted into target; a single top-level directory is stripped |
singlefile | Saved as <target>/<app> and made executable |
Returns 0 on success and 1 for every failure. It installs curl, jq and tar
if missing and calls ensure_usr_local_bin_persist at the end.
What differs from the regular function:
- GitHub only; there is no GitLab or Codeberg variant.
- No seventh argument (tag prefix), no pre-release support, no
var_appversion. - It always downloads and deploys. There is no "already installed" shortcut and
no
.pendingmarker. - If the release has no matching asset it fails; older releases are not searched.
- The asset pattern is turned into a regular expression and matched against the whole download URL, and the first match wins.
- No
.debhandling and no 7z archives. - Every failure returns 1 instead of a specific code.
From install/alpine-wakapi-install.sh:
fetch_and_deploy_gh_release "wakapi" "muety/wakapi" "prebuild" "latest" "/opt/wakapi" "wakapi_linux_$(arch_resolve).zip"fetch_and_deploy_gh
Alias that passes all arguments to fetch_and_deploy_gh_release. No script in
ProxmoxVE uses it.
check_for_gh_release
Compare the release GitHub marks as latest with ~/.<app>.
check_for_gh_release <app> <owner/repo> [pinned_version]| Return | Meaning |
|---|---|
| 0 | Update available, CHECK_UPDATE_RELEASE holds the version without a leading v |
| 1 | Up to date, held by the pin, or any error (DNS, API, no tag) |
With a pin: returns 1 when the pin equals the upstream latest or the installed
version, otherwise 0 with CHECK_UPDATE_RELEASE set to the pin.
Differences from the regular function: three arguments only (no pin reason, no tag
prefix), no pre-releases, a stripped instead of a raw tag in
CHECK_UPDATE_RELEASE, and errors are not distinguishable from "no update".
Because update_script runs with the regular library, the Alpine ct scripts
reach the regular check_for_gh_release. This version is only in effect while an
install script runs; no install script in ProxmoxVE calls it.
get_latest_github_release
Print the tag of the latest GitHub release.
get_latest_github_release <owner/repo> [strip_v]strip_v defaults to true. Returns 0, 22 when the API call failed, 250 when no
version could be read. Used by setup_uv.
github_api_call
GET a GitHub API URL with up to three attempts.
github_api_call <url> [output_file]output_file defaults to /dev/stdout; GITHUB_TOKEN is sent when set. Returns
0 on HTTP 200, otherwise 22. A 401 or 404 fails at once; a 403 and other errors
are retried after 2 s and 4 s. Unlike the regular function it never asks for a
token and has no fallback to github.com.
extract_version_from_json
Print one field of a JSON document.
extract_version_from_json <json> [field] [strip_v]field defaults to tag_name, strip_v to true. Returns 250 when the field is
empty or jq could not be installed.
Packages and downloads
need_tool
Install commands with apk when at least one of them is missing.
need_tool <name> [name ...]Each name is checked as a command. If any is missing, all names are passed to
apk add --no-cache, so a name has to be both the command and the package name.
Returns 0 on success, 1 when apk add failed.
ensure_dependencies
Same as need_tool; it exists so code written for the regular library works.
ensure_dependencies <name> [name ...]download_file
Download a URL to a file with retries.
download_file <url> <output> [max_retries] [show_progress]max_retries defaults to 3 (2 s apart), show_progress to false. Returns 0
on success, 250 after the last failed attempt, as in the regular library.
download_with_progress
Download a URL to a file, with a pv progress bar when the size is known.
download_with_progress <url> <output>Installs curl and pv if needed. Returns 0 on success, 1 on failure (the
regular function returns 7).
net_resolves
Test whether a host name is reachable or resolvable, using ping and nslookup.
net_resolves <host>Returns 0 when either succeeds.
has, lower
Two small utilities used throughout the file.
has <command> # returns 0 when the command exists
lower <string> # prints the string in lower caseSystem information
get_os_info, get_os_version_major, is_alpine
Read /etc/os-release.
get_os_info [id|codename|version|version_id|version_full|all]
get_os_version_major
is_alpineget_os_info prints the same fields as the regular function, all by default.
get_os_version_major prints the version up to the first dot. is_alpine returns
0 when the id is alpine.
get_system_arch
Print amd64 or arm64 from uname -m (other values are printed unchanged).
get_system_arch [mode]The argument is accepted for compatibility and ignored: Alpine has no dpkg.
version_gt
Test whether the first version is greater than the second.
version_gt <a> <b>Compares dot-separated parts numerically with awk. Returns 0 when a is
greater, 1 when equal or smaller.
cache_installed_version, get_cached_version
Store and read a version in /var/cache/app-versions/<name>_version.txt.
cache_installed_version <name> <version>
get_cached_version <name>get_cached_version prints the value and returns 0, or returns 1 when nothing is
stored.
create_temp_dir
Create a temporary directory, print its path and register it for removal on exit.
create_temp_dirThe first call sets an EXIT trap in the shell that runs the function. Captured
with $(create_temp_dir) that shell is the command substitution, as described for
the regular function.
ensure_usr_local_bin_persist
Make sure /usr/local/bin is in PATH for later logins.
ensure_usr_local_bin_persistWrites /etc/profile.d/10-localbin.sh and appends an export line to
/root/.profile and /root/.bashrc when those files exist and lack one.
Runtimes
These share their names with helpers in runtimes but are separate, smaller implementations. All return 0 on success and 1 on failure. No install script in ProxmoxVE calls them at the moment.
setup_yq
Install or update yq.
setup_yq| Variable | Default | Meaning |
|---|---|---|
FORCE_GH | 0 | 1 always downloads the binary from GitHub |
If the yq package is already installed through apk (and FORCE_GH is not 1)
it is upgraded with apk. Otherwise the latest mikefarah/yq binary for amd64 or
arm64 is installed as /usr/local/bin/yq.
setup_adminer
Download the latest adminer.php to /var/www/localhost/htdocs/adminer/index.php.
setup_adminerNo web server is installed or configured.
setup_uv
Install or update uv (musl build) as /usr/local/bin/uv.
setup_uv| Variable | Default | Meaning |
|---|---|---|
UV_VERSION | latest release | Version to install |
PYTHON_VERSION | unset | A version such as 3.12; the newest matching Python is installed with uv python install |
Does nothing when the requested version is already installed.
setup_java
Install OpenJDK from the Alpine repositories.
setup_java| Variable | Default | Meaning |
|---|---|---|
JAVA_VERSION | 21 | 17 installs openjdk17-jdk; any other value installs openjdk21-jdk |
Writes /etc/profile.d/20-java.sh, which sets JAVA_HOME and adds it to PATH.
setup_go
Install Go.
setup_go| Variable | Default | Meaning |
|---|---|---|
GO_VERSION | unset | Unset installs the go package with apk. A version installs the official tarball to /usr/local/go; major.minor (e.g. 1.22) is resolved to its latest patch release |
With a tarball install, go and gofmt are linked into /usr/local/bin.
setup_composer
Install or update Composer as /usr/local/bin/composer.
setup_composerIf no php command exists it installs php83-cli, php83-openssl, php83-phar
and php83-iconv, falling back to the unversioned php-* packages.
Internal functions
| Function | Role |
|---|---|
_cs_clean_target_dir | Empties the target directory for CLEAN_INSTALL, sparing mount points and CLEAN_INSTALL_KEEP paths |
_alpine_cleanup_temp_dirs | Exit trap behind create_temp_dir |
get_url | Defined inside fetch_and_deploy_gh_release; picks the asset URL for a pattern |