Skip to content

Common.sh functions

Guy Sheffer edited this page Oct 26, 2024 · 2 revisions

CustomPiOS comes with a set of common functions that you can use to do common things in an image

gitclone

call like this: gitclone OCTOPI_OCTOPRINT_REPO someDirectory -- this will do:

 sudo -u "${BASE_USER}" git clone -b $OCTOPI_OCTOPRINT_REPO_BRANCH --depth $OCTOPI_OCTOPRINT_REPO_DEPTH $OCTOPI_OCTOPRINT_REPO_BUILD someDirectory

and if $OCTOPI_OCTOPRINT_REPO_BUILD != $OCTOPI_OCTOPRINT_REPO_SHIP also:

 pushd someDirectory
   sudo -u "${BASE_USER}" git remote set-url origin $OCTOPI_OCTOPRINT_REPO_SHIP
 popd

if second parameter is not provided last URL segment of the BUILD repo URL minus the optional .git postfix will be used

unpack

call like this:

unpack /path/to/source /target user

this will copy all files & folders from source to target, preserving mode and timestamps and chown to user. If user is not provided, no chown will be performed


## is_installed
checks if a package is installed, returns 1 if installed and 0 if not.
usage:

is_installed <package_name>

systemctl_if_exists

checks if a systemctl exists

custompios_export

Export files in the image to an archive in the workspace folder Usage:

custompios_export [archive name] [files]

copy_and_export

Will copy like cp, and then save it for export Usage:

copy_and_export tar_file_name source(s) destination

copy_and_export_folder

Will copy a folder, and then save it for export, similar to copy_and_export Usage:

copy_and_export_folder tar_file_name source destination

set_config_var

Set a value for a specific variable in /boot/config.txt See https://github.com/RPi-Distro/raspi-config/blob/master/raspi-config#L231

apt_update_skip

Let you update apt-get update only of the cache is older than an hour. To save time updating only once in a build