Skip to main content
Community Scripts logo
Function reference

core.func

Reference for the messaging, execution, prompt and check functions every script gets from core/core.func.

core/core.func is the part of the engine that runs everywhere: on the host while a container is created, inside the container while the application is installed, during update, and in the standalone add-on and tool scripts. It holds colours, message output, the $STD wrapper, prompts, host checks and a few maintenance helpers.

How it is loaded

You rarely source it yourself:

ContextWho loads it
ct/*.sh on a Proxmox VE hostcore/build.func → ui/build-ui.func, which then calls load_functions and catch_errors
ct/*.sh on an Incus hostincus/core.func loads it and replaces several functions with Incus variants
install/*-install.sh in the containerlxc/install.func (the text in FUNCTIONS_FILE_PATH) during its bootstrap
tools/addon/*.shThe script sources it by URL, then calls load_functions

VM scripts do not load core/core.func; pve/vm-core.func carries its own copies of the message helpers.

The file guards itself with _CORE_FUNC_LOADED, exports COMPOSER_ALLOW_SUPERUSER=1, sets HOME when it is empty, and installs two default traps at the end: HUP → on_hup_keepalive and EXIT INT TERM → stop_spinner. catch_errors replaces them.

load_functions

load_functions

Runs color, formatting, icons, default_vars and set_std_mode once (guarded by __FUNCTIONS_LOADED). Add-on scripts call it directly, for example tools/addon/add-tailscale-lxc.sh:

source <(curl -fsSL "${COMMUNITY_SCRIPTS_CORE_URL:-https://raw.githubusercontent.com/community-scripts/core/main}/core/core.func")
# ...
load_functions

Colours, formatting and icons

These functions only set variables. Use the variables inside echo -e.

FunctionVariables
colorYW yellow, YWB bright yellow, BL cyan, RD bold red, GN bold green, DGN green, BGN underlined green, CL reset
color_spinnerCS_YW, CS_YWB, CS_CL (used by the spinner only)
formattingBFR (carriage return + clear line), BOLD, HOLD (one space), TAB (two spaces), TAB3 (six spaces)
iconsCM check mark, CROSS, INFO, HOURGLASS, DNSOK, DNSFAIL, OVERRIDE, OS, OSVERSION, CONTAINERTYPE, DISKSIZE, CPUCORE, RAMSIZE, SEARCH, VERBOSE_CROPPED, VERIFYPW, CONTAINERID, HOSTNAME, BRIDGE, NETWORK, GATEWAY, ICON_DISABLEIPV6, DEFAULT, MACADDRESS, VLANTAG, ROOTSSH, CREATING, ADVANCED, FUSE, GPU
default_varsRETRY_NUM=10, RETRY_EVERY=3, i=$RETRY_NUM

When dev_mode is set to anything, color turns GN, DGN and BGN red, so a dev run cannot be mistaken for a normal install.

The closing lines of ct/vaultwarden.sh show the usual use:

echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
echo -e "${INFO}${YW}Access it using the following URL:${CL}"
echo -e "${GATEWAY}${BGN}https://${IP}:8000${CL}"

Messages

FunctionArgumentsOutputLog line
msg_infomessagespinner + message on stdout, or a static line on stderr[INFO] message
msg_okmessagecheck mark + green message on stdout[OK] message
msg_errormessagecross + red message on stderr[ERROR] message
msg_warnmessagebulb + bright-yellow message on stderr[WARN] message
msg_customsymbol, colour, messagesymbol + coloured message on stdoutmessage
msg_debugtexttimestamped [DEBUG] line, only with var_full_verbose=1none
msg_devtext[DEV] line, only when dev_mode is setnone

Every log line is written by log_msg to the active log file with a timestamp and without colour codes.

msg_info

msg_info "Installing Dependencies"

Opens a step. It stops any running spinner, starts a new one in the background and returns immediately. The message is also recorded as the current step (CS_STEP), which the error handler and telemetry use to say where a run failed.

  • The spinner is replaced by a static hourglass line when verbose mode is on, when the OS is Alpine, or when stderr is not a terminal (see is_verbose_mode).
  • A message that is already open is not printed a second time.
  • An empty message does nothing.
  • With dev_mode=pause it waits for Enter after printing.

msg_ok

msg_ok "Installed Dependencies"

Closes a step: stops the spinner, clears the line and prints the message with a check mark. If an outer step is still open (a helper such as setup_nodejs opened and closed its own step inside yours), its spinner resumes.

Always pair the two, as in install/vaultwarden-install.sh:

msg_info "Installing Dependencies"
$STD apt install -y \
  build-essential \
  pkgconf \
  libssl-dev \
  libmariadb-dev-compat \
  libpq-dev \
  argon2 \
  ssl-cert
msg_ok "Installed Dependencies"

msg_error

msg_error "No ${APP} Installation Found!"

Prints the error and logs it. It does not exit; follow it with exit or return yourself, as ct/vaultwarden.sh does:

if [[ ! -f /etc/systemd/system/vaultwarden.service ]]; then
  msg_error "No ${APP} Installation Found!"
  exit
fi

The first msg_error of a step is kept in CS_ERROR_MSG and sent with the failure report.

msg_warn

msg_warn "Old Installation Found, you need to migrate your data and recreate to a new container"

A non-fatal notice (example from ct/actualbudget.sh). Like msg_error, it stops the spinner and does not resume it.

msg_custom

msg_custom "<symbol>" "<colour>" "<message>"
ArgumentDefaultMeaning
symbol[*]Any text or emoji shown in the icon column
colour\e[36mAn escape sequence, usually one of the color variables
messagenoneNothing is printed when it is empty

From ct/ampache.sh:

msg_custom "⚠️" "${YW}" "Complete database update by visiting: http://${LOCAL_IP}/update.php"

msg_debug

msg_debug "Using release $victoriametrics_release"

Prints only when var_full_verbose=1, and in that case also sets var_verbose=1. Example from ct/victoriametrics.sh.

msg_dev

msg_dev "Keep mode active - container ${CTID} preserved"

Prints only when dev_mode is non-empty. Used by the backends, not by application scripts.

fatal

fatal "<message>"

Calls msg_error and then sends SIGINT to the script (kill -INT $$), so the run ends through the interrupt handler with exit code 130. network_check in lxc/install.func uses it when GitHub host names do not resolve. No application script calls it directly.

exit_script

exit_script

Clears the screen, prints User exited script and exits. The engine's whiptail menus call it when you press Cancel.

$STD, silent and verbose mode

$STD is the prefix you put in front of commands whose output should not clutter the screen:

$STD apt install -y nginx

set_std_mode always sets STD="silent", so the line above runs silent apt install -y nginx.

silent

silent <command> [arguments...]
  • Appends the command's stdout and stderr to the active log file.
  • With VERBOSE=yes the output is shown on screen as well and still logged.
  • External programs run with SIGHUP ignored and, when stdin is a terminal, with stdin from /dev/null. Closing the console does not kill a running apt or npm. Shell functions run in the current shell so their side effects are kept.
  • apt is called with -o Apt::Cmd::Disable-Script-Warning=true.
  • On failure it returns the command's exit status and writes <logfile>.errinfo with the exit code, line, command, calling function, current step and the output of that one command. The error handler reads this file to show what the failing command printed.
  • On success it removes the .errinfo file.

silent does not exit by itself. The non-zero return triggers the ERR trap that catch_errors installed; append || true when a failure is acceptable.

$STD applies to one simple command. In $STD a | b only a is wrapped.

Verbose mode

VariableSet byEffect
VERBOSE=yesthe VERBOSE MODE question in Advanced Install, var_verbose=yes, the verbose update option, or a retry from the recovery menusilent shows command output live
var_verboseyou, on the command line or in a defaults filemapped to VERBOSE by the wizard
var_full_verbose=1youenables msg_debug

is_verbose_mode returns true when VERBOSE (or, if unset, var_verbose) is anything other than no, and also when stderr is not a terminal and CS_ANIMATION_OK is not 1. msg_info uses it to choose between the spinner and a static line.

set_std_mode also turns on set -x when DEV_MODE_TRACE=true.

Log files

get_active_logfile prints the file silent and the msg_* functions write to. The first variable that is set wins:

OrderVariableTypical value
1_HOST_LOGFILEthe host build log, set by the backend so host messages stay there
2INSTALL_LOG/root/.install-<SESSION_ID>.log inside the container
3BUILD_LOG/tmp/create-lxc-<SESSION_ID>.log on the host
4_CS_RUN_LOG/tmp/build-<date>_<time>.log, for tools without a build log
FunctionUse
log_msg "<text>"Append a timestamped line without colour codes to the active log
log_section "<name>"Append a banner with the section name
strip_ansi [text]Remove colour codes from the arguments, or from stdin when called without arguments

Spinner

spinner, stop_spinner and clear_line are used by the message functions. Call stop_spinner only if you print to the terminal yourself between msg_info and msg_ok. The spinner's PID is kept in SPINNER_PID and /tmp/.spinner.pid.

Prompts

All prompt functions answer on their own when nobody can: in unattended runs they return the default at once, and interactive prompts fall back to the default after a timeout.

is_unattended

Returns 0 (unattended) when:

  • MODE (or mode) is default, mydefaults, userdefaults or appdefaults (or 1, 3, 4);
  • MODE is advanced (or 2) and pveversion is not available, which is the case inside a container;
  • PHS_SILENT=1, or var_unattended / UNATTENDED is yes, true or 1;
  • stdin is not a terminal.

The backend exports MODE into the container, and the install script runs through lxc-attach without a terminal on stdin. In practice an install script therefore always takes the default. Read a var_* variable first and prompt only when it is empty.

prompt_confirm

prompt_confirm "<message>" [default] [timeout]
ArgumentDefaultMeaning
messageConfirm?Question text
defaultny or n; anything else counts as n
timeout60Seconds before the default is taken

Returns 0 for yes and 1 for no. An empty or invalid answer uses the default. From install/shlink-install.sh:

if prompt_confirm "Install Shlink Web Client?" "y" 60; then
  msg_info "Installing Dependencies"
  $STD apt install -y nginx
  msg_ok "Installed Dependencies"
  # ...
fi

prompt_input

value=$(prompt_input "<message>" [default] [timeout])

Prints the answer, or the default when the answer is empty, the timeout (default 60 seconds) passes, the run is unattended or stdin is not a terminal. The prompt itself goes to stderr, so command substitution captures only the value. From install/espocrm-install.sh:

if [[ -z "${var_admin_user:-}" ]]; then
  var_admin_user=$(prompt_input "EspoCRM admin username (a-z, 0-9, @ . _ -):" "admin" 60)
fi

prompt_input_required

value=$(prompt_input_required "<message>" [fallback] [timeout] [variable-name])
ArgumentDefaultMeaning
messageEnter required value:Question text
fallbackCHANGE_MEValue used when nobody answers
timeout120Seconds
variable-namenoneName of a variable to read first; if it is set, its value is returned without asking

Interactive runs get three attempts at a non-empty answer. Whenever the fallback is used, the variable name is added to the MISSING_REQUIRED_VALUES array. No script in ProxmoxVE uses it at the moment; the example is the one in the function's own header:

token=$(prompt_input_required "Enter API Token:" "YOUR_TOKEN_HERE" 60 "var_api_token")

show_missing_values_warning

show_missing_values_warning

Prints a box listing everything in MISSING_REQUIRED_VALUES and returns 1; returns 0 and prints nothing when the array is empty. Because it returns 1, call it as show_missing_values_warning || true under catch_errors.

prompt_select

choice=$(prompt_select "<message>" <default-number> <timeout> "<option 1>" "<option 2>" ...)

Shows a numbered list on stderr and prints the chosen option text. The default number is 1-based. The default option is returned in unattended runs, when /dev/tty is not readable, on timeout and on invalid input. Returns 1 when no options are given. All three leading arguments must be present because the function shifts them away. Example from the function's header (no script in ProxmoxVE uses it at the moment):

choice=$(prompt_select "Select database:" 1 30 "PostgreSQL" "MySQL" "SQLite")

prompt_password

password=$(prompt_password "<message>" [default] [timeout] [min-length])

Reads without echo. Pass generate as the default to get a random 16-character alphanumeric password when nobody types one. An answer shorter than min-length is replaced by the default. From install/foldingathome-install.sh:

if [[ -z "${var_fah_token:-}" ]]; then
  var_fah_token=$(prompt_password "Folding@home account token (Enter to skip):" "" 120)
fi

random_password

random_password [length]

Prints an alphanumeric (A-Za-z0-9) string from /dev/urandom, 24 characters by default. From install/adventurelog-install.sh:

SECRET_KEY="$(random_password 32)"

confirm_external_installer

confirm_external_installer "<source>" "<installer>"

Warns that code from a third party is about to run and asks Do you want to continue? [y/N].

  • var_external_installer answers the question without a prompt: y, yes or true continue, any other value declines.
  • Declining, or having no terminal to answer on, exits with code 254.

From install/bunkerweb-install.sh:

confirm_external_installer "install-bunkerweb.sh" "https://github.com/bunkerity/bunkerweb/raw/v${RELEASE}/misc/install-bunkerweb.sh"

Unattended:

var_external_installer=yes mode=default bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/ct/bunkerweb.sh)"

header_info

header_info

Clears the screen (only when stdout is a terminal and TERM is not dumb) and prints the ASCII banner for APP. Arguments are ignored; the name comes from APP, lower-cased with spaces removed. If no banner exists, a generic Community Scripts banner and the app name are printed.

get_header finds the banner in this order, for <type>/<name> and then <type>/<platform>/<name> (APP_TYPE defaults to ct; platform is pve or incus):

  1. headers/ in a local engine directory (COMMUNITY_SCRIPTS_CORE_DIR),
  2. the cache in /usr/local/community-scripts/headers/ (or the directory community_scripts_dir returns),
  3. ${COMMUNITY_SCRIPTS_CORE_URL}/headers/, saved to the cache.

Every ct script calls it, for example ct/vaultwarden.sh:

header_info "$APP"
variables
color
catch_errors

See Headers for how banners are generated.

Host and environment checks

FunctionPasses whenOtherwise
shell_checkthe shell is Bashexit 103
root_checkUID is 0 and the parent process is not sudoexit 104
on_pve_hostpveversion existsreturns 1, never exits
require_pve_hoston a Proxmox VE host and pve_check passesexit 232
confirm_not_pve_hostnot on a Proxmox VE host, or you answer yexit 0
require_debian_likenot Alpine and apt-get existsexit 238
pve_checkProxmox VE 8.0–8.9 or 9.0–9.2 with a healthy /etc/pveexit 232, 228, 210 or 1
arch_checkamd64, or arm64 with var_arm64 allowing itexit 106
ssh_checkalwaysonly warns
is_alpinethe OS is Alpinereturns 1

install_script runs shell_check, root_check, pve_check, ensure_whiptail, arch_check, arm64_notice and ssh_check in that order before the install menu opens.

pve_check

pve_check
  1. Not a Proxmox VE host → error, exit 232.
  2. pmxcfs_check:
    • /etc/pve not mounted → offers to restart pve-cluster (when a terminal and whiptail are available); still not mounted → exit 228.
    • /etc/pve/storage.cfg not readable → exit 228.
    • /etc/pve/corosync.conf exists and pvecm status does not report Quorate: Yes → exit 210.
  3. Version outside 8.0–8.9 and 9.0–9.2 → error naming the supported range, exit 1.

Exit code 105 ("Proxmox VE version not supported") is used by the VM path in pve/vm-core.func, not by pve_check. On Incus, incus/build.func replaces pve_check with its own check.

arch_check and var_arm64

arch_check

Accepts amd64 and arm64 hosts and exits 106 on anything else. On arm64 the script's var_arm64 decides:

var_arm64Behaviour on an arm64 host
yescontinues silently
noThis script does not support arm64., exit 106
unset or anything elsewarns that the script is unverified on arm64 and asks Continue anyway? (y/N); without a terminal it exits 106

Scripts declare it at the top, as ct/vaultwarden.sh does:

var_arm64="${var_arm64:-yes}"

arch_resolve

arch_resolve [amd64-value] [arm64-value]

Prints the first value on amd64 and the second on arm64. Without arguments it prints amd64 or arm64. The architecture comes from PCT_ARCH when set, otherwise from dpkg --print-architecture (or uname -m). On any other architecture it prints an error and returns 106.

From ct/agentdvr.sh, where upstream names its builds differently:

RELEASE=$(curl -fsSL "https://www.ispyconnect.com/api/Agent/DownloadLocation4?platform=$(arch_resolve "Linux64" "LinuxARM64")&fromVersion=0" | grep -o 'https://.*\.zip')

And without arguments in ct/victoriametrics.sh:

victoriametrics_filename="victoria-metrics-linux-$(arch_resolve)-${victoriametrics_release}.tar.gz"

require_pve_host, confirm_not_pve_host, require_debian_like

Guards for add-on scripts. A script that drives the node itself starts like tools/addon/add-tailscale-lxc.sh:

header_info
require_pve_host

A script meant to run inside a guest starts like tools/addon/coder-code-server.sh:

confirm_not_pve_host
require_debian_like

confirm_not_pve_host asks Continue anyway? (y/N) on a Proxmox VE host and exits 0 unless you answer y or yes.

Other checks

FunctionWhat it does
arm64_noticeOn arm64, shows a whiptail box saying ARM64 support is in active development
ssh_checkWarns when SSH_CLIENT is an address outside the host's own /24 network
ensure_whiptailInstalls whiptail with apt when it is missing; exit 100 if that fails
ensure_tputInstalls ncurses (Alpine) or ncurses-bin (apt) when tput is missing
reclaim_ttyTakes the terminal's foreground process group back after lxc-attach; call it right before reading from /dev/tty on the host

OS dispatch

run_os_setup and run_os_update

run_os_setup    # install script
run_os_update   # update_script in the ct script

Detect the OS family of the running system and call the matching function that your script defined:

FamilyDetected byrun_os_setup callsrun_os_update calls
debianID/ID_LIKE contains debian or ubuntusetup_deb_basedupdate_deb_based
alpine/etc/alpine-releasesetup_alpineupdate_alpine
rhelrhel, fedora, centossetup_rhel_basedupdate_rhel_based
susesusesetup_suse_basedupdate_suse_based
archarchsetup_arch_basedupdate_arch_based
gentoogentoosetup_gentoo_basedupdate_gentoo_based

If the function for the detected family is not defined, an error says so and the call returns 1. Define the functions before calling the dispatcher. ct/vaultwarden.sh:

function update_script() {
  header_info
  check_container_storage
  check_container_resources
  run_os_update
}

The dispatch looks at the running system, never at var_os.

Inside the container

get_lxc_ip

get_lxc_ip

Sets and exports LOCAL_IP. It sources /run/local-ip.env if present; if LOCAL_IP is still empty it looks at eth0, then hostname -I, then the routing table, IPv4 first and IPv6 after. Returns 1 with an error when nothing is found. The container bootstrap and the update path call it, so LOCAL_IP is already set in install scripts and in update_script. Add-ons call it themselves, as tools/addon/coder-code-server.sh:

get_lxc_ip
IP="$LOCAL_IP"

cleanup_lxc

cleanup_lxc

The last line of every install script. It:

  • cleans the package manager: apk cache clean; dnf autoremove and dnf clean all; zypper clean; pacman -Sc; or apt autoremove and apt clean;
  • deletes files named tmp* and tempfile* in /tmp and /var/tmp;
  • removes the caches of the tools that are installed: pip, uv, npm, yarn, pnpm (pnpm store prune), Go build cache, Cargo registry cache, gem, Composer;
  • prints Cleaned and sends a telemetry progress ping when POST_TO_API_DONE is set in that shell.

Failures in the cleanup are warnings and never fail the run. On updates it is called for you from the exit handler after update_script ends with status 0.

motd_ssh
customize
cleanup_lxc

motd_ssh and customize

These two are called next to cleanup_lxc but are defined in lxc/install.func, not in core/core.func. Neither takes arguments.

FunctionWhat it does
motd_sshWrites the login banner (/etc/profile.d/00_lxc-details.sh and /etc/motd), adds terminal setup to root's .bashrc and .bash_profile, and, when SSH_ROOT=yes, installs the SSH server if needed and sets PermitRootLogin yes
customizeWhen no root password was chosen: deletes the root password and configures console autologin. Always: writes /usr/bin/update through write_update_entrypoint, and stores SSH_AUTHORIZED_KEY in /root/.ssh/authorized_keys when one was given

See Containers for the rest of the in-container bootstrap.

apt helpers

FunctionWhat it does
apt_update_safeRuns apt-get update up to three times (waiting 5 and 10 seconds between attempts). After the third failure it warns and continues; it always returns 0. Hints at the Proxmox enterprise repository when the log shows a 401 or 403
apt_conffile_guardMakes dpkg keep your version of changed config files (--force-confdef, --force-confold) for the rest of the run, through a temporary APT_CONFIG
apt_conffile_reportLists config files for which a new upstream version was left next to yours, then removes the guard

apt_update_safe in ct/2fauth.sh:

apt_update_safe
$STD apt -y upgrade

The guard and the report are called by the engine (update_os, the update path and the exit handler); scripts do not call them.

Other helpers

FunctionWhat it does
configure_http_proxyWhen HTTP_PROXY, http_proxy or var_http_proxy is set: writes /etc/profile.d/90-http-proxy.sh, appends to /etc/environment, and writes /etc/apt/apt.conf.d/95http-proxy unless APT Cacher-NG is active. Called by update_os
check_or_create_swapReports active swap; otherwise asks whether to create /swapfile and for its size in MB. Returns 1 when declined or failed
ensure_profile_loadedSources /etc/profile.d/*.sh and ~/.profile once and adds /usr/local/bin to PATH. Does nothing on a Proxmox VE host
ensure_recorded_toolchainsRe-runs setup_rust, setup_go, setup_nodejs, setup_uv, setup_composer, setup_yq or setup_ruby when /var/cache/app-versions records the tool but its binary is gone

The update entry point

update inside a container is /usr/bin/update, a small generated script.

write_update_entrypoint

write_update_entrypoint "<slug>" "<script-name>" [scripts-base-url]
ArgumentMeaning
slugWebsite slug, stored as SCRIPT_SLUG
script-nameThe ct/<name>.sh to run, stored as UPDATE_SCRIPT_NAME. Nothing is written when it is empty
scripts-base-urlOverrides COMMUNITY_SCRIPTS_URL

Writes /usr/bin/update through a temporary file and an atomic mv. The generated script exports SCRIPT_SLUG, UPDATE_SCRIPT_NAME, COMMUNITY_SCRIPTS_URL, COMMUNITY_SCRIPTS_CORE_URL and COMMUNITY_SCRIPTS_WEBSITE_URL, then runs misc/update.sh from the engine. If that helper cannot be downloaded it runs ct/<script-name>.sh directly. customize calls it at install time:

write_update_entrypoint "$app" "$update_script_name"

migrate_update_entrypoint

migrate_update_entrypoint

Run at the start of every update. It rewrites /usr/bin/update when the file does not use misc/update.sh yet, still points at git.community-scripts.org, or has no valid UPDATE_SCRIPT_NAME. The script name and base URL are read from the old file so the container keeps updating from the repository it was built from.

When a ct script runs inside a container, start performs these steps before your update_script: ensure_profile_loaded, ensure_recorded_toolchains, get_lxc_ip, migrate_update_entrypoint, the status, OS and breaking-change guards, and apt_conffile_guard. See Updates.

Testing builds

cs_testing_state

cs_testing_state

Sets and exports CS_TESTING and CS_TESTING_URL. A script is a testing build when it declares var_testurl (a plain https:// URL of at most 200 characters; anything else is ignored with a warning) or when REPO_SOURCE is DevScripts. The backend calls it before the install so motd_ssh can show the feedback link.

Internal functions

Names starting with _cs_, _pve or _msg are internal and can change without notice. The ones you may meet when reading the code:

FunctionPurpose
_cs_host_archHost architecture as amd64 or arm64 (the Incus server's when driving a remote)
_cs_clearClear the screen without failing when clear is missing or there is no terminal
_pve_version, _pveam_available, _pveam_updateCached pveversion and pveam available output
_cs_probe_read, _cs_probe_rc, _cs_probe_dropRead the host probes core/build.func started in the background
_cs_shield_hangupRun a program with SIGHUP ignored
_cs_stdin_source/dev/tty, /dev/stdin or failure, for prompts
_cs_os_familyThe family name used by run_os_setup and run_os_update
_cs_live_baseRewrite a retired git.community-scripts.org URL to its GitHub raw URL
on_hup_keepaliveDefault SIGHUP handler before catch_errors: redirects output to the log and lets the run continue