From 7c31836d40923003a28985ad87eb3b7540effe08 Mon Sep 17 00:00:00 2001 From: 89luca89 Date: Sun, 12 Dec 2021 01:59:31 +0100 Subject: [PATCH] init/export: check if we're in a container earlier --- distrobox-export | 13 +++++++------ distrobox-init | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/distrobox-export b/distrobox-export index a3aad93ca1..969ccc790f 100755 --- a/distrobox-export +++ b/distrobox-export @@ -169,6 +169,13 @@ while :; do break ;; esac done + +# Also check we're running inside a container and not on the host +if [ ! -f /run/.containerenv ]; then + printf >&2 "You must run %s inside a container!\n" " $(basename "$0")" + exit 126 +fi + # Ensure the foundamental variables are set and not empty, we will not proceed if # they are not all set. if [ -z "${exported_app}" ] && @@ -190,12 +197,6 @@ if [ -n "${exported_bin}" ] && [ -z "${dest_path}" ]; then exit 2 fi -# Also check we're running inside a container and not on the host -if [ ! -f /run/.containerenv ]; then - printf >&2 "You must run %s inside a container...\n" " $(basename "$0")" - exit 126 -fi - set -o errexit set -o nounset # set verbosity diff --git a/distrobox-init b/distrobox-init index 065a29126f..c5c69c4ccf 100755 --- a/distrobox-init +++ b/distrobox-init @@ -93,6 +93,13 @@ while :; do esac done +# Also check we're running inside a container and not on the host +if [ ! -f /run/.containerenv ]; then + printf >&2 "You must run %s inside a container!\n" " $(basename "$0")" + printf >&2 "distrobox-init should only be used as an entrypoint for a distrobox!\n" + exit 126 +fi + # Ensure the foundamental variables are set and not empty, we will not proceed if # they are not all set. [ -z "${container_user_name}" ] && printf >&2 "Invalid arguments, missing username\n" && exit 2 @@ -100,12 +107,6 @@ done [ -z "${container_user_gid}" ] && printf >&2 "Invalid arguments, missing user gud\n" && exit 2 [ -z "${container_user_home}" ] && printf >&2 "Invalid argument, missing user home\n" && exit 2 -# Also check we're running inside a container and not on the host -if [ ! -f /run/.containerenv ]; then - printf >&2 "You must run %s inside a container...\n" " $(basename "$0")" - exit 126 -fi - set -o errexit set -o nounset # set verbosity