From 25ced537c155505b7e5d5cd7678572af7362ca55 Mon Sep 17 00:00:00 2001 From: Luca Di Maio Date: Thu, 2 May 2024 09:07:01 +0200 Subject: [PATCH] all: update formatting style Signed-off-by: Luca Di Maio --- distrobox | 3 ++- distrobox-assemble | 12 ++++++++---- distrobox-create | 16 +++++++++++----- distrobox-enter | 13 +++++++++---- distrobox-ephemeral | 13 +++++++++---- distrobox-export | 18 ++++++++++++------ distrobox-generate-entry | 7 +++++-- distrobox-host-exec | 3 ++- distrobox-init | 20 ++++++++++++++------ distrobox-list | 7 +++++-- distrobox-rm | 13 +++++++++---- distrobox-stop | 7 +++++-- distrobox-upgrade | 7 +++++-- install | 7 +++++-- uninstall | 3 ++- 15 files changed, 103 insertions(+), 46 deletions(-) diff --git a/distrobox b/distrobox index 59ce9dc..9025929 100755 --- a/distrobox +++ b/distrobox @@ -33,7 +33,8 @@ version="1.7.2.0" # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF distrobox version: ${version} diff --git a/distrobox-assemble b/distrobox-assemble index 7d36c21..2550a10 100755 --- a/distrobox-assemble +++ b/distrobox-assemble @@ -113,7 +113,8 @@ done # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF distrobox version: ${version} @@ -245,7 +246,8 @@ fi # None # Outputs: # execution of the proper distrobox-create command. -run_distrobox() { +run_distrobox() +{ name="${1}" # Skip item if --name used and no match is found @@ -456,7 +458,8 @@ run_distrobox() { # None # Outputs: # a value string sanitized -sanitize_variable() { +sanitize_variable() +{ variable="${1}" # If there are spaces but no quotes, let's add them @@ -479,7 +482,8 @@ sanitize_variable() { # None # Outputs: # None -parse_file() { +parse_file() +{ file="${1}" name="" diff --git a/distrobox-create b/distrobox-create index 48bae3f..33dc3f2 100755 --- a/distrobox-create +++ b/distrobox-create @@ -41,7 +41,9 @@ # containers. # # SUDO_USER is a variable set by SUDO and can be used to check whether the script was called by it. Same thing for DOAS_USER, set by DOAS. -if { [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ]; } && [ "$(id -ru)" -eq 0 ]; then +if { + [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ] +} && [ "$(id -ru)" -eq 0 ]; then printf >&2 "Running %s via SUDO/DOAS is not supported. Instead, please try running:\n" "$(basename "${0}")" printf >&2 " %s --root %s\n" "$(basename "${0}")" "$*" exit 1 @@ -164,7 +166,8 @@ fi # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF distrobox version: ${version} @@ -241,7 +244,8 @@ EOF # None # Outputs: # print usage with examples. -show_compatibility() { +show_compatibility() +{ if [ ! -e "${app_cache_dir}/distrobox-compatibility-${version}" ] || [ ! -s "${app_cache_dir}/distrobox-compatibility-${version}" ]; then mkdir -p "${app_cache_dir}" @@ -573,7 +577,8 @@ fi # None # Outputs: # prints the image name of the newly cloned container -get_clone_image() { +get_clone_image() +{ # We need to clone a container. # to do this we will commit the container and create a new tag. Then use it # as image for the new container. @@ -639,7 +644,8 @@ get_clone_image() { # None # Outputs: # prints the podman, docker or lilipod command to create the distrobox container -generate_create_command() { +generate_create_command() +{ # Set the container hostname the same as the container name. result_command="${container_manager} create" # use the host's namespace for ipc, network, pid, ulimit diff --git a/distrobox-enter b/distrobox-enter index 3cd3b38..e7a0427 100755 --- a/distrobox-enter +++ b/distrobox-enter @@ -55,7 +55,8 @@ trap cleanup TERM INT HUP EXIT # None # Outputs: # None -cleanup() { +cleanup() +{ rm -f "${app_cache_dir}/.${container_name}.fifo" if [ -n "${logs_pid:-}" ]; then kill "${logs_pid:-}" 2> /dev/null || : @@ -71,7 +72,9 @@ cleanup() { # containers. # # SUDO_USER is a variable set by SUDO and can be used to check whether the script was called by it. Same thing for DOAS_USER, set by DOAS. -if { [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ]; } && [ "$(id -ru)" -eq 0 ]; then +if { + [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ] +} && [ "$(id -ru)" -eq 0 ]; then printf >&2 "Running %s via SUDO/DOAS is not supported. Instead, please try running:\n" "$(basename "${0}")" printf >&2 " %s --root %s\n" "$(basename "${0}")" "$*" exit 1 @@ -161,7 +164,8 @@ fi # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF distrobox version: ${version} @@ -365,7 +369,8 @@ fi # XDG_CONFIG_DIRS # Outputs: # prints the podman, docker or lilipod command to enter the distrobox container -generate_enter_command() { +generate_enter_command() +{ result_command="${container_manager} exec" result_command="${result_command} --interactive" diff --git a/distrobox-ephemeral b/distrobox-ephemeral index 8ef9d0e..e5f15dc 100755 --- a/distrobox-ephemeral +++ b/distrobox-ephemeral @@ -31,7 +31,9 @@ # containers. # # SUDO_USER is a variable set by SUDO and can be used to check whether the script was called by it. Same thing for DOAS_USER, set by DOAS. -if { [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ]; } && [ "$(id -ru)" -eq 0 ]; then +if { + [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ] +} && [ "$(id -ru)" -eq 0 ]; then printf >&2 "Running %s via SUDO/DOAS is not supported. Instead, please try running:\n" "$(basename "${0}")" printf >&2 " %s --root %s\n" "$(basename "${0}")" "$*" exit 1 @@ -95,7 +97,8 @@ done # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF distrobox version: ${version} @@ -218,7 +221,8 @@ fi # None # Outputs: # prints the distrobox-create command handling special flags -generate_ephemeral_create_command() { +generate_ephemeral_create_command() +{ result_command="${distrobox_path}/distrobox-create" if [ -n "${container_manager_additional_flags}" ]; then result_command="${result_command} \ @@ -254,7 +258,8 @@ generate_ephemeral_create_command() { # None # Outputs: # None -cleanup() { +cleanup() +{ trap - TERM INT HUP # shellcheck disable=SC2086 "${distrobox_path}"/distrobox-rm ${extra_flags} --force "${name}" --yes diff --git a/distrobox-export b/distrobox-export index b698a12..73e3ab9 100755 --- a/distrobox-export +++ b/distrobox-export @@ -72,7 +72,8 @@ done # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF distrobox version: ${version} @@ -330,7 +331,8 @@ fi # None # Outputs: # print generated script. -generate_script() { +generate_script() +{ cat << EOF #!/bin/sh # distrobox_binary @@ -363,7 +365,8 @@ EOF # Outputs: # a generated_script in dest_path # or error code. -export_binary() { +export_binary() +{ # Ensure the binary we're exporting is installed if [ ! -f "${exported_bin}" ]; then printf >&2 "Error: cannot find %s.\n" "${exported_bin}" @@ -431,7 +434,8 @@ export_binary() { # needed icons in /run/host/$host_home/.local/share/icons # needed desktop files in /run/host/$host_home/.local/share/applications # or error code. -export_application() { +export_application() +{ canon_dirs="" IFS=":" @@ -622,7 +626,8 @@ export_application() { # Outputs: # a list of exported apps # or error code. -list_exported_applications() { +list_exported_applications() +{ # In this phase we search for applications exported. # First find command will grep through all files in the canonical directories # and only list files that contain the $DISTROBOX_ENTER_PATH. @@ -659,7 +664,8 @@ list_exported_applications() { # Outputs: # a list of exported apps # or error code. -list_exported_binaries() { +list_exported_binaries() +{ # In this phase we search for binaries exported. # First find command will grep through all files in the canonical directories # and only list files that contain the comment "# distrobox_binary". diff --git a/distrobox-generate-entry b/distrobox-generate-entry index 3111df0..2b98d3b 100755 --- a/distrobox-generate-entry +++ b/distrobox-generate-entry @@ -29,7 +29,9 @@ # containers. # # SUDO_USER is a variable set by SUDO and can be used to check whether the script was called by it. Same thing for DOAS_USER, set by DOAS. -if { [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ]; } && [ "$(id -ru)" -eq 0 ]; then +if { + [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ] +} && [ "$(id -ru)" -eq 0 ]; then printf >&2 "Running %s via SUDO/DOAS is not supported. Instead, please try running:\n" "$(basename "${0}")" printf >&2 " %s --root %s\n" "$(basename "${0}")" "$*" exit 1 @@ -90,7 +92,8 @@ done # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF distrobox version: ${version} diff --git a/distrobox-host-exec b/distrobox-host-exec index 41206c6..d9f1cd1 100755 --- a/distrobox-host-exec +++ b/distrobox-host-exec @@ -42,7 +42,8 @@ version="1.7.2.0" # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF distrobox version: ${version} diff --git a/distrobox-init b/distrobox-init index 93e6e40..0f1183b 100755 --- a/distrobox-init +++ b/distrobox-init @@ -60,7 +60,8 @@ version="1.7.2.0" # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF distrobox version: ${version} @@ -221,7 +222,8 @@ fi # None # Outputs: # Comma-separated list of locked mount flags -get_locked_mount_flags() { +get_locked_mount_flags() +{ src="$1" prev="" locked_flags="" @@ -267,7 +269,8 @@ get_locked_mount_flags() { # None # Outputs: # original path the link is pointing -init_readlink() { +init_readlink() +{ # shellcheck disable=SC2010 ls -l "${1}" | grep -Eo '\->.*' | cut -d' ' -f2- | sed 's|\.\./|/|g' } @@ -284,7 +287,8 @@ init_readlink() { # Outputs: # No output if all ok # Error if not -mount_bind() { +mount_bind() +{ source_dir="$1" target_dir="$2" mount_flags="" @@ -412,7 +416,9 @@ PATH="${PATH}:/bin:/sbin:/usr/bin:/usr/sbin" # Check if dependencies are met for the script to run. if [ "${upgrade}" -ne 0 ] || [ "${missing_packages}" -ne 0 ] || - { [ -n "${container_additional_packages}" ] && [ ! -e /.containersetupdone ]; }; then + { + [ -n "${container_additional_packages}" ] && [ ! -e /.containersetupdone ] + }; then # Detect the available package manager # install minimal dependencies needed to bootstrap the container: @@ -1694,7 +1700,9 @@ if [ -d "/usr/lib/rpm/macros.d/" ] && [ "${init}" -eq 0 ]; then EOF fi -if { [ -d "/etc/dpkg/dpkg.cfg.d/" ] || [ -d "/usr/share/libalpm/scripts" ]; } && [ "${init}" -eq 0 ]; then +if { + [ -d "/etc/dpkg/dpkg.cfg.d/" ] || [ -d "/usr/share/libalpm/scripts" ] +} && [ "${init}" -eq 0 ]; then printf "distrobox: Setting up package manager hooks...\n" cat << EOF > /etc/distrobox-pre-hook.sh #!/bin/sh diff --git a/distrobox-list b/distrobox-list index 6fe9d97..557fe23 100755 --- a/distrobox-list +++ b/distrobox-list @@ -30,7 +30,9 @@ # containers. # # SUDO_USER is a variable set by SUDO and can be used to check whether the script was called by it. Same thing for DOAS_USER, set by DOAS. -if { [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ]; } && [ "$(id -ru)" -eq 0 ]; then +if { + [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ] +} && [ "$(id -ru)" -eq 0 ]; then printf >&2 "Running %s via SUDO/DOAS is not supported. Instead, please try running:\n" "$(basename "${0}")" printf >&2 " %s --root %s\n" "$(basename "${0}")" "$*" exit 1 @@ -97,7 +99,8 @@ fi # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF distrobox version: ${version} diff --git a/distrobox-rm b/distrobox-rm index 01f370b..fb70994 100755 --- a/distrobox-rm +++ b/distrobox-rm @@ -33,7 +33,9 @@ # containers. # # SUDO_USER is a variable set by SUDO and can be used to check whether the script was called by it. Same thing for DOAS_USER, set by DOAS. -if { [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ]; } && [ "$(id -ru)" -eq 0 ]; then +if { + [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ] +} && [ "$(id -ru)" -eq 0 ]; then printf >&2 "Running %s via SUDO/DOAS is not supported. Instead, please try running:\n" "$(basename "${0}")" printf >&2 " %s --root %s\n" "$(basename "${0}")" "$*" exit 1 @@ -116,7 +118,8 @@ container_name_list="" # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF distrobox version: ${version} @@ -291,7 +294,8 @@ fi # None # Outputs: # None -cleanup_exports() { +cleanup_exports() +{ container_name="$1" IFS='ยค' printf "Removing exported binaries...\n" @@ -334,7 +338,8 @@ cleanup_exports() { # None # Outputs: # None -delete_container() { +delete_container() +{ container_name="$1" # Inspect the container we're working with. container_status="$(${container_manager} inspect --type container \ diff --git a/distrobox-stop b/distrobox-stop index 6faef99..74a904e 100755 --- a/distrobox-stop +++ b/distrobox-stop @@ -32,7 +32,9 @@ # containers. # # SUDO_USER is a variable set by SUDO and can be used to check whether the script was called by it. Same thing for DOAS_USER, set by DOAS. -if { [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ]; } && [ "$(id -ru)" -eq 0 ]; then +if { + [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ] +} && [ "$(id -ru)" -eq 0 ]; then printf >&2 "Running %s via SUDO/DOAS is not supported. Instead, please try running:\n" "$(basename "${0}")" printf >&2 " %s --root %s\n" "$(basename "${0}")" "$*" exit 1 @@ -111,7 +113,8 @@ fi # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF distrobox version: ${version} diff --git a/distrobox-upgrade b/distrobox-upgrade index bf07369..16489f1 100755 --- a/distrobox-upgrade +++ b/distrobox-upgrade @@ -24,7 +24,9 @@ # containers. # # SUDO_USER is a variable set by SUDO and can be used to check whether the script was called by it. Same thing for DOAS_USER, set by DOAS. -if { [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ]; } && [ "$(id -ru)" -eq 0 ]; then +if { + [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ] +} && [ "$(id -ru)" -eq 0 ]; then printf >&2 "Running %s via SUDO/DOAS is not supported. Instead, please try running:\n" "$(basename "${0}")" printf >&2 " %s --root %s\n" "$(basename "${0}")" "$*" exit 1 @@ -94,7 +96,8 @@ container_name="" # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF distrobox version: ${version} diff --git a/install b/install index 23f02bb..4914cf0 100755 --- a/install +++ b/install @@ -28,7 +28,8 @@ version=1.7.2.0 # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF install --prefix /usr/local @@ -132,7 +133,9 @@ if [ -e "${curr_dir}/distrobox-enter" ]; then else printf >&2 "\033[1;31m Checking dependencies...\n\033[0m" # check that we have base dependencies - if ! { command -v curl > /dev/null || command -v wget > /dev/null; } || ! command -v tar > /dev/null; then + if ! { + command -v curl > /dev/null || command -v wget > /dev/null + } || ! command -v tar > /dev/null; then printf >&2 "Online install depends on tar and either curl or wget\n" printf >&2 "Ensure you have all dependencies installed.\n" exit 1 diff --git a/uninstall b/uninstall index 359758f..fece786 100755 --- a/uninstall +++ b/uninstall @@ -26,7 +26,8 @@ verbose=0 # None # Outputs: # print usage with examples. -show_help() { +show_help() +{ cat << EOF uninstall --prefix /usr/local